MT#60558 move max license checks for POST /api/subscribers

* the relevant max license checkes are moved from
  Controller::API::Subscribers::POST to
  Utils::Subscribers::prepare_resource because there we fetch
  customer_id from the pilot subscriber in case of pbx subscriberadmin
  requests that is neccessary for PBX subscribers max license check.

Change-Id: I2d1c212d73fe5b9295d1595b4fffebeb67b61e5a
mr13.0
Kirill Solomko 1 year ago
parent 65ae07a97b
commit e2e1776090

@ -378,40 +378,6 @@ sub POST :Allow {
);
last unless $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) {
$self->error($c, HTTP_FORBIDDEN,
"Maximum number of subscribers for this platform is reached",
"Exceeded max number of license subscribers: $license_max_subscribers current: $current_subscribers_count",
);
last;
}
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) {
$self->error($c, 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",
);
last;
}
my $license_max_pbx_groups = $c->license_max_pbx_groups;
my $current_pbx_groups_count = $c->license_current_pbx_groups;
$c->log->debug("Current pbx groups: ". $current_pbx_groups_count);
$c->log->debug("License max pbx groups: ". $license_max_pbx_groups);
if (is_true($resource->{is_pbx_group}) &&
$license_max_pbx_groups >= 0 && $current_pbx_groups_count >= $license_max_pbx_groups) {
$self->error($c, 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",
);
last;
}
my $r = $self->prepare_resource($c, $schema, $resource);
last unless($r);
my $subscriber;

@ -365,8 +365,8 @@ sub prepare_resource {
resource => $resource,
item => $item,
err_code => sub {
my ($code,$msg) = @_;
$self->error($c, $code, $msg);
my ($code, $msg, @errors) = @_;
$self->error($c, $code, $msg, @errors);
},
validate_code => sub {
my ($r) = @_;

@ -367,6 +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;
}
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}($c, 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});
return unless($customer);
if(!$item && defined $customer->max_subscribers && $customer->voip_subscribers->search({

Loading…
Cancel
Save