From e09de1e78147e4b5c61f5f13d852bd33b2739d7b Mon Sep 17 00:00:00 2001 From: Kirill Solomko <ksolomko@sipwise.com> Date: Fri, 30 Aug 2024 12:56:42 +0200 Subject: [PATCH] MT#60558 invoke max subscribers/group license check only on POST * max subscribers/group license check is invoked only on POST to enable clients to modify existing entries even if the threshold is reached. Change-Id: I858b42ada5c95c179f901e43837b15358027011b --- lib/NGCP/Panel/Utils/Subscriber.pm | 58 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/lib/NGCP/Panel/Utils/Subscriber.pm b/lib/NGCP/Panel/Utils/Subscriber.pm index dc51461951..82c3d20df0 100644 --- a/lib/NGCP/Panel/Utils/Subscriber.pm +++ b/lib/NGCP/Panel/Utils/Subscriber.pm @@ -367,36 +367,38 @@ sub prepare_resource { } } - my $license_max_subscribers = $c->license_max_subscribers; - my $current_subscribers_count = $c->license_current_subscribers; - if ($license_max_subscribers >= 0 && $current_subscribers_count >= $license_max_subscribers) { - &{$err_code}(HTTP_FORBIDDEN, - "Maximum number of subscribers for this platform is reached", - "Exceeded max number of license subscribers: $license_max_subscribers current: $current_subscribers_count" - ); - return; - } + if ($c->req->method eq 'POST') { + my $license_max_subscribers = $c->license_max_subscribers; + my $current_subscribers_count = $c->license_current_subscribers; + if ($license_max_subscribers >= 0 && $current_subscribers_count >= $license_max_subscribers) { + &{$err_code}(HTTP_FORBIDDEN, + "Maximum number of subscribers for this platform is reached", + "Exceeded max number of license subscribers: $license_max_subscribers current: $current_subscribers_count" + ); + return; + } - my $license_max_pbx_subscribers = $c->license_max_pbx_subscribers; - my $current_pbx_subscribers_count = $c->license_current_pbx_subscribers; - if ($schema->resultset('contracts')->find($resource->{customer_id})->product->class eq 'pbxaccount' && - $license_max_pbx_subscribers >= 0 && $current_pbx_subscribers_count >= $license_max_pbx_subscribers) { - &{$err_code}(HTTP_FORBIDDEN, - "Maximum number of PBX subscribers for this platform is reached", - "Exceeded max number of license pbx subscribers: $license_max_pbx_subscribers current: $current_pbx_subscribers_count" - ); - return; - } + my $license_max_pbx_subscribers = $c->license_max_pbx_subscribers; + my $current_pbx_subscribers_count = $c->license_current_pbx_subscribers; + if ($schema->resultset('contracts')->find($resource->{customer_id})->product->class eq 'pbxaccount' && + $license_max_pbx_subscribers >= 0 && $current_pbx_subscribers_count >= $license_max_pbx_subscribers) { + &{$err_code}(HTTP_FORBIDDEN, + "Maximum number of PBX subscribers for this platform is reached", + "Exceeded max number of license pbx subscribers: $license_max_pbx_subscribers current: $current_pbx_subscribers_count" + ); + return; + } - my $license_max_pbx_groups = $c->license_max_pbx_groups; - my $current_pbx_groups_count = $c->license_current_pbx_groups; - if (is_true($resource->{is_pbx_group}) && - $license_max_pbx_groups >= 0 && $current_pbx_groups_count >= $license_max_pbx_groups) { - &{$err_code}(HTTP_FORBIDDEN, - "Maximum number of PBX groups for this platform is reached", - "Exceeded max number of license pbx groups: $license_max_pbx_groups current: $current_pbx_groups_count" - ); - return; + my $license_max_pbx_groups = $c->license_max_pbx_groups; + my $current_pbx_groups_count = $c->license_current_pbx_groups; + if (is_true($resource->{is_pbx_group}) && + $license_max_pbx_groups >= 0 && $current_pbx_groups_count >= $license_max_pbx_groups) { + &{$err_code}(HTTP_FORBIDDEN, + "Maximum number of PBX groups for this platform is reached", + "Exceeded max number of license pbx groups: $license_max_pbx_groups current: $current_pbx_groups_count" + ); + return; + } } my $customer = &$getcustomer_code($resource->{customer_id});