From b8568533cd6e4f5f7ebc51984b0990eac84f979f Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 26 Apr 2023 15:21:39 +0000 Subject: [PATCH] Bug 33363: Add separate permissions for creating and deleting suggestions There are a number of libraries that would like for their staff to be able to submit (and view existing) purchase suggestions from the borrower record, but not give the staff the ability to edit/manage/delete purchase suggestions. Test Plan: 1) Apply this patch 2) Run restart all the things! 3) Run updatedatabase 4) Verify anyone with the suggestions manage permissions now has the create and delete permissions as well 5) Verify anyone without the suggestions manage permission has not recieved the new permissions 6) Enable only the create permission for a librarian 7) Verify that librarian can only create new suggestions ( not manage or delete ) 8) Enable only the manage permission for a librarian 9) Verify that librarian can only manage existing suggestions ( not create or delete ) 10) Enable only the delete permission for a librarian 11) Verify that librarian can only delete suggestions ( not create or manage ) Signed-off-by: Michaela Sieber --- api/v1/swagger/paths/suggestions.yaml | 19 +- .../data/mysql/atomicupdate/bug_33363.pl | 16 ++ .../data/mysql/mandatory/userpermissions.sql | 2 + .../prog/en/includes/acquisitions-menu.inc | 2 +- .../prog/en/includes/circ-menu.inc | 2 +- .../intranet-tmpl/prog/en/includes/header.inc | 2 +- .../prog/en/includes/patron-search.inc | 2 +- .../prog/en/includes/permissions.inc | 10 + .../modules/members/purchase-suggestions.tt | 4 +- .../prog/en/modules/suggestion/suggestion.tt | 225 +++++++++++++----- members/purchase-suggestions.pl | 2 +- suggestion/suggestion.pl | 81 +++++-- t/Koha/Auth/Permissions.t | 2 + 13 files changed, 285 insertions(+), 84 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_33363.pl diff --git a/api/v1/swagger/paths/suggestions.yaml b/api/v1/swagger/paths/suggestions.yaml index 6e500bcf4cb..2058bb82bf5 100644 --- a/api/v1/swagger/paths/suggestions.yaml +++ b/api/v1/swagger/paths/suggestions.yaml @@ -41,7 +41,10 @@ $ref: "../swagger.yaml#/definitions/error" x-koha-authorization: permissions: - suggestions: suggestions_manage + suggestions: + - suggestions_manage + - suggestions_delete + - suggestions_create post: x-mojo-to: Suggestions#add operationId: addSuggestions @@ -100,7 +103,7 @@ $ref: "../swagger.yaml#/definitions/error" x-koha-authorization: permissions: - suggestions: suggestions_manage + suggestions: suggestions_create "/suggestions/{suggestion_id}": get: x-mojo-to: Suggestions#get @@ -139,7 +142,10 @@ $ref: "../swagger.yaml#/definitions/error" x-koha-authorization: permissions: - suggestions: suggestions_manage + suggestions: + - suggestions_manage + - suggestions_delete + - suggestions_create put: x-mojo-to: Suggestions#update operationId: updateSuggestion @@ -229,7 +235,7 @@ $ref: "../swagger.yaml#/definitions/error" x-koha-authorization: permissions: - suggestions: suggestions_manage + suggestions: suggestions_delete /suggestions/managers: get: x-mojo-to: Suggestions#list_managers @@ -281,4 +287,7 @@ $ref: "../swagger.yaml#/definitions/error" x-koha-authorization: permissions: - suggestions: suggestions_manage + suggestions: + - suggestions_manage + - suggestions_delete + - suggestions_create diff --git a/installer/data/mysql/atomicupdate/bug_33363.pl b/installer/data/mysql/atomicupdate/bug_33363.pl new file mode 100755 index 00000000000..46ceea7b42e --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_33363.pl @@ -0,0 +1,16 @@ +use Modern::Perl; + +return { + bug_number => "33363", + description => "Split suggestions_manage into three separate permissions for creating, updating, and deleting suggetions", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + $dbh->do(q{INSERT IGNORE INTO permissions (module_bit, code, description) VALUES (12, 'suggestions_create', 'Create purchase suggestions')}); + $dbh->do(q{INSERT IGNORE INTO permissions (module_bit, code, description) VALUES (12, 'suggestions_delete', 'Update purchase suggestions')}); + + $dbh->do(q{INSERT IGNORE INTO user_permissions (borrowernumber, module_bit, code) SELECT borrowernumber, 12, 'suggestions_create' FROM borrowers WHERE flags & (1 << 2)}); + $dbh->do(q{INSERT IGNORE INTO user_permissions (borrowernumber, module_bit, code) SELECT borrowernumber, 12, 'suggestions_delete' FROM borrowers WHERE flags & (1 << 2)}); + }, +}; diff --git a/installer/data/mysql/mandatory/userpermissions.sql b/installer/data/mysql/mandatory/userpermissions.sql index 729c075548a..bd8f20f6d05 100644 --- a/installer/data/mysql/mandatory/userpermissions.sql +++ b/installer/data/mysql/mandatory/userpermissions.sql @@ -87,7 +87,9 @@ INSERT INTO permissions (module_bit, code, description) VALUES (11, 'delete_invoices', 'Delete invoices'), (11, 'merge_invoices', 'Merge invoices'), (11, 'delete_baskets', 'Delete baskets'), + (12, 'suggestions_create', 'Create purchase suggestions'), (12, 'suggestions_manage', 'Manage purchase suggestions'), + (12, 'suggestions_delete', 'Delete purchase suggestions'), (13, 'edit_additional_contents', 'Write additional contents for the OPAC and staff interfaces (news and HTML customizations)'), (13, 'label_creator', 'Create printable labels and barcodes from catalog and patron data'), (13, 'edit_calendar', 'Define days when the library is closed'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc index 2130e187925..df067e6edfc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc @@ -6,7 +6,7 @@
  • Acquisitions home
  • Advanced search
  • [% IF ( CAN_user_acquisition_order_receive ) %]
  • Late orders
  • [% END %] - [% IF ( CAN_user_suggestions_suggestions_manage ) %]
  • Suggestions
  • [% END %] + [% IF ( suggestion && ( CAN_user_suggestions_suggestions_create || CAN_user_suggestions_suggestions_manage || CAN_user_suggestions_suggestions_delete ) ) %]
  • Suggestions
  • [% END %]
  • Invoices
  • [% IF Koha.Preference('EDIFACT') && CAN_user_acquisition_edi_manage %]
  • EDIFACT messages
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc index 6facc63971c..8dbcfb0ef5e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc @@ -175,7 +175,7 @@ [% END %] [% END %] - [% IF CAN_user_suggestions_suggestions_manage %] + [% IF CAN_user_suggestions_suggestions_create || CAN_user_suggestions_suggestions_manage || CAN_user_suggestions_suggestions_delete %] [% IF ( suggestionsview ) %]
  • [% ELSE %]
  • [% END %]Purchase suggestions
  • [% END %] [% IF CAN_user_borrowers_edit_borrowers && useDischarge %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc index b08087fccfa..603e9db5529 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/header.inc @@ -58,7 +58,7 @@ [% IF ( CAN_user_reports ) %]
  • Reports
  • [% END %] - [% IF ( CAN_user_suggestions_suggestions_manage ) %] + [% IF ( CAN_user_suggestions_suggestions_create || CAN_user_suggestions_suggestions_manage || CAN_user_suggestions_suggestions_delete ) %]
  • Suggestions
  • [% END %] [% IF ( CAN_user_tools || CAN_user_clubs ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc index 28e87b47ca3..953d9637f0a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -137,7 +137,7 @@ [% END %] [% IF filter == 'suggestions_managers' %] -
    Only staff with superlibrarian or suggestions_manage permissions are returned in the search results
    +
    Only staff with superlibrarian or rull suggestions permissions are returned in the search results
    [% ELSIF filter == 'orders_managers' OR filter == 'baskets_managers' %]
    Only staff with superlibrarian or acquisitions permissions (or order_manage permission if granular permissions are enabled) are returned in the search results
    [% ELSIF filter == 'funds_owners' OR filter == 'funds_users' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc index 742e6e1c359..49bb1ee6795 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc @@ -422,11 +422,21 @@ Add manual credits to a patron account ([% name | html %]) + [%- CASE 'suggestions_create' -%] + + Create purchase suggestions + + ([% name | html %]) [%- CASE 'suggestions_manage' -%] Manage purchase suggestions ([% name | html %]) + [%- CASE 'suggestions_delete' -%] + + Delete purchase suggestions + + ([% name | html %]) [%- CASE 'budget_add_del' -%] Add and delete funds (but can't modify funds) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/purchase-suggestions.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/purchase-suggestions.tt index 6d9ea00d024..5260673ff51 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/purchase-suggestions.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/purchase-suggestions.tt @@ -44,7 +44,9 @@

    Purchase suggestions

    - New purchase suggestion + [% IF CAN_user_suggestions_suggestions_create %] + New purchase suggestion + [% END %]
    [% IF suggestions.size %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt index 5d9e0bf8f45..14332702d55 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt @@ -97,15 +97,19 @@ [% INCLUDE 'messages.inc' %]
    - Edit -
    - [% INCLUDE 'csrf-token.inc' %] -
    - - - -
    -
    + [% IF CAN_user_suggestions_suggestions_manage %] + Edit + [% END %] + [% IF CAN_user_suggestions_suggestions_delete %] +
    + [% INCLUDE 'csrf-token.inc' %] +
    + + + +
    +
    + [% END %]
    @@ -340,6 +344,12 @@ A similar document already exists: [% m.title | html %]. Click on "Confirm your suggestion" to ignore this message. [% CASE 'manager_not_enough_permissions' %] The manager you selected does not have sufficient permissions. + [% CASE 'no_manage_permission' %] + You do not have permissions to manage suggestions + [% CASE 'no_create_permission' %] + You do not have permissions to create suggestions + [% CASE 'no_delete_permission' %] + You do not have permissions to delete suggestions [% CASE %] [% m.code | html %] [% END %] @@ -560,7 +570,11 @@
    - You + [% IF CAN_user_suggestions_suggestions_manage %] + You + [% ELSE %] + Nobody + [% END %] [% IF managedby_patron.borrowernumber && logged_in_user.borrowernumber != managedby_patron.borrowernumber %] | Previously was [% INCLUDE 'patron-title.inc' patron=managedby_patron hide_patron_infos_if_needed=1 %] [% Branches.GetName( managedby_patron.branchcode ) | html %] ([% managedby_patron.category.description | html %]) @@ -570,7 +584,10 @@ [% IF managedby_patron.borrowernumber && logged_in_user.borrowernumber != managedby_patron.borrowernumber %] Keep existing manager [% END %] - + + [% IF CAN_user_suggestions_suggestions_manage %] + + [% END %]
    @@ -665,7 +682,13 @@ [% IF op == 'else' %]
    +<<<<<<< HEAD New purchase suggestion +======= + [% IF CAN_user_suggestions_suggestions_create %] + New purchase suggestion + [% END %] +>>>>>>> 3c401bd9c7d (Bug 33363: Add separate permissions for creating and deleting suggestions)

    Suggestions management

    @@ -860,6 +883,7 @@
    +<<<<<<< HEAD Edit
    @@ -887,49 +928,104 @@

    Change selected suggestions

    -
    -
    -
    -
    - - + + + [% IF (statusselected_ASKED ) %] + + [% ELSE %] + + [% END %] + + [% IF (statusselected_ACCEPTED ) %] + + [% ELSE %] + + [% END %] + + [% IF (statusselected_CHECKED ) %] + + [% ELSE %] + + [% END %] + + [% IF ( statusselected_REJECTED ) %] + + [% ELSE %] + + [% END %] + + [% IF ( statusselected_ORDERED ) %] + + [% ELSE %] + + [% END %] + + [% FOREACH s IN SuggestionStatuses %] + + [% END %] + + + + + + + + Cancel + +
    - [% FOREACH s IN SuggestionStatuses %] - - [% END %] - + + +
    +
    + +
    +
    + +
    +
    + + [% PROCESS 'av-build-dropbox.inc' name="suggestion_itemtype", category="SUGGEST_FORMAT", size = 20 %] + + +
    +
    + +
    +
    + +
    +
    + Update manager + Select manager + + + + +
    +
    + +
    +
    + [% END %] +<<<<<<< HEAD +======= + [% IF CAN_user_suggestions_suggestions_delete %] +
    +
    + Delete selected + +
    -
    - +
    + +>>>>>>> 3c401bd9c7d (Bug 33363: Add separate permissions for creating and deleting suggestions) +
    + + [% END %] + [% IF CAN_user_suggestions_suggestions_manage %] +
    +
    + Archive selected + + +
    + +
    +
    +
    + [% END %] [% ELSE %] diff --git a/members/purchase-suggestions.pl b/members/purchase-suggestions.pl index 0268582befb..c56a493d9ce 100755 --- a/members/purchase-suggestions.pl +++ b/members/purchase-suggestions.pl @@ -32,7 +32,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "members/purchase-suggestions.tt", query => $input, type => "intranet", - flagsrequired => { suggestions => 'suggestions_manage' }, + flagsrequired => { suggestions => '*' }, } ); diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index fa462bbf8af..7d13db3bafe 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -126,10 +126,12 @@ my ( $template, $borrowernumber, $cookie, $userflags ) = get_template_and_user( template_name => "suggestion/suggestion.tt", query => $input, type => "intranet", - flagsrequired => { suggestions => 'suggestions_manage' }, + flagsrequired => { suggestions => '*' }, } ); +my $librarian = Koha::Patrons->find($borrowernumber); + $borrowernumber = $input->param('borrowernumber') if ( $input->param('borrowernumber') ); $template->param('borrowernumber' => $borrowernumber); my $branchfilter = $input->param('branchcode') || C4::Context->userenv->{'branch'}; @@ -138,8 +140,10 @@ my $branchfilter = $input->param('branchcode') || C4::Context->userenv->{'branch ## Operations ## +my @messages; if ( $op =~ /cud-save/ ) { my @messages; + my $biblio = MarcRecordFromNewSuggestion({ title => $suggestion_only->{title}, author => $suggestion_only->{author}, @@ -198,7 +202,13 @@ if ( $op =~ /cud-save/ ) { if exists $suggestion_only->{branchcode} && $suggestion_only->{branchcode} eq ""; - &ModSuggestion($suggestion_only); + if ( $librarian->has_permission( { 'suggestions' => 'suggestions_manage' } ) ) { + &ModSuggestion($suggestion_only); + } + else { + push @messages, { type => 'error', code => 'no_manage_permission' }; + $template->param( messages => \@messages, ); + } if ( $notify ) { my $patron = Koha::Patrons->find( $suggestion_only->{managedby} ); @@ -238,7 +248,13 @@ if ( $op =~ /cud-save/ ) { } else { ## Adding some informations related to suggestion - Koha::Suggestion->new($suggestion_only)->store(); + if ( $librarian->has_permission({ 'suggestions' => 'suggestions_create' }) ) { + Koha::Suggestion->new($suggestion_only)->store(); + } + else { + push @messages, { type => 'error', code => 'no_delete_permission' }; + $template->param( messages => \@messages ); + } } # empty fields, to avoid filter in "SearchSuggestion" } @@ -300,17 +316,28 @@ elsif ($op eq "cud-update_status" ) { $suggestion->{reason} = $reason; } - foreach my $suggestionid (@editsuggestions) { - next unless $suggestionid; - $suggestion->{suggestionid} = $suggestionid; - &ModSuggestion($suggestion); + if ( $librarian->has_permission( { 'suggestions' => 'suggestions_manage' } ) ) { + foreach my $suggestionid (@editsuggestions) { + next unless $suggestionid; + $suggestion->{suggestionid} = $suggestionid; + &ModSuggestion($suggestion); + } + redirect_with_params($input); } - redirect_with_params($input); -}elsif ($op eq "cud-delete" ) { - foreach my $delete_field (@editsuggestions) { - &DelSuggestion( $borrowernumber, $delete_field,'intranet' ); + else { + push @messages, { type => 'error', code => 'no_manage_permission' }; + $template->param( messages => \@messages, ); + } +} elsif ($op eq "cud-delete" ) { + if ( $librarian->has_permission( { 'suggestions' => 'suggestions_delete' } ) ) { + foreach my $delete_field (@editsuggestions) { + &DelSuggestion( $borrowernumber, $delete_field, 'intranet' ); + } + redirect_with_params($input); + } else { + push @messages, { type => 'error', code => 'no_delete_permission' }; + $template->param( messages => \@messages, ); } - redirect_with_params($input); } elsif ($op eq "cud-archive" ) { Koha::Suggestions->find($_)->update({ archived => 1 }) for @editsuggestions; @@ -321,18 +348,32 @@ elsif ($op eq "cud-unarchive" ) { redirect_with_params($input); } elsif ( $op eq 'cud-update_itemtype' ) { - foreach my $suggestionid (@editsuggestions) { - next unless $suggestionid; - &ModSuggestion({ suggestionid => $suggestionid, itemtype => $new_itemtype }); + if ( $librarian->has_permission( { 'suggestions' => 'suggestions_manage' } ) ) { + my $new_itemtype = $input->param('suggestion_itemtype'); + foreach my $suggestionid (@editsuggestions) { + next unless $suggestionid; + &ModSuggestion({ suggestionid => $suggestionid, itemtype => $new_itemtype }); + } + redirect_with_params($input); + } + else { + push @messages, { type => 'error', code => 'no_manage_permission' }; + $template->param( messages => \@messages, ); } - redirect_with_params($input); } elsif ( $op eq 'cud-update_manager' ) { - foreach my $suggestionid (@editsuggestions) { - next unless $suggestionid; - &ModSuggestion({ suggestionid => $suggestionid, managedby => $sugg_managedby }); + if ( $librarian->has_permission( { 'suggestions' => 'suggestions_manage' } ) ) { + my $managedby = $input->param('suggestion_managedby'); + foreach my $suggestionid (@editsuggestions) { + next unless $suggestionid; + &ModSuggestion({ suggestionid => $suggestionid, managedby => $managedby }); + } + redirect_with_params($input); + } + else { + push @messages, { type => 'error', code => 'no_manage_permission' }; + $template->param( messages => \@messages, ); } - redirect_with_params($input); } elsif ( $op eq 'show' ) { $suggestion_ref=&GetSuggestion($$suggestion_ref{'suggestionid'}); diff --git a/t/Koha/Auth/Permissions.t b/t/Koha/Auth/Permissions.t index 67c1066fe03..037ce083991 100755 --- a/t/Koha/Auth/Permissions.t +++ b/t/Koha/Auth/Permissions.t @@ -239,7 +239,9 @@ subtest 'superlibrarian tests' => sub { 'CAN_user_stockrotation_manage_rota_items' => 1, 'CAN_user_stockrotation_manage_rotas' => 1, 'CAN_user_stockrotation' => 1, + 'CAN_user_suggestions_suggestions_create' => 1, 'CAN_user_suggestions_suggestions_manage' => 1, + 'CAN_user_suggestions_suggestions_delete' => 1, 'CAN_user_suggestions' => 1, 'CAN_user_superlibrarian' => 1, 'CAN_user_tools_access_files' => 1, -- 2.30.2