Bug 32030: rename filter_by_have_subpermission with filter_by_have_permission
Signed-off-by: Jonathan Field <jonathan.field@ptfs-europe.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
70938a6f11
commit
e1224f9b9b
5 changed files with 36 additions and 20 deletions
|
@ -520,15 +520,17 @@ sub filter_by_amount_owed {
|
|||
return $self->search( $where, $attrs );
|
||||
}
|
||||
|
||||
=head3 filter_by_have_subpermission
|
||||
=head3 filter_by_have_permission
|
||||
|
||||
my $patrons = Koha::Patrons->search->filter_by_have_subpermission('suggestions.suggestions_manage');
|
||||
my $patrons = Koha::Patrons->search->filter_by_have_permission('suggestions.suggestions_manage');
|
||||
|
||||
Filter patrons who have a given subpermission
|
||||
my $patrons = Koha::Patrons->search->filter_by_have_permission('suggestions');
|
||||
|
||||
Filter patrons who have a given subpermission or the whole permission.
|
||||
|
||||
=cut
|
||||
|
||||
sub filter_by_have_subpermission {
|
||||
sub filter_by_have_permission {
|
||||
my ($self, $subpermission) = @_;
|
||||
|
||||
my ($p, $sp) = split '\.', $subpermission;
|
||||
|
@ -546,12 +548,16 @@ sub filter_by_have_subpermission {
|
|||
-or => [
|
||||
\"me.flags & (1 << $bit)",
|
||||
{ 'me.flags' => 1 },
|
||||
{
|
||||
-and => [
|
||||
{ 'user_permissions.module_bit' => $bit },
|
||||
{ 'user_permissions.code' => $sp }
|
||||
]
|
||||
}
|
||||
(
|
||||
$sp
|
||||
? {
|
||||
-and => [
|
||||
{ 'user_permissions.module_bit' => $bit },
|
||||
{ 'user_permissions.code' => $sp }
|
||||
]
|
||||
}
|
||||
: ()
|
||||
)
|
||||
]
|
||||
]
|
||||
},
|
||||
|
|
|
@ -46,7 +46,7 @@ sub list_managers {
|
|||
|
||||
return try {
|
||||
|
||||
my $patrons_rs = Koha::Patrons->search->filter_by_have_subpermission('acquisition.order_manage');
|
||||
my $patrons_rs = Koha::Patrons->search->filter_by_have_permission('acquisition.order_manage');
|
||||
my $patrons = $c->objects->search( $patrons_rs );
|
||||
|
||||
return $c->render(
|
||||
|
|
|
@ -66,7 +66,7 @@ sub list_owners {
|
|||
|
||||
return try {
|
||||
|
||||
my $patrons_rs = Koha::Patrons->search->filter_by_have_subpermission('acquisition.budget_modify');
|
||||
my $patrons_rs = Koha::Patrons->search->filter_by_have_permission('acquisition.budget_modify');
|
||||
my $patrons = $c->objects->search( $patrons_rs );
|
||||
|
||||
return $c->render(
|
||||
|
@ -90,7 +90,7 @@ sub list_users {
|
|||
|
||||
return try {
|
||||
|
||||
my $patrons_rs = Koha::Patrons->search->filter_by_have_subpermission('acquisition.budget_modify');
|
||||
my $patrons_rs = Koha::Patrons->search->filter_by_have_permission('acquisition.budget_modify');
|
||||
my $patrons = $c->objects->search( $patrons_rs );
|
||||
|
||||
return $c->render(
|
||||
|
|
|
@ -237,7 +237,7 @@ sub list_managers {
|
|||
|
||||
return try {
|
||||
|
||||
my $patrons_rs = Koha::Patrons->search->filter_by_have_subpermission('suggestions.suggestions_manage');
|
||||
my $patrons_rs = Koha::Patrons->search->filter_by_have_permission('suggestions.suggestions_manage');
|
||||
my $patrons = $c->objects->search( $patrons_rs );
|
||||
|
||||
return $c->render(
|
||||
|
|
|
@ -2463,8 +2463,8 @@ subtest 'filter_by_amount_owed' => sub {
|
|||
|
||||
};
|
||||
|
||||
subtest 'filter_by_have_subpermission' => sub {
|
||||
plan tests => 4;
|
||||
subtest 'filter_by_have_permission' => sub {
|
||||
plan tests => 5;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
|
@ -2503,7 +2503,7 @@ subtest 'filter_by_have_subpermission' => sub {
|
|||
is_deeply(
|
||||
[
|
||||
Koha::Patrons->search( { branchcode => $library->branchcode } )
|
||||
->filter_by_have_subpermission('suggestions.suggestions_manage')
|
||||
->filter_by_have_permission('suggestions.suggestions_manage')
|
||||
->get_column('borrowernumber')
|
||||
],
|
||||
[ $patron_1->borrowernumber, $patron_2->borrowernumber ],
|
||||
|
@ -2513,7 +2513,7 @@ subtest 'filter_by_have_subpermission' => sub {
|
|||
is_deeply(
|
||||
[
|
||||
Koha::Patrons->search( { branchcode => $library->branchcode } )
|
||||
->filter_by_have_subpermission('acquisition.order_manage')
|
||||
->filter_by_have_permission('acquisition.order_manage')
|
||||
->get_column('borrowernumber')
|
||||
],
|
||||
[ $patron_1->borrowernumber, $patron_3->borrowernumber ],
|
||||
|
@ -2523,16 +2523,26 @@ subtest 'filter_by_have_subpermission' => sub {
|
|||
is_deeply(
|
||||
[
|
||||
Koha::Patrons->search( { branchcode => $library->branchcode } )
|
||||
->filter_by_have_subpermission('parameters.manage_cities')
|
||||
->filter_by_have_permission('parameters.manage_cities')
|
||||
->get_column('borrowernumber')
|
||||
],
|
||||
[ $patron_1->borrowernumber ],
|
||||
'Only Superlibrarian is returned'
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
[
|
||||
Koha::Patrons->search( { branchcode => $library->branchcode } )
|
||||
->filter_by_have_permission('suggestions')
|
||||
->get_column('borrowernumber')
|
||||
],
|
||||
[ $patron_1->borrowernumber, $patron_2->borrowernumber ],
|
||||
'Superlibrarian and patron with suggestions'
|
||||
);
|
||||
|
||||
throws_ok {
|
||||
Koha::Patrons->search( { branchcode => $library->branchcode } )
|
||||
->filter_by_have_subpermission('dont_exist.subperm');
|
||||
->filter_by_have_permission('dont_exist.subperm');
|
||||
} 'Koha::Exceptions::ObjectNotFound';
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue