TT#69405 - Allow reseller to view subscriberregistrations

* Change DB fetch to get reseller based on
	   subscriber's customer rather than domain

	 * Added check for existence of field before
	   filtering by it. This was actually causing
	   non-superusers to not see registrations

Change-Id: I7bd39dfcd24a2bc8793a49ba58ab4b2f49f4c821
changes/36/35036/4
Flaviu Mates 6 years ago
parent ffce52becc
commit 71e950d758

@ -52,23 +52,6 @@ has current_source_alias => (
default => 'me',
);
has _domain_resellers => (
is => 'rw',
isa => sub { die "$_[0] must be HASHREF" unless $_[0] && ref $_[0] eq 'HASH' },
lazy => 1,
default => sub {
my $self = shift;
my $h = {};
my $domres_rs = $self->_c->model('DB')->resultset('domain_resellers')->search(undef, {
join => 'domain'
});
while ((my $res = $domres_rs->next)) {
$h->{$res->domain->domain} = $res->reseller_id;
}
return $h;
},
);
sub count {
my ($self) = @_;
@ -108,7 +91,12 @@ sub find {
} else {
$entry{expires} = "1970-01-01 00:00:00";
}
if (exists $filter->{reseller_id} && $filter->{reseller_id} != $self->_domain_resellers->{$entry{domain}}) {
my $subscribers_reseller = $self->_c->model('DB')->resultset('provisioning_voip_subscribers')->search({username => $entry{username}}, {
join => { 'contract' => { 'contact' => 'reseller' } },
'+select' => ['reseller.id'],
'+as' => ['reseller_id']
})->first;
if (exists $filter->{reseller_id} && $filter->{reseller_id} != $subscribers_reseller->get_column('reseller_id')) {
return;
}
return NGCP::Panel::Utils::RedisLocationResultSource->new(_data => \%entry);
@ -184,7 +172,12 @@ sub _rows_from_mapkey {
$entry{expires} = "1970-01-01 00:00:00";
}
if (exists $filter->{reseller_id} && $filter->{reseller_id} != $self->_domain_resellers->{$entry{domain}}) {
my $subscribers_reseller = $self->_c->model('DB')->resultset('provisioning_voip_subscribers')->search({username => $entry{username}}, {
join => { 'contract' => { 'contact' => 'reseller' } },
'+select' => ['reseller.id'],
'+as' => ['reseller_id']
})->first;
if (exists $filter->{reseller_id} && $filter->{reseller_id} != $subscribers_reseller->get_column('reseller_id')) {
next;
}
my $res = NGCP::Panel::Utils::RedisLocationResultSource->new(_data => \%entry);
@ -209,7 +202,7 @@ sub _filter {
next if ($colname =~ /\./); # we don't support joined table columns
$filter_applied = 1;
if (defined $condition && ref $condition eq "") {
if (lc($row->$colname) ne lc($condition)) {
if ($row->$colname && lc($row->$colname) ne lc($condition)) {
$match = 0;
last;
} else {

Loading…
Cancel
Save