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:
Jonathan Druart 2022-03-08 12:10:30 +01:00 committed by Tomas Cohen Arazi
parent 70938a6f11
commit e1224f9b9b
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
5 changed files with 36 additions and 20 deletions

View file

@ -520,15 +520,17 @@ sub filter_by_amount_owed {
return $self->search( $where, $attrs ); 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 =cut
sub filter_by_have_subpermission { sub filter_by_have_permission {
my ($self, $subpermission) = @_; my ($self, $subpermission) = @_;
my ($p, $sp) = split '\.', $subpermission; my ($p, $sp) = split '\.', $subpermission;
@ -546,12 +548,16 @@ sub filter_by_have_subpermission {
-or => [ -or => [
\"me.flags & (1 << $bit)", \"me.flags & (1 << $bit)",
{ 'me.flags' => 1 }, { 'me.flags' => 1 },
{ (
-and => [ $sp
{ 'user_permissions.module_bit' => $bit }, ? {
{ 'user_permissions.code' => $sp } -and => [
] { 'user_permissions.module_bit' => $bit },
} { 'user_permissions.code' => $sp }
]
}
: ()
)
] ]
] ]
}, },

View file

@ -46,7 +46,7 @@ sub list_managers {
return try { 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 ); my $patrons = $c->objects->search( $patrons_rs );
return $c->render( return $c->render(

View file

@ -66,7 +66,7 @@ sub list_owners {
return try { 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 ); my $patrons = $c->objects->search( $patrons_rs );
return $c->render( return $c->render(
@ -90,7 +90,7 @@ sub list_users {
return try { 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 ); my $patrons = $c->objects->search( $patrons_rs );
return $c->render( return $c->render(

View file

@ -237,7 +237,7 @@ sub list_managers {
return try { 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 ); my $patrons = $c->objects->search( $patrons_rs );
return $c->render( return $c->render(

View file

@ -2463,8 +2463,8 @@ subtest 'filter_by_amount_owed' => sub {
}; };
subtest 'filter_by_have_subpermission' => sub { subtest 'filter_by_have_permission' => sub {
plan tests => 4; plan tests => 5;
$schema->storage->txn_begin; $schema->storage->txn_begin;
@ -2503,7 +2503,7 @@ subtest 'filter_by_have_subpermission' => sub {
is_deeply( is_deeply(
[ [
Koha::Patrons->search( { branchcode => $library->branchcode } ) Koha::Patrons->search( { branchcode => $library->branchcode } )
->filter_by_have_subpermission('suggestions.suggestions_manage') ->filter_by_have_permission('suggestions.suggestions_manage')
->get_column('borrowernumber') ->get_column('borrowernumber')
], ],
[ $patron_1->borrowernumber, $patron_2->borrowernumber ], [ $patron_1->borrowernumber, $patron_2->borrowernumber ],
@ -2513,7 +2513,7 @@ subtest 'filter_by_have_subpermission' => sub {
is_deeply( is_deeply(
[ [
Koha::Patrons->search( { branchcode => $library->branchcode } ) Koha::Patrons->search( { branchcode => $library->branchcode } )
->filter_by_have_subpermission('acquisition.order_manage') ->filter_by_have_permission('acquisition.order_manage')
->get_column('borrowernumber') ->get_column('borrowernumber')
], ],
[ $patron_1->borrowernumber, $patron_3->borrowernumber ], [ $patron_1->borrowernumber, $patron_3->borrowernumber ],
@ -2523,16 +2523,26 @@ subtest 'filter_by_have_subpermission' => sub {
is_deeply( is_deeply(
[ [
Koha::Patrons->search( { branchcode => $library->branchcode } ) Koha::Patrons->search( { branchcode => $library->branchcode } )
->filter_by_have_subpermission('parameters.manage_cities') ->filter_by_have_permission('parameters.manage_cities')
->get_column('borrowernumber') ->get_column('borrowernumber')
], ],
[ $patron_1->borrowernumber ], [ $patron_1->borrowernumber ],
'Only Superlibrarian is returned' '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 { throws_ok {
Koha::Patrons->search( { branchcode => $library->branchcode } ) Koha::Patrons->search( { branchcode => $library->branchcode } )
->filter_by_have_subpermission('dont_exist.subperm'); ->filter_by_have_permission('dont_exist.subperm');
} 'Koha::Exceptions::ObjectNotFound'; } 'Koha::Exceptions::ObjectNotFound';