TT#176050 add expand support on array of ids

* it is possible to expand arrays of ids now
* add expand support for pbx_group_ids
* add expand support for pxb_groupmember_ids
* remove _password and _webpassword internally prepared fields
  from expands by subscriber_id, pbx_group_ids, pbx_groupmember_ids

Change-Id: I7651aae4c58d98943e82d1eda6b24d260ff2480a
mr11.0
Kirill Solomko 3 years ago
parent 60a39881b6
commit 938f6ba05c

@ -92,7 +92,7 @@ has_field 'subscriber_id' => (
element_attr => {
expand => {
class => 'NGCP::Panel::Role::API::Subscribers',
remove_fields => [qw(password webpassword)],
remove_fields => [qw(password webpassword _password _webpassword)],
allowed_roles => [qw(admin reseller ccareadmin ccare subscriberadmin)],
},
},
@ -168,4 +168,26 @@ has_field 'voucher_id' => (
},
);
has_field 'pbx_group_ids' => (
type => 'PosInteger',
element_attr => {
expand => {
class => 'NGCP::Panel::Role::API::Subscribers',
remove_fields => [qw(password webpassword _password _webpassword)],
allowed_roles => [qw(admin reseller ccareadmin ccare subscriberadmin subscriber)],
},
},
);
has_field 'pbx_groupmember_ids' => (
type => 'PosInteger',
element_attr => {
expand => {
class => 'NGCP::Panel::Role::API::Subscribers',
remove_fields => [qw(password webpassword _password _webpassword)],
allowed_roles => [qw(admin reseller ccareadmin ccare subscriberadmin subscriber)],
},
},
);
1;

@ -1355,11 +1355,34 @@ sub expand_field {
return unless $expand->{allowed_roles};
return unless any { $c->user->roles eq $_ } @{$expand->{allowed_roles}};
my $id = $resource->{$field} // return $found; # null value but the field exists
my $to = $expand->{to} // $field . '_expand';
my $id = $resource->{$field} // return $found; # null value but the field exists
my $to = $expand->{to} // $field . '_expand';
my $class = $expand->{class} // return;
my $form = $class->get_form($c) // return;
if (ref $id eq 'ARRAY') {
for (my $i=0; $i<=$#$id; $i++) {
my $a_id = $id->[$i];
$resource->{$to}[$i] =
$self->get_expanded_field_data($c, $expand, $resource, $field, $class, $form, $a_id);
if ($subfield) {
$found = $self->expand_field($c, $resource->{$to}[$i], $form, $subfield);
}
}
} else {
$resource->{$to} =
$self->get_expanded_field_data($c, $expand, $resource, $field, $class, $form, $id);
if ($subfield) {
$found = $self->expand_field($c, $resource->[$to], $form, $subfield);
}
}
return defined $found;
}
sub get_expanded_field_data {
my ($self, $c, $expand, $resource, $field, $class, $form, $id) = @_;
my $item = $class->item_by_id($c, $id) // return;
my $item_res = $class->resource_from_item($c, $item, $form);
@ -1369,13 +1392,7 @@ sub expand_field {
delete @{$data}{@{$remove_fields}};
}
$resource->{$to} = $data;
if ($subfield) {
$found = $self->expand_field($c, $resource->{$to}, $form, $subfield);
}
return defined $found;
return $data;
}
sub get_mandatory_params {

Loading…
Cancel
Save