TT#18850 add Manager Secretary feature, API Prefer='internal'

* new "Manager Secretary" call forwarding type
    * new /api/managersecretary
        - controls "Manager Secretary" call forwarding auto set
    * support Prefer='internal' to avoid all form validations,
      and creations as well as no hal is created but json body
      is returned instead. only usable on port 1442 for
      internal ngcp api clients.
    * Role/API valid_uuid() check

Change-Id: I826138d8cdbce737c09c3b98bc7bdd905d09e81c
changes/99/14599/18
Kirill Solomko 8 years ago
parent 8cd3572eed
commit dee760a15b

@ -0,0 +1,170 @@
package NGCP::Panel::Controller::API::ManagerSecretary;
use NGCP::Panel::Utils::Generic qw(:all);
use Sipwise::Base;
use boolean qw(true);
use NGCP::Panel::Utils::DataHal qw();
use NGCP::Panel::Utils::DataHalLink qw();
use HTTP::Headers qw();
use HTTP::Status qw(:constants);
use NGCP::Panel::Utils::DateTime;
use Path::Tiny qw(path);
use Safe::Isa qw($_isa);
require Catalyst::ActionRole::ACL;
require Catalyst::ActionRole::CheckTrailingSlash;
require NGCP::Panel::Role::HTTPMethods;
require Catalyst::ActionRole::RequireSSL;
use Data::Dumper;
sub allowed_methods{
return [qw/GET OPTIONS HEAD/];
}
sub api_description {
return 'API Control for manager secretary call forwardings';
};
sub query_params {
return [
];
}
sub documentation_sample {
return {
};
}
use parent qw/Catalyst::Controller NGCP::Panel::Role::API::ManagerSecretary/;
sub resource_name{
return 'managersecretary';
}
sub dispatch_path{
return '/api/managersecretary/';
}
sub relation{
return 'http://purl.org/sipwise/ngcp-api/#rel-managersecretary';
}
__PACKAGE__->config(
action => {
map { $_ => {
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller subscriberadmin subscriber/],
Args => 0,
Does => [qw(ACL CheckTrailingSlash RequireSSL)],
Method => $_,
Path => __PACKAGE__->dispatch_path,
} } @{ __PACKAGE__->allowed_methods },
},
);
sub gather_default_action_roles {
my ($self, %args) = @_; my @roles = ();
push @roles, 'NGCP::Panel::Role::HTTPMethods' if $args{attributes}->{Method};
return @roles;
}
sub auto :Private {
my ($self, $c) = @_;
$self->set_body($c);
$self->log_request($c);
return 1;
}
sub GET :Allow {
my ($self, $c) = @_;
my $page = $c->request->params->{page} // 1;
my $rows = $c->request->params->{rows} // 10;
{
my $preference = $self->require_preference($c);
my $cfs = $self->item_rs($c, "managersecretary");
(my $total_count, $cfs) = $self->paginate_order_collection($c, $cfs);
if ($preference && $preference eq 'internal') {
my @items = ();
foreach my $item ($cfs->all) {
push @items, $self->resource_from_item($c, $item);
}
$c->response->status(HTTP_OK);
$c->response->header(Preference_Applied => 'return=internal');
$c->response->body(JSON::to_json(\@items));
return;
}
my (@embedded, @links);
my $form = $self->get_form($c);
for my $cf ($cfs->all) {
try {
push @embedded, $self->hal_from_item($c, $cf, $form);
push @links, NGCP::Panel::Utils::DataHalLink->new(
relation => 'ngcp:'.$self->resource_name,
href => sprintf('%s%s', $self->dispatch_path, $cf->id),
);
}
}
push @links,
NGCP::Panel::Utils::DataHalLink->new(
relation => 'curies',
href => 'http://purl.org/sipwise/ngcp-api/#rel-{rel}',
name => 'ngcp',
templated => true,
),
NGCP::Panel::Utils::DataHalLink->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
NGCP::Panel::Utils::DataHalLink->new(relation => 'self', href => sprintf('%s?page=%s&rows=%s', $self->dispatch_path, $page, $rows));
if(($total_count / $rows) > $page ) {
push @links, NGCP::Panel::Utils::DataHalLink->new(relation => 'next', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page + 1, $rows));
}
if($page > 1) {
push @links, NGCP::Panel::Utils::DataHalLink->new(relation => 'prev', href => sprintf('%s?page=%d&rows=%d', $self->dispatch_path, $page - 1, $rows));
}
my $hal = NGCP::Panel::Utils::DataHal->new(
embedded => [@embedded],
links => [@links],
);
$hal->resource({
total_count => $total_count,
});
my $response = HTTP::Response->new(HTTP_OK, undef,
HTTP::Headers->new($hal->http_headers(skip_links => 1)), $hal->as_json);
$c->response->headers($response->headers);
$c->response->body($response->content);
return;
}
return;
}
sub HEAD :Allow {
my ($self, $c) = @_;
$c->forward(qw(GET));
$c->response->body(q());
return;
}
sub OPTIONS :Allow {
my ($self, $c) = @_;
my $allowed_methods = $self->allowed_methods_filtered($c);
$c->response->headers(HTTP::Headers->new(
Allow => join(', ', @{ $allowed_methods }),
Accept_Post => 'application/hal+json; profile=http://purl.org/sipwise/ngcp-api/#rel-'.$self->resource_name,
));
$c->response->content_type('application/json');
$c->response->body(JSON::to_json({ methods => $allowed_methods })."\n");
return;
}
sub end : Private {
my ($self, $c) = @_;
$self->log_response($c);
return 1;
}
1;
# vim: set tabstop=4 expandtab:

@ -0,0 +1,227 @@
package NGCP::Panel::Controller::API::ManagerSecretaryItem;
use NGCP::Panel::Utils::Generic qw(:all);
use Sipwise::Base;
use boolean qw(true);
use NGCP::Panel::Utils::DataHal qw();
use NGCP::Panel::Utils::DataHalLink qw();
use HTTP::Headers qw();
use HTTP::Status qw(:constants);
use NGCP::Panel::Utils::ValidateJSON qw();
use NGCP::Panel::Utils::DateTime;
use Path::Tiny qw(path);
use Safe::Isa qw($_isa);
require Catalyst::ActionRole::ACL;
require NGCP::Panel::Role::HTTPMethods;
require Catalyst::ActionRole::RequireSSL;
sub allowed_methods{
return [qw/GET OPTIONS HEAD PUT DELETE/];
}
use parent qw/Catalyst::Controller NGCP::Panel::Role::API::ManagerSecretary/;
sub resource_name{
return 'managersecretary';
}
sub dispatch_path{
return '/api/managersecretary/';
}
sub relation{
return 'http://purl.org/sipwise/ngcp-api/#rel-managersecretary';
}
sub journal_query_params {
my($self,$query_params) = @_;
return $self->get_journal_query_params($query_params);
}
__PACKAGE__->config(
action => {
(map { $_ => {
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller subscriberadmin subscriber/],
Args => 1,
Does => [qw(ACL RequireSSL)],
Method => $_,
Path => __PACKAGE__->dispatch_path,
} } @{ __PACKAGE__->allowed_methods }),
@{ __PACKAGE__->get_journal_action_config(__PACKAGE__->resource_name,{
ACLDetachTo => '/api/root/invalid_user',
AllowedRole => [qw/admin reseller subscriberadmin subscriber/],
Does => [qw(ACL RequireSSL)],
}) }
},
);
sub gather_default_action_roles {
my ($self, %args) = @_; my @roles = ();
push @roles, 'NGCP::Panel::Role::HTTPMethods' if $args{attributes}->{Method};
return @roles;
}
sub auto :Private {
my ($self, $c) = @_;
$self->set_body($c);
$self->log_request($c);
return 1;
}
sub GET :Allow {
my ($self, $c, $id) = @_;
{
my $preference = $self->require_preference($c);
last unless $preference;
last unless $self->valid_uuid($c, $id);
my $item = $self->item_by_uuid($c, $id);
last unless $self->resource_exists($c, 'managersecretary' => $item);
if ($preference eq 'internal') {
$c->response->status(HTTP_OK);
$c->response->header(Preference_Applied => 'return=internal');
$c->response->body($self->json_from_item($c, $item));
} else {
my $hal = $self->hal_from_item($c, $item);
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
(map { # XXX Data::HAL must be able to generate links with multiple relations
s|rel="(http://purl.org/sipwise/ngcp-api/#rel-resellers)"|rel="item $1"|r
=~ s/rel=self/rel="item self"/r;
} $hal->http_headers),
), $hal->as_json);
$c->response->headers($response->headers);
$c->response->body($response->content);
}
}
return;
}
sub HEAD :Allow {
my ($self, $c, $id) = @_;
$c->forward(qw(GET));
$c->response->body(q());
return;
}
sub OPTIONS :Allow {
my ($self, $c, $id) = @_;
my $allowed_methods = $self->allowed_methods_filtered($c);
$c->response->headers(HTTP::Headers->new(
Allow => join(', ', @{ $allowed_methods }),
Accept_Patch => 'application/json-patch+json',
));
$c->response->content_type('application/json');
$c->response->body(JSON::to_json({ methods => $allowed_methods })."\n");
return;
}
sub PUT :Allow {
my ($self, $c, $id) = @_;
my $guard = $c->model('DB')->txn_scope_guard;
{
my $preference = $self->require_preference($c);
last unless $preference;
my $item = $self->item_by_uuid($c, $id);
last unless $self->resource_exists($c, managersecretary => $item);
my ($hal, $form, $old_resource, $resource);
unless ($preference eq 'internal') {
$form = $self->get_form($c);
}
$item = $self->update_item($c, $item, $old_resource, $resource, $form, $preference);
unless ($item) {
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to update manager secretary callforward.");
last;
}
unless ($preference eq 'internal') {
$hal = $self->hal_from_item($c, $item);
last unless $self->add_update_journal_item_hal($c,{ hal => $hal, id => $id });
}
$guard->commit;
if ('internal' eq $preference) {
$c->response->status(HTTP_OK);
$c->response->header(Preference_Applied => 'return=internal');
$c->response->body(q());
} elsif ('minimal' eq $preference) {
$c->response->status(HTTP_NO_CONTENT);
$c->response->header(Preference_Applied => 'return=minimal');
$c->response->body(q());
} else {
my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new(
$hal->http_headers,
), $hal->as_json);
$c->response->headers($response->headers);
$c->response->header(Preference_Applied => 'return=representation');
$c->response->body($response->content);
}
}
return;
}
sub DELETE :Allow {
my ($self, $c, $id) = @_;
my $guard = $c->model('DB')->txn_scope_guard;
{
my $preference = $self->require_preference($c);
last unless $preference;
my $item = $self->item_by_uuid($c, $id);
last unless $self->resource_exists($c, managersecretary => $item);
my ($form, $old_resource, $resource);
if ($preference ne 'internal') {
$form = $self->get_form($c);
last unless $self->add_delete_journal_item_hal($c,{ hal_from_item => sub {
my $self = shift;
my ($c) = @_;
return $self->hal_from_item($c, $item); },
id => $id});
}
try {
$item = $self->update_item($c, $item, $old_resource, $resource, $form, $preference);
} catch($e) {
$c->log->error("Failed to delete manager secretary callforward with id '$id': $e");
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Internal Server Error");
last;
}
$guard->commit;
if ('internal' eq $preference) {
$c->response->status(HTTP_OK);
$c->response->header(Preference_Applied => 'return=internal');
$c->response->body(q());
} else {
$c->response->status(HTTP_NO_CONTENT);
$c->response->body(q());
}
}
return;
}
sub get_journal_methods{
return [qw/handle_item_base_journal handle_journals_get handle_journalsitem_get handle_journals_options handle_journalsitem_options handle_journals_head handle_journalsitem_head/];
}
sub end : Private {
my ($self, $c) = @_;
$self->log_response($c);
return 1;
}
1;
# vim: set tabstop=4 expandtab:

@ -646,7 +646,7 @@ sub preferences :Chained('base') :PathPart('preferences') :Args(0) {
@dset = map { { $_->get_columns } } $map->destination_set->voip_cf_destinations->search({},
{ order_by => { -asc => 'priority' }})->all;
foreach my $d(@dset) {
$d->{as_string} = NGCP::Panel::Utils::Subscriber::destination_as_string($c, $d);
$d->{as_string} = NGCP::Panel::Utils::Subscriber::destination_as_string($c, $d, $prov_subscriber);
}
$dset_name = $map->destination_set->name;
}
@ -1279,7 +1279,7 @@ sub preferences_callforward_destinationset :Chained('base') :PathPart('preferenc
my @dests = map { { $_->get_columns } } $set->voip_cf_destinations->search({},
{ order_by => { -asc => 'priority' }})->all;
foreach my $d(@dests) {
$d->{as_string} = NGCP::Panel::Utils::Subscriber::destination_as_string($c, $d);
$d->{as_string} = NGCP::Panel::Utils::Subscriber::destination_as_string($c, $d, $prov_subscriber);
}
push @sets, { name => $set->name, id => $set->id, destinations => \@dests };
}

@ -71,6 +71,8 @@ sub build_destinations {
{ label => 'Custom Announcement', value => 'customhours' };
push @options, { label => 'Local Subscriber', value => 'localuser' }
if($c->config->{features}->{callthrough} || $c->config->{features}->{callingcard} );
push @options, { label => 'Manager Secretary', value => 'managersecretary' }
if($c->config->{features}->{manager_secretary});
}
push @options, { label => 'URI/Number', value => 'uri' };

@ -0,0 +1,42 @@
package NGCP::Panel::Form::ManagerSecretaryAPI;
use HTML::FormHandler::Moose;
use HTML::FormHandler::Widget::Block::Bootstrap;
extends 'HTML::FormHandler';
has '+widget_wrapper' => (default => 'Bootstrap');
sub build_render_list {[qw/fields actions/]}
sub build_form_element_class {[qw(form-horizontal)]}
has_field 'id' => (
type => 'Hidden',
noupdate => 1,
);
has_field 'uuid' => (
type => 'Text',
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['The subscriber UUID.'],
},
);
has_field 'secretary_numbers' => (
type => 'Repeatable',
do_wrapper => 1,
do_label => 0,
);
has_field 'secretary_numbers.number' => (
type => 'Text',
);
has_block 'fields' => (
tag => 'div',
class => [qw(modal-body)],
render_list => [qw(uuid secretary_numbers)],
);
1;
# vim: set tabstop=4 expandtab:

@ -48,14 +48,16 @@ sub build_destinations {
push @options, { label => 'Call Through', value => 'callthrough' }
if($c->config->{features}->{callthrough});
if($c->config->{features}->{cloudpbx} && $c->stash->{pbx}){
push @options,
push @options,
{ label => 'Auto Attendant', value => 'autoattendant' },
{ label => 'Office Hours Announcement', value => 'officehours' };
}
push @options,
push @options,
{ label => 'Custom Announcement', value => 'customhours' };
push @options, { label => 'Local Subscriber', value => 'localuser' }
push @options, { label => 'Local Subscriber', value => 'localuser' }
if($c->config->{features}->{callthrough} || $c->config->{features}->{callingcard} );
push @options, { label => 'Manager Secretary', value => 'managersecretary' }
if($c->config->{features}->{manager_secretary});
}
push @options, { label => 'URI/Number', value => 'uri' };
@ -119,7 +121,7 @@ sub validate_destination{
my ( $self, $field ) = @_;
my $result = 0;
(my($uri_field)) = grep {'destination' eq $_->name} ($field->field('uri')->fields);
if( 'uri' eq $field->field('destination')->value
if( 'uri' eq $field->field('destination')->value
&& !$uri_field->value ){
$uri_field->add_error($uri_field->label . " is empty");
$result = 0;

@ -367,9 +367,13 @@ sub get_uploads {
sub require_preference {
my ($self, $c) = @_;
return 'minimal' unless $c->request->header('Prefer');
my $ngcp_ua_header = $c->request->header("NGCP-UserAgent") // '';
my @preference = grep { 'return' eq $_->[0] } split_header_words($c->request->header('Prefer'));
return $preference[0][1]
if 1 == @preference && ('minimal' eq $preference[0][1] || 'representation' eq $preference[0][1]);
if 1 == @preference && $preference[0][1] =~ /^(minimal|representation)$/;
return $preference[0][1]
if 1 == @preference && $preference[0][1] eq 'internal' &&
$ngcp_ua_header eq "NGCP::API::Client";
$self->error($c, HTTP_BAD_REQUEST, "Header 'Prefer' must be either 'return=minimal' or 'return=representation'.");
}
@ -432,6 +436,13 @@ sub valid_id {
return;
}
sub valid_uuid {
my ($self, $c, $uuid) = @_;
return 1 if $uuid =~ /^[a-f0-9\-]+$/;
$self->error($c, HTTP_BAD_REQUEST, "Invalid uuid in request URI");
return;
}
sub require_valid_patch {
my ($self, $c, $json, $ops) = @_;

@ -0,0 +1,279 @@
package NGCP::Panel::Role::API::ManagerSecretary;
use NGCP::Panel::Utils::Generic qw(:all);
use Sipwise::Base;
use parent 'NGCP::Panel::Role::API';
use boolean qw(true);
use NGCP::Panel::Utils::DataHal qw();
use NGCP::Panel::Utils::DataHalLink qw();
use HTTP::Status qw(:constants);
use JSON::Types;
use NGCP::Panel::Form::ManagerSecretaryAPI;
use NGCP::Panel::Utils::Subscriber;
use NGCP::Panel::Utils::Preferences;
use Readonly;
use Data::Dumper;
Readonly my $dset_name => 'ms_autoset';
sub get_form {
my ($self, $c) = @_;
return NGCP::Panel::Form::ManagerSecretaryAPI->new(ctx => $c);
}
sub hal_from_item {
my ($self, $c, $item, $form) = @_;
my $type = "managersecretary";
my $prov_sub = $item->provisioning_voip_subscriber;
die "no provisioning_voip_subscriber" unless $prov_sub;
my $hal = NGCP::Panel::Utils::DataHal->new(
links => [
NGCP::Panel::Utils::DataHalLink->new(
relation => 'curies',
href => 'http://purl.org/sipwise/ngcp-api/#rel-{rel}',
name => 'ngcp',
templated => true,
),
NGCP::Panel::Utils::DataHalLink->new(relation => 'collection', href => sprintf("%s", $self->dispatch_path)),
NGCP::Panel::Utils::DataHalLink->new(relation => 'profile', href => 'http://purl.org/sipwise/ngcp-api/'),
NGCP::Panel::Utils::DataHalLink->new(relation => 'self', href => sprintf("%s%s", $self->dispatch_path, $item->uuid)),
NGCP::Panel::Utils::DataHalLink->new(relation => "ngcp:$type", href => sprintf("/api/%s/%s", $type, $item->uuid)),
NGCP::Panel::Utils::DataHalLink->new(relation => 'ngcp:subscribers', href => sprintf("/api/subscribers/%s", $item->uuid)),
$self->get_journal_relation_link($item->id),
],
relation => 'ngcp:'.$self->resource_name,
);
my $allowed_prefs = NGCP::Panel::Utils::Preferences::get_subscriber_allowed_prefs(
c => $c,
prov_subscriber => $prov_sub,
pref_list => [qw/cfu cfb cft cfna cfs/],
);
my $resource = {};
for my $item_cf ($prov_sub->voip_cf_mappings->all) {
next unless $allowed_prefs->{$item_cf->type};
my $dset = $item_cf->destination_set;
next unless $dset->name eq $dset_name;
next unless $dset->voip_cf_destinations->count;
$resource = $self->_get_content($c, $item);
last;
}
$form //= $self->get_form($c);
$form->clear();
return unless $self->validate_form(
c => $c,
form => $form,
resource => $resource,
run => 0,
);
$hal->resource($resource);
return $hal;
}
sub resource_from_item {
my ($self, $c, $item) = @_;
my $prov_sub = $item->provisioning_voip_subscriber;
my $resource = {};
for my $item_cf ($prov_sub->voip_cf_mappings->all) {
my $dset = $item_cf->destination_set;
next unless $dset->name eq $dset_name;
next unless $dset->voip_cf_destinations->count;
$resource = $self->_get_content($c, $item);
last;
}
return unless %$resource;
return $resource;
}
sub json_from_item {
my ($self, $c, $item) = @_;
my $resource = $self->resource_from_item($c, $item);
return unless $resource;
return JSON::to_json($resource);
}
sub _get_content {
my ($self, $c, $item) = @_;
my $prov_sub = $item->provisioning_voip_subscriber;
my $pref_rs = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, attribute => 'secretary_numbers', prov_subscriber => $prov_sub);
my @secretary_numbers = ();
if ($pref_rs) {
map { push @secretary_numbers, { number => $_->value } } $pref_rs->all;
}
return { uuid => $prov_sub->uuid,
secretary_numbers => [ @secretary_numbers ] };
}
sub _item_rs {
my ($self, $c) = @_;
my $filter = {};
if ($c->request->method eq 'GET') {
$filter = { 'destination_set.name' => $dset_name };
}
my $item_rs = $c->model('DB')->resultset('voip_subscribers')->search({
'me.status' => { '!=' => 'terminated' },
%$filter
},{
'prefetch' => { 'provisioning_voip_subscriber' =>
{ 'voip_cf_mappings' => 'destination_set' } },
});
if ($c->user->roles eq "reseller") {
$item_rs = $item_rs->search({
'contact.reseller_id' => $c->user->reseller_id,
}, {
join => { 'contract' => 'contact' },
});
} elsif ($c->user->roles eq 'subscriberadmin') {
$item_rs = $item_rs->search({
'contract.id' => $c->user->account_id,
}, {
join => 'contract',
});
} elsif ($c->user->roles eq 'subscriber') {
$item_rs = $item_rs->search({
'me.uuid' => $c->user->uuid,
});
}
return $item_rs;
}
sub item_by_uuid {
my ($self, $c, $id) = @_;
return $self->item_rs($c)->search_rs({'me.uuid' => $id})->first;
}
sub update_item {
my ($self, $c, $item, $old_resource, $resource, $form, $preference) = @_;
unless ($item) {
$self->error($c, HTTP_NOT_FOUND, "Unknown subscriber.");
return;
}
my $prov_sub = $item->provisioning_voip_subscriber;
die "need provisioning_voip_subscriber" unless $prov_sub;
delete $resource->{id};
my $cf_type = 'cfu';
if (!$preference || $preference ne 'internal') {
my $allowed_prefs = NGCP::Panel::Utils::Preferences::get_subscriber_allowed_prefs(
c => $c,
prov_subscriber => $prov_sub,
pref_list => [qw/cfu cfb cft cfna cfs/],
);
return unless $allowed_prefs->{$cf_type};
return unless $self->validate_form(
c => $c,
form => $form,
resource => $resource,
run => 1,
);
}
try {
my $enable = $c->request->method eq 'PUT';
my $mapping = $c->model('DB')->resultset('voip_cf_mappings')->search_rs({
subscriber_id => $prov_sub->id,
type => $cf_type,
});
my $dset;
my $mapping_count = $mapping->count;
if ($mapping_count > 1) {
foreach my $m ($mapping->all) {
$m->delete;
}
return unless $enable;
}
if ($mapping_count == 1) {
$mapping = $mapping->first;
$dset = $mapping->destination_set;
} elsif ($enable) {
$mapping = $c->model('DB')->resultset('voip_cf_mappings')->create({
subscriber_id => $prov_sub->id,
type => $cf_type,
});
$mapping->discard_changes; # get our row
}
my $cf_preference = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, prov_subscriber => $prov_sub, attribute => $cf_type);
unless ($enable) {
if ($dset && $dset->name eq $dset_name) {
$dset->delete;
}
$cf_preference->delete if $cf_preference;
return;
}
if ($cf_preference->first) {
$cf_preference->first->update({ value => $mapping->id });
} else {
$cf_preference->create({ value => $mapping->id });
}
my $primary_nr_rs = $item->primary_number;
my $number;
if ($primary_nr_rs) {
$number = $primary_nr_rs->cc . ($primary_nr_rs->ac //'') . $primary_nr_rs->sn;
} else {
$number = $item->uuid;
}
if (!$dset || $dset->name ne $dset_name) {
$dset = $mapping->create_related('destination_set',
{ name => $dset_name, subscriber_id => $prov_sub->id });
$mapping->update({ destination_set_id => $dset->id });
}
my $destination = NGCP::Panel::Utils::Subscriber::field_to_destination(
destination => 'managersecretary',
number => $number,
domain => '',
uri => '',
cf_type => $cf_type,
c => $c,
subscriber => $prov_sub
);
$dset->voip_cf_destinations->update_or_create({
destination => $destination,
priority => 1,
});
$dset->discard_changes if $dset; # update destinations
} catch($e) {
$c->log->error("Error Updating '$cf_type': $e");
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "CallForward '$cf_type' could not be updated.");
return;
}
$item->discard_changes;
return $item;
}
1;
# vim: set tabstop=4 expandtab:

@ -84,6 +84,18 @@ sub destination_as_string {
return "Office Hours Announcement";
} elsif($dest =~ /^sip:custom-hours\@app\.local$/) {
return "Custom Announcement";
} elsif($dest =~ /\@managersecretary\.local$/) {
my $sn_rs = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, attribute => 'secretary_numbers',
prov_subscriber => $subscriber);
my @sn_list = ();
if ($sn_rs) {
foreach my $l ($sn_rs->all) {
next if $l->value =~ /^#/;
push @sn_list, $l->value;
}
}
return "MS to " . (@sn_list ? join(',', @sn_list) : 'unknown');
} else {
my $d = $dest;
$d =~ s/^sips?://;
@ -1205,6 +1217,8 @@ sub field_to_destination {
$d = "sip:office-hours\@app.local";
} elsif($d eq "customhours") {
$d = "sip:custom-hours\@app.local";
} elsif($d eq "managersecretary") {
$d = "sip:$number\@managersecretary.local";
} else {
my $v = $uri;
$v =~ s/^sips?://;
@ -1245,6 +1259,8 @@ sub destination_to_field {
$d = 'officehours';
} elsif($d =~ /^sip:custom-hours\@app\.local$/) {
$d = 'customhours';
} elsif($d =~ /\@managersecretary\.local$/) {
$d = 'managersecretary';
} else {
$duri = $d;
$d = 'uri';

@ -40,7 +40,7 @@ sub cfs {
my @dset = map { { $_->get_columns } } $map->destination_set->voip_cf_destinations->search({},
{ order_by => { -asc => 'priority' }})->all;
foreach my $d (@dset) {
my $as_string = NGCP::Panel::Utils::Subscriber::destination_as_string($c, $d);
my $as_string = NGCP::Panel::Utils::Subscriber::destination_as_string($c, $d, $prov_subscriber);
delete @$d{keys %$d};
$d->{as_string} = $as_string;
}

Loading…
Cancel
Save