From 4ccc5f6d175d724a997e27ba52c90389abf244f1 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Sun, 1 Mar 2026 16:58:37 +0000 Subject: [PATCH] Bug 17387: (follow-up) move records_restore under editcatalogue permission MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The restore functionality is a cataloguing operation and should live under the editcatalogue permission module (bit 9) rather than tools (bit 13), consistent with where it appears in the UI. Update all references: - userpermissions.sql and atomicupdate: module_bit 13 → 9 - Swagger x-koha-authorization: tools → editcatalogue - CGI flagsrequired: tools → editcatalogue - Templates: CAN_user_tools_records_restore → CAN_user_editcatalogue_records_restore - C4::Auth::get_cataloguing_page_permissions: remove from tools sub-perms list (editcatalogue '*' already covers it) - Tests: module_bit 13 → 9 Signed-off-by: Michaela Sponsored-by: ByWater Solutions Signed-off-by: Martin Renvoize --- C4/Auth.pm | 1 - api/v1/swagger/paths/deleted_biblios.yaml | 2 +- api/v1/swagger/paths/deleted_items.yaml | 2 +- .../atomicupdate/bug_17387-item_biblio-undelete.pl | 4 ++-- installer/data/mysql/mandatory/userpermissions.sql | 2 +- .../intranet-tmpl/prog/en/includes/cat-menu.inc | 4 ++-- .../prog/en/modules/cataloguing/cataloging-home.tt | 4 ++-- t/db_dependent/api/v1/deleted_biblios.t | 14 +++++++++----- t/db_dependent/api/v1/deleted_items.t | 14 +++++++++----- tools/restore-records.pl | 2 +- 10 files changed, 28 insertions(+), 21 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index a6bb73d79ca..b5308ae4a42 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -2305,7 +2305,6 @@ sub get_cataloguing_page_permissions { marc_modification_templates records_batchdel records_batchmod - records_restore stage_marc_import upload_cover_images ); diff --git a/api/v1/swagger/paths/deleted_biblios.yaml b/api/v1/swagger/paths/deleted_biblios.yaml index 117ac1521a6..cf290da7783 100644 --- a/api/v1/swagger/paths/deleted_biblios.yaml +++ b/api/v1/swagger/paths/deleted_biblios.yaml @@ -206,4 +206,4 @@ $ref: "../swagger.yaml#/definitions/error" x-koha-authorization: permissions: - tools: records_restore + editcatalogue: records_restore diff --git a/api/v1/swagger/paths/deleted_items.yaml b/api/v1/swagger/paths/deleted_items.yaml index f0196d7f8cf..fab57604430 100644 --- a/api/v1/swagger/paths/deleted_items.yaml +++ b/api/v1/swagger/paths/deleted_items.yaml @@ -164,4 +164,4 @@ $ref: "../swagger.yaml#/definitions/error" x-koha-authorization: permissions: - tools: records_restore + editcatalogue: records_restore diff --git a/installer/data/mysql/atomicupdate/bug_17387-item_biblio-undelete.pl b/installer/data/mysql/atomicupdate/bug_17387-item_biblio-undelete.pl index 35080c8079d..44f92f26d32 100755 --- a/installer/data/mysql/atomicupdate/bug_17387-item_biblio-undelete.pl +++ b/installer/data/mysql/atomicupdate/bug_17387-item_biblio-undelete.pl @@ -11,11 +11,11 @@ return { $dbh->do( q{ INSERT IGNORE INTO permissions (module_bit, code, description) - VALUES (13, 'records_restore', 'Restore deleted records') + VALUES (9, 'records_restore', 'Restore deleted bibliographic records and items') } ); - say_success( $out, "Added new permission 'tools:records_restore'" ); + say_success( $out, "Added new permission 'editcatalogue:records_restore'" ); }, }; diff --git a/installer/data/mysql/mandatory/userpermissions.sql b/installer/data/mysql/mandatory/userpermissions.sql index bd9e2b373d8..35f02b0fc66 100644 --- a/installer/data/mysql/mandatory/userpermissions.sql +++ b/installer/data/mysql/mandatory/userpermissions.sql @@ -70,6 +70,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES ( 9, 'edit_any_item', 'Edit any item regardless of home library'), ( 9, 'edit_locked_records', 'Edit locked records'), ( 9, 'set_record_sources', 'Set record source'), + ( 9, 'records_restore', 'Restore deleted bibliographic records and items'), (10, 'payout', 'Perform account payout action'), (10, 'refund', 'Perform account refund action'), (10, 'discount', 'Perform account discount action'), @@ -132,7 +133,6 @@ INSERT INTO permissions (module_bit, code, description) VALUES (13, 'records_batchmod', 'Perform batch modification of records (biblios or authorities)'), (13, 'marc_modification_templates', 'Manage marc modification templates'), (13, 'records_batchdel', 'Perform batch deletion of records (bibliographic or authority)'), - (13, 'records_restore', 'Restore deleted bibliographic records and items'), (13, 'access_files', 'Access to the files stored on the server'), (13, 'upload_general_files', 'Upload any file'), (13, 'upload_manage', 'Manage uploaded files'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-menu.inc index 5ebcbdc3297..deecefa3a7d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-menu.inc @@ -43,7 +43,7 @@ [% END %] - [% IF ( CAN_user_tools_items_batchmod || CAN_user_tools_items_batchdel || CAN_user_tools_records_batchmod || CAN_user_tools_records_batchdel || CAN_user_tools_records_restore || CAN_user_tools_marc_modification_templates ) %] + [% IF ( CAN_user_tools_items_batchmod || CAN_user_tools_items_batchdel || CAN_user_tools_records_batchmod || CAN_user_tools_records_batchdel || CAN_user_editcatalogue_records_restore || CAN_user_tools_marc_modification_templates ) %]
Batch editing
    [% IF ( CAN_user_tools_items_batchmod ) %] @@ -71,7 +71,7 @@ MARC modification templates [% END %] - [% IF ( CAN_user_tools_records_restore ) %] + [% IF ( CAN_user_editcatalogue_records_restore ) %]
  • Restore deleted records
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/cataloging-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/cataloging-home.tt index c7ad12c9e49..def483e0ea3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/cataloging-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/cataloging-home.tt @@ -120,7 +120,7 @@
    - [% IF ( CAN_user_tools_items_batchmod || CAN_user_tools_items_batchdel || CAN_user_tools_records_batchmod || CAN_user_tools_records_batchdel || CAN_user_tools_records_restore || CAN_user_tools_marc_modification_templates ) %] + [% IF ( CAN_user_tools_items_batchmod || CAN_user_tools_items_batchdel || CAN_user_tools_records_batchmod || CAN_user_tools_records_batchdel || CAN_user_editcatalogue_records_restore || CAN_user_tools_marc_modification_templates ) %]

    Batch editing

      [% IF ( CAN_user_tools_items_batchmod ) %] @@ -149,7 +149,7 @@ MARC modification templates [% END %] - [% IF ( CAN_user_tools_records_restore ) %] + [% IF ( CAN_user_editcatalogue_records_restore ) %]
    • Restore deleted records
    • diff --git a/t/db_dependent/api/v1/deleted_biblios.t b/t/db_dependent/api/v1/deleted_biblios.t index daf7f30c0ef..1a734546f1c 100755 --- a/t/db_dependent/api/v1/deleted_biblios.t +++ b/t/db_dependent/api/v1/deleted_biblios.t @@ -293,7 +293,7 @@ subtest 'restore() tests' => sub { source => 'UserPermission', value => { borrowernumber => $librarian->borrowernumber, - module_bit => 13, + module_bit => 9, code => 'records_restore', } } @@ -326,7 +326,8 @@ subtest 'restore() tests' => sub { $t->put_ok("//$unauth_userid:$password@/api/v1/deleted/biblios/$biblionumber")->status_is(403); - $t->put_ok("//$userid:$password@/api/v1/deleted/biblios/$biblionumber")->status_is(200) + $t->put_ok("//$userid:$password@/api/v1/deleted/biblios/$biblionumber") + ->status_is(200) ->json_is( '/biblio_id' => $biblionumber ); my $restored_biblio = Koha::Biblios->find($biblionumber); @@ -362,7 +363,7 @@ subtest 'restore() with library group permissions tests' => sub { source => 'UserPermission', value => { borrowernumber => $librarian->borrowernumber, - module_bit => 13, + module_bit => 9, code => 'records_restore', } } @@ -413,8 +414,11 @@ subtest 'restore() with library group permissions tests' => sub { $t->put_ok( "//$userid:$password@/api/v1/deleted/biblios/$biblionumber" => { 'Content-Type' => 'application/json' } => - $body )->status_is(200)->json_is( '/biblio_id' => $biblionumber ) - ->json_is( '/restored_items/0' => $item1_id )->json_is( '/skipped_items/0' => $item2_id ); + $body ) + ->status_is(200) + ->json_is( '/biblio_id' => $biblionumber ) + ->json_is( '/restored_items/0' => $item1_id ) + ->json_is( '/skipped_items/0' => $item2_id ); my $restored_biblio = Koha::Biblios->find($biblionumber); ok( $restored_biblio, 'Biblio restored' ); diff --git a/t/db_dependent/api/v1/deleted_items.t b/t/db_dependent/api/v1/deleted_items.t index 76514504cf7..a3aabbbfb91 100755 --- a/t/db_dependent/api/v1/deleted_items.t +++ b/t/db_dependent/api/v1/deleted_items.t @@ -120,7 +120,8 @@ subtest 'get() tests' => sub { my $non_existent_id = $item_id + 99999; - $t->get_ok("//$userid:$password@/api/v1/deleted/items/$non_existent_id")->status_is(404) + $t->get_ok("//$userid:$password@/api/v1/deleted/items/$non_existent_id") + ->status_is(404) ->json_is( '/error' => 'Item not found' ); $schema->storage->txn_rollback; @@ -147,7 +148,7 @@ subtest 'restore() tests' => sub { source => 'UserPermission', value => { borrowernumber => $librarian->borrowernumber, - module_bit => 13, + module_bit => 9, code => 'records_restore', } } @@ -196,7 +197,9 @@ subtest 'restore() tests' => sub { $item_without_biblio->delete; Koha::Biblios->find($orphan_biblio_id)->delete; - $t->put_ok("//$userid:$password@/api/v1/deleted/items/$orphan_item_id")->status_is(409)->json_has('/error') + $t->put_ok("//$userid:$password@/api/v1/deleted/items/$orphan_item_id") + ->status_is(409) + ->json_has('/error') ->json_like( '/error', qr/Bibliographic record not found/ ); $schema->storage->txn_rollback; @@ -223,7 +226,7 @@ subtest 'restore() with library group permissions tests' => sub { source => 'UserPermission', value => { borrowernumber => $librarian->borrowernumber, - module_bit => 13, + module_bit => 9, code => 'records_restore', } } @@ -262,7 +265,8 @@ subtest 'restore() with library group permissions tests' => sub { my $restored_item = Koha::Items->find($item_allowed_id); ok( $restored_item, 'Item from allowed library restored' ); - $t->put_ok("//$userid:$password@/api/v1/deleted/items/$item_restricted_id")->status_is(403) + $t->put_ok("//$userid:$password@/api/v1/deleted/items/$item_restricted_id") + ->status_is(403) ->json_is( '/error' => 'You do not have permission to restore items from this library.' ); my $not_restored = Koha::Items->find($item_restricted_id); diff --git a/tools/restore-records.pl b/tools/restore-records.pl index ef83c80957b..caebeb64e76 100755 --- a/tools/restore-records.pl +++ b/tools/restore-records.pl @@ -31,7 +31,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( template_name => "tools/restore-records.tt", query => $input, type => "intranet", - flagsrequired => { tools => 'records_restore' }, + flagsrequired => { editcatalogue => 'records_restore' }, } ); -- 2.53.0