MT#62178 fix external_id, profile auto removal for subscriber roles

* fix 'subscriber' and 'subscriberadmin' roles using PATCH to cause
  external_id, and profile fields removed.
* remove profile_id field from the 'subscriber' and 'subscriberadmin'
  form

Change-Id: Id8bb068ca7fcac2c0c5954f2ed79e841d18ac398
mr13.3
Kirill Solomko 2 months ago
parent ef4442feeb
commit 97e457c92b

@ -137,14 +137,15 @@ sub PATCH :Allow {
);
last unless $json;
my $patch_mode = 1;
my ($form) = $self->get_form($c);
my $old_resource = $self->resource_from_item($c, $subscriber, $form);
my $old_resource = $self->resource_from_item($c, $subscriber, $form, $patch_mode);
$old_resource = clone($old_resource);
my $resource = $self->apply_patch($c, $old_resource, $json);
last unless $resource;
my $update = 1;
my $r = $self->prepare_resource($c, $schema, $resource, $subscriber);
my $r = $self->prepare_resource($c, $schema, $resource, $subscriber, $patch_mode);
last unless $r;
$resource = $r->{resource};

@ -143,16 +143,6 @@ has_field 'customer_id' => (
},
);
has_field 'profile' => (
type => '+NGCP::Panel::Field::SubscriberProfile',
label => 'Subscriber Profile',
validate_when_empty => 0,
element_attr => {
rel => ['tooltip'],
title => ['The profile defining the actual feature set for this subscriber.'],
},
);
has_field 'display_name' => (
type => 'Text',
label => 'Display Name',

@ -46,7 +46,7 @@ sub get_form {
}
sub resource_from_item {
my ($self, $c, $item, $form) = @_;
my ($self, $c, $item, $form, $patch_mode) = @_;
my $pref;
my $bill_resource = { $item->get_inflated_columns };
@ -80,15 +80,26 @@ sub resource_from_item {
}
my $sippassword = $resource{password};
my $webpassword = $resource{webpassword};
if(!$form){
($form) = $self->get_form($c);
}
# form validation during PATCH causes
# fields to be removed from the %resource
# and then apply_patch() removes the fields
# that were not a part the PATCH ops from
# the database, therefore a copy of the resource
# is validated instead, preserving the original one
# when $patch_mode is enabled
my %validate_resource = %resource;
last unless $self->validate_form(
c => $c,
resource => \%resource,
resource => $patch_mode ? \%validate_resource : \%resource,
form => $form,
run => 0,
);
$resource{_password} = $sippassword;
$resource{_webpassword} = $webpassword;
@ -203,10 +214,6 @@ sub resource_from_item {
}
}
} else {
# fields we never want to see
foreach my $k(qw/profile_set_id external_id/) {
delete $resource{$k};
}
delete $resource{'password'} if $c->user->roles eq 'subscriber';
if ($c->user->roles eq "subscriberadmin") {
@ -357,7 +364,7 @@ sub get_customer {
}
sub prepare_resource {
my ($self, $c, $schema, $resource, $item) = @_;
my ($self, $c, $schema, $resource, $item, $patch_mode) = @_;
return NGCP::Panel::Utils::Subscriber::prepare_resource(
c => $c,
@ -371,9 +378,17 @@ sub prepare_resource {
validate_code => sub {
my ($r) = @_;
my ($form) = $self->get_form($c);
# form validation during PATCH causes
# fields to be removed from the %resource
# and then apply_patch() removes the fields
# that were not a part the PATCH ops from
# the database, therefore a copy of the resource
# is validated instead, preserving the original one
# when $patch_mode is enabled
my %validate_resource = %{$r};
return $self->validate_form(
c => $c,
resource => $r,
resource => $patch_mode ? \%validate_resource : $r,
form => $form,
);
},

Loading…
Cancel
Save