* create /api/resellerbrandinglogos/ endpoint
which will return the reseller's branding logo
* the endpoint can be used directly with /{reseller_id}
or with /?subscriber_id={subscriber_id} to get
the logo of subscriber's customer contact reseller
Change-Id: I5db19e208ae21cf7c685d46aa77b5032c26554de
mr9.2
parent
c0638b5a71
commit
733f4ac68f
@ -0,0 +1,51 @@
|
|||||||
|
package NGCP::Panel::Controller::API::ResellerBrandingLogos;
|
||||||
|
|
||||||
|
use Sipwise::Base;
|
||||||
|
use NGCP::Panel::Utils::Generic qw(:all);
|
||||||
|
|
||||||
|
use HTTP::Status qw(:constants);
|
||||||
|
|
||||||
|
use parent qw/NGCP::Panel::Role::Entities NGCP::Panel::Role::API::ResellerBrandingLogos/;
|
||||||
|
|
||||||
|
__PACKAGE__->set_config();
|
||||||
|
|
||||||
|
sub config_allowed_roles {
|
||||||
|
return [qw/admin reseller subscriberadmin subscriber/];
|
||||||
|
}
|
||||||
|
|
||||||
|
sub allowed_methods{
|
||||||
|
return [qw/GET OPTIONS HEAD/];
|
||||||
|
}
|
||||||
|
|
||||||
|
sub api_description {
|
||||||
|
return 'Used to download the reseller branding logo image. Returns a binary attachment with the correct content type (e.g. image/jpeg) of the image.';
|
||||||
|
};
|
||||||
|
|
||||||
|
sub GET :Allow {
|
||||||
|
my ($self, $c) = @_;
|
||||||
|
my $item = $self->item_rs($c);
|
||||||
|
|
||||||
|
unless($c->req->param('subscriber_id')) {
|
||||||
|
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "subscriber_id parameter is mandatory.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unless($item->first) {
|
||||||
|
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Invalid subscriber_id. Subscriber not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $branding = $item->first->branding;
|
||||||
|
|
||||||
|
unless($branding || $branding->logo) {
|
||||||
|
$self->error($c, HTTP_NOT_FOUND, "No branding logo available for this reseller");
|
||||||
|
return;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$c->response->content_type($branding->logo_image_type);
|
||||||
|
$c->response->body($branding->logo);
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
# vim: set tabstop=4 expandtab:
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package NGCP::Panel::Controller::API::ResellerBrandingLogosItem;
|
||||||
|
use Sipwise::Base;
|
||||||
|
|
||||||
|
use NGCP::Panel::Utils::Generic qw(:all);
|
||||||
|
|
||||||
|
use parent qw/NGCP::Panel::Role::EntitiesItem NGCP::Panel::Role::API::ResellerBrandingLogos/;
|
||||||
|
|
||||||
|
use HTTP::Status qw(:constants);
|
||||||
|
|
||||||
|
__PACKAGE__->set_config({
|
||||||
|
GET => {
|
||||||
|
ReturnContentType => 'binary',
|
||||||
|
},
|
||||||
|
log_response => 0,
|
||||||
|
allowed_roles => [qw/admin reseller subscriberadmin subscriber/],
|
||||||
|
});
|
||||||
|
|
||||||
|
sub allowed_methods{
|
||||||
|
return [qw/GET OPTIONS HEAD/];
|
||||||
|
}
|
||||||
|
|
||||||
|
sub get_item_binary_data{
|
||||||
|
my($self, $c, $id, $item) = @_;
|
||||||
|
|
||||||
|
my $branding = $item->branding;
|
||||||
|
|
||||||
|
if ($branding && $branding->logo) {
|
||||||
|
my $data = $branding->logo;
|
||||||
|
my $mime_type = $branding->logo_image_type;
|
||||||
|
my $fext = $mime_type;
|
||||||
|
$fext =~ s/^.*?([a-zA-Z0-9]+)$/$1/;
|
||||||
|
return (\$data, $mime_type, 'reseller_'.$item->id.'_branding_logo.'.$fext);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$self->error($c, HTTP_NOT_FOUND, "No branding logo available for this reseller");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
# vim: set tabstop=4 expandtab:
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
package NGCP::Panel::Role::API::ResellerBrandingLogos;
|
||||||
|
use NGCP::Panel::Utils::Generic qw(:all);
|
||||||
|
|
||||||
|
use Sipwise::Base;
|
||||||
|
|
||||||
|
use parent 'NGCP::Panel::Role::API';
|
||||||
|
|
||||||
|
sub resource_name{
|
||||||
|
return 'resellerbrandinglogos';
|
||||||
|
}
|
||||||
|
sub dispatch_path{
|
||||||
|
return '/api/resellerbrandinglogos/';
|
||||||
|
}
|
||||||
|
sub relation{
|
||||||
|
return 'http://purl.org/sipwise/ngcp-api/#rel-resellerbrandinglogos';
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _item_rs {
|
||||||
|
my ($self, $c) = @_;
|
||||||
|
my $item_rs;
|
||||||
|
if ($c->req->param('subscriber_id')) {
|
||||||
|
$item_rs = $c->model('DB')->resultset('resellers')->search(
|
||||||
|
{
|
||||||
|
'voip_subscribers.id' => $c->req->param('subscriber_id')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
join => { 'contacts' => { 'contracts' => 'voip_subscribers' } }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$item_rs = $c->model('DB')->resultset('resellers')->search({
|
||||||
|
status => { '!=' => 'terminated' }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if ($c->user->roles eq "admin") {
|
||||||
|
} elsif ($c->user->roles eq "reseller") {
|
||||||
|
$item_rs = $item_rs->search({ reseller_id => $c->user->reseller_id });
|
||||||
|
} elsif ($c->user->roles eq "subscriberadmin" || $c->user->roles eq "subscriber") {
|
||||||
|
my $reseller_id = $c->user->contract->contact->reseller_id;
|
||||||
|
return unless $reseller_id;
|
||||||
|
$item_rs = $item_rs->search({
|
||||||
|
reseller_id => $reseller_id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return $item_rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub get_form {
|
||||||
|
my ($self, $c) = @_;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
# vim: set tabstop=4 expandtab:
|
||||||
Loading…
Reference in new issue