MT#65432 add cf sets subscriber_id support subscriberadmin

* subscriberadmin role can now correctly provide with a subscriber_id
  under which the cf set is created/updated, only ones that belong
  to the same customer are valid. The behaviour remains unchanged
  if the subscriber_id is omitted as the subscriberadmin id is used
  in this case.

Change-Id: I51f0333e51865e91a127338ac5f888eb88d15271
(cherry picked from commit 9470652038)
mr26.0
Kirill Solomko 3 weeks ago
parent a8bf89d60d
commit 3401540d0a

@ -69,15 +69,29 @@ sub create_item {
my $dset;
if($c->user->roles eq "subscriberadmin") {
$resource->{subscriber_id} //= $c->user->voip_subscriber->id;
} elsif($c->user->roles eq "subscriber") {
if ($c->user->roles eq "subscriberadmin") {
$resource->{subscriber_id} ||= $c->user->voip_subscriber->id;
} elsif ($c->user->roles eq "subscriber") {
$resource->{subscriber_id} = $c->user->voip_subscriber->id;
} elsif (!defined $resource->{subscriber_id}) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Missing mandatory field 'subscriber_id'");
return;
}
my $b_subscriber = $schema->resultset('voip_subscribers')->find({
my $b_subscriber;
if ($c->user->roles eq "subscriberadmin") {
my $customer_id = $c->user->account_id;
$b_subscriber = $schema->resultset('voip_subscribers')->search({
id => $resource->{subscriber_id},
contract_id => $customer_id,
})->first;
} else {
$b_subscriber = $schema->resultset('voip_subscribers')->find({
id => $resource->{subscriber_id},
});
}
unless($b_subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'.");
return;

@ -68,15 +68,29 @@ sub create_item {
my $tset;
if($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") {
if ($c->user->roles eq "subscriberadmin") {
$resource->{subscriber_id} ||= $c->user->voip_subscriber->id;
} elsif ($c->user->roles eq "subscriber") {
$resource->{subscriber_id} = $c->user->voip_subscriber->id;
} elsif(!defined $resource->{subscriber_id}) {
} elsif (!defined $resource->{subscriber_id}) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Missing mandatory field 'subscriber_id'");
return;
}
my $b_subscriber = $schema->resultset('voip_subscribers')->find({
my $b_subscriber;
if ($c->user->roles eq "subscriberadmin") {
my $customer_id = $c->user->account_id;
$b_subscriber = $schema->resultset('voip_subscribers')->search({
id => $resource->{subscriber_id},
contract_id => $customer_id,
})->first;
} else {
$b_subscriber = $schema->resultset('voip_subscribers')->find({
id => $resource->{subscriber_id},
});
}
unless($b_subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'.");
return;

@ -23,8 +23,6 @@ sub get_form {
my ($self, $c) = @_;
if($c->user->roles eq "subscriber") {
return NGCP::Panel::Form::get("NGCP::Panel::Form::CallForward::CFBNumberSetSubAPI", $c);
} elsif($c->user->roles eq "subscriberadmin") {
return NGCP::Panel::Form::get("NGCP::Panel::Form::CallForward::CFBNumberSetSubAPI", $c);
} else {
return NGCP::Panel::Form::get("NGCP::Panel::Form::CallForward::CFBNumberSetAPI", $c);
}
@ -97,16 +95,29 @@ sub check_resource {
my $schema = $c->model('DB');
if($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") {
if ($c->user->roles eq "subscriberadmin") {
$resource->{subscriber_id} ||= $c->user->voip_subscriber->id;
} elsif ($c->user->roles eq "subscriber") {
$resource->{subscriber_id} = $c->user->voip_subscriber->id;
} elsif(!defined $resource->{subscriber_id}) {
} elsif (!defined $resource->{subscriber_id}) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Missing mandatory field 'subscriber_id'");
return;
}
my $b_subscriber = $schema->resultset('voip_subscribers')->find({
my $b_subscriber;
if ($c->user->roles eq "subscriberadmin") {
my $customer_id = $c->user->account_id;
$b_subscriber = $schema->resultset('voip_subscribers')->search({
id => $resource->{subscriber_id},
contract_id => $customer_id,
})->first;
} else {
$b_subscriber = $schema->resultset('voip_subscribers')->find({
id => $resource->{subscriber_id},
});
}
unless($b_subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'.");
return;

@ -18,8 +18,6 @@ sub get_form {
my ($self, $c) = @_;
if($c->user->roles eq "subscriber") {
return NGCP::Panel::Form::get("NGCP::Panel::Form::CallForward::CFDestinationSetSubAPI", $c);
} elsif($c->user->roles eq "subscriberadmin") {
return NGCP::Panel::Form::get("NGCP::Panel::Form::CallForward::CFDestinationSetSubAPI", $c);
} else {
return NGCP::Panel::Form::get("NGCP::Panel::Form::CallForward::CFDestinationSetAPI", $c);
}
@ -175,14 +173,10 @@ sub update_item {
resource => $resource,
);
if($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") {
$resource->{subscriber_id} = $c->user->voip_subscriber->id;
}
if (! exists $resource->{destinations} ) {
$resource->{destinations} = [];
}
if(!NGCP::Panel::Utils::CallForwards::check_destinations(
c => $c,
schema => $schema,
@ -195,7 +189,29 @@ sub update_item {
return;
}
my $b_subscriber = $schema->resultset('voip_subscribers')->find($resource->{subscriber_id});
if ($c->user->roles eq "subscriberadmin") {
$resource->{subscriber_id} //= $c->user->voip_subscriber->id;
} elsif ($c->user->roles eq "subscriber") {
$resource->{subscriber_id} = $c->user->voip_subscriber->id;
} elsif (!defined $resource->{subscriber_id}) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Missing mandatory field 'subscriber_id'");
return;
}
my $b_subscriber;
if ($c->user->roles eq "subscriberadmin") {
my $customer_id = $c->user->account_id;
$b_subscriber = $schema->resultset('voip_subscribers')->search({
id => $resource->{subscriber_id},
contract_id => $customer_id,
})->first;
} else {
$b_subscriber = $schema->resultset('voip_subscribers')->find({
id => $resource->{subscriber_id},
});
}
unless ($b_subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'.");
return;

@ -19,8 +19,6 @@ sub get_form {
my ($self, $c) = @_;
if($c->user->roles eq "subscriber") {
return NGCP::Panel::Form::get("NGCP::Panel::Form::CallForward::CFSourceSetSubAPI", $c);
} elsif($c->user->roles eq "subscriberadmin") {
return NGCP::Panel::Form::get("NGCP::Panel::Form::CallForward::CFSourceSetSubAPI", $c);
} else {
return NGCP::Panel::Form::get("NGCP::Panel::Form::CallForward::CFSourceSetAPI", $c);
}
@ -137,40 +135,13 @@ sub update_item {
resource => $resource,
);
if (! exists $resource->{sources} ) {
$resource->{sources} = [];
}
if (ref $resource->{sources} ne "ARRAY") {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid field 'sources'. Must be an array.");
return;
}
if($c->user->roles eq "subscriber" || $c->user->roles eq "subscriberadmin") {
$resource->{subscriber_id} = $c->user->voip_subscriber->id;
}
# elsif($c->user->roles eq "subscriberadmin") {
# $resource->{subscriber_id} //= $c->user->id;
#}
my $b_subscriber = $schema->resultset('voip_subscribers')->find($resource->{subscriber_id});
unless ($b_subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'.");
return;
}
my $subscriber = $b_subscriber->provisioning_voip_subscriber;
unless($subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid subscriber.");
last;
}
#if($c->user->roles eq "subscriberadmin" && $subscriber->account_id != $c->user->account_id) {
# $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid subscriber.");
# last;
#}
return unless $self->process_form_resource($c, $item, $old_resource, $resource, $form);
return unless $self->check_duplicate($c, $item, $old_resource, $resource, $form);
return unless $self->check_resource($c, $item, $old_resource, $resource, $form);
my $b_subscriber = $schema->resultset('voip_subscribers')->find($resource->{subscriber_id});
my $subscriber = $b_subscriber->provisioning_voip_subscriber;
try {
$item->update({
name => $resource->{name},
@ -196,7 +167,9 @@ sub update_item {
sub process_form_resource{
my($self,$c, $item, $old_resource, $resource, $form, $process_extras) = @_;
if($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") {
if ($c->user->roles eq "subscriberadmin") {
$resource->{subscriber_id} ||= $c->user->voip_subscriber->id;
} elsif ($c->user->roles eq "subscriber") {
$resource->{subscriber_id} = $c->user->voip_subscriber->id;
} elsif(!defined $resource->{subscriber_id}) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Missing mandatory field 'subscriber_id'");
@ -211,9 +184,20 @@ sub check_resource {
my $schema = $c->model('DB');
my $b_subscriber = $schema->resultset('voip_subscribers')->find({
id => $resource->{subscriber_id},
});
my $b_subscriber;
if ($c->user->roles eq "subscriberadmin") {
my $customer_id = $c->user->account_id;
$b_subscriber = $schema->resultset('voip_subscribers')->search({
id => $resource->{subscriber_id},
contract_id => $customer_id,
})->first;
} else {
$b_subscriber = $schema->resultset('voip_subscribers')->find({
id => $resource->{subscriber_id},
});
}
unless($b_subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'.");
return;

@ -19,7 +19,7 @@ use NGCP::Panel::Utils::DateTime qw();
sub get_form {
my ($self, $c) = @_;
if($c->user->roles eq "subscriber" || $c->user->roles eq "subscriberadmin") {
if ($c->user->roles eq "subscriber") {
return NGCP::Panel::Form::get("NGCP::Panel::Form::CallForward::CFTimeSetSubAPI", $c);
} else {
return NGCP::Panel::Form::get("NGCP::Panel::Form::CallForward::CFTimeSetAPI", $c);
@ -441,11 +441,29 @@ sub update_item {
return;
}
if($c->user->roles eq "subscriber" || $c->user->roles eq "subscriberadmin") {
if ($c->user->roles eq "subscriberadmin") {
$resource->{subscriber_id} //= $c->user->voip_subscriber->id;
} elsif ($c->user->roles eq "subscriber") {
$resource->{subscriber_id} = $c->user->voip_subscriber->id;
} elsif (!defined $resource->{subscriber_id}) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Missing mandatory field 'subscriber_id'");
return;
}
my $b_subscriber;
if ($c->user->roles eq "subscriberadmin") {
my $customer_id = $c->user->account_id;
$b_subscriber = $schema->resultset('voip_subscribers')->search({
id => $resource->{subscriber_id},
contract_id => $customer_id,
})->first;
} else {
$b_subscriber = $schema->resultset('voip_subscribers')->find({
id => $resource->{subscriber_id},
});
}
my $b_subscriber = $schema->resultset('voip_subscribers')->find($resource->{subscriber_id});
unless ($b_subscriber) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'subscriber_id'.");
return;

Loading…
Cancel
Save