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;
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
# for proper PUT behavior
$customer = $self->update_item($c, $customer, $old_resource, $resource, 1, "contracts");

@ -27,6 +27,17 @@ class_has 'query_params' => (
is => 'ro',
isa => 'ArrayRef',
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',
description => 'Filter for customers belonging to a specific reseller',

@ -20,7 +20,10 @@ sub item_rs {
my ($self, $c) = @_;
# 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;
}
@ -132,12 +135,12 @@ sub update_customer {
$resource->{modify_timestamp} = $now;
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}) {
$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) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid 'billing_profile_id', reseller doesn't match customer contact reseller");
return;

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

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

Loading…
Cancel
Save