* this endpoint is designed to provide with basic subscribers info such as display_name, primary_number, pbx_extension and only available for customers with product class 'pbxaccount'. * only GET methods are allowed for this endpoint. Change-Id: I181b863e2c3e5fad34c03a291f64fd7ddb587702mr13.3
parent
4eace822b5
commit
e66c568efc
@ -0,0 +1,75 @@
|
||||
package NGCP::Panel::Controller::API::PbxUsers;
|
||||
|
||||
use parent qw/NGCP::Panel::Role::Entities NGCP::Panel::Role::API::PbxUsers/;
|
||||
|
||||
use Sipwise::Base;
|
||||
use NGCP::Panel::Utils::Generic qw(:all);
|
||||
use HTTP::Status qw(:constants);
|
||||
|
||||
sub allowed_methods {
|
||||
return [qw/GET OPTIONS HEAD/];
|
||||
}
|
||||
|
||||
sub api_description {
|
||||
return 'Returns subscribers with PBX related info.';
|
||||
};
|
||||
|
||||
__PACKAGE__->set_config({
|
||||
allowed_roles => {
|
||||
Default => [qw/admin reseller ccareadmin ccare subscriberadmin subscriber/],
|
||||
},
|
||||
});
|
||||
|
||||
sub query_params {
|
||||
return [
|
||||
{
|
||||
param => 'primary_number',
|
||||
description => 'Filter for subscribers of contracts with a specific primary number pattern',
|
||||
query => {
|
||||
first => sub {
|
||||
my ($q,$is_pattern) = escape_search_string_pattern(shift,0,1,1);
|
||||
{ \['concat(primary_number.cc, primary_number.ac, primary_number.sn) like ?', $q ] };
|
||||
|
||||
},
|
||||
second => sub {
|
||||
return { join => 'primary_number' }
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
param => 'pbx_extension',
|
||||
description => 'Filter for subscribers of contracts with a specific PBX extension',
|
||||
query => {
|
||||
first => sub {
|
||||
my ($q,$is_pattern) = escape_search_string_pattern(shift,0,1,1);
|
||||
{ 'provisioning_voip_subscriber.pbx_extension' => { like => $q } };
|
||||
|
||||
},
|
||||
second => sub {
|
||||
return { join => 'provisioning_voip_subscriber' }
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
param => 'display_name',
|
||||
description => 'Filter for subscribers of contracts with a specific display name',
|
||||
query => {
|
||||
first => sub {
|
||||
my ($q,$is_pattern) = escape_search_string_pattern(shift);
|
||||
{
|
||||
'attribute.attribute' => 'display_name',
|
||||
'voip_usr_preferences.value' => { like => $q }
|
||||
};
|
||||
|
||||
},
|
||||
second => sub {
|
||||
return { join => { 'provisioning_voip_subscriber' => { 'voip_usr_preferences' => 'attribute' } } }
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# vim: set tabstop=4 expandtab:
|
@ -0,0 +1,21 @@
|
||||
package NGCP::Panel::Controller::API::PbxUsersItem;
|
||||
|
||||
use parent qw/NGCP::Panel::Role::EntitiesItem NGCP::Panel::Role::API::PbxUsers/;
|
||||
|
||||
use Sipwise::Base;
|
||||
use NGCP::Panel::Utils::Generic qw(:all);
|
||||
use HTTP::Status qw(:constants);
|
||||
|
||||
sub allowed_methods{
|
||||
return [qw/GET OPTIONS HEAD/];
|
||||
}
|
||||
|
||||
__PACKAGE__->set_config({
|
||||
allowed_roles => {
|
||||
Default => [qw/admin reseller ccareadmin ccare subscriberadmin subscriber/],
|
||||
},
|
||||
});
|
||||
|
||||
1;
|
||||
|
||||
# vim: set tabstop=4 expandtab:
|
@ -0,0 +1,95 @@
|
||||
package NGCP::Panel::Form::Pbx::UserAPI;
|
||||
|
||||
use HTML::FormHandler::Moose;
|
||||
extends 'HTML::FormHandler';
|
||||
|
||||
use HTML::FormHandler::Widget::Block::Bootstrap;
|
||||
|
||||
has '+widget_wrapper' => ( default => 'Bootstrap' );
|
||||
has_field 'submitid' => ( type => 'Hidden' );
|
||||
sub build_render_list {[qw/submitid fields actions/]}
|
||||
sub build_form_element_class {[qw(form-horizontal)]}
|
||||
|
||||
has_field 'id' => (
|
||||
type => 'Hidden',
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The internal id of the pbx user'],
|
||||
},
|
||||
);
|
||||
|
||||
has_field 'primary_number' => (
|
||||
type => '+NGCP::Panel::Field::E164',
|
||||
order => 99,
|
||||
required => 0,
|
||||
label => 'E164 Number',
|
||||
do_label => 1,
|
||||
do_wrapper => 1,
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The main E.164 number (containing a cc, ac and sn attribute) used for inbound and outbound calls.']
|
||||
},
|
||||
);
|
||||
|
||||
has_field 'display_name' => (
|
||||
type => 'Text',
|
||||
label => 'Display Name',
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The person\'s name, which is then used in XMPP contact lists or auto-provisioned phones, and which can be used as network-provided display name in SIP calls.']
|
||||
},
|
||||
maxlength => 128,
|
||||
);
|
||||
|
||||
has_field 'pbx_extension' => (
|
||||
type => 'Text',
|
||||
label => 'PBX Extension',
|
||||
element_attr => {
|
||||
rel => ['tooltip'],
|
||||
title => ['The PBX extension used for short dialling. If provided, the primary number will automatically be derived from the pilot subscriber\'s primary number suffixed by this extension.']
|
||||
},
|
||||
);
|
||||
|
||||
has_field 'save' => (
|
||||
type => 'Submit',
|
||||
value => 'Save',
|
||||
element_class => [qw/btn btn-primary/],
|
||||
label => '',
|
||||
);
|
||||
|
||||
has_block 'fields' => (
|
||||
tag => 'div',
|
||||
class => [qw/modal-body/],
|
||||
render_list => [qw/id primary_number display_name pbx_extension/],
|
||||
);
|
||||
|
||||
has_block 'actions' => (
|
||||
tag => 'div',
|
||||
class => [qw/modal-footer/],
|
||||
render_list => [qw/save/],
|
||||
);
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
NGCP::Panel::Form::Pbx::UserAPI
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
A helper to manipulate the subscriber forms
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Sipwise Development Team
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
This library is free software. You can redistribute it and/or modify
|
||||
it under the same terms as Perl itself.
|
||||
|
||||
=cut
|
||||
|
||||
# vim: set tabstop=4 expandtab:
|
@ -0,0 +1,100 @@
|
||||
package NGCP::Panel::Role::API::PbxUsers;
|
||||
|
||||
use parent qw/NGCP::Panel::Role::API/;
|
||||
|
||||
use Sipwise::Base;
|
||||
use NGCP::Panel::Utils::Generic qw(:all);
|
||||
use NGCP::Panel::Utils::API;
|
||||
use HTTP::Status qw(:constants);
|
||||
|
||||
sub item_name {
|
||||
return 'pbxuser';
|
||||
}
|
||||
|
||||
sub resource_name {
|
||||
return 'pbxusers';
|
||||
}
|
||||
|
||||
sub dispatch_path {
|
||||
return '/api/pbxusers/';
|
||||
}
|
||||
|
||||
sub relation {
|
||||
return 'http://purl.org/sipwise/ngcp-api/#rel-pbxusers';
|
||||
}
|
||||
|
||||
sub get_form {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my $form = (NGCP::Panel::Form::get("NGCP::Panel::Form::Pbx::UserAPI", $c));
|
||||
print "GOT FORM: $form\n";
|
||||
return $form
|
||||
}
|
||||
|
||||
sub _item_rs {
|
||||
my ($self, $c, $type) = @_;
|
||||
|
||||
my $item_rs = $c->model('DB')->resultset('voip_subscribers')
|
||||
->search({
|
||||
'me.status' => { '!=' => 'terminated' },
|
||||
'product.class' => 'pbxaccount',
|
||||
'provisioning_voip_subscriber.is_pbx_group' => 0,
|
||||
},{
|
||||
join => [
|
||||
{ 'contract' => 'contact' },
|
||||
{ 'contract' => 'product'},
|
||||
'provisioning_voip_subscriber',
|
||||
],
|
||||
});
|
||||
if ($c->user->roles eq 'reseller' || $c->user->roles eq 'ccare') {
|
||||
$item_rs = $item_rs->search({
|
||||
'contact.reseller_id' => $c->user->reseller_id,
|
||||
});
|
||||
} elsif ($c->user->roles eq 'subscriberadmin') {
|
||||
$item_rs = $item_rs->search({
|
||||
'contract_id' => $c->user->account_id,
|
||||
});
|
||||
} elsif ($c->user->roles eq 'subscriber') {
|
||||
$item_rs = $item_rs->search({
|
||||
'contract_id' => $c->user->account_id,
|
||||
});
|
||||
}
|
||||
return $item_rs;
|
||||
}
|
||||
|
||||
sub resource_from_item {
|
||||
my ($self, $c, $item, $form) = @_;
|
||||
|
||||
my %resource;
|
||||
my $prov_sub = $item->provisioning_voip_subscriber;
|
||||
|
||||
$resource{id} = int($item->id);
|
||||
|
||||
if ($item->primary_number) {
|
||||
$resource{primary_number}->{cc} = $item->primary_number->cc;
|
||||
$resource{primary_number}->{ac} = $item->primary_number->ac;
|
||||
$resource{primary_number}->{sn} = $item->primary_number->sn;
|
||||
$resource{primary_number}->{number_id} = int($item->primary_number->id);
|
||||
}
|
||||
|
||||
my $display_name_pref = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
|
||||
c => $c,
|
||||
attribute => 'display_name',
|
||||
prov_subscriber => $prov_sub,
|
||||
)->first;
|
||||
|
||||
$resource{display_name} = $display_name_pref ? $display_name_pref->value : undef;
|
||||
$resource{pbx_extension} = $prov_sub->pbx_extension;
|
||||
|
||||
return unless $self->validate_form(
|
||||
c => $c,
|
||||
form => $form,
|
||||
resource => \%resource,
|
||||
run => 0,
|
||||
);
|
||||
|
||||
return \%resource;
|
||||
}
|
||||
|
||||
1;
|
||||
# vim: set tabstop=4 expandtab:
|
Loading…
Reference in new issue