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;
}
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(
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');
+ });
}
},
};
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
<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>
});
$("#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");