MT#3933 API: Handle subscriber lock/termination

agranig/dummydel
Andreas Granig 12 years ago
parent 74d8f8305b
commit c61b9eec5d

@ -41,11 +41,16 @@ sub auto :Private {
sub GET : Allow {
my ($self, $c) = @_;
my $blacklist = {
"DomainPreferenceDefs" => 1,
"SubscriberPreferenceDefs" => 1,
};
my @colls = $self->get_collections;
foreach my $coll(@colls) {
my $mod = $coll;
$mod =~ s/^.+\/([a-zA-Z0-9_]+)\.pm$/$1/;
next if($mod eq "DomainPreferenceDefs"); # not a "real" collection
next if(exists $blacklist->{$mod});
my $rel = lc $mod;
my $full_mod = 'NGCP::Panel::Controller::API::'.$mod;

@ -460,49 +460,8 @@ sub terminate :Chained('base') :PathPart('terminate') :Args(0) :Does(ACL) :ACLDe
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/subscriber'));
}
my $schema = $c->model('DB');
try {
$schema->txn_do(sub {
if($subscriber->provisioning_voip_subscriber->is_pbx_group) {
my $pbx_group = $schema->resultset('voip_pbx_groups')->find({
subscriber_id => $subscriber->provisioning_voip_subscriber->id
});
if($pbx_group) {
$pbx_group->provisioning_voip_subscribers->update_all({
pbx_group_id => undef,
});
}
$pbx_group->delete;
}
my $prov_subscriber = $subscriber->provisioning_voip_subscriber;
if($prov_subscriber) {
NGCP::Panel::Utils::Subscriber::update_pbx_group_prefs(
c => $c,
schema => $schema,
old_group_id => $prov_subscriber->voip_pbx_group->id,
new_group_id => undef,
username => $prov_subscriber->username,
domain => $prov_subscriber->domain->domain,
) if($prov_subscriber->voip_pbx_group);
$prov_subscriber->delete;
}
if ($c->user->roles eq 'subscriberadmin') {
NGCP::Panel::Utils::Subscriber::update_subadmin_sub_aliases(
schema => $schema,
subscriber_id => $subscriber->id,
contract_id => $subscriber->contract_id,
alias_selected => [], #none, thus moving them back to our subadmin
sadmin_id => $schema->resultset('voip_subscribers')
->find({uuid => $c->user->uuid})->id
);
} else {
$subscriber->voip_numbers->update_all({
subscriber_id => undef,
reseller_id => undef,
});
}
$subscriber->update({ status => 'terminated' });
});
NGCP::Panel::Utils::Subscriber::terminate(c => $c, subscriber => $subscriber);
$c->flash(messages => [{type => 'success', text => $c->loc('Successfully terminated subscriber') }]);
} catch($e) {
NGCP::Panel::Utils::Message->error(

@ -97,7 +97,7 @@ has_field 'status' => (
label => 'Status',
element_attr => {
rel => ['tooltip'],
title => ['The status of the subscriber.']
title => ['The status of the subscriber (one of "active", "locked", "terminated").']
},
);

@ -195,8 +195,7 @@ sub require_preference {
my @preference = grep { 'return' eq $_->[0] } split_header_words($c->request->header('Prefer'));
return $preference[0][1]
if 1 == @preference && ('minimal' eq $preference[0][1] || 'representation' eq $preference[0][1]);
$self->error($c, HTTP_BAD_REQUEST, "This request is required to express an expectation about the response. Use the 'Prefer' header with either 'return=representation' or 'return='minimal' preference.");
return;
return 'minimal';
}
sub require_wellformed_json {

@ -3,7 +3,7 @@ use Moose::Role;
use Sipwise::Base;
use boolean qw(true);
use Try::Tiny;
use TryCatch;
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Status qw(:constants);

@ -3,7 +3,7 @@ use Moose::Role;
use Sipwise::Base;
use boolean qw(true);
use Try::Tiny;
use TryCatch;
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Status qw(:constants);

@ -3,7 +3,7 @@ use Moose::Role;
use Sipwise::Base;
use boolean qw(true);
use Try::Tiny;
use TryCatch;
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Status qw(:constants);

@ -3,7 +3,7 @@ use Moose::Role;
use Sipwise::Base;
use boolean qw(true);
use Try::Tiny;
use TryCatch;
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Status qw(:constants);

@ -3,7 +3,7 @@ use Moose::Role;
use Sipwise::Base;
use boolean qw(true);
use Try::Tiny;
use TryCatch;
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Status qw(:constants);

@ -3,7 +3,7 @@ use Moose::Role;
use Sipwise::Base;
use boolean qw(true);
use Try::Tiny;
use TryCatch;
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Status qw(:constants);

@ -3,7 +3,7 @@ use Moose::Role;
use Sipwise::Base;
use boolean qw(true);
use Try::Tiny;
use TryCatch;
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Status qw(:constants);
@ -332,6 +332,34 @@ sub update_item {
my $alias_numbers = $full_resource->{alias_numbers};
my $preferences = $full_resource->{preferences};
my $old_lock = $
if($subscriber->status ne $resource->{status}) {
if($resource->{status} eq 'locked') {
$resource->{lock} = 4;
} elsif($subscriber->status eq 'locked' && $resource->{status} eq 'active') {
$resource->{lock} ||= 0;
} elsif($resource->{status} eq 'terminated') {
try {
NGCP::Panel::Utils::Subscriber::terminate(c => $c, subscriber => $subscriber);
} catch($e) {
$c->log->error("failed to terminate subscriber id ".$subscriber->id);
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to terminate subscriber");
}
return;
}
}
try {
NGCP::Panel::Utils::Subscriber::lock_provisoning_voip_subscriber(
c => $c,
prov_subscriber => $subscriber->provisioning_voip_subscriber,
level => $resource->{lock},
);
} catch($e) {
$c->log->error("failed to lock subscriber id ".$subscriber->id." with level ".$resource->{lock});
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to update subscriber lock");
return;
}
NGCP::Panel::Utils::Subscriber::update_subscriber_numbers(
schema => $c->model('DB'),
primary_number => $resource->{e164},

@ -3,7 +3,7 @@ use Moose::Role;
use Sipwise::Base;
use boolean qw(true);
use Try::Tiny;
use TryCatch;
use Data::HAL qw();
use Data::HAL::Link qw();
use HTTP::Status qw(:constants);

@ -562,6 +562,56 @@ sub update_subadmin_sub_aliases {
}
}
sub terminate {
my %params = @_;
my $c = $params{c};
my $subscriber = $params{subscriber};
my $schema = $c->model('DB');
$schema->txn_do(sub {
if($subscriber->provisioning_voip_subscriber->is_pbx_group) {
my $pbx_group = $schema->resultset('voip_pbx_groups')->find({
subscriber_id => $subscriber->provisioning_voip_subscriber->id
});
if($pbx_group) {
$pbx_group->provisioning_voip_subscribers->update_all({
pbx_group_id => undef,
});
}
$pbx_group->delete;
}
my $prov_subscriber = $subscriber->provisioning_voip_subscriber;
if($prov_subscriber) {
update_pbx_group_prefs(
c => $c,
schema => $schema,
old_group_id => $prov_subscriber->voip_pbx_group->id,
new_group_id => undef,
username => $prov_subscriber->username,
domain => $prov_subscriber->domain->domain,
) if($prov_subscriber->voip_pbx_group);
$prov_subscriber->delete;
}
if ($c->user->roles eq 'subscriberadmin') {
update_subadmin_sub_aliases(
schema => $schema,
subscriber_id => $subscriber->id,
contract_id => $subscriber->contract_id,
alias_selected => [], #none, thus moving them back to our subadmin
sadmin_id => $schema->resultset('voip_subscribers')
->find({uuid => $c->user->uuid})->id
);
} else {
$subscriber->voip_numbers->update_all({
subscriber_id => undef,
reseller_id => undef,
});
}
$subscriber->update({ status => 'terminated' });
});
}
1;
=head1 NAME

Loading…
Cancel
Save