From 4037e6ceca90bc4bf3cb2a7fcb90daf084c9abf7 Mon Sep 17 00:00:00 2001 From: Kyle Hall Date: Thu, 6 Oct 2022 10:08:45 -0400 Subject: [PATCH] Bug 24606: Add item template editor permission Signed-off-by: David Nind Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- cataloguing/additem.pl | 22 +++++++------- .../data/mysql/atomicupdate/bug_24606.pl | 5 ++++ .../prog/en/includes/permissions.inc | 5 ++++ .../prog/en/modules/cataloguing/additem.tt | 29 ++++++++++++++----- .../prog/js/cataloging_additem.js | 2 +- 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 6287982c49..60ca31efd5 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -186,7 +186,7 @@ my $use_template_for_session = $input->param('use_template_for_session') || $inp my $template_id = $input->param('template_id') || $input->cookie('ItemEditorSessionTemplateId'); if ( $delete_template_submit ) { my $t = Koha::Item::Templates->find($template_id); - $t->delete if $t && $t->borrowernumber eq $loggedinuser; + $t->delete if $t && ( $t->borrowernumber eq $loggedinuser || haspermission( $uid, { 'editcatalogue' => 'manage_item_editor_templates' } ) ); $template_id = undef; $use_template_for_session = undef; } @@ -276,15 +276,17 @@ if ($op eq "additem") { if ($replace_template_id) { my $template = Koha::Item::Templates->find($replace_template_id); - if ($template) { - $template->update( - { - id => $replace_template_id, - is_shared => $template_is_shared ? 1 : 0, - contents => $item->unblessed, - } - ); - } + $template->update( + { + id => $replace_template_id, + is_shared => $template_is_shared ? 1 : 0, + contents => $item->unblessed, + } + ) if $template && ( + $template->borrowernumber eq $loggedinuser + || + haspermission( $uid, { 'editcatalogue' => 'manage_item_editor_templates' } ) + ); } else { my $template = Koha::Item::Template->new( diff --git a/installer/data/mysql/atomicupdate/bug_24606.pl b/installer/data/mysql/atomicupdate/bug_24606.pl index 76406122d9..18b0eba217 100755 --- a/installer/data/mysql/atomicupdate/bug_24606.pl +++ b/installer/data/mysql/atomicupdate/bug_24606.pl @@ -19,6 +19,11 @@ return { CONSTRAINT `bn` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; }); + + $dbh->do(q{ + INSERT IGNORE INTO permissions (module_bit, code, description) VALUES + ( 9, 'manage_item_editor_templates', 'Update and delete item editor template owned by others'); + }); } }, }; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc index c071e1a2b0..336021f500 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc @@ -361,6 +361,11 @@ Create, update and delete item groups, add or remove items from an item group ([% name | html %]) + [%- CASE 'manage_item_editor_templates' -%] + + Create, update and delete item editor templates owned by others + + ([% name | html %]) [%- CASE 'remaining_permissions' -%] Remaining permissions for managing fines and fees diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index 47286abb90..57676fc2f4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -169,18 +169,26 @@ [% FOREACH t IN item_templates.owned %] [% IF t.id == template_id %] - + [% ELSE %] - + [% END %] [% END %] [% FOREACH t IN item_templates.shared %] [% IF t.id == template_id %] - + [% IF CAN_user_editcatalogue_manage_item_editor_templates %] + + [% ELSE %] + + [% END %] [% ELSE %] - + [% IF CAN_user_editcatalogue_manage_item_editor_templates %] + + [% ELSE %] + + [% END %] [% END %] [% END %] @@ -262,10 +270,17 @@
Save template diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js index 9bd660ad3b..1f9f5e2964 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js @@ -85,7 +85,7 @@ $(document).ready(function(){ }); $("#template_id").on("change", function() { - if ( $(this).find(":selected").data("owner") ) { + if ( $(this).find(":selected").data("editor") ) { $("#delete_template_submit").removeAttr("disabled"); } else { $("#delete_template_submit").attr("disabled", "disabled"); -- 2.39.5