From e89b61c5190e3e374c2c3bcb3dce444c64c718cf Mon Sep 17 00:00:00 2001 From: Stoiko Ivanov Date: Tue, 2 Feb 2021 14:03:15 +0100 Subject: [PATCH 1/1] api: statistics: add common method for details 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 Signed-off-by: Thomas Lamprecht --- src/PMG/API2/Statistics.pm | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/PMG/API2/Statistics.pm b/src/PMG/API2/Statistics.pm index 72bfeb5..d3ecbf8 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,60 @@ 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: remove for PMG 7.0 - handled by 'details' API call which allows addresses containing '/' __PACKAGE__->register_method ({ name => 'contactdetails', path => 'contact/{contact}', @@ -425,6 +480,7 @@ __PACKAGE__->register_method ({ return $res; }}); +# FIXME: remove for PMG 7.0 - handled by 'details' API call which allows addresses containing '/' __PACKAGE__->register_method ({ name => 'senderdetails', path => 'sender/{sender}', @@ -536,6 +592,7 @@ __PACKAGE__->register_method ({ return $res; }}); +# FIXME: remove for PMG 7.0 - handled by 'details' API call which allows addresses containing '/' __PACKAGE__->register_method ({ name => 'receiverdetails', path => 'receiver/{receiver}', -- 2.39.2