TT#9850 remove interceptions when terminating a reseller

+ as resellers always are only terminated but not deleted,
  interceptions never got dropped.
+ its not possible to remove existing interceptions once
  a reseller is terminated, so delete them when terminating
  the reseller.

Change-Id: I30f829b0e5a4ce48946e9ce54274715a35ffee71
changes/35/11335/6
Rene Krenn 9 years ago
parent 197653554b
commit 5007fd5538

@ -7,7 +7,7 @@ use Sipwise::Base;
sub create_email_templates{ sub create_email_templates{
my %params = @_; my %params = @_;
my($c, $reseller) = @params{qw/c reseller/}; my($c, $reseller) = @params{qw/c reseller/};
foreach ( $c->model('DB')->resultset('email_templates')->search_rs({ 'reseller_id' => undef })->all){ foreach ( $c->model('DB')->resultset('email_templates')->search_rs({ 'reseller_id' => undef })->all){
my $email_template = { $_->get_inflated_columns }; my $email_template = { $_->get_inflated_columns };
delete $email_template->{id}; delete $email_template->{id};
@ -19,12 +19,12 @@ sub create_email_templates{
sub check_reseller_create_item { sub check_reseller_create_item {
my ($c,$reseller_id,$err_code) = @_; my ($c,$reseller_id,$err_code) = @_;
#my ($c,$reseller_id,$err_code) = @params{qw/c reseller_id err_code/}; #my ($c,$reseller_id,$err_code) = @params{qw/c reseller_id err_code/};
my $schema = $c->model('DB'); my $schema = $c->model('DB');
if (!defined $err_code || ref $err_code ne 'CODE') { if (!defined $err_code || ref $err_code ne 'CODE') {
$err_code = sub { return 0; }; $err_code = sub { return 0; };
} }
if ($c->user->roles eq "admin") { if ($c->user->roles eq "admin") {
if (defined $reseller_id) { if (defined $reseller_id) {
my $reseller = $schema->resultset('resellers')->find($reseller_id); my $reseller = $schema->resultset('resellers')->find($reseller_id);
@ -51,24 +51,24 @@ sub check_reseller_create_item {
return 0 unless &{$err_code}("Creating items associated with a reseller is allowed for admin and reseller users only."); return 0 unless &{$err_code}("Creating items associated with a reseller is allowed for admin and reseller users only.");
} }
return 1; return 1;
} }
sub check_reseller_update_item { sub check_reseller_update_item {
my ($c,$new_reseller_id,$old_reseller_id,$err_code) = @_; my ($c,$new_reseller_id,$old_reseller_id,$err_code) = @_;
#my ($c,$new_reseller_id,$old_reseller_id,$err_code) = @params{qw/c new_reseller_id old_reseller_id err_code/}; #my ($c,$new_reseller_id,$old_reseller_id,$err_code) = @params{qw/c new_reseller_id old_reseller_id err_code/};
my $schema = $c->model('DB'); my $schema = $c->model('DB');
if (!defined $err_code || ref $err_code ne 'CODE') { if (!defined $err_code || ref $err_code ne 'CODE') {
$err_code = sub { return 0; }; $err_code = sub { return 0; };
} }
if ($c->user->roles eq "admin") { if ($c->user->roles eq "admin") {
if (defined $new_reseller_id) { if (defined $new_reseller_id) {
if (defined $old_reseller_id) { if (defined $old_reseller_id) {
if ($new_reseller_id != $old_reseller_id) { if ($new_reseller_id != $old_reseller_id) {
return 0 unless &{$err_code}("Changing the reseller ID is not allowed."); return 0 unless &{$err_code}("Changing the reseller ID is not allowed.");
} }
} else { } else {
return 0 unless &{$err_code}("Cannot set a reseller ID if it was unset before."); return 0 unless &{$err_code}("Cannot set a reseller ID if it was unset before.");
} }
@ -84,7 +84,7 @@ sub check_reseller_update_item {
if (defined $old_reseller_id) { if (defined $old_reseller_id) {
if ($new_reseller_id != $old_reseller_id) { if ($new_reseller_id != $old_reseller_id) {
return 0 unless &{$err_code}("Changing the reseller ID is not allowed."); return 0 unless &{$err_code}("Changing the reseller ID is not allowed.");
} }
} else { } else {
return 0 unless &{$err_code}("Cannot set the reseller ID if it was unset before."); return 0 unless &{$err_code}("Cannot set the reseller ID if it was unset before.");
} }
@ -99,25 +99,25 @@ sub check_reseller_update_item {
return 0 unless &{$err_code}("Updating items associated with a reseller is allowed for admin and reseller users only."); return 0 unless &{$err_code}("Updating items associated with a reseller is allowed for admin and reseller users only.");
} }
return 1; return 1;
} }
sub check_reseller_delete_item { sub check_reseller_delete_item {
my ($c,$reseller_id,$err_code) = @_; my ($c,$reseller_id,$err_code) = @_;
#my ($c,$reseller_id,$err_code) = @params{qw/c reseller_id err_code/}; #my ($c,$reseller_id,$err_code) = @params{qw/c reseller_id err_code/};
my $schema = $c->model('DB'); my $schema = $c->model('DB');
if (!defined $err_code || ref $err_code ne 'CODE') { if (!defined $err_code || ref $err_code ne 'CODE') {
$err_code = sub { return 0; }; $err_code = sub { return 0; };
} }
if ($c->user->roles eq "admin") { if ($c->user->roles eq "admin") {
#ok #ok
} elsif($c->user->roles eq "reseller") { } elsif($c->user->roles eq "reseller") {
if (defined $reseller_id) { if (defined $reseller_id) {
if ($c->user->reseller_id != $reseller_id) { if ($c->user->reseller_id != $reseller_id) {
return 0 unless &{$err_code}("Deleting items with a reseller ID other than the user's reseller ID is not allowed."); return 0 unless &{$err_code}("Deleting items with a reseller ID other than the user's reseller ID is not allowed.");
} }
} else { } else {
return 0 unless &{$err_code}("Deleting items with undefined reseller ID not allowed."); return 0 unless &{$err_code}("Deleting items with undefined reseller ID not allowed.");
} }
@ -125,18 +125,18 @@ sub check_reseller_delete_item {
return 0 unless &{$err_code}("Deleting items associated with a reseller is allowed for admin and reseller users only."); return 0 unless &{$err_code}("Deleting items associated with a reseller is allowed for admin and reseller users only.");
} }
return 1; return 1;
} }
sub _handle_reseller_status_change { sub _handle_reseller_status_change {
my ($c, $reseller) = @_; my ($c, $reseller) = @_;
my $contract = $reseller->contract; my $contract = $reseller->contract;
$contract->update({ status => $reseller->status }); $contract->update({ status => $reseller->status });
NGCP::Panel::Utils::Contract::recursively_lock_contract( NGCP::Panel::Utils::Contract::recursively_lock_contract(
c => $c, c => $c,
contract => $contract, contract => $contract,
); );
if($reseller->status eq "terminated") { if($reseller->status eq "terminated") {
#delete ncos_levels #delete ncos_levels
$reseller->ncos_levels->delete_all; $reseller->ncos_levels->delete_all;
@ -151,6 +151,7 @@ sub _handle_reseller_status_change {
$reseller->email_templates->delete_all; $reseller->email_templates->delete_all;
$reseller->emergency_containers->search_related_rs('emergency_mappings')->delete_all; $reseller->emergency_containers->search_related_rs('emergency_mappings')->delete_all;
$reseller->emergency_containers->delete_all; $reseller->emergency_containers->delete_all;
$reseller->voip_intercepts->delete_all;
} }
} }

Loading…
Cancel
Save