|
|
|
|
@ -3,10 +3,10 @@ use Sipwise::Base;
|
|
|
|
|
|
|
|
|
|
BEGIN { extends 'Catalyst::Controller'; }
|
|
|
|
|
|
|
|
|
|
use NGCP::Panel::Form::SubscriberProfile::CatalogAdmin;
|
|
|
|
|
use NGCP::Panel::Form::SubscriberProfile::CatalogReseller;
|
|
|
|
|
use NGCP::Panel::Form::SubscriberProfile::SetAdmin;
|
|
|
|
|
use NGCP::Panel::Form::SubscriberProfile::SetReseller;
|
|
|
|
|
use NGCP::Panel::Form::SubscriberProfile::Profile;
|
|
|
|
|
use NGCP::Panel::Form::SubscriberProfile::CatalogClone;
|
|
|
|
|
use NGCP::Panel::Form::SubscriberProfile::SetClone;
|
|
|
|
|
use NGCP::Panel::Form::SubscriberProfile::ProfileClone;
|
|
|
|
|
use NGCP::Panel::Utils::Message;
|
|
|
|
|
use NGCP::Panel::Utils::Navigation;
|
|
|
|
|
@ -18,67 +18,67 @@ sub auto {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub catalog_list :Chained('/') :PathPart('subscriberprofile') :CaptureArgs(0) :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) {
|
|
|
|
|
sub set_list :Chained('/') :PathPart('subscriberprofile') :CaptureArgs(0) {
|
|
|
|
|
my ( $self, $c ) = @_;
|
|
|
|
|
|
|
|
|
|
$c->stash->{cat_rs} = $c->model('DB')->resultset('voip_subscriber_profile_catalogs');
|
|
|
|
|
$c->stash->{set_rs} = $c->model('DB')->resultset('voip_subscriber_profile_sets');
|
|
|
|
|
if($c->user->roles eq "admin") {
|
|
|
|
|
} elsif($c->user->roles eq "reseller") {
|
|
|
|
|
$c->stash->{cat_rs} = $c->stash->{cat_rs}->search({
|
|
|
|
|
$c->stash->{set_rs} = $c->stash->{set_rs}->search({
|
|
|
|
|
reseller_id => $c->user->reseller_id
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
$c->stash->{cat_rs} = $c->stash->{cat_rs}->search({
|
|
|
|
|
$c->stash->{set_rs} = $c->stash->{set_rs}->search({
|
|
|
|
|
reseller_id => $c->user->voip_subscriber->contract->contact->reseller_id,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$c->stash->{cat_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, [
|
|
|
|
|
$c->stash->{set_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, [
|
|
|
|
|
{ name => 'id', search => 1, title => $c->loc('#') },
|
|
|
|
|
{ name => 'reseller.name', search => 1, title => $c->loc('Reseller') },
|
|
|
|
|
{ name => 'name', search => 1, title => $c->loc('Name') },
|
|
|
|
|
{ name => 'description', search => 1, title => $c->loc('Description') },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$c->stash(template => 'subprofile/cat_list.tt');
|
|
|
|
|
$c->stash(template => 'subprofile/set_list.tt');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub catalog_root :Chained('catalog_list') :PathPart('') :Args(0) {
|
|
|
|
|
sub set_root :Chained('set_list') :PathPart('') :Args(0) :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub catalog_ajax :Chained('catalog_list') :PathPart('ajax') :Args(0) {
|
|
|
|
|
sub set_ajax :Chained('set_list') :PathPart('ajax') :Args(0) :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
my $rs = $c->stash->{cat_rs};
|
|
|
|
|
NGCP::Panel::Utils::Datatables::process($c, $rs, $c->stash->{cat_dt_columns});
|
|
|
|
|
my $rs = $c->stash->{set_rs};
|
|
|
|
|
NGCP::Panel::Utils::Datatables::process($c, $rs, $c->stash->{set_dt_columns});
|
|
|
|
|
$c->detach( $c->view("JSON") );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub catalog_base :Chained('catalog_list') :PathPart('') :CaptureArgs(1) {
|
|
|
|
|
my ($self, $c, $cat_id) = @_;
|
|
|
|
|
sub set_base :Chained('set_list') :PathPart('') :CaptureArgs(1) {
|
|
|
|
|
my ($self, $c, $set_id) = @_;
|
|
|
|
|
|
|
|
|
|
unless($cat_id && $cat_id->is_integer) {
|
|
|
|
|
unless($set_id && $set_id->is_integer) {
|
|
|
|
|
NGCP::Panel::Utils::Message->error(
|
|
|
|
|
c => $c,
|
|
|
|
|
log => 'Invalid subscriber profile catalog id detected',
|
|
|
|
|
desc => $c->loc('Invalid subscriber profile catalog id detected'),
|
|
|
|
|
log => 'Invalid subscriber profile set id detected',
|
|
|
|
|
desc => $c->loc('Invalid subscriber profile set id detected'),
|
|
|
|
|
);
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/subscriberprofile'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $res = $c->stash->{cat_rs}->find($cat_id);
|
|
|
|
|
my $res = $c->stash->{set_rs}->find($set_id);
|
|
|
|
|
unless(defined($res)) {
|
|
|
|
|
NGCP::Panel::Utils::Message->error(
|
|
|
|
|
c => $c,
|
|
|
|
|
log => 'Subscriber profile catalog does not exist',
|
|
|
|
|
desc => $c->loc('Subscriber profile catalog does not exist'),
|
|
|
|
|
log => 'Subscriber profile set does not exist',
|
|
|
|
|
desc => $c->loc('Subscriber profile set does not exist'),
|
|
|
|
|
);
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/subscriberprofile'));
|
|
|
|
|
}
|
|
|
|
|
$c->stash(cat => $res);
|
|
|
|
|
$c->stash(set => $res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub catalog_create :Chained('catalog_list') :PathPart('create') :Args(0) {
|
|
|
|
|
sub set_create :Chained('set_list') :PathPart('create') :Args(0) :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
|
|
|
|
|
my $posted = ($c->request->method eq 'POST');
|
|
|
|
|
@ -86,9 +86,9 @@ sub catalog_create :Chained('catalog_list') :PathPart('create') :Args(0) {
|
|
|
|
|
$params = $params->merge($c->session->{created_objects});
|
|
|
|
|
my $form;
|
|
|
|
|
if($c->user->roles eq "admin") {
|
|
|
|
|
$form = NGCP::Panel::Form::SubscriberProfile::CatalogAdmin->new;
|
|
|
|
|
$form = NGCP::Panel::Form::SubscriberProfile::SetAdmin->new;
|
|
|
|
|
} else {
|
|
|
|
|
$form = NGCP::Panel::Form::SubscriberProfile::CatalogReseller->new;
|
|
|
|
|
$form = NGCP::Panel::Form::SubscriberProfile::SetReseller->new;
|
|
|
|
|
}
|
|
|
|
|
$form->process(
|
|
|
|
|
posted => $posted,
|
|
|
|
|
@ -114,16 +114,16 @@ sub catalog_create :Chained('catalog_list') :PathPart('create') :Args(0) {
|
|
|
|
|
$form->values->{reseller_id} = $c->user->reseller_id;
|
|
|
|
|
}
|
|
|
|
|
delete $form->values->{reseller};
|
|
|
|
|
$c->stash->{cat_rs}->create($form->values);
|
|
|
|
|
$c->stash->{set_rs}->create($form->values);
|
|
|
|
|
|
|
|
|
|
delete $c->session->{created_objects}->{reseller};
|
|
|
|
|
});
|
|
|
|
|
$c->flash(messages => [{type => 'success', text => $c->loc('Subscriber profile catalog successfully created')}]);
|
|
|
|
|
$c->flash(messages => [{type => 'success', text => $c->loc('Subscriber profile set successfully created')}]);
|
|
|
|
|
} catch($e) {
|
|
|
|
|
NGCP::Panel::Utils::Message->error(
|
|
|
|
|
c => $c,
|
|
|
|
|
error => $e,
|
|
|
|
|
desc => $c->loc('Failed to create subscriber profile catalog.'),
|
|
|
|
|
desc => $c->loc('Failed to create subscriber profile set.'),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/subscriberprofile'));
|
|
|
|
|
@ -133,19 +133,19 @@ sub catalog_create :Chained('catalog_list') :PathPart('create') :Args(0) {
|
|
|
|
|
$c->stash(create_flag => 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub catalog_edit :Chained('catalog_base') :PathPart('edit') {
|
|
|
|
|
sub set_edit :Chained('set_base') :PathPart('edit') :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
|
|
|
|
|
my $cat = $c->stash->{cat};
|
|
|
|
|
my $set = $c->stash->{set};
|
|
|
|
|
my $posted = ($c->request->method eq 'POST');
|
|
|
|
|
my $params = { $cat->get_inflated_columns };
|
|
|
|
|
my $params = { $set->get_inflated_columns };
|
|
|
|
|
$params->{reseller}{id} = delete $params->{reseller_id};
|
|
|
|
|
$params = $params->merge($c->session->{created_objects});
|
|
|
|
|
my $form;
|
|
|
|
|
if($c->user->roles eq "admin") {
|
|
|
|
|
$form = NGCP::Panel::Form::SubscriberProfile::CatalogAdmin->new;
|
|
|
|
|
$form = NGCP::Panel::Form::SubscriberProfile::SetAdmin->new;
|
|
|
|
|
} else {
|
|
|
|
|
$form = NGCP::Panel::Form::SubscriberProfile::CatalogReseller->new;
|
|
|
|
|
$form = NGCP::Panel::Form::SubscriberProfile::SetReseller->new;
|
|
|
|
|
}
|
|
|
|
|
$form->process(
|
|
|
|
|
posted => $posted,
|
|
|
|
|
@ -171,16 +171,16 @@ sub catalog_edit :Chained('catalog_base') :PathPart('edit') {
|
|
|
|
|
$form->values->{reseller_id} = $c->user->reseller_id;
|
|
|
|
|
}
|
|
|
|
|
delete $form->values->{reseller};
|
|
|
|
|
$cat->update($form->values);
|
|
|
|
|
$set->update($form->values);
|
|
|
|
|
|
|
|
|
|
delete $c->session->{created_objects}->{reseller};
|
|
|
|
|
});
|
|
|
|
|
$c->flash(messages => [{type => 'success', text => $c->loc('Subscriber profile catalog successfully updated')}]);
|
|
|
|
|
$c->flash(messages => [{type => 'success', text => $c->loc('Subscriber profile set successfully updated')}]);
|
|
|
|
|
} catch($e) {
|
|
|
|
|
NGCP::Panel::Utils::Message->error(
|
|
|
|
|
c => $c,
|
|
|
|
|
error => $e,
|
|
|
|
|
desc => $c->loc('Failed to update subscriber profile catalog.'),
|
|
|
|
|
desc => $c->loc('Failed to update subscriber profile set.'),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/subscriberprofile'));
|
|
|
|
|
@ -190,39 +190,39 @@ sub catalog_edit :Chained('catalog_base') :PathPart('edit') {
|
|
|
|
|
$c->stash(edit_flag => 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub catalog_delete :Chained('catalog_base') :PathPart('delete') {
|
|
|
|
|
sub set_delete :Chained('set_base') :PathPart('delete') :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
my $schema = $c->model('DB');
|
|
|
|
|
$schema->txn_do(sub{
|
|
|
|
|
$schema->resultset('provisioning_voip_subscribers')->search({
|
|
|
|
|
profile_catalog_id => $c->stash->{cat}->id
|
|
|
|
|
profile_set_id => $c->stash->{set}->id
|
|
|
|
|
})->update({
|
|
|
|
|
profile_catalog_id => undef,
|
|
|
|
|
profile_set_id => undef,
|
|
|
|
|
profile_id => undef,
|
|
|
|
|
});
|
|
|
|
|
$c->stash->{cat}->voip_subscriber_profiles->delete;
|
|
|
|
|
$c->stash->{cat}->delete;
|
|
|
|
|
$c->stash->{set}->voip_subscriber_profiles->delete;
|
|
|
|
|
$c->stash->{set}->delete;
|
|
|
|
|
});
|
|
|
|
|
$c->flash(messages => [{type => 'success', text => $c->loc('Subscriber profile catalog successfully deleted')}]);
|
|
|
|
|
$c->flash(messages => [{type => 'success', text => $c->loc('Subscriber profile set successfully deleted')}]);
|
|
|
|
|
} catch($e) {
|
|
|
|
|
NGCP::Panel::Utils::Message->error(
|
|
|
|
|
c => $c,
|
|
|
|
|
error => $e,
|
|
|
|
|
desc => $c->loc('Failed to delete subscriber profile catalog.'),
|
|
|
|
|
desc => $c->loc('Failed to delete subscriber profile set.'),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/subscriberprofile'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub catalog_clone :Chained('catalog_base') :PathPart('clone') :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) {
|
|
|
|
|
sub set_clone :Chained('set_base') :PathPart('clone') :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
|
|
|
|
|
my $posted = ($c->request->method eq 'POST');
|
|
|
|
|
my $params = { $c->stash->{cat}->get_inflated_columns };
|
|
|
|
|
my $params = { $c->stash->{set}->get_inflated_columns };
|
|
|
|
|
$params = $params->merge($c->session->{created_objects});
|
|
|
|
|
my $form = NGCP::Panel::Form::SubscriberProfile::CatalogClone->new;
|
|
|
|
|
my $form = NGCP::Panel::Form::SubscriberProfile::SetClone->new;
|
|
|
|
|
$form->process(
|
|
|
|
|
posted => $posted,
|
|
|
|
|
params => $c->request->params,
|
|
|
|
|
@ -238,16 +238,16 @@ sub catalog_clone :Chained('catalog_base') :PathPart('clone') :Does(ACL) :ACLDet
|
|
|
|
|
try {
|
|
|
|
|
my $schema = $c->model('DB');
|
|
|
|
|
$schema->txn_do(sub {
|
|
|
|
|
my $new_cat = $schema->resultset('voip_subscriber_profile_catalogs')->create({
|
|
|
|
|
my $new_set = $schema->resultset('voip_subscriber_profile_sets')->create({
|
|
|
|
|
%{ $form->values },
|
|
|
|
|
reseller_id => $c->stash->{cat}->reseller_id,
|
|
|
|
|
reseller_id => $c->stash->{set}->reseller_id,
|
|
|
|
|
});
|
|
|
|
|
foreach my $prof($c->stash->{cat}->voip_subscriber_profiles->all) {
|
|
|
|
|
foreach my $prof($c->stash->{set}->voip_subscriber_profiles->all) {
|
|
|
|
|
my $old = { $prof->get_inflated_columns };
|
|
|
|
|
foreach(qw/id catalog_id/) {
|
|
|
|
|
foreach(qw/id set_id/) {
|
|
|
|
|
delete $old->{$_};
|
|
|
|
|
}
|
|
|
|
|
my $new_prof = $new_cat->voip_subscriber_profiles->create($old);
|
|
|
|
|
my $new_prof = $new_set->voip_subscriber_profiles->create($old);
|
|
|
|
|
my @old_attributes = $prof->profile_attributes->all;
|
|
|
|
|
foreach my $attr (@old_attributes) {
|
|
|
|
|
$new_prof->profile_attributes->create({
|
|
|
|
|
@ -274,14 +274,14 @@ sub catalog_clone :Chained('catalog_base') :PathPart('clone') :Does(ACL) :ACLDet
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub profile_list :Chained('catalog_base') :PathPart('profile') :CaptureArgs(0) {
|
|
|
|
|
sub profile_list :Chained('set_base') :PathPart('profile') :CaptureArgs(0) {
|
|
|
|
|
my ( $self, $c ) = @_;
|
|
|
|
|
|
|
|
|
|
$c->stash->{profile_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, [
|
|
|
|
|
{ name => 'id', search => 1, title => $c->loc('#') },
|
|
|
|
|
{ name => 'name', search => 1, title => $c->loc('Name') },
|
|
|
|
|
{ name => 'description', search => 1, title => $c->loc('Description') },
|
|
|
|
|
{ name => 'catalog_default', search => 0, title => $c->loc('Default') },
|
|
|
|
|
{ name => 'set_default', search => 0, title => $c->loc('Default') },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$c->stash(template => 'subprofile/profile_list.tt');
|
|
|
|
|
@ -293,7 +293,7 @@ sub profile_root :Chained('profile_list') :PathPart('') :Args(0) :Does(ACL) :ACL
|
|
|
|
|
|
|
|
|
|
sub profile_ajax :Chained('profile_list') :PathPart('ajax') :Args(0) {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
my $rs = $c->stash->{cat}->voip_subscriber_profiles;
|
|
|
|
|
my $rs = $c->stash->{set}->voip_subscriber_profiles;
|
|
|
|
|
NGCP::Panel::Utils::Datatables::process($c, $rs, $c->stash->{profile_dt_columns});
|
|
|
|
|
$c->detach( $c->view("JSON") );
|
|
|
|
|
}
|
|
|
|
|
@ -310,18 +310,18 @@ sub profile_base :Chained('profile_list') :PathPart('') :CaptureArgs(1) :Does(AC
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/rewrite'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $res = $c->stash->{cat}->voip_subscriber_profiles->find($profile_id);
|
|
|
|
|
my $res = $c->stash->{set}->voip_subscriber_profiles->find($profile_id);
|
|
|
|
|
unless(defined($res)) {
|
|
|
|
|
NGCP::Panel::Utils::Message->error(
|
|
|
|
|
c => $c,
|
|
|
|
|
log => 'Subscriber profile does not exist',
|
|
|
|
|
desc => $c->loc('Subscriber profile does not exist'),
|
|
|
|
|
);
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/subscriberprofile/profile_root', [$c->stash->{cat}->id]));
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/subscriberprofile/profile_root', [$c->stash->{set}->id]));
|
|
|
|
|
}
|
|
|
|
|
$c->stash(
|
|
|
|
|
profile => $res,
|
|
|
|
|
close_target => $c->uri_for_action('/subscriberprofile/profile_root', [$c->stash->{cat}->id]),
|
|
|
|
|
close_target => $c->uri_for_action('/subscriberprofile/profile_root', [$c->stash->{set}->id]),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -349,19 +349,19 @@ sub profile_create :Chained('profile_list') :PathPart('create') :Args(0) :Does(A
|
|
|
|
|
my $schema = $c->model('DB');
|
|
|
|
|
$schema->txn_do(sub {
|
|
|
|
|
my $attributes = delete $form->values->{attribute};
|
|
|
|
|
if($form->values->{catalog_default}) {
|
|
|
|
|
if($form->values->{set_default}) {
|
|
|
|
|
# new profile is default, clear any previous default profiles
|
|
|
|
|
$c->stash->{cat}->voip_subscriber_profiles->update({
|
|
|
|
|
catalog_default => 0,
|
|
|
|
|
$c->stash->{set}->voip_subscriber_profiles->update({
|
|
|
|
|
set_default => 0,
|
|
|
|
|
});
|
|
|
|
|
} elsif(!$c->stash->{cat}->voip_subscriber_profiles->search({
|
|
|
|
|
catalog_default => 1,
|
|
|
|
|
} elsif(!$c->stash->{set}->voip_subscriber_profiles->search({
|
|
|
|
|
set_default => 1,
|
|
|
|
|
})->count) {
|
|
|
|
|
|
|
|
|
|
# no previous default profile, make this one default
|
|
|
|
|
$form->values->{catalog_default} = 1;
|
|
|
|
|
$form->values->{set_default} = 1;
|
|
|
|
|
}
|
|
|
|
|
my $profile = $c->stash->{cat}->voip_subscriber_profiles->create($form->values);
|
|
|
|
|
my $profile = $c->stash->{set}->voip_subscriber_profiles->create($form->values);
|
|
|
|
|
|
|
|
|
|
# TODO: should we rather take the name and load the id from db,
|
|
|
|
|
# instead of trusting the id coming from user input?
|
|
|
|
|
@ -381,7 +381,7 @@ sub profile_create :Chained('profile_list') :PathPart('create') :Args(0) :Does(A
|
|
|
|
|
desc => $c->loc('Failed to create subscriber profile.'),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/subscriberprofile/profile_root', [$c->stash->{cat}->id]));
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/subscriberprofile/profile_root', [$c->stash->{set}->id]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$c->stash(form => $form);
|
|
|
|
|
@ -415,19 +415,19 @@ sub profile_edit :Chained('profile_base') :PathPart('edit') :Does(ACL) :ACLDetac
|
|
|
|
|
my $schema = $c->model('DB');
|
|
|
|
|
$schema->txn_do(sub {
|
|
|
|
|
my $attributes = delete $form->values->{attribute};
|
|
|
|
|
if($form->values->{catalog_default}) {
|
|
|
|
|
if($form->values->{set_default}) {
|
|
|
|
|
# new profile is default, clear any previous default profiles
|
|
|
|
|
$c->stash->{cat}->voip_subscriber_profiles->search({
|
|
|
|
|
$c->stash->{set}->voip_subscriber_profiles->search({
|
|
|
|
|
id => { '!=' => $profile->id },
|
|
|
|
|
})->update({
|
|
|
|
|
catalog_default => 0,
|
|
|
|
|
set_default => 0,
|
|
|
|
|
});
|
|
|
|
|
} elsif(!$c->stash->{cat}->voip_subscriber_profiles->search({
|
|
|
|
|
catalog_default => 1,
|
|
|
|
|
} elsif(!$c->stash->{set}->voip_subscriber_profiles->search({
|
|
|
|
|
set_default => 1,
|
|
|
|
|
})->count) {
|
|
|
|
|
|
|
|
|
|
# no previous default profile, make this one default
|
|
|
|
|
$form->values->{catalog_default} = 1;
|
|
|
|
|
$form->values->{set_default} = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$profile->update($form->values);
|
|
|
|
|
@ -453,7 +453,7 @@ sub profile_edit :Chained('profile_base') :PathPart('edit') :Does(ACL) :ACLDetac
|
|
|
|
|
desc => $c->loc('Failed to update subscriber profile.'),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/subscriberprofile/profile_root', [$c->stash->{cat}->id]));
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/subscriberprofile/profile_root', [$c->stash->{set}->id]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$c->stash(form => $form);
|
|
|
|
|
@ -473,11 +473,11 @@ sub profile_delete :Chained('profile_base') :PathPart('delete') :Does(ACL) :ACLD
|
|
|
|
|
# TODO: set this to another profile, or reject deletion if profile is in use
|
|
|
|
|
profile_id => undef,
|
|
|
|
|
});
|
|
|
|
|
if($profile->catalog_default && $c->stash->{cat}->voip_subscriber_profiles->count > 1) {
|
|
|
|
|
$c->stash->{cat}->voip_subscriber_profiles->search({
|
|
|
|
|
if($profile->set_default && $c->stash->{set}->voip_subscriber_profiles->count > 1) {
|
|
|
|
|
$c->stash->{set}->voip_subscriber_profiles->search({
|
|
|
|
|
id => { '!=' => $profile->id },
|
|
|
|
|
})->first->update({
|
|
|
|
|
catalog_default => 1,
|
|
|
|
|
set_default => 1,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
$profile->delete;
|
|
|
|
|
@ -490,7 +490,7 @@ sub profile_delete :Chained('profile_base') :PathPart('delete') :Does(ACL) :ACLD
|
|
|
|
|
desc => $c->loc('Failed to delete subscriber profile.'),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/subscriberprofile/profile_root', [$c->stash->{cat}->id]));
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/subscriberprofile/profile_root', [$c->stash->{set}->id]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub profile_clone :Chained('profile_base') :PathPart('clone') :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) {
|
|
|
|
|
@ -515,9 +515,9 @@ sub profile_clone :Chained('profile_base') :PathPart('clone') :Does(ACL) :ACLDet
|
|
|
|
|
try {
|
|
|
|
|
my $schema = $c->model('DB');
|
|
|
|
|
$schema->txn_do(sub {
|
|
|
|
|
$form->values->{catalog_default} = 0;
|
|
|
|
|
$form->values->{catalog_id} = $c->stash->{cat}->id;
|
|
|
|
|
my $new_profile = $c->stash->{cat}->voip_subscriber_profiles->create($form->values);
|
|
|
|
|
$form->values->{set_default} = 0;
|
|
|
|
|
$form->values->{set_id} = $c->stash->{set}->id;
|
|
|
|
|
my $new_profile = $c->stash->{set}->voip_subscriber_profiles->create($form->values);
|
|
|
|
|
my @old_attributes = $c->stash->{profile}->profile_attributes->all;
|
|
|
|
|
foreach my $attr (@old_attributes) {
|
|
|
|
|
$new_profile->profile_attributes->create({
|
|
|
|
|
@ -534,7 +534,7 @@ sub profile_clone :Chained('profile_base') :PathPart('clone') :Does(ACL) :ACLDet
|
|
|
|
|
desc => $c->loc('Failed to clone subscriber profile.'),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/subscriberprofile/profile_root', [$c->stash->{cat}->id]));
|
|
|
|
|
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for_action('/subscriberprofile/profile_root', [$c->stash->{set}->id]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$c->stash(form => $form);
|
|
|
|
|
|