From 70936e01be4e88abc92a89ab05bb4d7270edb202 Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Wed, 1 Jul 2015 15:55:04 +0200 Subject: [PATCH] MT#13717 prevent editing profiles and networks ... and create system contact button Change-Id: Ia8861c079be9a3aca80b45d9053b3f1ae69a931d --- lib/NGCP/Panel/Controller/Billing.pm | 31 +++++++++++----------- lib/NGCP/Panel/Controller/Customer.pm | 5 +--- lib/NGCP/Panel/Controller/Network.pm | 31 +++++++++++----------- lib/NGCP/Panel/Controller/Package.pm | 16 +++++------ lib/NGCP/Panel/Form/Contract/Base.pm | 4 +-- lib/NGCP/Panel/Role/API/BillingNetworks.pm | 8 +++--- lib/NGCP/Panel/Role/API/BillingProfiles.pm | 8 +++--- lib/NGCP/Panel/Role/API/ProfilePackages.pm | 6 ++--- t/api-journals.t | 2 +- 9 files changed, 52 insertions(+), 59 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Billing.pm b/lib/NGCP/Panel/Controller/Billing.pm index bc985c63a4..459c5e7d2c 100644 --- a/lib/NGCP/Panel/Controller/Billing.pm +++ b/lib/NGCP/Panel/Controller/Billing.pm @@ -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, diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index 44c7dab0b9..09e1797be5 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -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) { diff --git a/lib/NGCP/Panel/Controller/Network.pm b/lib/NGCP/Panel/Controller/Network.pm index 80a0cf2c8f..ecc4157f2d 100644 --- a/lib/NGCP/Panel/Controller/Network.pm +++ b/lib/NGCP/Panel/Controller/Network.pm @@ -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, diff --git a/lib/NGCP/Panel/Controller/Package.pm b/lib/NGCP/Panel/Controller/Package.pm index 2173b11bbc..5cc02c2548 100644 --- a/lib/NGCP/Panel/Controller/Package.pm +++ b/lib/NGCP/Panel/Controller/Package.pm @@ -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, diff --git a/lib/NGCP/Panel/Form/Contract/Base.pm b/lib/NGCP/Panel/Form/Contract/Base.pm index 3df5d68df0..be83efb4a9 100644 --- a/lib/NGCP/Panel/Form/Contract/Base.pm +++ b/lib/NGCP/Panel/Form/Contract/Base.pm @@ -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.'] }, ); diff --git a/lib/NGCP/Panel/Role/API/BillingNetworks.pm b/lib/NGCP/Panel/Role/API/BillingNetworks.pm index 803582e500..3730e34c6d 100644 --- a/lib/NGCP/Panel/Role/API/BillingNetworks.pm +++ b/lib/NGCP/Panel/Role/API/BillingNetworks.pm @@ -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}; diff --git a/lib/NGCP/Panel/Role/API/BillingProfiles.pm b/lib/NGCP/Panel/Role/API/BillingProfiles.pm index ed5f0302fc..415e521353 100644 --- a/lib/NGCP/Panel/Role/API/BillingProfiles.pm +++ b/lib/NGCP/Panel/Role/API/BillingProfiles.pm @@ -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); diff --git a/lib/NGCP/Panel/Role/API/ProfilePackages.pm b/lib/NGCP/Panel/Role/API/ProfilePackages.pm index 69dc194f33..540220e708 100644 --- a/lib/NGCP/Panel/Role/API/ProfilePackages.pm +++ b/lib/NGCP/Panel/Role/API/ProfilePackages.pm @@ -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( diff --git a/t/api-journals.t b/t/api-journals.t index 24f3e76089..24c1664d08 100644 --- a/t/api-journals.t +++ b/t/api-journals.t @@ -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)" : '')); } }