|
|
|
@ -11,18 +11,42 @@ use NGCP::Panel::Utils::DataHal qw();
|
|
|
|
|
use NGCP::Panel::Utils::DataHalLink qw();
|
|
|
|
|
use HTTP::Status qw(:constants);
|
|
|
|
|
use NGCP::Panel::Form::Reminder::API;
|
|
|
|
|
use NGCP::Panel::Utils::Preferences;
|
|
|
|
|
|
|
|
|
|
sub _item_rs {
|
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
|
|
|
|
|
my $item_rs = $c->model('DB')->resultset('voip_reminder');
|
|
|
|
|
if($c->user->roles eq "admin") {
|
|
|
|
|
} elsif($c->user->roles eq "reseller") {
|
|
|
|
|
if ($c->user->roles eq "admin") {
|
|
|
|
|
} elsif ($c->user->roles eq "reseller") {
|
|
|
|
|
$item_rs = $item_rs->search({
|
|
|
|
|
'contact.reseller_id' => $c->user->reseller_id
|
|
|
|
|
},{
|
|
|
|
|
join => { subscriber => { voip_subscriber => { contract => 'contact' } } },
|
|
|
|
|
});
|
|
|
|
|
} elsif ($c->user->roles eq "subscriberadmin") {
|
|
|
|
|
$item_rs = $item_rs->search({
|
|
|
|
|
'contract.id' => $c->user->account_id,
|
|
|
|
|
'-or' => [
|
|
|
|
|
'voip_subscriber_profile_left.id' => undef,
|
|
|
|
|
'attribute.attribute' => 'reminder',
|
|
|
|
|
],
|
|
|
|
|
},{
|
|
|
|
|
join => { subscriber => [
|
|
|
|
|
{ voip_subscriber => 'contract' },
|
|
|
|
|
{ voip_subscriber_profile_left => { profile_attributes => 'attribute' } },
|
|
|
|
|
] },
|
|
|
|
|
});
|
|
|
|
|
} elsif ($c->user->roles eq "subscriber") {
|
|
|
|
|
$item_rs = $item_rs->search({
|
|
|
|
|
'subscriber.uuid' => $c->user->uuid,
|
|
|
|
|
'-or' => [
|
|
|
|
|
'voip_subscriber_profile_left.id' => undef,
|
|
|
|
|
'attribute.attribute' => 'reminder',
|
|
|
|
|
],
|
|
|
|
|
},{
|
|
|
|
|
join => { 'subscriber' => { voip_subscriber_profile_left => {profile_attributes => 'attribute' } } },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return $item_rs;
|
|
|
|
|
}
|
|
|
|
@ -97,6 +121,17 @@ sub update_item {
|
|
|
|
|
my $sub = $self->get_subscriber_by_id($c, $resource->{subscriber_id} );
|
|
|
|
|
return unless $sub;
|
|
|
|
|
|
|
|
|
|
my $allowed_prefs = NGCP::Panel::Utils::Preferences::get_subscriber_allowed_prefs(
|
|
|
|
|
c => $c,
|
|
|
|
|
prov_subscriber => $sub->provisioning_voip_subscriber,
|
|
|
|
|
pref_list => ['reminder'],
|
|
|
|
|
);
|
|
|
|
|
unless ($allowed_prefs->{reminder}) {
|
|
|
|
|
$c->log->error("Not permitted to edit reminder via subscriber profile");
|
|
|
|
|
$self->error($c, HTTP_FORBIDDEN, "Not permitted to edit reminder");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$resource->{subscriber_id} = $sub->provisioning_voip_subscriber->id;
|
|
|
|
|
|
|
|
|
|
my $dup = $c->model('DB')->resultset('voip_reminder')->search({
|
|
|
|
@ -114,26 +149,38 @@ sub update_item {
|
|
|
|
|
return $item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub get_subscriber_by_id{
|
|
|
|
|
sub get_subscriber_by_id {
|
|
|
|
|
my ($self, $c, $subscriber_id) = @_;
|
|
|
|
|
|
|
|
|
|
my $sub_rs = $c->model('DB')->resultset('voip_subscribers')->search({
|
|
|
|
|
'me.id' => $subscriber_id,
|
|
|
|
|
});
|
|
|
|
|
if($c->user->roles eq "reseller") {
|
|
|
|
|
if ($c->user->roles eq "reseller") {
|
|
|
|
|
$sub_rs = $sub_rs->search({
|
|
|
|
|
'contact.reseller_id' => $c->user->reseller_id,
|
|
|
|
|
},{
|
|
|
|
|
join => { contract => 'contact' },
|
|
|
|
|
});
|
|
|
|
|
} elsif ($c->user->roles eq "subscriberadmin") {
|
|
|
|
|
$sub_rs = $sub_rs->search({
|
|
|
|
|
'contract.id' => $c->user->account_id,
|
|
|
|
|
},{
|
|
|
|
|
join => 'contract',
|
|
|
|
|
});
|
|
|
|
|
} elsif ($c->user->roles eq "subscriber") {
|
|
|
|
|
# quitely override any given subscriber_id, we don't need it
|
|
|
|
|
$sub_rs = $c->model('DB')->resultset('voip_subscribers')->search({
|
|
|
|
|
'me.uuid' => $c->user->uuid,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
my $sub = $sub_rs->first;
|
|
|
|
|
unless($sub && $sub->provisioning_voip_subscriber) {
|
|
|
|
|
unless ($sub && $sub->provisioning_voip_subscriber) {
|
|
|
|
|
$c->log->error("invalid subscriber_id '$subscriber_id'"); # TODO: user, message, trace, ...
|
|
|
|
|
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Subscriber does not exist");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return $sub;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
1;
|
|
|
|
|
# vim: set tabstop=4 expandtab:
|
|
|
|
|