MT#13717 prevent editing profiles and networks

... and create system contact button

Change-Id: Ia8861c079be9a3aca80b45d9053b3f1ae69a931d
changes/19/2019/1
Rene Krenn 10 years ago
parent fa07c1727d
commit 70936e01be

@ -162,6 +162,14 @@ sub edit :Chained('base') :PathPart('edit') {
my $schema = $c->model('DB');
$schema->txn_do(sub {
unless($c->stash->{profile_result}->get_column('contract_cnt') == 0) {
die('Cannnot modify billing profile that is still used in profile mappings');
}
unless($c->stash->{profile_result}->get_column('package_cnt') == 0) {
die('Cannnot modify billing profile that is still used in profile packages');
}
$c->stash->{profile_result}->update($form->values);
# if prepaid flag changed, update all subscribers for customers
@ -305,23 +313,14 @@ sub terminate :Chained('base') :PathPart('terminate') :Args(0) {
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/billing'));
}
#todo: putting the profile fetch into a transaction wouldn't help since the count columns a prone to phantom reads...
unless($profile->get_column('contract_cnt') == 0) {
NGCP::Panel::Utils::Message->error(
c => $c,
desc => $c->loc('Cannnot terminate billing profile that is still used in profile mappings'),
);
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/billing'));
}
unless($profile->get_column('package_cnt') == 0) {
NGCP::Panel::Utils::Message->error(
c => $c,
desc => $c->loc('Cannnot terminate billing profile that is still used in profile packages'),
);
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/billing'));
}
try {
#todo: putting the profile fetch into a transaction wouldn't help since the count columns a prone to phantom reads...
unless($profile->get_column('contract_cnt') == 0) {
die('Cannnot terminate billing profile that is still used in profile mappings');
}
unless($profile->get_column('package_cnt') == 0) {
die('Cannnot terminate billing profile that is still used in profile packages');
}
$profile->update({
status => 'terminated',
terminate_timestamp => NGCP::Panel::Utils::DateTime::current_local,

@ -374,11 +374,8 @@ sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) {
$c->stash(future_billing_mappings => $future_billing_mappings );
}
sub base_restricted :Chained('base') :PathPart('') :CaptureArgs(0) {
sub base_restricted :Chained('base') :PathPart('') :CaptureArgs(0) :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) {
my ($self, $c) = @_;
if($c->user->roles eq "subscriberadmin") {
$c->detach('/denied_page');
}
}
sub edit :Chained('base_restricted') :PathPart('edit') :Args(0) {

@ -178,6 +178,14 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
try {
$c->model('DB')->schema->txn_do( sub {
unless($c->stash->{network_result}->get_column('contract_cnt') == 0) {
die('Cannnot modify billing network that is still used in profile mappings');
}
unless($c->stash->{network_result}->get_column('package_cnt') == 0) {
die('Cannnot modify billing network that is still used in profile packages');
}
$c->stash->{'network_result'}->update({
name => $form->values->{name},
description => $form->values->{description},
@ -247,23 +255,14 @@ sub terminate :Chained('base') :PathPart('terminate') :Args(0) {
my ($self, $c) = @_;
my $network = $c->stash->{network_result};
#todo: putting the network fetch into a transaction wouldn't help since the count columns a prone to phantom reads...
unless($network->get_column('contract_cnt') == 0) {
NGCP::Panel::Utils::Message->error(
c => $c,
desc => $c->loc('Cannnot terminate billing network that is still used in profile mappings'),
);
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/network'));
}
unless($network->get_column('package_cnt') == 0) {
NGCP::Panel::Utils::Message->error(
c => $c,
desc => $c->loc('Cannnot terminate billing network that is still used in profile packages'),
);
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/network'));
}
try {
#todo: putting the network fetch into a transaction wouldn't help since the count columns a prone to phantom reads...
unless($network->get_column('contract_cnt') == 0) {
die('Cannnot terminate billing network that is still used in profile mappings');
}
unless($network->get_column('package_cnt') == 0) {
die('Cannnot terminate billing network that is still used in profile packages');
}
$network->update({
status => 'terminated',
#terminate_timestamp => NGCP::Panel::Utils::DateTime::current_local,

@ -208,6 +208,9 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
push(@mappings_to_create,@{delete $form->values->{underrun_profiles}});
push(@mappings_to_create,@{delete $form->values->{topup_profiles}});
$c->model('DB')->schema->txn_do( sub {
unless($c->stash->{'package_result'}->get_column('contract_cnt') == 0) {
die('Cannnot modify profile package that is still assigned to contracts');
}
my $profile_package = $c->stash->{'package_result'}->update($form->values);
$profile_package->profiles->delete;
foreach my $mapping (@mappings_to_create) {
@ -241,16 +244,11 @@ sub terminate :Chained('base') :PathPart('terminate') :Args(0) {
my ($self, $c) = @_;
my $package = $c->stash->{package_result};
#todo: putting the package fetch into a transaction wouldn't help since the count columns a prone to phantom reads...
unless($package->get_column('contract_cnt') == 0) {
NGCP::Panel::Utils::Message->error(
c => $c,
desc => $c->loc('Cannnot terminate profile package that is still assigned to contracts'),
);
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/package'));
}
try {
#todo: putting the package fetch into a transaction wouldn't help since the count columns a prone to phantom reads...
unless($package->get_column('contract_cnt') == 0) {
die('Cannnot terminate profile package that is still assigned to contracts');
}
$package->update({
status => 'terminated',
#terminate_timestamp => NGCP::Panel::Utils::DateTime::current_local,

@ -63,7 +63,7 @@ has_field 'billing_profiles.start' => (
type => '+NGCP::Panel::Field::DateTime',
element_attr => {
rel => ['tooltip'],
title => ['The date when the billing profile gets active.']
title => ['The datetime (YYYY-MM-DD HH:mm:ss) when the billing profile gets active.']
},
);
@ -71,7 +71,7 @@ has_field 'billing_profiles.end' => (
type => '+NGCP::Panel::Field::DateTime',
element_attr => {
rel => ['tooltip'],
title => ['The date when the billing profile is no longer used.']
title => ['The datetime (YYYY-MM-DD HH:mm:ss) when the billing profile is revoked.']
},
);

@ -119,18 +119,18 @@ sub update_item {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, $err);
});
if(exists $resource->{status} && $resource->{status} eq 'terminated') {
#if(exists $resource->{status} && $resource->{status} eq 'terminated') {
unless($item->get_column('contract_cnt') == 0) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY,
"Cannnot terminate billing_network that is still used in profile mappings of contracts)");
"Cannnot modify or terminate billing_network that is still used in profile mappings of contracts)");
return;
}
unless($item->get_column('package_cnt') == 0) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY,
"Cannnot terminate billing_network that is still used in profile sets of profile packages)");
"Cannnot modify or terminate billing_network that is still used in profile sets of profile packages)");
return;
}
}
#}
return unless $self->prepare_blocks_resource($c,$resource);
my $blocks = delete $resource->{blocks};

@ -115,18 +115,18 @@ sub update_profile {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, $err);
});
if(exists $resource->{status} && $resource->{status} eq 'terminated') {
#if(exists $resource->{status} && $resource->{status} eq 'terminated') {
unless($profile->get_column('contract_cnt') == 0) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY,
"Cannnot terminate billing_profile that is still used in profile mappings of contracts");
"Cannnot modify or terminate billing_profile that is still used in profile mappings of contracts");
return;
}
unless($profile->get_column('package_cnt') == 0) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY,
"Cannnot terminate billing_profile that is still used in profile sets of profile packages");
"Cannnot modify or terminate billing_profile that is still used in profile sets of profile packages");
return;
}
}
#}
my $old_prepaid = $profile->prepaid;
$profile->update($resource);

@ -135,10 +135,10 @@ sub update_item {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, $err);
});
if(exists $resource->{status} && $resource->{status} eq 'terminated') {
#if(exists $resource->{status} && $resource->{status} eq 'terminated') {
unless($item->get_column('contract_cnt') == 0) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY,
"Cannnot terminate profile_package that is still assigned to contracts");
"Cannnot modify or terminate profile_package that is still assigned to contracts");
return;
}
#unless($item->get_column('contract_cnt') == 0) {
@ -146,7 +146,7 @@ sub update_item {
# "Cannnot terminate billing_network that is still used in profile sets of profile packages");
# return;
#}
}
#}
my $mappings_to_create = [];
return unless NGCP::Panel::Utils::ProfilePackages::prepare_profile_package(

@ -2424,7 +2424,7 @@ sub _test_journal_collection {
} while($nexturi);
ok((scalar keys $journals) == 0,"check if journal collection lists all created journal items" . (defined $total_count ? " ($total_count)" : ''));
ok((scalar keys %$journals) == 0,"check if journal collection lists all created journal items" . (defined $total_count ? " ($total_count)" : ''));
}
}

Loading…
Cancel
Save