Bug 24606: Add item template editor permission
authorKyle Hall <kyle@bywatersolutions.com>
Thu, 6 Oct 2022 14:08:45 +0000 (10:08 -0400)
committerTomas Cohen Arazi <tomascohen@theke.io>
Thu, 10 Nov 2022 17:25:23 +0000 (14:25 -0300)
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
cataloguing/additem.pl
installer/data/mysql/atomicupdate/bug_24606.pl
koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt
koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js

index 6287982..60ca31e 100755 (executable)
@@ -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(
index 7640612..18b0eba 100755 (executable)
@@ -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');
+            });
         }
     },
 };
index c071e1a..336021f 100644 (file)
             Create, update and delete item groups, add or remove items from an item group
         </span>
         <span class="permissioncode">([% name | html %])</span>
+    [%- CASE 'manage_item_editor_templates' -%]
+        <span class="sub_permission manage_item_editor_templates_subpermission">
+            Create, update and delete item editor templates owned by others
+        </span>
+        <span class="permissioncode">([% name | html %])</span>
     [%- CASE 'remaining_permissions' -%]
         <span class="sub_permission remaining_permissions_subpermission">
             Remaining permissions for managing fines and fees
index 47286ab..57676fc 100644 (file)
             <optgroup label="My templates">
                 [% FOREACH t IN item_templates.owned %]
                     [% IF t.id == template_id %]
-                        <option data-owner="1" value="[% t.id | html %]" selected="selected">[% t.name | html %][% IF t.is_shared %] (shared)[% END %]</option>
+                        <option data-editor="1" value="[% t.id | html %]" selected="selected">[% t.name | html %][% IF t.is_shared %] (shared)[% END %]</option>
                     [% ELSE %]
-                        <option data-owner="1" value="[% t.id | html %]">[% t.name | html %][% IF t.is_shared %] (shared)[% END %]</option>
+                        <option data-editor="1" value="[% t.id | html %]">[% t.name | html %][% IF t.is_shared %] (shared)[% END %]</option>
                     [% END %]
                 [% END %]
             </optgroup>
             <optgroup label="Shared templates">
                 [% FOREACH t IN item_templates.shared %]
                     [% IF t.id == template_id %]
-                        <option data-owner="0" value="[% t.id | html %]" selected="selected">[% t.name | html %]</option>
+                        [% IF CAN_user_editcatalogue_manage_item_editor_templates %]
+                            <option data-editor="1" value="[% t.id | html %]" selected="selected">[% t.name | html %]</option>
+                        [% ELSE %]
+                            <option data-editor="0" value="[% t.id | html %]" selected="selected">[% t.name | html %]</option>
+                        [% END %]
                     [% ELSE %]
-                        <option data-owner="0" value="[% t.id | html %]">[% t.name | html %]</option>
+                        [% IF CAN_user_editcatalogue_manage_item_editor_templates %]
+                            <option data-editor="1" value="[% t.id | html %]">[% t.name | html %]</option>
+                        [% ELSE %]
+                            <option data-editor="0" value="[% t.id | html %]">[% t.name | html %]</option>
+                        [% END %]
                     [% END %]
                 [% END %]
             </optgroup>
     <fieldset id="save_as_template_span">
         <legend>Save template</legend>
         <select name="replace_template_id" id="replace_template_id" class="select2" style="width: 20em">
-            <option value="0" selected="selected">Save as new</option>
-            <optgroup label="Update existing">
+            <option value="0" selected="selected">Save as new template</option>
+            <optgroup label="Update existing template">
                 [% FOREACH t IN item_templates.owned %]
-                    <option data-owner="1" value="[% t.id | html %]">[% t.name | html %][% IF t.is_shared %] (shared)[% END %]</option>
+                    <option data-editor="1" value="[% t.id | html %]">[% t.name | html %][% IF t.is_shared %] (shared)[% END %]</option>
+                [% END %]
+                [% IF CAN_user_editcatalogue_manage_item_editor_templates && item_templates.shared.count %]
+                    <optgroup label="Update shared template">
+                        [% FOREACH t IN item_templates.shared %]
+                            <option data-editor="1" value="[% t.id | html %]">[% t.name | html %][% IF t.is_shared %] (shared)[% END %]</option>
+                        [% END %]
+                    </optgroup>
                 [% END %]
             </optgroup>
         </select>
index 9bd660a..1f9f5e2 100644 (file)
@@ -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");