MT#56234 get_usr_preference changes

* as_admin param is no longer needed as get_usr_preference()
  fetches actually set preference for a susbcriber and used
  only by the code (not exposed directly to 'subscriber',
  'subscriberadmin' roles
* with the aforedescribed, get_usr_preference() no longer
  filters by expose_to_customer, expose_to_subscriber for
  'subscriber' and 'subscriberadmin' roles
* refactor get_usr_preferences() to be simple and in line
  with the other get_*_preferences() as it's mainly responsible
  for fetching the preference as requested by the internal
  code

Change-Id: Ia52d8f4ebfd854901bf446e29fb475dea1fba866
mr11.2
Kirill Solomko 3 years ago
parent 6d487452bb
commit 6c179dd5c4

@ -2705,7 +2705,6 @@ sub master :Chained('base') :PathPart('details') :CaptureArgs(0) {
c => $c,
attribute => 'lock',
prov_subscriber => $c->stash->{subscriber}->provisioning_voip_subscriber,
as_admin => 1,
);
}
@ -2718,7 +2717,6 @@ sub details :Chained('master') :PathPart('') :Args(0) :Does(ACL) :ACLDetachTo('/
c => $c,
attribute => 'lock',
prov_subscriber => $c->stash->{subscriber}->provisioning_voip_subscriber,
as_admin => 1,
);
my $locklevel = $c->stash->{prov_lock}->first ? $c->stash->{prov_lock}->first->value : 0;
$c->stash->{prov_lock_string} = NGCP::Panel::Utils::Subscriber::get_lock_string($locklevel);
@ -2883,7 +2881,6 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
my $display_pref = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, attribute => 'display_name',
prov_subscriber => $prov_subscriber,
as_admin => 1,
);
if($display_pref->first) {
$params->{display_name} = $display_pref->first->value;

@ -143,7 +143,7 @@ sub resource_from_item {
})->all;
$pref = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, attribute => 'display_name', as_admin => 1,
c => $c, attribute => 'display_name',
prov_subscriber => $item->provisioning_voip_subscriber);
if($pref->first && $pref->first->value) {
$resource{display_name} = $pref->first->value;

@ -2434,39 +2434,18 @@ sub get_usr_preference_rs {
my $attribute = $params{attribute};
my $prov_subscriber = $params{prov_subscriber};
my $schema = $params{schema} // $c->model('DB');
my $as_admin = $params{as_admin} // 0;
my $pref_rs = $schema->resultset('voip_preferences')->search_rs({
return unless $prov_subscriber;
my $preference = $schema->resultset('voip_preferences')->find({
attribute => $attribute,
usr_pref => 1,
!$as_admin && $c->user->roles eq 'subscriberadmin'
? (-or => [ expose_to_customer => 1, internal => { '!=' => 0 } ]) : (),
!$as_admin && $c->user->roles eq 'subscriber'
? (-or => [ expose_to_subscriber => 1, internal => { '!=' => 0 } ]) : (),
})->first;
return unless $pref_rs;
my $attribute_id = $pref_rs->id;
# filter by allowed attrs from profile
if (($c->user->roles eq 'subscriberadmin' || $c->user->roles eq 'subscriber') &&
$prov_subscriber && $prov_subscriber->voip_subscriber_profile) {
my $found_attr = $prov_subscriber->voip_subscriber_profile
->profile_attributes->search_rs({
attribute_id => $attribute_id,
})->first;
return unless $found_attr;
}
$pref_rs = $pref_rs->voip_usr_preferences;
if ($prov_subscriber) {
$pref_rs = $pref_rs->search({
subscriber_id => $prov_subscriber->id,
attribute_id => $attribute_id
});
}
});
return unless $preference;
return $pref_rs;
return $preference->voip_usr_preferences->search_rs({
subscriber_id => $prov_subscriber->id,
});
}
sub get_prof_preference_rs {

Loading…
Cancel
Save