From 681d5e93c3564527c2aabf539f13543ddbb842d7 Mon Sep 17 00:00:00 2001 From: Irina Peshinskaya Date: Mon, 7 May 2018 04:52:06 +0200 Subject: [PATCH] TT#36055 Introduce container_resource parameter for preferences Change-Id: I0dac074f325e3911e266b3ead659a0d0860d2b8c --- lib/NGCP/Panel/Controller/API/CustomerPreferences.pm | 4 ++++ .../Panel/Controller/API/CustomerPreferencesItem.pm | 4 ++++ lib/NGCP/Panel/Controller/API/DomainPreferences.pm | 4 ++++ .../Panel/Controller/API/DomainPreferencesItem.pm | 4 ++++ lib/NGCP/Panel/Controller/API/PbxDevicePreferences.pm | 4 ++++ .../Panel/Controller/API/PbxDevicePreferencesItem.pm | 4 ++++ .../Controller/API/PbxDeviceProfilePreferences.pm | 4 ++++ .../Controller/API/PbxDeviceProfilePreferencesItem.pm | 4 ++++ .../Panel/Controller/API/PeeringServerPreferences.pm | 4 ++++ .../Controller/API/PeeringServerPreferencesItem.pm | 4 ++++ lib/NGCP/Panel/Controller/API/ProfilePreferences.pm | 4 ++++ .../Panel/Controller/API/ProfilePreferencesItem.pm | 4 ++++ .../Panel/Controller/API/SubscriberPreferences.pm | 4 ++++ .../Panel/Controller/API/SubscriberPreferencesItem.pm | 4 ++++ lib/NGCP/Panel/Role/API/Preferences.pm | 11 +++++++++++ 15 files changed, 67 insertions(+) diff --git a/lib/NGCP/Panel/Controller/API/CustomerPreferences.pm b/lib/NGCP/Panel/Controller/API/CustomerPreferences.pm index 9b02d27fa4..8ed5314f46 100644 --- a/lib/NGCP/Panel/Controller/API/CustomerPreferences.pm +++ b/lib/NGCP/Panel/Controller/API/CustomerPreferences.pm @@ -15,6 +15,10 @@ sub allowed_methods{ return [qw/GET OPTIONS HEAD/]; } +sub container_resource_type{ + return 'contracts'; +} + sub api_description { return 'Specifies certain properties (preferences) for a Customer. The full list of properties can be obtained via CustomerPreferenceDefs.'; }; diff --git a/lib/NGCP/Panel/Controller/API/CustomerPreferencesItem.pm b/lib/NGCP/Panel/Controller/API/CustomerPreferencesItem.pm index ee9fa92dc5..010987e7f5 100644 --- a/lib/NGCP/Panel/Controller/API/CustomerPreferencesItem.pm +++ b/lib/NGCP/Panel/Controller/API/CustomerPreferencesItem.pm @@ -32,6 +32,10 @@ sub relation{ return 'http://purl.org/sipwise/ngcp-api/#rel-customerpreferences'; } +sub container_resource_type{ + return 'contracts'; +} + sub journal_query_params { my($self,$query_params) = @_; return $self->get_journal_query_params($query_params); diff --git a/lib/NGCP/Panel/Controller/API/DomainPreferences.pm b/lib/NGCP/Panel/Controller/API/DomainPreferences.pm index 7200e361a0..c53505c3b0 100644 --- a/lib/NGCP/Panel/Controller/API/DomainPreferences.pm +++ b/lib/NGCP/Panel/Controller/API/DomainPreferences.pm @@ -41,6 +41,10 @@ sub relation{ return 'http://purl.org/sipwise/ngcp-api/#rel-domainpreferences'; } +sub container_resource_type{ + return 'domains'; +} + __PACKAGE__->set_config({ allowed_roles => [qw/admin reseller/], }); diff --git a/lib/NGCP/Panel/Controller/API/DomainPreferencesItem.pm b/lib/NGCP/Panel/Controller/API/DomainPreferencesItem.pm index 4092efe08c..a6efadef2d 100644 --- a/lib/NGCP/Panel/Controller/API/DomainPreferencesItem.pm +++ b/lib/NGCP/Panel/Controller/API/DomainPreferencesItem.pm @@ -24,6 +24,10 @@ sub resource_name{ return 'domainpreferences'; } +sub container_resource_type{ + return 'domains'; +} + sub dispatch_path{ return '/api/domainpreferences/'; } diff --git a/lib/NGCP/Panel/Controller/API/PbxDevicePreferences.pm b/lib/NGCP/Panel/Controller/API/PbxDevicePreferences.pm index e5f77b8f5a..5f20469826 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDevicePreferences.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDevicePreferences.pm @@ -24,6 +24,10 @@ sub resource_name{ return 'pbxdevicepreferences'; } +sub container_resource_type{ + return 'pbxdevicemodels'; +} + sub dispatch_path{ return '/api/pbxdevicepreferences/'; } diff --git a/lib/NGCP/Panel/Controller/API/PbxDevicePreferencesItem.pm b/lib/NGCP/Panel/Controller/API/PbxDevicePreferencesItem.pm index 7e902fc9e5..594ba3c354 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDevicePreferencesItem.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDevicePreferencesItem.pm @@ -32,6 +32,10 @@ sub relation{ return 'http://purl.org/sipwise/ngcp-api/#rel-pbxdevicepreferences'; } +sub container_resource_type { + return 'pbxdevicemodels'; +} + sub journal_query_params { my($self,$query_params) = @_; return $self->get_journal_query_params($query_params); diff --git a/lib/NGCP/Panel/Controller/API/PbxDeviceProfilePreferences.pm b/lib/NGCP/Panel/Controller/API/PbxDeviceProfilePreferences.pm index 1a985fb8ec..9c4fe1bb34 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDeviceProfilePreferences.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDeviceProfilePreferences.pm @@ -24,6 +24,10 @@ sub resource_name{ return 'pbxdeviceprofilepreferences'; } +sub container_resource_type{ + return 'pbxdeviceprofiles'; +} + sub dispatch_path{ return '/api/pbxdeviceprofilepreferences/'; } diff --git a/lib/NGCP/Panel/Controller/API/PbxDeviceProfilePreferencesItem.pm b/lib/NGCP/Panel/Controller/API/PbxDeviceProfilePreferencesItem.pm index 57e1527e34..7eef98553e 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDeviceProfilePreferencesItem.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDeviceProfilePreferencesItem.pm @@ -24,6 +24,10 @@ sub resource_name{ return 'pbxdeviceprofilepreferences'; } +sub container_resource_type{ + return 'pbxdeviceprofiles'; +} + sub dispatch_path{ return '/api/pbxdeviceprofilepreferences/'; } diff --git a/lib/NGCP/Panel/Controller/API/PeeringServerPreferences.pm b/lib/NGCP/Panel/Controller/API/PeeringServerPreferences.pm index 9a36d1e430..b3c9d9c52b 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringServerPreferences.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringServerPreferences.pm @@ -32,6 +32,10 @@ sub resource_name{ return 'peeringserverpreferences'; } +sub container_resource_type{ + return 'peerings'; +} + sub dispatch_path{ return '/api/peeringserverpreferences/'; } diff --git a/lib/NGCP/Panel/Controller/API/PeeringServerPreferencesItem.pm b/lib/NGCP/Panel/Controller/API/PeeringServerPreferencesItem.pm index fe481f6adb..541ff07f69 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringServerPreferencesItem.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringServerPreferencesItem.pm @@ -24,6 +24,10 @@ sub resource_name{ return 'peeringserverpreferences'; } +sub container_resource_type{ + return 'peerings'; +} + sub dispatch_path{ return '/api/peeringserverpreferences/'; } diff --git a/lib/NGCP/Panel/Controller/API/ProfilePreferences.pm b/lib/NGCP/Panel/Controller/API/ProfilePreferences.pm index 5ef05fcefe..380040f4d2 100644 --- a/lib/NGCP/Panel/Controller/API/ProfilePreferences.pm +++ b/lib/NGCP/Panel/Controller/API/ProfilePreferences.pm @@ -24,6 +24,10 @@ sub resource_name{ return 'profilepreferences'; } +sub container_resource_type{ + return 'profiles'; +} + sub dispatch_path{ return '/api/profilepreferences/'; } diff --git a/lib/NGCP/Panel/Controller/API/ProfilePreferencesItem.pm b/lib/NGCP/Panel/Controller/API/ProfilePreferencesItem.pm index 6c4d5b1e09..ac6247a8a8 100644 --- a/lib/NGCP/Panel/Controller/API/ProfilePreferencesItem.pm +++ b/lib/NGCP/Panel/Controller/API/ProfilePreferencesItem.pm @@ -24,6 +24,10 @@ sub resource_name{ return 'profilepreferences'; } +sub container_resource_type{ + return 'profiles'; +} + sub dispatch_path{ return '/api/profilepreferences/'; } diff --git a/lib/NGCP/Panel/Controller/API/SubscriberPreferences.pm b/lib/NGCP/Panel/Controller/API/SubscriberPreferences.pm index 3a61d40511..792d89939e 100644 --- a/lib/NGCP/Panel/Controller/API/SubscriberPreferences.pm +++ b/lib/NGCP/Panel/Controller/API/SubscriberPreferences.pm @@ -66,6 +66,10 @@ sub resource_name{ return 'subscriberpreferences'; } +sub container_resource_type{ + return 'subscribers'; +} + sub dispatch_path{ return '/api/subscriberpreferences/'; } diff --git a/lib/NGCP/Panel/Controller/API/SubscriberPreferencesItem.pm b/lib/NGCP/Panel/Controller/API/SubscriberPreferencesItem.pm index 9336fce05f..82ebc1b709 100644 --- a/lib/NGCP/Panel/Controller/API/SubscriberPreferencesItem.pm +++ b/lib/NGCP/Panel/Controller/API/SubscriberPreferencesItem.pm @@ -25,6 +25,10 @@ sub resource_name{ return 'subscriberpreferences'; } +sub container_resource_type{ + return 'subscribers'; +} + sub dispatch_path{ return '/api/subscriberpreferences/'; } diff --git a/lib/NGCP/Panel/Role/API/Preferences.pm b/lib/NGCP/Panel/Role/API/Preferences.pm index 5c596d3b7d..d669697250 100644 --- a/lib/NGCP/Panel/Role/API/Preferences.pm +++ b/lib/NGCP/Panel/Role/API/Preferences.pm @@ -24,6 +24,7 @@ sub get_form { sub hal_from_item { my ($self, $c, $item, $type) = @_; + $type //= $self->container_resource_type; my $print_type = $type; $print_type = "customers" if $print_type eq "contracts"; my $hal = Data::HAL->new( @@ -60,6 +61,8 @@ sub _check_profile { sub get_resource { my ($self, $c, $item, $type) = @_; + $type //= $self->container_resource_type; + my $prefs; my %profile_attrs = (); # for filtering profiles based list my %profile_allowed_attrs; # for filtering subscriber attrs on its profile @@ -273,6 +276,7 @@ sub get_resource { sub _item_rs { my ($self, $c, $type) = @_; my $item_rs; + $type //= $self->container_resource_type; if($type eq "domains") { # we actually return the domain rs here, as we can easily @@ -380,6 +384,7 @@ sub _item_rs { sub item_by_id { my ($self, $c, $id, $type) = @_; + $type //= $self->container_resource_type; my $item_rs = $self->item_rs($c, $type); return $item_rs->find($id); } @@ -439,6 +444,12 @@ sub get_preference_rs { sub update_item { my ($self, $c, $item, $old_resource, $resource, $replace, $type) = @_; + if (ref $replace || !defined $replace) { + $replace = uc($c->request->method) eq 'PUT'; + } + if (ref $type || !defined $type) { + $type = $self->container_resource_type; + } delete $resource->{id}; my $accessor; my $elem;