From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api v3 1/2] api: statistics: add common method for details
Date: Tue, 2 Feb 2021 14:03:15 +0100 [thread overview]
Message-ID: <20210202130317.31873-2-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20210202130317.31873-1-s.ivanov@proxmox.com>
This patch changes adds a new method, which yields the detail statistics
for a particular address.
Depending on the provided type argument it returns the same information as
the contact/sender/receiver detail calls.
This allows the statistics to be displayed for addresses containing
'/' in their localpart, once this is permitted in our api schema.
the idea follows a similar change for the user blocklists in
e8d909c11faeb5a4f84f39ef50e0eaf8ea65046d
By adding a new API method we can eventually drop the old methods with 7.0
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
src/PMG/API2/Statistics.pm | 63 ++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/src/PMG/API2/Statistics.pm b/src/PMG/API2/Statistics.pm
index 72bfeb5..7de6d78 100644
--- a/src/PMG/API2/Statistics.pm
+++ b/src/PMG/API2/Statistics.pm
@@ -44,6 +44,7 @@ __PACKAGE__->register_method ({
return [
{ name => "contact" },
+ { name => "detail" },
{ name => "domains" },
{ name => "mail" },
{ name => "mailcount" },
@@ -322,6 +323,62 @@ sub get_detail_statistics {
return $res;
}
+__PACKAGE__->register_method ({
+ name => 'detailstats',
+ path => 'detail',
+ method => 'GET',
+ description => "Detailed Statistics.",
+ permissions => { check => [ 'admin', 'qmanager', 'audit'] },
+ parameters => {
+ additionalProperties => 0,
+ properties => $default_properties->({
+ type => {
+ description => "Type of statistics",
+ type => 'string',
+ enum => [ 'contact', 'sender', 'receiver' ],
+ },
+ address => get_standard_option('pmg-email-address', {
+ description => "Email address.",
+ }),
+ filter => {
+ description => "Address filter.",
+ type => 'string',
+ maxLength => 512,
+ optional => 1,
+ },
+ orderby => $api_properties->{orderby},
+ }),
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => $detail_return_properties->({
+ sender => {
+ description => "Sender email. (for contact and receiver statistics)",
+ type => 'string',
+ optional => 1,
+ },
+ receiver => {
+ description => "Receiver email. (for sender statistics)",
+ type => 'string',
+ optional => 1,
+ },
+ }),
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $type = $param->{type};
+ $param->{$type} = $param->{address};
+
+ return get_detail_statistics($param->{type}, $param);
+ }});
+
+# FIXME: change for PMG 7.0 - remove support for providing addresses as path
+# addresses can contain '/' which breaks API path resolution - hardcode
+# 'detail' for the path pattern.
__PACKAGE__->register_method ({
name => 'contactdetails',
path => 'contact/{contact}',
@@ -425,6 +482,9 @@ __PACKAGE__->register_method ({
return $res;
}});
+# FIXME: change for PMG 7.0 - remove support for providing addresses as path
+# addresses can contain '/' which breaks API path resolution - hardcode
+# 'detail' for the path pattern.
__PACKAGE__->register_method ({
name => 'senderdetails',
path => 'sender/{sender}',
@@ -536,6 +596,9 @@ __PACKAGE__->register_method ({
return $res;
}});
+# FIXME: change for PMG 7.0 - remove support for providing addresses as path
+# addresses can contain '/' which breaks API path resolution - hardcode
+# 'detail' for the path pattern.
__PACKAGE__->register_method ({
name => 'receiverdetails',
path => 'receiver/{receiver}',
--
2.20.1
next prev parent reply other threads:[~2021-02-02 13:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-02 13:03 [pmg-devel] [PATCH pmg-api/pmg-gui v3] allow / in local part of pmg-email-address Stoiko Ivanov
2021-02-02 13:03 ` Stoiko Ivanov [this message]
2021-02-11 9:15 ` [pmg-devel] applied: [PATCH pmg-api v3 1/2] api: statistics: add common method for details Thomas Lamprecht
2021-02-02 13:03 ` [pmg-devel] [PATCH pmg-api v3 2/2] utils: allow '/' inside email address localpart Stoiko Ivanov
2021-02-11 9:15 ` [pmg-devel] applied: " Thomas Lamprecht
2021-02-02 13:03 ` [pmg-devel] [PATCH pmg-gui v3 1/1] statistics: use new api call for detailed stats Stoiko Ivanov
2021-02-19 13:59 ` [pmg-devel] applied: " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210202130317.31873-2-s.ivanov@proxmox.com \
--to=s.ivanov@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox