MT#7797 Filter for terminated customers.

- Allow status=xxx in collection
- Fix moving customercontacts
gjungwirth/voicemail_number
Andreas Granig 12 years ago
parent 4f370287af
commit 9115b48f70

@ -147,8 +147,6 @@ sub PUT :Allow {
last unless $resource; last unless $resource;
my $old_resource = $self->get_resource($c, $customer, "contracts"); my $old_resource = $self->get_resource($c, $customer, "contracts");
use Data::Printer; print ">>>>>>>>>>>>>>>> old resource\n"; p $old_resource;
# last param is "replace" to delete all existing prefs # last param is "replace" to delete all existing prefs
# for proper PUT behavior # for proper PUT behavior
$customer = $self->update_item($c, $customer, $old_resource, $resource, 1, "contracts"); $customer = $self->update_item($c, $customer, $old_resource, $resource, 1, "contracts");

@ -27,6 +27,17 @@ class_has 'query_params' => (
is => 'ro', is => 'ro',
isa => 'ArrayRef', isa => 'ArrayRef',
default => sub {[ default => sub {[
{
param => 'status',
description => 'Filter for customers with a specific status',
query => {
first => sub {
my $q = shift;
{ 'me.status' => $q };
},
second => sub { },
},
},
{ {
param => 'reseller_id', param => 'reseller_id',
description => 'Filter for customers belonging to a specific reseller', description => 'Filter for customers belonging to a specific reseller',

@ -20,7 +20,10 @@ sub item_rs {
my ($self, $c) = @_; my ($self, $c) = @_;
# returns a contracts rs filtered based on role # returns a contracts rs filtered based on role
my $item_rs = NGCP::Panel::Utils::Contract::get_customer_rs(c => $c); my $item_rs = NGCP::Panel::Utils::Contract::get_customer_rs(
c => $c,
include_terminated => 1,
);
return $item_rs; return $item_rs;
} }
@ -132,12 +135,12 @@ sub update_customer {
$resource->{modify_timestamp} = $now; $resource->{modify_timestamp} = $now;
my $billing_profile; my $billing_profile;
$billing_profile = $c->model('DB')->resultset('billing_profiles')->find($resource->{billing_profile_id});
unless($billing_profile) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'billing_profile_id', doesn't exist");
return;
}
if($old_resource->{billing_profile_id} != $resource->{billing_profile_id}) { if($old_resource->{billing_profile_id} != $resource->{billing_profile_id}) {
$billing_profile = $c->model('DB')->resultset('billing_profiles')->find($resource->{billing_profile_id});
unless($billing_profile) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'billing_profile_id', doesn't exist");
return;
}
unless($billing_profile->reseller_id == $customer->contact->reseller_id) { unless($billing_profile->reseller_id == $customer->contact->reseller_id) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'billing_profile_id', reseller doesn't match customer contact reseller"); $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'billing_profile_id', reseller doesn't match customer contact reseller");
return; return;

@ -242,9 +242,6 @@ sub item_by_id {
sub get_preference_rs { sub get_preference_rs {
my ($self, $c, $type, $elem, $attr) = @_; my ($self, $c, $type, $elem, $attr) = @_;
use Data::Printer; print ">>>>>>>>>>>>>>>> get_preference_rs, type=$type, elem=$elem, attr=$attr\n";
my $rs; my $rs;
if($type eq "domains") { if($type eq "domains") {
$rs = NGCP::Panel::Utils::Preferences::get_dom_preference_rs( $rs = NGCP::Panel::Utils::Preferences::get_dom_preference_rs(
@ -315,7 +312,6 @@ sub update_item {
$pref_type = 'peer_pref'; $pref_type = 'peer_pref';
$reseller_id = 1; $reseller_id = 1;
} elsif($type eq "contracts") { } elsif($type eq "contracts") {
use Data::Printer; print ">>>>>>>>>>>>>>>> prepare resource\n"; p $resource; p $old_resource;
delete $resource->{customer_id}; delete $resource->{customer_id};
delete $old_resource->{customer_id}; delete $old_resource->{customer_id};
$accessor = $item->id; $accessor = $item->id;
@ -354,7 +350,6 @@ sub update_item {
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Internal Server Error."); $self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Internal Server Error.");
return; return;
}; };
use Data::Printer; print ">>>>>>>>>>>>>>>> done deleteting old for PUT\n";
} else { } else {
# in case of PATCH, we remove only those entries marked for removal in the patch # in case of PATCH, we remove only those entries marked for removal in the patch
try { try {
@ -407,11 +402,8 @@ sub update_item {
} }
foreach my $pref(keys %{ $resource }) { foreach my $pref(keys %{ $resource }) {
use Data::Printer; print ">>>>>>>>>>>>>>>> handling pref $pref\n";
next unless(defined $resource->{$pref}); next unless(defined $resource->{$pref});
use Data::Printer; print ">>>>>>>>>>>>>>>> $pref is defined, get rs for type $type\n";
my $rs = $self->get_preference_rs($c, $type, $elem, $pref); my $rs = $self->get_preference_rs($c, $type, $elem, $pref);
use Data::Printer; print ">>>>>>>>>>>>>>>> got an rs\n";
unless($rs) { unless($rs) {
$c->log->debug("removing unknown preference '$pref' from update"); $c->log->debug("removing unknown preference '$pref' from update");
next; next;

@ -204,7 +204,7 @@ sub get_contract_rs {
my $dtf = $schema->storage->datetime_parser; my $dtf = $schema->storage->datetime_parser;
my $rs = $schema->resultset('contracts') my $rs = $schema->resultset('contracts')
->search({ ->search({
'me.status' => { '!=' => 'terminated' }, $params{include_terminated} ? () : ('me.status' => { '!=' => 'terminated' }),
'billing_mappings.id' => { 'billing_mappings.id' => {
'=' => $mapping_rs->search({ '=' => $mapping_rs->search({
contract_id => { -ident => 'me.id' }, contract_id => { -ident => 'me.id' },
@ -246,6 +246,7 @@ sub get_customer_rs {
my $customers = get_contract_rs( my $customers = get_contract_rs(
schema => $c->model('DB'), schema => $c->model('DB'),
include_terminated => $params{include_terminated},
); );
$customers = $customers->search({ $customers = $customers->search({

Loading…
Cancel
Save