Bug 24606: Add item template editor permission

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>
This commit is contained in:
Kyle Hall 2022-10-06 10:08:45 -04:00 committed by Tomas Cohen Arazi
parent 859a917618
commit 4037e6ceca
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
5 changed files with 45 additions and 18 deletions

View file

@ -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(

View file

@ -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');
});
}
},
};

View file

@ -361,6 +361,11 @@
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

View file

@ -169,18 +169,26 @@
<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>
@ -262,10 +270,17 @@
<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>

View 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");