diff --git a/lib/NGCP/Panel/Controller/API/Subscribers.pm b/lib/NGCP/Panel/Controller/API/Subscribers.pm index d5503363c3..549a842b90 100644 --- a/lib/NGCP/Panel/Controller/API/Subscribers.pm +++ b/lib/NGCP/Panel/Controller/API/Subscribers.pm @@ -315,15 +315,15 @@ sub GET :Allow { contract_id_field => 'contract_id'); my $now = NGCP::Panel::Utils::DateTime::current_local; my (@embedded, @links, %contract_map); - my $form = $self->get_form($c); + my ($form,$form_exceptions) //= $self->get_form($c); for my $subscriber (@$subscribers) { my $contract = $subscriber->contract; NGCP::Panel::Utils::ProfilePackages::get_contract_balance(c => $c, contract => $contract, now => $now) if !exists $contract_map{$contract->id}; #apply underrun lock level $contract_map{$contract->id} = 1; - my $resource = $self->resource_from_item($c, $subscriber, $form); - push @embedded, $self->hal_from_item($c, $subscriber, $resource, $form); + my $resource = $self->resource_from_item($c, $subscriber, $form,$form_exceptions); + push @embedded, $self->hal_from_item($c, $subscriber, $resource, $form,$form_exceptions); push @links, NGCP::Panel::Utils::DataHalLink->new( relation => 'ngcp:'.$self->resource_name, href => sprintf('%s%d', $self->dispatch_path, $subscriber->id), @@ -479,10 +479,10 @@ sub POST :Allow { last unless $self->add_create_journal_item_hal($c,sub { my $self = shift; my ($c) = @_; - my $_form = $self->get_form($c); + my ($_form,$_form_exceptions) = $self->get_form($c); my $_subscriber = $self->item_by_id($c, $subscriber->id); - my $_resource = $self->resource_from_item($c, $_subscriber, $_form); - return $self->hal_from_item($c,$_subscriber,$_resource,$_form); }); + my $_resource = $self->resource_from_item($c, $_subscriber, $_form,$_form_exceptions); + return $self->hal_from_item($c,$_subscriber,$_resource,$_form,$_form_exceptions); }); $guard->commit; diff --git a/lib/NGCP/Panel/Controller/API/SubscribersItem.pm b/lib/NGCP/Panel/Controller/API/SubscribersItem.pm index 975a0b6522..ef2c0c85ce 100644 --- a/lib/NGCP/Panel/Controller/API/SubscribersItem.pm +++ b/lib/NGCP/Panel/Controller/API/SubscribersItem.pm @@ -70,7 +70,7 @@ sub auto :Private { sub GET :Allow { my ($self, $c, $id) = @_; $c->model('DB')->set_transaction_isolation('READ COMMITTED'); - my $guard = $c->model('DB')->txn_scope_guard; + my $guard = $c->model('DB')->txn_scope_guard; { last unless $self->valid_id($c, $id); my $subscriber = $self->item_by_id($c, $id); @@ -79,11 +79,11 @@ sub GET :Allow { my $balance = NGCP::Panel::Utils::ProfilePackages::get_contract_balance(c => $c, contract => $subscriber->contract, ); #apply underrun lock level - - - my $form = $self->get_form($c); - my $resource = $self->resource_from_item($c, $subscriber, $form); - my $hal = $self->hal_from_item($c, $subscriber, $resource, $form); + + + my ($form, $form_exceptions) = $self->get_form($c); + my $resource = $self->resource_from_item($c, $subscriber, $form, $form_exceptions); + my $hal = $self->hal_from_item($c, $subscriber, $resource, $form, $form_exceptions); $guard->commit; #potential db write ops in hal_from my $response = HTTP::Response->new(HTTP_OK, undef, HTTP::Headers->new( @@ -128,7 +128,7 @@ sub PUT :Allow { } my $schema = $c->model('DB'); - $schema->set_transaction_isolation('READ COMMITTED'); + $schema->set_transaction_isolation('READ COMMITTED'); my $guard = $schema->txn_scope_guard; { my $preference = $self->require_preference($c); @@ -138,7 +138,7 @@ sub PUT :Allow { last unless $self->resource_exists($c, subscriber => $subscriber); my $balance = NGCP::Panel::Utils::ProfilePackages::get_contract_balance(c => $c, contract => $subscriber->contract, - ); #apply underrun lock level + ); #apply underrun lock level my $resource = $self->get_valid_put_data( c => $c, id => $id, @@ -147,15 +147,15 @@ sub PUT :Allow { last unless $resource; my $r = $self->prepare_resource($c, $schema, $resource, $subscriber); last unless $r; - + $resource = $r->{resource}; - my $form = $self->get_form($c); - $subscriber = $self->update_item($c, $schema, $subscriber, $r, $resource, $form); + my ($form, $form_exceptions) = $self->get_form($c); + $subscriber = $self->update_item($c, $schema, $subscriber, $r, $resource, $form, $form_exceptions); last unless $subscriber; $resource = $self->resource_from_item($c, $subscriber, $form); - my $hal = $self->hal_from_item($c, $subscriber, $resource, $form); + my $hal = $self->hal_from_item($c, $subscriber, $resource, $form); last unless $self->add_update_journal_item_hal($c,$hal); $guard->commit; @@ -197,7 +197,7 @@ sub PATCH :Allow { last unless $self->resource_exists($c, subscriber => $subscriber); my $balance = NGCP::Panel::Utils::ProfilePackages::get_contract_balance(c => $c, contract => $subscriber->contract, - ); #apply underrun lock level + ); #apply underrun lock level my $json = $self->get_valid_patch_data( c => $c, id => $id, @@ -206,8 +206,8 @@ sub PATCH :Allow { ); last unless $json; - my $form = $self->get_form($c); - my $old_resource = $self->resource_from_item($c, $subscriber, $form); + my ($form, $form_exceptions) = $self->get_form($c); + my $old_resource = $self->resource_from_item($c, $subscriber, $form, $form_exceptions); $old_resource = clone($old_resource); my $resource = $self->apply_patch($c, $old_resource, $json); last unless $resource; @@ -223,7 +223,7 @@ sub PATCH :Allow { $resource = $self->resource_from_item($c, $subscriber, $form); my $hal = $self->hal_from_item($c, $subscriber, $resource, $form); last unless $self->add_update_journal_item_hal($c,$hal); - + $guard->commit; if ('minimal' eq $preference) { @@ -292,13 +292,13 @@ sub DELETE :Allow { last unless $self->add_delete_journal_item_hal($c,sub { my $self = shift; my ($c) = @_; - my $_form = $self->get_form($c); + my ($_form,$_form_exceptions) = $self->get_form($c); #my $_subscriber = $self->item_by_id($c, $id); - my $_resource = $self->resource_from_item($c, $subscriber, $_form); - return $self->hal_from_item($c,$subscriber,$_resource,$_form); }); - + my $_resource = $self->resource_from_item($c, $subscriber, $_form, $_form_exceptions); + return $self->hal_from_item($c,$subscriber,$_resource,$_form, $_form_exceptions); }); + NGCP::Panel::Utils::Subscriber::terminate(c => $c, subscriber => $subscriber); - + $guard->commit; $c->response->status(HTTP_NO_CONTENT); @@ -309,7 +309,7 @@ sub DELETE :Allow { 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) = @_; diff --git a/lib/NGCP/Panel/Form/Subscriber.pm b/lib/NGCP/Panel/Form/Subscriber.pm index de291fc12a..995e2d47c1 100644 --- a/lib/NGCP/Panel/Form/Subscriber.pm +++ b/lib/NGCP/Panel/Form/Subscriber.pm @@ -36,9 +36,9 @@ has_field 'webusername' => ( type => 'Text', label => 'Web Username', required => 0, - element_attr => { - rel => ['tooltip'], - title => ['The username to log into the CSC Panel.'] + element_attr => { + rel => ['tooltip'], + title => ['The username to log into the CSC Panel.'] }, ); @@ -46,9 +46,9 @@ has_field 'webpassword' => ( type => 'Text', label => 'Web Password', required => 0, - element_attr => { - rel => ['tooltip'], - title => ['The password to log into the CSC Panel.'] + element_attr => { + rel => ['tooltip'], + title => ['The password to log into the CSC Panel.'] }, ); @@ -69,14 +69,14 @@ has_field 'username' => ( type => '+NGCP::Panel::Field::Identifier', label => 'SIP Username', required => 1, - element_attr => { - rel => ['tooltip'], - title => ['The username for SIP and XMPP services.'] + element_attr => { + rel => ['tooltip'], + title => ['The username for SIP and XMPP services.'] }, ); has_field 'domain' => ( - #fields will be or will be not renamed to the name_id for the API documentation, Anyway, it will be not duplicated, so "or name or id" is not correct + #fields will be or will be not renamed to the name_id for the API documentation, Anyway, it will be not duplicated, so "or name or id" is not correct type => '+NGCP::Panel::Field::Domain', label => 'SIP Domain', validate_when_empty => 1, @@ -84,13 +84,13 @@ has_field 'domain' => ( rel => ['tooltip'], title => ['The domain id this subscriber belongs to.'], implicit_parameter => { - type => "String", - required => 0, - validate_when_empty => 0, - element_attr => { - title => ['The domain name this subscriber belongs to.'], - }, - }, + type => "String", + required => 0, + validate_when_empty => 0, + element_attr => { + title => ['The domain name this subscriber belongs to.'], + }, + }, }, ); @@ -98,9 +98,9 @@ has_field 'password' => ( type => 'Text', label => 'SIP Password', required => 1, - element_attr => { - rel => ['tooltip'], - title => ['The password to authenticate for SIP and XMPP services.'] + element_attr => { + rel => ['tooltip'], + title => ['The password to authenticate for SIP and XMPP services.'] }, ); @@ -123,9 +123,9 @@ has_field 'administrative' => ( type => 'Boolean', label => 'Administrative', required => 0, - element_attr => { - rel => ['tooltip'], - title => ['Whether the subscriber can configure other subscribers within his Customer account.'] + element_attr => { + rel => ['tooltip'], + title => ['Whether the subscriber can configure other subscribers within his Customer account.'] }, ); @@ -133,9 +133,9 @@ has_field 'external_id' => ( type => 'Text', label => 'External ID', required => 0, - element_attr => { - rel => ['tooltip'], - title => ['An external id, e.g. provided by a 3rd party provisioning.'] + element_attr => { + rel => ['tooltip'], + title => ['An external id, e.g. provided by a 3rd party provisioning.'] }, ); diff --git a/lib/NGCP/Panel/Form/Subscriber/SubscriberAPI.pm b/lib/NGCP/Panel/Form/Subscriber/SubscriberAPI.pm index cb60c209e8..71cd6949a5 100644 --- a/lib/NGCP/Panel/Form/Subscriber/SubscriberAPI.pm +++ b/lib/NGCP/Panel/Form/Subscriber/SubscriberAPI.pm @@ -6,8 +6,8 @@ extends 'NGCP::Panel::Form::Subscriber'; sub build_render_list {[qw/submitid fields actions/]} sub build_form_element_class {[qw(form-horizontal)]} -has_field 'customer' => ( - type => '+NGCP::Panel::Field::CustomerContract', +has_field 'customer_id' => ( + type => 'PosInteger', label => 'Customer', validate_when_empty => 1, element_attr => { @@ -232,6 +232,7 @@ sub update_fields { return; } + 1; # vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Form/Subscriber/SubscriberSubAdminAPI.pm b/lib/NGCP/Panel/Form/Subscriber/SubscriberSubAdminAPI.pm index 612a70d0af..9b7dffd92b 100644 --- a/lib/NGCP/Panel/Form/Subscriber/SubscriberSubAdminAPI.pm +++ b/lib/NGCP/Panel/Form/Subscriber/SubscriberSubAdminAPI.pm @@ -34,7 +34,7 @@ has_field 'username' => ( ); has_field 'domain' => ( - #fields will be or will be not renamed to the name_id for the API documentation, Anyway, it will be not duplicated, so "or name or id" is not correct + #fields will be or will be not renamed to the name_id for the API documentation, Anyway, it will be not duplicated, so "or name or id" is not correct type => '+NGCP::Panel::Field::Domain', label => 'SIP Domain', validate_when_empty => 1, @@ -42,13 +42,13 @@ has_field 'domain' => ( rel => ['tooltip'], title => ['The domain id this subscriber belongs to.'], implicit_parameter => { - type => "String", - required => 0, - validate_when_empty => 0, - element_attr => { - title => ['The domain name this subscriber belongs to.'], - }, - }, + type => "String", + required => 0, + validate_when_empty => 0, + element_attr => { + title => ['The domain name this subscriber belongs to.'], + }, + }, }, ); diff --git a/lib/NGCP/Panel/Role/API/Subscribers.pm b/lib/NGCP/Panel/Role/API/Subscribers.pm index b23ee197fc..c6b4afed1a 100644 --- a/lib/NGCP/Panel/Role/API/Subscribers.pm +++ b/lib/NGCP/Panel/Role/API/Subscribers.pm @@ -23,14 +23,14 @@ sub get_form { my ($self, $c) = @_; if($c->user->roles eq "admin" || $c->user->roles eq "reseller") { - return NGCP::Panel::Form::get("NGCP::Panel::Form::Subscriber::SubscriberAPI", $c); + return (NGCP::Panel::Form::get("NGCP::Panel::Form::Subscriber::SubscriberAPI", $c),[qw/customer_id/]); } elsif($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") { - return NGCP::Panel::Form::get("NGCP::Panel::Form::Subscriber::SubscriberSubAdminAPI", $c); + return (NGCP::Panel::Form::get("NGCP::Panel::Form::Subscriber::SubscriberSubAdminAPI", $c),[qw/customer_id/]); } } sub resource_from_item { - my ($self, $c, $item, $form) = @_; + my ($self, $c, $item, $form, $form_exceptions) = @_; my $pref; my $bill_resource = { $item->get_inflated_columns }; @@ -60,13 +60,14 @@ sub resource_from_item { $resource{email} = undef; $resource{timezone} = undef; } - - - $form //= $self->get_form($c); + if(!$form){ + ($form,$form_exceptions) = $self->get_form($c); + } last unless $self->validate_form( c => $c, resource => \%resource, form => $form, + exceptions => $form_exceptions, run => 0, ); @@ -153,7 +154,7 @@ sub resource_from_item { } sub hal_from_item { - my ($self, $c, $item, $resource, $form) = @_; + my ($self, $c, $item, $resource, $form, $form_exceptions) = @_; my $is_sub = 1; if($c->user->roles eq "admin" || $c->user->roles eq "reseller") { $is_sub = 0; @@ -362,11 +363,12 @@ sub prepare_resource { } } - my $form = $self->get_form($c); + my ($form,$form_exceptions) = $self->get_form($c); return unless $self->validate_form( c => $c, resource => $resource, form => $form, + exceptions => $form_exceptions, ); unless($domain) { @@ -594,7 +596,7 @@ sub prepare_resource { } sub update_item { - my ($self, $c, $schema, $item, $full_resource, $resource, $form) = @_; + my ($self, $c, $schema, $item, $full_resource, $resource, $form, $form_exceptions) = @_; if($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") { $self->error($c, HTTP_FORBIDDEN, "Read-only resource for authenticated role");