diff --git a/lib/NGCP/Panel/Form/Administrator/Admin.pm b/lib/NGCP/Panel/Form/Administrator/Admin.pm index 16edbdf4ea..6ebdb1ee96 100644 --- a/lib/NGCP/Panel/Form/Administrator/Admin.pm +++ b/lib/NGCP/Panel/Form/Administrator/Admin.pm @@ -8,6 +8,12 @@ has_field 'reseller' => ( type => '+NGCP::Panel::Field::Reseller', label => 'Reseller', validate_when_empty => 1, + element_attr => { + expand => { + class => 'NGCP::Panel::Role::API::Resellers', + id_field => 'reseller_id', + }, + }, ); has_block 'fields' => ( tag => 'div', diff --git a/lib/NGCP/Panel/Form/Contact/Admin.pm b/lib/NGCP/Panel/Form/Contact/Admin.pm index 93aea49033..cf22f6786e 100644 --- a/lib/NGCP/Panel/Form/Contact/Admin.pm +++ b/lib/NGCP/Panel/Form/Contact/Admin.pm @@ -8,7 +8,11 @@ has_field 'reseller' => ( validate_when_empty => 1, element_attr => { rel => ['tooltip'], - title => ['The reseller id this contact belongs to.'] + title => ['The reseller id this contact belongs to.'], + expand => { + class => 'NGCP::Panel::Role::API::Resellers', + id_field => 'reseller_id', + }, }, ); diff --git a/lib/NGCP/Panel/Form/Contract/BaseAPI.pm b/lib/NGCP/Panel/Form/Contract/BaseAPI.pm index b128486730..71275a1a45 100644 --- a/lib/NGCP/Panel/Form/Contract/BaseAPI.pm +++ b/lib/NGCP/Panel/Form/Contract/BaseAPI.pm @@ -8,7 +8,12 @@ has_field 'contact_id' => ( required => 1, element_attr => { rel => ['tooltip'], - title => ['The contact id this contract belongs to.'] + title => ['The contact id this contract belongs to.'], + expand => { + class => 'NGCP::Panel::Role::API::CustomerContacts', + id_field => 'contact_id', + alias => 'contact', + }, }, ); @@ -17,7 +22,12 @@ has_field 'billing_profile_id' => ( required => 0, element_attr => { rel => ['tooltip'], - title => ['The billing profile id used to charge this contract, which will become active immediately. This field is required if the profile definition mode is not defined or the \'id\' mode is used.'] + title => ['The billing profile id used to charge this contract, which will become active immediately. This field is required if the profile definition mode is not defined or the \'id\' mode is used.'], + expand => { + class => 'NGCP::Panel::Role::API::BillingProfiles', + id_field => 'billing_profile_id', + alias => 'billing_profile', + }, }, ); diff --git a/lib/NGCP/Panel/Form/Domain/Admin.pm b/lib/NGCP/Panel/Form/Domain/Admin.pm index 2a0e520736..87913ab21d 100644 --- a/lib/NGCP/Panel/Form/Domain/Admin.pm +++ b/lib/NGCP/Panel/Form/Domain/Admin.pm @@ -8,7 +8,11 @@ has_field 'reseller' => ( validate_when_empty => 1, element_attr => { rel => ['tooltip'], - title => ['The reseller id to assign this domain to.'] + title => ['The reseller id to assign this domain to.'], + expand => { + class => 'NGCP::Panel::Role::API::Resellers', + id_field => 'reseller_id', + }, }, ); diff --git a/lib/NGCP/Panel/Form/Reseller.pm b/lib/NGCP/Panel/Form/Reseller.pm index d98f86d891..1538929bb8 100644 --- a/lib/NGCP/Panel/Form/Reseller.pm +++ b/lib/NGCP/Panel/Form/Reseller.pm @@ -16,7 +16,11 @@ has_field 'contract' => ( validate_when_empty => 1, element_attr => { rel => ['tooltip'], - title => ['The contract used for this reseller.'] + title => ['The contract used for this reseller.'], + expand => { + class => 'NGCP::Panel::Role::API::Contracts', + id_field => 'contract_id', + }, }, ); diff --git a/lib/NGCP/Panel/Form/Subscriber.pm b/lib/NGCP/Panel/Form/Subscriber.pm index 514bd1587f..8cc5b9b2a2 100644 --- a/lib/NGCP/Panel/Form/Subscriber.pm +++ b/lib/NGCP/Panel/Form/Subscriber.pm @@ -91,6 +91,10 @@ has_field 'domain' => ( title => ['The domain name this subscriber belongs to.'], }, }, + expand => { + class => 'NGCP::Panel::Role::API::Domains', + id_field => 'domain_id', + }, }, ); diff --git a/lib/NGCP/Panel/Form/Subscriber/AutoAttendantAPI.pm b/lib/NGCP/Panel/Form/Subscriber/AutoAttendantAPI.pm index 4a69db8ff8..7c3ecab969 100644 --- a/lib/NGCP/Panel/Form/Subscriber/AutoAttendantAPI.pm +++ b/lib/NGCP/Panel/Form/Subscriber/AutoAttendantAPI.pm @@ -61,6 +61,14 @@ has_block 'fields' => ( has_field 'subscriber_id' => ( type => '+NGCP::Panel::Field::PosInteger', + element_attr => { + expand => { + class => 'NGCP::Panel::Role::API::Subscribers', + alias => 'subscriber', + id_field => 'subscriber_id', + remove_fields => [qw(password webpassword)], + }, + }, ); sub validate_slots_destination { diff --git a/lib/NGCP/Panel/Form/Subscriber/SubscriberAPI.pm b/lib/NGCP/Panel/Form/Subscriber/SubscriberAPI.pm index b9c0da82e9..bbb32825a2 100644 --- a/lib/NGCP/Panel/Form/Subscriber/SubscriberAPI.pm +++ b/lib/NGCP/Panel/Form/Subscriber/SubscriberAPI.pm @@ -12,7 +12,13 @@ has_field 'customer_id' => ( validate_when_empty => 1, element_attr => { rel => ['tooltip'], - title => ['The contract used for this subscriber.'] + title => ['The contract used for this subscriber.'], + expand => { + class => 'NGCP::Panel::Role::API::Customers', + alias => 'customer', + id_field => 'customer_id', + fetch => 0, + }, }, ); diff --git a/lib/NGCP/Panel/Role/API.pm b/lib/NGCP/Panel/Role/API.pm index 7f6d3e6452..1c867aa6bb 100644 --- a/lib/NGCP/Panel/Role/API.pm +++ b/lib/NGCP/Panel/Role/API.pm @@ -1272,10 +1272,57 @@ sub hal_from_item { } $resource->{id} = $self->get_item_id($c, $item); $resource = $self->post_process_hal_resource($c, $item, $resource, $form); + + $self->expand_fields($c, $resource); + $hal->resource({%$resource}); return $hal; } +sub expand_fields { + my ($self, $c, $resource) = @_; + + my $expand_param = $c->req->param('expand') // return 1; + my $all = $expand_param eq 'all' ? 1 : 0; + my @expand_fields = split /,/, $expand_param; + my @found_fields = (); + + my $resource_form = $self->get_form($c); + return unless $resource_form; + + foreach my $field ($resource_form->fields) { + my $attr = $field->element_attr; + my $expand = $attr->{expand} // next; + my $alias = $expand->{alias} // $field->name; + my $class = $expand->{class} // next; + my $id_field = $expand->{id_field} // next; + my $fetch = $expand->{fetch} // 0; + my $id = $resource->{$id_field} // next; + next unless $all || grep { /^$id_field$/ } @expand_fields; + my $form = $class->get_form($c) // next; + my $item = $class->item_by_id($c, $id) // next; + my $data = $class->resource_from_item($c, $item, $form); + $data = $class->post_process_hal_resource($c, $item, $data, $form); + push @found_fields, $id_field; + if (my $remove_fields = $expand->{remove_fields}) { + delete @{$data}{@{$remove_fields}}; + } + if ($fetch && $data->{$id_field}) { + $resource->{$alias} = $data->{$id_field}; + } else { + $resource->{$alias} = $data; + } + } + + unless ($all || $#expand_fields == $#found_fields) { + $c->log->debug("Provided expand fields are invalid"); + $self->error($c, HTTP_CONFLICT, "Provided expand fields are invalid"); + return; + } + + return 1; +} + sub get_mandatory_params { my ($self, $c, $href_type, $item, $resource, $params) = @_; #href type - item or collection diff --git a/lib/NGCP/Panel/Role/API/AutoAttendants.pm b/lib/NGCP/Panel/Role/API/AutoAttendants.pm index 35f59a23c9..02ff077d4a 100644 --- a/lib/NGCP/Panel/Role/API/AutoAttendants.pm +++ b/lib/NGCP/Panel/Role/API/AutoAttendants.pm @@ -18,12 +18,28 @@ sub get_form { return NGCP::Panel::Form::get("NGCP::Panel::Form::Subscriber::AutoAttendantAPI", $c); } -sub hal_from_item { - my ($self, $c, $item) = @_; +sub resource_from_item { + my ($self, $c, $item, $form) = @_; my $p_subs = $item->provisioning_voip_subscriber; my $resource = { subscriber_id => $item->id, slots => $self->_autoattendants_from_subscriber($p_subs) }; + $form //= $self->get_form($c); + return unless $self->validate_form( + c => $c, + form => $form, + resource => $resource, + run => 0, + ); + + return $resource; +} + +sub hal_from_item { + my ($self, $c, $item) = @_; + + my $resource = $self->resource_from_item($c, $item); + my $hal = Data::HAL->new( links => [ Data::HAL::Link->new( @@ -42,22 +58,7 @@ sub hal_from_item { relation => 'ngcp:'.$self->resource_name, ); - my $form = $self->get_form($c); - return unless $self->validate_form( - c => $c, - form => $form, - resource => $resource, - run => 0, - ); - - if ($c->req->param('expand') && is_int($c->req->param('expand')) && $c->req->param('expand') == 1) { - my $subscriber_form = NGCP::Panel::Role::API::Subscribers->get_form($c); - $resource->{subscriber} = NGCP::Panel::Role::API::Subscribers->resource_from_item($c, $item, $subscriber_form); - #don't show passwords here - delete $resource->{subscriber}->{webpassword}; - delete $resource->{subscriber}->{password}; - } - + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/BalanceIntervals.pm b/lib/NGCP/Panel/Role/API/BalanceIntervals.pm index 13ce544d08..6f4c4c4598 100644 --- a/lib/NGCP/Panel/Role/API/BalanceIntervals.pm +++ b/lib/NGCP/Panel/Role/API/BalanceIntervals.pm @@ -135,6 +135,7 @@ sub hal_from_balance { ); #$resource{id} = int($item->contract->id); + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/BillingFees.pm b/lib/NGCP/Panel/Role/API/BillingFees.pm index c957fb5c03..e1491f2544 100644 --- a/lib/NGCP/Panel/Role/API/BillingFees.pm +++ b/lib/NGCP/Panel/Role/API/BillingFees.pm @@ -71,6 +71,8 @@ sub hal_from_fee { $resource{id} = int($fee->id); $resource{billing_profile_id} = int($fee->billing_profile_id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/BillingNetworks.pm b/lib/NGCP/Panel/Role/API/BillingNetworks.pm index 7e7c5b5f73..9006da7585 100644 --- a/lib/NGCP/Panel/Role/API/BillingNetworks.pm +++ b/lib/NGCP/Panel/Role/API/BillingNetworks.pm @@ -61,6 +61,8 @@ sub hal_from_item { resource => \%resource, run => 0, ); + + $self->expand_fields($c, \%resource); $hal->resource(\%resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/BillingProfiles.pm b/lib/NGCP/Panel/Role/API/BillingProfiles.pm index 726c5a061a..45de5a49d1 100644 --- a/lib/NGCP/Panel/Role/API/BillingProfiles.pm +++ b/lib/NGCP/Panel/Role/API/BillingProfiles.pm @@ -91,6 +91,7 @@ sub hal_from_item { relation => 'ngcp:'.$self->resource_name, ); + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/BillingZones.pm b/lib/NGCP/Panel/Role/API/BillingZones.pm index 36a9fd2679..8df19ec377 100644 --- a/lib/NGCP/Panel/Role/API/BillingZones.pm +++ b/lib/NGCP/Panel/Role/API/BillingZones.pm @@ -72,6 +72,8 @@ sub hal_from_zone { $resource{id} = int($zone->id); $resource{billing_profile_id} = int($zone->billing_profile_id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/CCMapEntries.pm b/lib/NGCP/Panel/Role/API/CCMapEntries.pm index 941b046d84..33bf4d811d 100644 --- a/lib/NGCP/Panel/Role/API/CCMapEntries.pm +++ b/lib/NGCP/Panel/Role/API/CCMapEntries.pm @@ -61,6 +61,7 @@ sub hal_from_item { run => 0, ); + $self->expand_fields($c, \%resource); $hal->resource(\%resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/CFDestinationSets.pm b/lib/NGCP/Panel/Role/API/CFDestinationSets.pm index d9a791db4f..846548e5da 100644 --- a/lib/NGCP/Panel/Role/API/CFDestinationSets.pm +++ b/lib/NGCP/Panel/Role/API/CFDestinationSets.pm @@ -73,6 +73,8 @@ sub hal_from_item { resource => \%resource, run => 0, ); + + $self->expand_fields($c, \%resource); $hal->resource(\%resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/CFMappings.pm b/lib/NGCP/Panel/Role/API/CFMappings.pm index 01671be228..f306babae9 100644 --- a/lib/NGCP/Panel/Role/API/CFMappings.pm +++ b/lib/NGCP/Panel/Role/API/CFMappings.pm @@ -96,6 +96,8 @@ sub hal_from_item { ); $resource->{cft_ringtimeout} = $ringtimeout_preference; $resource->{id} = int($item->id); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/CFSourceSets.pm b/lib/NGCP/Panel/Role/API/CFSourceSets.pm index 7a9384fb77..615d89ffe7 100644 --- a/lib/NGCP/Panel/Role/API/CFSourceSets.pm +++ b/lib/NGCP/Panel/Role/API/CFSourceSets.pm @@ -65,6 +65,8 @@ sub hal_from_item { resource => \%resource, run => 0, ); + + $self->expand_fields($c, \%resource); $hal->resource(\%resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/CFTimeSets.pm b/lib/NGCP/Panel/Role/API/CFTimeSets.pm index b11af424a3..805d311463 100644 --- a/lib/NGCP/Panel/Role/API/CFTimeSets.pm +++ b/lib/NGCP/Panel/Role/API/CFTimeSets.pm @@ -342,6 +342,8 @@ sub hal_from_item { resource => \%resource, run => 0, ); + + $self->expand_fields($c, \%resource); $hal->resource(\%resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/CallForwards.pm b/lib/NGCP/Panel/Role/API/CallForwards.pm index d61a36005f..fb65dabe59 100644 --- a/lib/NGCP/Panel/Role/API/CallForwards.pm +++ b/lib/NGCP/Panel/Role/API/CallForwards.pm @@ -79,6 +79,7 @@ sub hal_from_item { } } + $self->expand_fields($c, \%resource); $hal->resource(\%resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/CallQueues.pm b/lib/NGCP/Panel/Role/API/CallQueues.pm index b3b33ca34a..98ae766a5d 100644 --- a/lib/NGCP/Panel/Role/API/CallQueues.pm +++ b/lib/NGCP/Panel/Role/API/CallQueues.pm @@ -146,6 +146,8 @@ sub hal_from_item { ); my $resource = $self->resource_from_item($c, $item, $form); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/CallRecordingStreams.pm b/lib/NGCP/Panel/Role/API/CallRecordingStreams.pm index 31ec32bc56..e573b9b6de 100644 --- a/lib/NGCP/Panel/Role/API/CallRecordingStreams.pm +++ b/lib/NGCP/Panel/Role/API/CallRecordingStreams.pm @@ -94,6 +94,8 @@ sub hal_from_item { ); my $resource = $self->resource_from_item($c, $item, $form); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/Calls.pm b/lib/NGCP/Panel/Role/API/Calls.pm index 2cba0f2c38..d38f792ef5 100644 --- a/lib/NGCP/Panel/Role/API/Calls.pm +++ b/lib/NGCP/Panel/Role/API/Calls.pm @@ -67,6 +67,8 @@ sub hal_from_item { ); $resource->{id} = int($item->id); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/Contracts.pm b/lib/NGCP/Panel/Role/API/Contracts.pm index 587ebcd5f8..b3a612920b 100644 --- a/lib/NGCP/Panel/Role/API/Contracts.pm +++ b/lib/NGCP/Panel/Role/API/Contracts.pm @@ -37,20 +37,45 @@ sub get_form { return NGCP::Panel::Form::get("NGCP::Panel::Form::Contract::ContractAPI", $c); } -sub hal_from_contract { - my ($self, $c, $contract, $form, $now) = @_; +sub resource_from_item { + my ($self, $c, $item, $form, $now) = @_; - my $billing_mapping = NGCP::Panel::Utils::BillingMappings::get_actual_billing_mapping(c => $c, now => $now, contract => $contract, ); + my %resource = $item->get_inflated_columns; + + $now //= NGCP::Panel::Utils::DateTime::current_local; + my $billing_mapping = NGCP::Panel::Utils::BillingMappings::get_actual_billing_mapping(c => $c, now => $now, contract => $item, ); my $billing_profile_id = $billing_mapping->billing_profile->id; - my $future_billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_future_mappings($contract); - my $billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_mappings($contract); + my $future_billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_future_mappings($item); + my $billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_mappings($item); #contract balances are created with GET api/contracts/4711 NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c, - contract => $contract, + contract => $item, now => $now); - my %resource = $contract->get_inflated_columns; + $form //= $self->get_form($c); + return unless $self->validate_form( + c => $c, + form => $form, + resource => \%resource, + run => 0, + ); + + $resource{type} = $item->product->class; + $resource{billing_profiles} = $future_billing_profiles; + $resource{all_billing_profiles} = $billing_profiles; + + $resource{id} = int($item->id); + $resource{billing_profile_id} = $billing_profile_id ? int($billing_profile_id) : undef; + $resource{billing_profile_definition} = 'id'; + + return \%resource; +} + +sub hal_from_contract { + my ($self, $c, $contract, $form, $now) = @_; + + my $resource = $self->resource_from_item($c, $contract, $form, $now); my @profile_links = (); my @network_links = (); @@ -81,22 +106,8 @@ sub hal_from_contract { relation => 'ngcp:'.$self->resource_name, ); - $form //= $self->get_form($c); - return unless $self->validate_form( - c => $c, - form => $form, - resource => \%resource, - run => 0, - ); - - $resource{type} = $contract->product->class; - $resource{billing_profiles} = $future_billing_profiles; - $resource{all_billing_profiles} = $billing_profiles; - - $resource{id} = int($contract->id); - $resource{billing_profile_id} = $billing_profile_id ? int($billing_profile_id) : undef; - $resource{billing_profile_definition} = 'id'; - $hal->resource({%resource}); + $self->expand_fields($c, $resource); + $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/CustomerBalances.pm b/lib/NGCP/Panel/Role/API/CustomerBalances.pm index 0b27e50e6b..fd0053220b 100644 --- a/lib/NGCP/Panel/Role/API/CustomerBalances.pm +++ b/lib/NGCP/Panel/Role/API/CustomerBalances.pm @@ -74,6 +74,8 @@ sub hal_from_item { ); $resource->{id} = int($item->contract->id); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/CustomerContacts.pm b/lib/NGCP/Panel/Role/API/CustomerContacts.pm index 43ae963ffe..bfb5869b9c 100644 --- a/lib/NGCP/Panel/Role/API/CustomerContacts.pm +++ b/lib/NGCP/Panel/Role/API/CustomerContacts.pm @@ -40,9 +40,33 @@ sub get_form { } } +sub resource_from_item { + my ($self, $c, $item, $form) = @_; + + my %resource = $item->get_inflated_columns; + + $resource{country}{id} = delete $resource{country}; + $resource{timezone}{name} = delete $resource{timezone}; + + $form //= $self->get_form($c); + $self->validate_form( + c => $c, + resource => \%resource, + form => $form, + run => 0, + ); + + $resource{id} = int($item->id); + $resource{country} = $resource{country}{id}; + $resource{timezone} = $resource{timezone}{name}; + + return \%resource; +} + sub hal_from_contact { my ($self, $c, $contact, $form) = @_; - my %resource = $contact->get_inflated_columns; + + my $resource = $self->resource_from_item($c, $contact, $form); my $hal = Data::HAL->new( links => [ @@ -60,20 +84,8 @@ sub hal_from_contact { relation => 'ngcp:'.$self->resource_name, ); - $resource{country}{id} = delete $resource{country}; - $resource{timezone}{name} = delete $resource{timezone}; - $form //= $self->get_form($c); - $self->validate_form( - c => $c, - resource => \%resource, - form => $form, - run => 0, - ); - $resource{country} = $resource{country}{id}; - $resource{timezone} = $resource{timezone}{name}; - - $resource{id} = int($contact->id); - $hal->resource({%resource}); + $self->expand_fields($c, $resource); + $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/CustomerFraudPreferences.pm b/lib/NGCP/Panel/Role/API/CustomerFraudPreferences.pm index 084293dec6..bb58d25d10 100644 --- a/lib/NGCP/Panel/Role/API/CustomerFraudPreferences.pm +++ b/lib/NGCP/Panel/Role/API/CustomerFraudPreferences.pm @@ -48,6 +48,7 @@ sub hal_from_item { run => 0, ); + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/CustomerLocations.pm b/lib/NGCP/Panel/Role/API/CustomerLocations.pm index de9d9827c8..6b14fb43cd 100644 --- a/lib/NGCP/Panel/Role/API/CustomerLocations.pm +++ b/lib/NGCP/Panel/Role/API/CustomerLocations.pm @@ -60,6 +60,8 @@ sub hal_from_item { resource => \%resource, run => 0, ); + + $self->expand_fields($c, \%resource); $hal->resource(\%resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/CustomerZoneCosts.pm b/lib/NGCP/Panel/Role/API/CustomerZoneCosts.pm index a692272303..a5b3471d08 100644 --- a/lib/NGCP/Panel/Role/API/CustomerZoneCosts.pm +++ b/lib/NGCP/Panel/Role/API/CustomerZoneCosts.pm @@ -51,6 +51,8 @@ sub hal_from_item { my $resource = $self->resource_from_item($c, $item); return unless $resource; + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/Customers.pm b/lib/NGCP/Panel/Role/API/Customers.pm index 14ddae7325..131f050317 100644 --- a/lib/NGCP/Panel/Role/API/Customers.pm +++ b/lib/NGCP/Panel/Role/API/Customers.pm @@ -34,6 +34,46 @@ sub get_form { return NGCP::Panel::Form::get("NGCP::Panel::Form::Contract::CustomerAPI", $c); } +sub resource_from_item { + my ($self, $c, $item, $form, $now) = @_; + + my %resource = $item->get_inflated_columns; + + $now //= NGCP::Panel::Utils::DateTime::current_local; + my $billing_mapping = NGCP::Panel::Utils::BillingMappings::get_actual_billing_mapping(c => $c, now => $now, contract => $item); + my $billing_profile_id = $billing_mapping->billing_profile->id; + my $future_billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_future_mappings($item); + my $billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_mappings($item); + + NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c, + contract => $item, + now => $now); + + $form //= $self->get_form($c); + return unless $self->validate_form( + c => $c, + form => $form, + resource => \%resource, + run => 0, + ); + + foreach my $field (qw/create_timestamp activate_timestamp modify_timestamp terminate_timestamp/) { + $resource{$field} = defined $resource{$field} + ? NGCP::Panel::Utils::DateTime::to_string(NGCP::Panel::Utils::DateTime::from_string($resource{$field})) + : undef; + } + # return the virtual "type" instead of the actual product id + $resource{type} = $item->product->class; #$billing_mapping->product->class; + $resource{billing_profiles} = $future_billing_profiles; + $resource{all_billing_profiles} = $billing_profiles; + + $resource{id} = int($item->id); + $resource{billing_profile_id} = int($billing_profile_id); + $resource{billing_profile_definition} = 'id'; + + return \%resource; +} + sub hal_from_customer { my ($self, $c, $customer, $form, $now) = @_; @@ -43,16 +83,7 @@ sub hal_from_customer { $is_adm = 1; } - my $billing_mapping = NGCP::Panel::Utils::BillingMappings::get_actual_billing_mapping(c => $c, now => $now, contract => $customer, ); - my $billing_profile_id = $billing_mapping->billing_profile->id; - my $future_billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_future_mappings($customer); - my $billing_profiles = NGCP::Panel::Utils::BillingMappings::resource_from_mappings($customer); - - NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c, - contract => $customer, - now => $now); - - my %resource = $customer->get_inflated_columns; + my $resource = $self->resource_from_item($c, $customer, $form, $now); my @profile_links = (); my @network_links = (); @@ -96,26 +127,8 @@ sub hal_from_customer { relation => 'ngcp:'.$self->resource_name, ); - $form //= $self->get_form($c); - return unless $self->validate_form( - c => $c, - form => $form, - resource => \%resource, - run => 0, - ); - - foreach my $field (qw/create_timestamp activate_timestamp modify_timestamp terminate_timestamp/){ - $resource{$field} = defined $resource{$field} ? NGCP::Panel::Utils::DateTime::to_string(NGCP::Panel::Utils::DateTime::from_string($resource{$field})) : undef ; - } - # return the virtual "type" instead of the actual product id - $resource{type} = $customer->product->class; #$billing_mapping->product->class; - $resource{billing_profiles} = $future_billing_profiles; - $resource{all_billing_profiles} = $billing_profiles; - - $resource{id} = int($customer->id); - $resource{billing_profile_id} = int($billing_profile_id); - $resource{billing_profile_definition} = 'id'; - $hal->resource({%resource}); + $self->expand_fields($c, $resource); + $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/Domains.pm b/lib/NGCP/Panel/Role/API/Domains.pm index ab58399976..d0706ce6af 100644 --- a/lib/NGCP/Panel/Role/API/Domains.pm +++ b/lib/NGCP/Panel/Role/API/Domains.pm @@ -22,10 +22,34 @@ sub get_form { return; } -sub hal_from_item { +sub resource_from_item { my ($self, $c, $item, $form) = @_; + my %resource = $item->get_inflated_columns; + $form //= $self->get_form($c); + + $self->validate_form( + c => $c, + resource => \%resource, + form => $form, + run => 0, + ); + + $resource{id} = int($item->id); + + if ($c->user->roles eq "admin" && $item->domain_resellers->first) { + $resource{reseller_id} = int($item->domain_resellers->first->reseller_id) + } + + return \%resource; +} + +sub hal_from_item { + my ($self, $c, $item, $form) = @_; + + my $resource = $self->resource_from_item($c, $item, $form); + my $hal = Data::HAL->new( links => [ Data::HAL::Link->new( @@ -44,73 +68,8 @@ sub hal_from_item { relation => 'ngcp:'.$self->resource_name, ); - $form //= $self->get_form($c); - - $self->validate_form( - c => $c, - resource => \%resource, - form => $form, - run => 0, - ); - - $resource{id} = int($item->id); - if($c->user->roles eq "admin") { - $resource{reseller_id} = - int($item->domain_resellers->first->reseller_id) - if($item->domain_resellers->first); - } elsif($c->user->roles eq "reseller") { - } - -=pod - # TODO: do we really want to provide this info, as you can't actually - # PUT/PATCH/POST it? Or should you? - $resource{preferences} = {}; - foreach my $pref($item->provisioning_voip_domain->voip_dom_preferences->all) { - next if($pref->attribute->internal); - my $plain = { "boolean" => 1, "int" => 1, "string" => 1 }; - if(exists $plain->{$pref->attribute->data_type}) { - # plain key/value pairs - my $value; - SWITCH: for ($pref->attribute->data_type) { - /^int$/ && do { - $value = int($pref->value); - last SWITCH; - }; - /^boolean$/ && do { - $value = JSON::Types::bool($pref->value); - last SWITCH; - }; - # default - $value = $pref->value; - } # SWITCH - if($pref->attribute->max_occur != 1) { - $resource{preferences}{$pref->attribute->attribute} = $value; - } else { - $resource{preferences}{$pref->attribute->attribute} = [] - unless(exists $resource{preferences}{$pref->attribute->attribute}); - push @{ $resource{preferences}{$pref->attribute->attribute} }, $value; - } - } else { - # enum mappings - my $value; - SWITCH: for ($pref->attribute->data_type) { - /^int$/ && do { - $value = int($pref->value); - last SWITCH; - }; - /^boolean$/ && do { - $value = JSON::Types::bool($pref->value); - last SWITCH; - }; - # default - $value = $pref->value; - } # SWITCH - $resource{preferences}{$pref->attribute->attribute} = $value; - } - } -=cut - - $hal->resource({%resource}); + $self->expand_fields($c, $resource); + $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/EmailTemplates.pm b/lib/NGCP/Panel/Role/API/EmailTemplates.pm index 9dadde7e28..b0cb6bddd7 100644 --- a/lib/NGCP/Panel/Role/API/EmailTemplates.pm +++ b/lib/NGCP/Panel/Role/API/EmailTemplates.pm @@ -61,6 +61,8 @@ sub hal_from_item { ); $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/EmergencyMappingContainers.pm b/lib/NGCP/Panel/Role/API/EmergencyMappingContainers.pm index 8fb2d3f32f..2bdaaf0836 100644 --- a/lib/NGCP/Panel/Role/API/EmergencyMappingContainers.pm +++ b/lib/NGCP/Panel/Role/API/EmergencyMappingContainers.pm @@ -66,6 +66,8 @@ sub hal_from_item { ); $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/EmergencyMappings.pm b/lib/NGCP/Panel/Role/API/EmergencyMappings.pm index 72fb0bbd28..9b700983fa 100644 --- a/lib/NGCP/Panel/Role/API/EmergencyMappings.pm +++ b/lib/NGCP/Panel/Role/API/EmergencyMappings.pm @@ -60,6 +60,8 @@ sub hal_from_item { ); $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/Events.pm b/lib/NGCP/Panel/Role/API/Events.pm index de6597bbfa..90e0a508ca 100644 --- a/lib/NGCP/Panel/Role/API/Events.pm +++ b/lib/NGCP/Panel/Role/API/Events.pm @@ -107,6 +107,8 @@ sub hal_from_item { ); $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/Interceptions.pm b/lib/NGCP/Panel/Role/API/Interceptions.pm index 8117528c7b..ff1c23d2ed 100644 --- a/lib/NGCP/Panel/Role/API/Interceptions.pm +++ b/lib/NGCP/Panel/Role/API/Interceptions.pm @@ -53,6 +53,8 @@ sub hal_from_item { ); $resource->{id} = int($item->id); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/InvoiceTemplates.pm b/lib/NGCP/Panel/Role/API/InvoiceTemplates.pm index 478f81e509..786fdb341a 100644 --- a/lib/NGCP/Panel/Role/API/InvoiceTemplates.pm +++ b/lib/NGCP/Panel/Role/API/InvoiceTemplates.pm @@ -61,6 +61,8 @@ sub hal_from_item { ); $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/LnpCarriers.pm b/lib/NGCP/Panel/Role/API/LnpCarriers.pm index 9ddaa6127b..07151a96f2 100644 --- a/lib/NGCP/Panel/Role/API/LnpCarriers.pm +++ b/lib/NGCP/Panel/Role/API/LnpCarriers.pm @@ -53,6 +53,8 @@ sub hal_from_item { ); $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/MailToFaxSettings.pm b/lib/NGCP/Panel/Role/API/MailToFaxSettings.pm index 1b73856292..0ed071fe29 100644 --- a/lib/NGCP/Panel/Role/API/MailToFaxSettings.pm +++ b/lib/NGCP/Panel/Role/API/MailToFaxSettings.pm @@ -86,7 +86,9 @@ sub hal_from_item { resource => \%resource, run => 0, ); + $self->post_process_hal_resource($c, $item, \%resource, $form); + $self->expand_fields($c, \%resource); $hal->resource(\%resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/MaliciousCalls.pm b/lib/NGCP/Panel/Role/API/MaliciousCalls.pm index 837302140f..082dcd18ae 100644 --- a/lib/NGCP/Panel/Role/API/MaliciousCalls.pm +++ b/lib/NGCP/Panel/Role/API/MaliciousCalls.pm @@ -65,6 +65,8 @@ sub hal_from_item { ); $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/ManagerSecretary.pm b/lib/NGCP/Panel/Role/API/ManagerSecretary.pm index dc308608da..64f1112089 100644 --- a/lib/NGCP/Panel/Role/API/ManagerSecretary.pm +++ b/lib/NGCP/Panel/Role/API/ManagerSecretary.pm @@ -74,6 +74,7 @@ sub hal_from_item { run => 0, ); + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/NcosLevels.pm b/lib/NGCP/Panel/Role/API/NcosLevels.pm index 3c43f3f6cc..6c635b3766 100644 --- a/lib/NGCP/Panel/Role/API/NcosLevels.pm +++ b/lib/NGCP/Panel/Role/API/NcosLevels.pm @@ -62,6 +62,8 @@ sub hal_from_item { ); $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/NcosLnpCarriers.pm b/lib/NGCP/Panel/Role/API/NcosLnpCarriers.pm index 4b8814ec3a..bd01a2be3e 100644 --- a/lib/NGCP/Panel/Role/API/NcosLnpCarriers.pm +++ b/lib/NGCP/Panel/Role/API/NcosLnpCarriers.pm @@ -55,6 +55,8 @@ sub hal_from_item { $resource{id} = int($item->id); $resource{carrier_id} = int($item->lnp_provider_id); delete $resource{lnp_provider_id}; + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/PbxDeviceConfigs.pm b/lib/NGCP/Panel/Role/API/PbxDeviceConfigs.pm index ee4d99f796..38b6f47508 100644 --- a/lib/NGCP/Panel/Role/API/PbxDeviceConfigs.pm +++ b/lib/NGCP/Panel/Role/API/PbxDeviceConfigs.pm @@ -64,6 +64,8 @@ sub hal_from_item { $resource->{id} = int($item->id); delete $resource->{data}; + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/PbxDeviceFirmwares.pm b/lib/NGCP/Panel/Role/API/PbxDeviceFirmwares.pm index ed6ad441f5..2bff283137 100644 --- a/lib/NGCP/Panel/Role/API/PbxDeviceFirmwares.pm +++ b/lib/NGCP/Panel/Role/API/PbxDeviceFirmwares.pm @@ -63,6 +63,8 @@ sub hal_from_item { ); $resource->{id} = int($item->id); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/PbxDeviceProfiles.pm b/lib/NGCP/Panel/Role/API/PbxDeviceProfiles.pm index bdf3685bf7..bfc916e606 100644 --- a/lib/NGCP/Panel/Role/API/PbxDeviceProfiles.pm +++ b/lib/NGCP/Panel/Role/API/PbxDeviceProfiles.pm @@ -41,6 +41,8 @@ sub hal_from_item { ); my $resource = $self->resource_from_item($c, $item); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/PbxDevices.pm b/lib/NGCP/Panel/Role/API/PbxDevices.pm index 6dee408339..6c1a19a4a6 100644 --- a/lib/NGCP/Panel/Role/API/PbxDevices.pm +++ b/lib/NGCP/Panel/Role/API/PbxDevices.pm @@ -41,6 +41,7 @@ sub hal_from_item { ); my $resource = $self->resource_from_item($c, $item); + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/PeeringGroups.pm b/lib/NGCP/Panel/Role/API/PeeringGroups.pm index fc61adb2b8..683d2ead14 100644 --- a/lib/NGCP/Panel/Role/API/PeeringGroups.pm +++ b/lib/NGCP/Panel/Role/API/PeeringGroups.pm @@ -59,6 +59,8 @@ sub hal_from_item { ); $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/PeeringInboundRules.pm b/lib/NGCP/Panel/Role/API/PeeringInboundRules.pm index 1c3763967b..ca75402ec6 100644 --- a/lib/NGCP/Panel/Role/API/PeeringInboundRules.pm +++ b/lib/NGCP/Panel/Role/API/PeeringInboundRules.pm @@ -53,6 +53,8 @@ sub hal_from_item { ); $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/PeeringRules.pm b/lib/NGCP/Panel/Role/API/PeeringRules.pm index fa681a0124..b2a752dd7d 100644 --- a/lib/NGCP/Panel/Role/API/PeeringRules.pm +++ b/lib/NGCP/Panel/Role/API/PeeringRules.pm @@ -53,6 +53,8 @@ sub hal_from_item { ); $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/PeeringServers.pm b/lib/NGCP/Panel/Role/API/PeeringServers.pm index 7d1fa8a0ed..2db3ecb67a 100644 --- a/lib/NGCP/Panel/Role/API/PeeringServers.pm +++ b/lib/NGCP/Panel/Role/API/PeeringServers.pm @@ -53,6 +53,8 @@ sub hal_from_item { ); $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/Preferences.pm b/lib/NGCP/Panel/Role/API/Preferences.pm index 1a2a93d25a..a9d98c186e 100644 --- a/lib/NGCP/Panel/Role/API/Preferences.pm +++ b/lib/NGCP/Panel/Role/API/Preferences.pm @@ -45,6 +45,8 @@ sub hal_from_item { ); my $resource = $self->get_resource($c, $item, $type); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/ProfilePackages.pm b/lib/NGCP/Panel/Role/API/ProfilePackages.pm index b5dbfac502..b8fefeffe8 100644 --- a/lib/NGCP/Panel/Role/API/ProfilePackages.pm +++ b/lib/NGCP/Panel/Role/API/ProfilePackages.pm @@ -81,6 +81,8 @@ sub hal_from_item { resource => \%resource, run => 0, ); + + $self->expand_fields($c, \%resource); $hal->resource(\%resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/Reminders.pm b/lib/NGCP/Panel/Role/API/Reminders.pm index dc633b02d9..aa2cf6fa7a 100644 --- a/lib/NGCP/Panel/Role/API/Reminders.pm +++ b/lib/NGCP/Panel/Role/API/Reminders.pm @@ -87,6 +87,8 @@ sub hal_from_item { ); $resource->{id} = int($item->id); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/Resellers.pm b/lib/NGCP/Panel/Role/API/Resellers.pm index 03b4ef6d5b..4c0df00c1e 100644 --- a/lib/NGCP/Panel/Role/API/Resellers.pm +++ b/lib/NGCP/Panel/Role/API/Resellers.pm @@ -25,15 +25,30 @@ sub get_form { return NGCP::Panel::Form::get("NGCP::Panel::Form::ResellerAPI", $c); } +sub resource_from_item { + my ($self, $c, $item, $form) = @_; + + my %resource = $item->get_inflated_columns; + + $resource{enable_rtc} = $item->rtc_user ? JSON::true : JSON::false; + + $form //= $self->get_form($c); + return unless $self->validate_form( + c => $c, + form => $form, + resource => \%resource, + run => 0, + ); + + $resource{id} = int($item->id); + + return \%resource; +} + sub hal_from_reseller { my ($self, $c, $reseller, $form) = @_; - my %resource = $reseller->get_inflated_columns; - if ($reseller->rtc_user) { - $resource{enable_rtc} = JSON::true; - } else { - $resource{enable_rtc} = JSON::false; - } + my $resource = $self->resource_from_item($c, $reseller, $form); # TODO: we should return the relations in embedded fields, # if the structure is returned for one single item @@ -61,16 +76,8 @@ sub hal_from_reseller { relation => 'ngcp:'.$self->resource_name, ); - $form //= $self->get_form($c); - return unless $self->validate_form( - c => $c, - form => $form, - resource => \%resource, - run => 0, - ); - - $resource{id} = int($reseller->id); - $hal->resource({%resource}); + $self->expand_fields($c, $resource); + $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/RtcApps.pm b/lib/NGCP/Panel/Role/API/RtcApps.pm index 3241854c33..beb8f87b2d 100644 --- a/lib/NGCP/Panel/Role/API/RtcApps.pm +++ b/lib/NGCP/Panel/Role/API/RtcApps.pm @@ -70,6 +70,7 @@ sub hal_from_item { ); } + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/RtcNetworks.pm b/lib/NGCP/Panel/Role/API/RtcNetworks.pm index 6530362202..62274fc09f 100644 --- a/lib/NGCP/Panel/Role/API/RtcNetworks.pm +++ b/lib/NGCP/Panel/Role/API/RtcNetworks.pm @@ -70,6 +70,7 @@ sub hal_from_item { ); } + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/RtcSessions.pm b/lib/NGCP/Panel/Role/API/RtcSessions.pm index 38c3be1b2f..ad565229b9 100644 --- a/lib/NGCP/Panel/Role/API/RtcSessions.pm +++ b/lib/NGCP/Panel/Role/API/RtcSessions.pm @@ -64,6 +64,7 @@ sub hal_from_item { relation => 'ngcp:'.$self->resource_name, ); + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/SoundFiles.pm b/lib/NGCP/Panel/Role/API/SoundFiles.pm index 6af87a0a33..4a59778293 100644 --- a/lib/NGCP/Panel/Role/API/SoundFiles.pm +++ b/lib/NGCP/Panel/Role/API/SoundFiles.pm @@ -98,6 +98,8 @@ sub hal_from_item { ); $resource->{id} = int($item->id); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/SpeedDials.pm b/lib/NGCP/Panel/Role/API/SpeedDials.pm index 2a9acf19ff..c99d42c494 100644 --- a/lib/NGCP/Panel/Role/API/SpeedDials.pm +++ b/lib/NGCP/Panel/Role/API/SpeedDials.pm @@ -54,6 +54,7 @@ sub hal_from_item { run => 0, ); + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/SubscriberLocationMappings.pm b/lib/NGCP/Panel/Role/API/SubscriberLocationMappings.pm index 4f8c3d280c..6530cf5e94 100644 --- a/lib/NGCP/Panel/Role/API/SubscriberLocationMappings.pm +++ b/lib/NGCP/Panel/Role/API/SubscriberLocationMappings.pm @@ -62,6 +62,8 @@ sub hal_from_item { ); $resource->{id} = int($item->id); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/SubscriberProfileSets.pm b/lib/NGCP/Panel/Role/API/SubscriberProfileSets.pm index 0ec52154a9..e531b09074 100644 --- a/lib/NGCP/Panel/Role/API/SubscriberProfileSets.pm +++ b/lib/NGCP/Panel/Role/API/SubscriberProfileSets.pm @@ -62,6 +62,8 @@ sub hal_from_item { ); $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/SubscriberProfiles.pm b/lib/NGCP/Panel/Role/API/SubscriberProfiles.pm index 46e78caf39..916279221e 100644 --- a/lib/NGCP/Panel/Role/API/SubscriberProfiles.pm +++ b/lib/NGCP/Panel/Role/API/SubscriberProfiles.pm @@ -64,6 +64,8 @@ sub hal_from_item { $resource->{attributes} = delete $resource->{attribute}; $resource->{id} = int($item->id); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/SubscriberRegistrations.pm b/lib/NGCP/Panel/Role/API/SubscriberRegistrations.pm index 0bbd19d627..4879086340 100644 --- a/lib/NGCP/Panel/Role/API/SubscriberRegistrations.pm +++ b/lib/NGCP/Panel/Role/API/SubscriberRegistrations.pm @@ -166,6 +166,7 @@ sub hal_from_item { $resource->{id} = ($item->id =~ /^\d+$/) ? int($item->id) : $item->id; + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/Subscribers.pm b/lib/NGCP/Panel/Role/API/Subscribers.pm index bab4d43ffc..2465a84896 100644 --- a/lib/NGCP/Panel/Role/API/Subscribers.pm +++ b/lib/NGCP/Panel/Role/API/Subscribers.pm @@ -266,6 +266,7 @@ sub hal_from_item { relation => 'ngcp:'.$self->resource_name, ); + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/SystemContacts.pm b/lib/NGCP/Panel/Role/API/SystemContacts.pm index 10e021612b..cd6ed5d9be 100644 --- a/lib/NGCP/Panel/Role/API/SystemContacts.pm +++ b/lib/NGCP/Panel/Role/API/SystemContacts.pm @@ -64,6 +64,8 @@ sub hal_from_contact { $resource{timezone} = $resource{timezone}{name}; $resource{id} = int($contact->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/TopupLogs.pm b/lib/NGCP/Panel/Role/API/TopupLogs.pm index 947d68adf3..4b9cea79e1 100644 --- a/lib/NGCP/Panel/Role/API/TopupLogs.pm +++ b/lib/NGCP/Panel/Role/API/TopupLogs.pm @@ -81,6 +81,8 @@ sub hal_from_item { ); $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/TrustedSources.pm b/lib/NGCP/Panel/Role/API/TrustedSources.pm index b141504ea6..d1c6e9f0fc 100644 --- a/lib/NGCP/Panel/Role/API/TrustedSources.pm +++ b/lib/NGCP/Panel/Role/API/TrustedSources.pm @@ -64,6 +64,8 @@ sub hal_from_item { ); $resource->{id} = int($item->id); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/UpnRewriteSets.pm b/lib/NGCP/Panel/Role/API/UpnRewriteSets.pm index 3282c04a57..2c1db86a7b 100644 --- a/lib/NGCP/Panel/Role/API/UpnRewriteSets.pm +++ b/lib/NGCP/Panel/Role/API/UpnRewriteSets.pm @@ -69,6 +69,8 @@ sub hal_from_item { ); $resource->{id} = int($item->id); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/VoicemailSettings.pm b/lib/NGCP/Panel/Role/API/VoicemailSettings.pm index 9f93e51984..87a63c205c 100644 --- a/lib/NGCP/Panel/Role/API/VoicemailSettings.pm +++ b/lib/NGCP/Panel/Role/API/VoicemailSettings.pm @@ -73,6 +73,8 @@ sub hal_from_item { ); $resource->{id} = int($item->provisioning_voip_subscriber->voip_subscriber->id); + + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/Voicemails.pm b/lib/NGCP/Panel/Role/API/Voicemails.pm index 747e5863a9..b907d2ac03 100644 --- a/lib/NGCP/Panel/Role/API/Voicemails.pm +++ b/lib/NGCP/Panel/Role/API/Voicemails.pm @@ -69,6 +69,7 @@ sub hal_from_item { ); my $resource = $self->resource_from_item($c, $item, $form); + $self->expand_fields($c, $resource); $hal->resource($resource); return $hal; } diff --git a/lib/NGCP/Panel/Role/API/Vouchers.pm b/lib/NGCP/Panel/Role/API/Vouchers.pm index bd82911bb4..4cd326ec55 100644 --- a/lib/NGCP/Panel/Role/API/Vouchers.pm +++ b/lib/NGCP/Panel/Role/API/Vouchers.pm @@ -68,6 +68,8 @@ sub hal_from_item { delete $resource{code}; } $resource{id} = int($item->id); + + $self->expand_fields($c, \%resource); $hal->resource({%resource}); return $hal; }