From 139dabf56285d6d88885066816f8b58a840dd957 Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Tue, 6 May 2014 09:33:56 +0200 Subject: [PATCH] MT#6827 API pbxdevice* improvements search queries, description and form validation --- .../Panel/Controller/API/PbxDeviceConfigs.pm | 24 ++++++++++++++++++- .../Panel/Controller/API/PbxDeviceModels.pm | 24 ++++++++++++++++++- .../Panel/Controller/API/PbxDeviceProfiles.pm | 13 +++++++++- lib/NGCP/Panel/Role/API/PbxDeviceConfigs.pm | 19 +++++++++------ lib/NGCP/Panel/Role/API/PbxDeviceModels.pm | 3 +-- lib/NGCP/Panel/Role/API/PbxDeviceProfiles.pm | 7 +++++- 6 files changed, 77 insertions(+), 13 deletions(-) diff --git a/lib/NGCP/Panel/Controller/API/PbxDeviceConfigs.pm b/lib/NGCP/Panel/Controller/API/PbxDeviceConfigs.pm index 5dfeb2ce29..fb7836f2c6 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDeviceConfigs.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDeviceConfigs.pm @@ -18,13 +18,35 @@ class_has 'api_description' => ( is => 'ro', isa => 'Str', default => - 'TODO', + 'Specifies a config to be set in PbxDeviceProfiles.', ); class_has 'query_params' => ( is => 'ro', isa => 'ArrayRef', default => sub {[ + { + param => 'content_type', + description => 'Filter for configs matching a content_type pattern', + query => { + first => sub { + my $q = shift; + { content_type => { like => $q } }; + }, + second => sub {}, + }, + }, + { + param => 'version', + description => 'Filter for configs matching a version name pattern', + query => { + first => sub { + my $q = shift; + { version => { like => $q } }; + }, + second => sub {}, + }, + }, ]}, ); diff --git a/lib/NGCP/Panel/Controller/API/PbxDeviceModels.pm b/lib/NGCP/Panel/Controller/API/PbxDeviceModels.pm index 923f382c30..258ebb2690 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDeviceModels.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDeviceModels.pm @@ -18,13 +18,35 @@ class_has 'api_description' => ( is => 'ro', isa => 'Str', default => - 'TODO', + 'Specifies a model to be set in PbxDeviceConfigs.', ); class_has 'query_params' => ( is => 'ro', isa => 'ArrayRef', default => sub {[ + { + param => 'model', + description => 'Filter for models matching a model name pattern', + query => { + first => sub { + my $q = shift; + { model => { like => $q } }; + }, + second => sub {}, + }, + }, + { + param => 'vendor', + description => 'Filter for models matching a vendor name pattern', + query => { + first => sub { + my $q = shift; + { vendor => { like => $q } }; + }, + second => sub {}, + }, + }, ]}, ); diff --git a/lib/NGCP/Panel/Controller/API/PbxDeviceProfiles.pm b/lib/NGCP/Panel/Controller/API/PbxDeviceProfiles.pm index 01c7c5f991..9076adcb12 100644 --- a/lib/NGCP/Panel/Controller/API/PbxDeviceProfiles.pm +++ b/lib/NGCP/Panel/Controller/API/PbxDeviceProfiles.pm @@ -18,13 +18,24 @@ class_has 'api_description' => ( is => 'ro', isa => 'Str', default => - 'TODO', + 'Specifies a profile to be set in PbxDevices.', ); class_has 'query_params' => ( is => 'ro', isa => 'ArrayRef', default => sub {[ + { + param => 'name', + description => 'Filter for profiles matching a name pattern', + query => { + first => sub { + my $q = shift; + { name => { like => $q } }; + }, + second => sub {}, + }, + }, ]}, ); diff --git a/lib/NGCP/Panel/Role/API/PbxDeviceConfigs.pm b/lib/NGCP/Panel/Role/API/PbxDeviceConfigs.pm index b14352cb8f..ac87566209 100644 --- a/lib/NGCP/Panel/Role/API/PbxDeviceConfigs.pm +++ b/lib/NGCP/Panel/Role/API/PbxDeviceConfigs.pm @@ -53,13 +53,12 @@ sub resource_from_item { delete $resource{device_id}; my $form = $self->get_form($c); -# return unless $self->validate_form( -# c => $c, -# form => $form, -# resource => \%resource, -# run => 0, -# ); - $resource{id} += 0; + return unless $self->validate_form( + c => $c, + form => $form, + resource => \%resource, + run => 0, + ); return \%resource; } @@ -67,6 +66,12 @@ sub resource_from_item { sub item_rs { my ($self, $c) = @_; my $item_rs = $c->model('DB')->resultset('autoprov_configs'); + if($c->user->roles eq "admin") { + } elsif ($c->user->roles eq "reseller") { + $item_rs = $item_rs->search( + { 'device.reseller_id' => $c->user->reseller_id, }, + { prefetch => 'device', }); + } return $item_rs; } diff --git a/lib/NGCP/Panel/Role/API/PbxDeviceModels.pm b/lib/NGCP/Panel/Role/API/PbxDeviceModels.pm index fecc112432..44a8eb9f5c 100644 --- a/lib/NGCP/Panel/Role/API/PbxDeviceModels.pm +++ b/lib/NGCP/Panel/Role/API/PbxDeviceModels.pm @@ -59,8 +59,7 @@ sub resource_from_item { resource => \%resource, run => 0, ); - $resource{id} += 0; - $resource{reseller_id} += 0; + $resource{reseller_id} = $item->reseller_id + 0; return \%resource; } diff --git a/lib/NGCP/Panel/Role/API/PbxDeviceProfiles.pm b/lib/NGCP/Panel/Role/API/PbxDeviceProfiles.pm index 2cd5007d35..66095a351a 100644 --- a/lib/NGCP/Panel/Role/API/PbxDeviceProfiles.pm +++ b/lib/NGCP/Panel/Role/API/PbxDeviceProfiles.pm @@ -59,7 +59,6 @@ sub resource_from_item { resource => \%resource, run => 0, ); - $resource{id} += 0; return \%resource; } @@ -67,6 +66,12 @@ sub resource_from_item { sub item_rs { my ($self, $c) = @_; my $item_rs = $c->model('DB')->resultset('autoprov_profiles'); + if($c->user->roles eq "admin") { + } elsif ($c->user->roles eq "reseller") { + $item_rs = $item_rs->search( + { 'device.reseller_id' => $c->user->reseller_id, }, + { prefetch => { 'config' => 'device', }}); + } return $item_rs; }