TT#182101 Phonebook feature is hidden for CE

* templates now rely on c.config.general.ngcp_type and hide
  the Phonebook feature everywhere if ngcp_type is CE
* introduce "allowed_ngcp_types" config for Controller::API::*
  that is an array, and when specified, only the ngcp_type
  roles are allowed, otherwise if not specified all ngcp types
  allowed (default)
* Controller::API::Root:
    - filter controllers from the documentation rendedring
      that have allowed_ngcp_type config
      specified and do not match the current ngcp type
* Role::API Role::Entities*
   - new method check_allowed_ngcp_types()
   - check_allowed_ngcp_types() is now called in Entities and
     EntitiesItem auto() and denies to 404 Path not found if
     the ngcp type does not match
* "Phonebook" UI is now hidden for CE
* /api/phonebookentries is now hidden for CE

Change-Id: I41d4b2f87121f281472be3775b862333923fe37f
mr11.0
Kirill Solomko 3 years ago
parent a61497297c
commit 09b589738d

@ -15,6 +15,7 @@ __PACKAGE__->set_config({
},
allowed_roles => [qw/admin reseller subscriberadmin subscriber/],
mandatory_parameters => { 'single' => [qw/reseller_id customer_id subscriber_id/],},
allowed_ngcp_types => [qw/carrier sppro/],
});
sub allowed_methods{

@ -8,6 +8,7 @@ use parent qw/NGCP::Panel::Role::EntitiesItem NGCP::Panel::Role::API::PhonebookE
__PACKAGE__->set_config({
allowed_roles => [qw/admin reseller subscriberadmin subscriber/],
mandatory_parameters => { 'single' => [qw/reseller_id customer_id subscriber_id/],},
allowed_ngcp_types => [qw/carrier sppro/],
});
sub allowed_methods{

@ -101,6 +101,12 @@ sub GET : Allow {
next unless $user_roles{$role};
}
my $allowed_ngcp_types = $full_mod->config->{allowed_ngcp_types} // [];
if (@{$allowed_ngcp_types}) {
next unless grep { /^\Q$c->config->{general}{ngcp_type}\E$/ }
@{$allowed_ngcp_types};
}
my $query_params = [];
if($full_mod->can('query_params')) {
$query_params = $full_mod->query_params;

@ -1574,6 +1574,18 @@ sub post_process_commit{
return;
}
sub check_allowed_ngcp_types {
my ($self, $c) = @_;
my $allowed_ngcp_types = $self->get_config('allowed_ngcp_types') // [];
if (@{$allowed_ngcp_types} &&
!grep { /^\Q$c->config->{general}{ngcp_type}\E$/ }
@{$allowed_ngcp_types}) {
return;
}
return 1;
}
sub validate_request {
my ($self, $c) = @_;
@ -1674,6 +1686,10 @@ sub allowed_methods{
return $_[0]->config->{allowed_methods};
}
sub allowed_ngcp_types {
return $_[0]->config->{allowed_ngcp_types};
}
#------ /accessors ---
sub return_representation{
my($self, $c, %params) = @_;

@ -20,6 +20,10 @@ sub auto :Private {
if ($self->get_config('log_request')) {
$self->log_request($c);
}
if (! $self->check_allowed_ngcp_types($c)) {
$self->error($c, HTTP_NOT_FOUND, "Path not found");
return;
}
return $self->validate_request($c);
}

@ -24,6 +24,10 @@ sub auto :Private {
if ($self->get_config('log_request')) {
$self->log_request($c);
}
if (! $self->check_allowed_ngcp_types($c)) {
$self->error($c, HTTP_NOT_FOUND, "Path not found");
return;
}
return $self->validate_request($c);
}

@ -772,6 +772,7 @@ $(function() {
</div>
[% END -%]
[% IF c.config.general.ngcp_type != 'spce' -%]
[% IF (c.user.roles == "subscriberadmin" && product.class == "pbxaccount") ||
c.user.roles == "admin" || c.user.roles == "reseller" ||
c.user.roles == "ccareadmin" || c.user.roles == "ccare" -%]
@ -817,6 +818,7 @@ $(function() {
</div>
</div>
[% END -%]
[% END -%]
</div>

@ -419,6 +419,7 @@
</div>
</div>
[% IF c.config.general.ngcp_type != 'spce' -%]
[% IF c.user.roles == "admin" || c.user.roles == "reseller" -%]
<div class="accordion-group">
<div class="accordion-heading">
@ -496,6 +497,7 @@
</div>
[% END -%]
[% END -%]
</div>

@ -351,6 +351,7 @@ function process_pbx_items(moveId,direction){
</div>
[% END -%]
[% IF c.config.general.ngcp_type != 'spce' -%]
[% IF (c.user.roles == "subscriberadmin" && product.class == "pbxaccount") ||
c.user.roles == "admin" || c.user.roles == "reseller" || c.user.roles == "ccareadmin" || c.user.roles == "ccare" -%]
<div class="accordion-group">
@ -391,6 +392,7 @@ function process_pbx_items(moveId,direction){
</div>
</div>
[% END -%]
[% END -%]
</div>

@ -93,7 +93,9 @@
[% END -%]
<li><a href="[% c.uri_for('/lnp') %]">[% c.loc('Number Porting') %]</a></li>
<li><a href="[% c.uri_for('/emergencymapping') %]">[% c.loc('Emergency Mappings') %]</a></li>
[% IF c.config.general.ngcp_type != 'spce' -%]
<li><a href="[% c.uri_for('/phonebook') %]">[% c.loc('Phonebook') %]</a></li>
[% END -%]
<li><a href="[% c.uri_for('/timeset') %]">[% c.loc('Time Sets') %]</a></li>
</ul>
</li>

@ -54,7 +54,9 @@
<li><a href="[% c.uri_for('/maliciouscall') %]">[% c.loc('Malicious Calls') %]</a></li>
[% END -%]
<li><a href="[% c.uri_for('/emergencymapping') %]">[% c.loc('Emergency Mappings') %]</a></li>
[% IF c.config.general.ngcp_type != 'spce' -%]
<li><a href="[% c.uri_for('/phonebook') %]">[% c.loc('Phonebook') %]</a></li>
[% END -%]
</ul>
</li>
[% # vim: set tabstop=4 syntax=html expandtab: -%]

Loading…
Cancel
Save