Merge branch 'master' of git.mgm.sipwise.com:ngcp-panel

agranig/subprof
Irina Peshinskaya 11 years ago
commit dcccfa9232

@ -0,0 +1,30 @@
package NGCP::Panel::Form::Contract::ProductOptional;
use HTML::FormHandler::Moose;
extends 'NGCP::Panel::Form::Contract::Basic';
has_field 'product' => (
type => '+NGCP::Panel::Field::Product',
label => 'Product',
required => 0,
);
has_field 'max_subscribers' => (
type => 'PosInteger',
label => 'Max Subscribers',
required => 0,
element_attr => {
rel => ['tooltip'],
title => ['Optionally set the maximum number of subscribers for this contract. Leave empty for unlimited.']
},
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/contact billing_profile product max_subscribers status external_id/],
);
1;
# vim: set tabstop=4 expandtab:

@ -41,7 +41,7 @@ sub hal_from_contract {
my ($self, $c, $contract, $form) = @_; my ($self, $c, $contract, $form) = @_;
my $billing_mapping = $contract->billing_mappings->find($contract->get_column('bmid')); my $billing_mapping = $contract->billing_mappings->find($contract->get_column('bmid'));
my $billing_profile_id = $billing_mapping->billing_profile->id; my $billing_profile_id = $billing_mapping->billing_profile_id;
my $stime = NGCP::Panel::Utils::DateTime::current_local()->truncate(to => 'month'); my $stime = NGCP::Panel::Utils::DateTime::current_local()->truncate(to => 'month');
my $etime = $stime->clone->add(months => 1); my $etime = $stime->clone->add(months => 1);
my $contract_balance = $contract->contract_balances my $contract_balance = $contract->contract_balances
@ -57,7 +57,7 @@ sub hal_from_contract {
contract => $contract, contract => $contract,
); );
} catch($e) { } catch($e) {
$self->log->error("Failed to create current contract balance for contract id '".$contract->id."': $e"); $c->log->error("Failed to create current contract balance for contract id '".$contract->id."': $e");
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Internal Server Error."); $self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Internal Server Error.");
return; return;
} }

@ -14,7 +14,7 @@ use HTTP::Status qw(:constants);
use NGCP::Panel::Utils::DateTime; use NGCP::Panel::Utils::DateTime;
use NGCP::Panel::Utils::Contract; use NGCP::Panel::Utils::Contract;
use NGCP::Panel::Utils::Preferences; use NGCP::Panel::Utils::Preferences;
use NGCP::Panel::Form::Contract::ProductSelect qw(); use NGCP::Panel::Form::Contract::ProductOptional;
sub item_rs { sub item_rs {
my ($self, $c) = @_; my ($self, $c) = @_;
@ -49,7 +49,7 @@ sub item_rs {
sub get_form { sub get_form {
my ($self, $c) = @_; my ($self, $c) = @_;
return NGCP::Panel::Form::Contract::PeeringReseller->new; return NGCP::Panel::Form::Contract::ProductOptional->new;
} }
sub hal_from_customer { sub hal_from_customer {
@ -184,11 +184,11 @@ sub update_customer {
} }
} }
my $old_ext_id = $customer->external_id; my $old_ext_id = $customer->external_id // '';
$customer->update($resource); $customer->update($resource);
if($customer->external_id ne $old_ext_id) { if(($customer->external_id // '') ne $old_ext_id) {
foreach my $sub($customer->voip_subscribers->all) { foreach my $sub($customer->voip_subscribers->all) {
my $prov_sub = $sub->provisioning_voip_subscriber; my $prov_sub = $sub->provisioning_voip_subscriber;
next unless($prov_sub); next unless($prov_sub);

@ -25,25 +25,35 @@ my $ssl_ca_cert = $ENV{API_SSL_CA_CERT} || "/etc/ssl/ngcp/api/ca-cert.pem";
my ($ua, $res); my ($ua, $res);
$ua = LWP::UserAgent->new; $ua = LWP::UserAgent->new;
# invalid cert SKIP: {
$ua->ssl_opts( if (! -e $invalid_ssl_client_cert) {
SSL_cert_file => $invalid_ssl_client_cert, skip ("Skip Invalid client certificate, we have none", 1);
SSL_key_file => $invalid_ssl_client_key, }
SSL_ca_file => $ssl_ca_cert, # invalid cert
); $ua->ssl_opts(
$res = $ua->get($uri.'/api/'); SSL_cert_file => $invalid_ssl_client_cert,
is($res->code, 400, "check invalid client certificate") SSL_key_file => $invalid_ssl_client_key,
|| note ($res->message); SSL_ca_file => $ssl_ca_cert,
);
$res = $ua->get($uri.'/api/');
is($res->code, 400, "check invalid client certificate")
|| note ($res->message);
}
# unauth cert SKIP: {
$ua->ssl_opts( if (! -e $unauth_ssl_client_cert) {
SSL_cert_file => $unauth_ssl_client_cert, skip ("Skip unauthorized client certificate, we have none", 1);
SSL_key_file => $unauth_ssl_client_key, }
SSL_ca_file => $ssl_ca_cert, # unauth cert
); $ua->ssl_opts(
$res = $ua->get($uri.'/api/'); SSL_cert_file => $unauth_ssl_client_cert,
is($res->code, 403, "check unauthorized client certificate") SSL_key_file => $unauth_ssl_client_key,
|| note ($res->message); SSL_ca_file => $ssl_ca_cert,
);
$res = $ua->get($uri.'/api/');
is($res->code, 403, "check unauthorized client certificate")
|| note ($res->message);
}
# successful auth # successful auth
$ua->ssl_opts( $ua->ssl_opts(

@ -162,7 +162,7 @@ my @allcontracts = ();
my $nexturi = $uri.'/api/contracts/?page=1&rows=5'; my $nexturi = $uri.'/api/contracts/?page=1&rows=5';
do { do {
$res = $ua->get($nexturi); $res = $ua->get($nexturi);
is($res->code, 200, "fetch contacts page"); is($res->code, 200, "fetch contracts page");
my $collection = JSON::from_json($res->decoded_content); my $collection = JSON::from_json($res->decoded_content);
my $selfuri = $uri . $collection->{_links}->{self}->{href}; my $selfuri = $uri . $collection->{_links}->{self}->{href};
is($selfuri, $nexturi, "check _links.self.href of collection"); is($selfuri, $nexturi, "check _links.self.href of collection");

@ -44,13 +44,33 @@ $ua->ssl_opts(
} }
my @links = $res->header('Link'); my @links = $res->header('Link');
my $rels = { contracts => 1, contacts => 1, }; my $rels = { contracts => 1,
subscriberpreferences => 1,
subscriberpreferencedefs => 1,
domainpreferencedefs => 1,
billingzones => 1,
systemcontacts => 1,
domains => 1,
billingfees => 1,
rewriterules => 1,
resellers => 1,
rewriterules => 1,
resellers => 1,
rewriterulesets => 1,
customercontacts => 1,
billingprofiles => 1,
customers => 1,
domainpreferences => 1,
subscribers => 1,
};
foreach my $link(@links) { foreach my $link(@links) {
ok($link =~ /^<\/api\/[a-z]+\/>; rel=\"collection http:\/\/purl\.org\/sipwise\/ngcp-api\/#rel-([a-z]+s)\"$/, "check for valid link syntax"); my $rex = qr/^<\/api\/[a-z]+\/>; rel=\"collection http:\/\/purl\.org\/sipwise\/ngcp-api\/#rel-([a-z]+s)\"$/;
ok(exists $rels->{$1}, "check for '$1' collection in Link"); like($link, $rex, "check for valid link syntax");
delete $rels->{$1}; my ($relname) = ($link =~ $rex);
ok(exists $rels->{$relname}, "check for '$relname' collection in Link");
delete $rels->{$relname};
} }
ok(keys %{ $rels } == 0, "check if all collections are present in Link"); is(scalar (keys %{ $rels }), 0, "check if all collections are present in Link");
} }
done_testing; done_testing;

Loading…
Cancel
Save