From b8e77881678b840ae1b145deecf72b09a6a29a7b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 8 Mar 2022 12:03:14 +0100 Subject: [PATCH] Bug 32030: ERM - Users Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/ERM/Agreement.pm | 14 ++ Koha/ERM/Agreement/UserRole.pm | 58 +++++++ Koha/ERM/Agreement/UserRoles.pm | 53 +++++++ Koha/REST/V1/ERM.pm | 58 +++++++ api/v1/swagger/paths/erm_users.yaml | 47 ++++++ api/v1/swagger/swagger.yaml | 4 + erm/agreements.pl | 15 ++ .../prog/en/includes/patron-search.inc | 6 +- .../prog/en/modules/erm/agreements.tt | 143 ++++++++++++++++-- 9 files changed, 385 insertions(+), 13 deletions(-) create mode 100644 Koha/ERM/Agreement/UserRole.pm create mode 100644 Koha/ERM/Agreement/UserRoles.pm create mode 100644 Koha/REST/V1/ERM.pm create mode 100644 api/v1/swagger/paths/erm_users.yaml diff --git a/Koha/ERM/Agreement.pm b/Koha/ERM/Agreement.pm index bfa687657b..2b8789b36c 100644 --- a/Koha/ERM/Agreement.pm +++ b/Koha/ERM/Agreement.pm @@ -22,6 +22,7 @@ use Koha::Database; use base qw(Koha::Object); use Koha::ERM::Agreement::Periods; +use Koha::ERM::Agreement::UserRoles; =head1 NAME @@ -46,6 +47,19 @@ sub periods { return Koha::ERM::Agreement::Periods->_new_from_dbic($periods_rs); } +=head3 user_roles + +Returns the user roles for this agreement + +=cut + +sub user_roles { + my ( $self ) = @_; + + my $user_roles_rs = $self->_result->erm_agreement_user_roles; + return Koha::ERM::Agreement::UserRoles->_new_from_dbic($user_roles_rs); +} + =head2 Internal methods =head3 _type diff --git a/Koha/ERM/Agreement/UserRole.pm b/Koha/ERM/Agreement/UserRole.pm new file mode 100644 index 0000000000..9e749ac123 --- /dev/null +++ b/Koha/ERM/Agreement/UserRole.pm @@ -0,0 +1,58 @@ +package Koha::ERM::Agreement::UserRole; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Koha::Database; + +use Koha::Patrons; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::ERM::Agreement::UserRole - Koha Agreement UserRole Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 patron + +Return the patron linked to this user role + +=cut + +sub patron { + my ( $self ) = @_; + my $patron_rs = $self->_result->user; + return Koha::Patron->_new_from_dbic($patron_rs); +} + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'ErmAgreementUserRole'; +} + +1; diff --git a/Koha/ERM/Agreement/UserRoles.pm b/Koha/ERM/Agreement/UserRoles.pm new file mode 100644 index 0000000000..f200f25834 --- /dev/null +++ b/Koha/ERM/Agreement/UserRoles.pm @@ -0,0 +1,53 @@ +package Koha::ERM::Agreement::UserRoles; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + + +use Koha::Database; + +use Koha::ERM::Agreement::UserRole; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::ERM::Agreement::UserRoles- Koha Agreement UserRole Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'ErmAgreementUserRole'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::ERM::Agreement::UserRole'; +} + +1; diff --git a/Koha/REST/V1/ERM.pm b/Koha/REST/V1/ERM.pm new file mode 100644 index 0000000000..3f98a8e12d --- /dev/null +++ b/Koha/REST/V1/ERM.pm @@ -0,0 +1,58 @@ +package Koha::REST::V1::ERM; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Mojo::Base 'Mojolicious::Controller'; + +use Koha::Patrons; + +use Try::Tiny qw( catch try ); + +=head1 NAME + +Koha::REST::V1::Acquisitions::Funds + +=head1 API + +=head2 Class methods + +=head3 list_users + +Return the list of possible ERM' users + +=cut + +sub list_users { + my $c = shift->openapi->valid_input or return; + + return try { + + my $patrons_rs = Koha::Patrons->search->filter_by_have_permission('erm'); + my $patrons = $c->objects->search( $patrons_rs ); + + return $c->render( + status => 200, + openapi => $patrons + ); + } + catch { + $c->unhandled_exception($_); + }; +} + +1; diff --git a/api/v1/swagger/paths/erm_users.yaml b/api/v1/swagger/paths/erm_users.yaml new file mode 100644 index 0000000000..b06bb217d7 --- /dev/null +++ b/api/v1/swagger/paths/erm_users.yaml @@ -0,0 +1,47 @@ +--- +/erm/users: + get: + x-mojo-to: ERM#list_users + operationId: listERMUsers + description: This resource returns a list of patron allowed to be users of the ERM module + summary: List possibe users for ERM + tags: + - ERM + parameters: + - $ref: ../parameters.yaml#/match + - $ref: ../parameters.yaml#/order_by + - $ref: ../parameters.yaml#/page + - $ref: ../parameters.yaml#/per_page + - $ref: ../parameters.yaml#/q_param + - $ref: ../parameters.yaml#/q_body + - $ref: ../parameters.yaml#/q_header + produces: + - application/json + responses: + "200": + description: A list of ERM' users + schema: + type: array + items: + $ref: ../definitions.yaml#/patron + "403": + description: Access forbidden + schema: + $ref: ../definitions.yaml#/error + "500": + description: | + Internal server error. Possible `error_code` attribute values: + + * `internal_server_error` + schema: + $ref: ../definitions.yaml#/error + "503": + description: Under maintenance + schema: + $ref: ../definitions.yaml#/error + x-koha-authorization: + permissions: + erm: 1 + x-koha-embed: + - extended_attributes + diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index 1bc55f73d7..62daad3655 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -157,6 +157,10 @@ paths: $ref: ./paths/config_smtp_servers.yaml#/~1config~1smtp_servers "/config/smtp_servers/{smtp_server_id}": $ref: "./paths/config_smtp_servers.yaml#/~1config~1smtp_servers~1{smtp_server_id}" + /erm/agreements: + $ref: ./paths/erm_agreements.yaml#/~1erm~1agreements + /erm/users: + $ref: ./paths/erm_users.yaml#/~1erm~1users /holds: $ref: ./paths/holds.yaml#/~1holds "/holds/{hold_id}": diff --git a/erm/agreements.pl b/erm/agreements.pl index 432b950009..88dfa1a550 100755 --- a/erm/agreements.pl +++ b/erm/agreements.pl @@ -107,6 +107,7 @@ elsif ( $op eq 'add_validate' ) { if ( $stored ) { if ( $agreement_id ) { $agreement->periods->delete; + $agreement->user_roles->delete; } for my $unique_id ( $input->multi_param('period_unique_id') ) { my $started_on = $input->param( 'started_on_' . $unique_id ); @@ -129,6 +130,20 @@ elsif ( $op eq 'add_validate' ) { } )->store; } + + for my $unique_id ( $input->multi_param('user_unique_id') ) { + my $user_id = $input->param('user_id_' . $unique_id); + next unless $user_id; + my $role = $input->param('user_role_' . $unique_id); + Koha::ERM::Agreement::UserRole->new( + { + agreement_id => $agreement->agreement_id, + user_id => $user_id, + role => $role, + } + )->store; + } + } }); $op = 'list'; 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 3d1de0eb15..cb97afa9c3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -103,7 +103,7 @@ [%# - Browse by last name %] [%# - The table %] [%# Get the following parameters: %] -[%# - filter: can be 'suggestions_managers', 'orders_managers', 'funds_owners' or 'funds_users' to filter patrons on their permissions %] +[%# - filter: can be 'suggestions_managers', 'orders_managers', 'funds_owners', 'funds_users' or 'erm_users' to filter patrons on their permissions %] [%# - table_id: the ID of the table %] [%# open_on_row_click: See patron_search_js %] [%# columns: See patron_search_js %] @@ -115,6 +115,8 @@
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' %]
Only staff with superlibrarian or acquisitions permissions (or budget_modify permission if granular permissions are enabled) are returned in the search results
+ [% ELSIF filter == 'erm_users' %] +
Only staff with superlibrarian or ERM permissions are returned in the search results
[% END %]
@@ -269,6 +271,8 @@ let patron_search_url = '/api/v1/acquisitions/funds/owners'; [% CASE 'funds_users' %] let patron_search_url = '/api/v1/acquisitions/funds/users'; + [% CASE 'erm_users' %] + let patron_search_url = '/api/v1/erm/users'; [% CASE %] let patron_search_url = '/api/v1/patrons'; [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/erm/agreements.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/erm/agreements.tt index 9505b3684a..092b61e3f4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/erm/agreements.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/erm/agreements.tt @@ -218,7 +218,53 @@ [% ELSE %] [% PROCESS agreement_period id => 1 %] [% END %] - + + + +[% BLOCK agreement_user %] +
+ + User [% id | html %] + Remove this user + + + +
    +
  1. + + + [% IF u %] + + [% INCLUDE 'patron-title.inc' patron = u.patron %] + + + [% END %] + + (Select user) +
  2. + +
  3. + + +
  4. +
+
+[% END %] + +
+ Users + [% IF agreement.user_roles.count %] + [% FOR u IN agreement.user_roles %] + [% PROCESS agreement_user user => u, id => loop.count %] + [% END %] + [% ELSE %] + [% PROCESS agreement_user, id => 1 %] + [% END %] + +
@@ -321,6 +367,7 @@ [% INCLUDE 'calendar.inc' %] [% INCLUDE 'datatables.inc' %] [% INCLUDE 'columns_settings.inc' %] + [% INCLUDE 'js-patron-format.inc' %] [% END %] [% INCLUDE 'intranet-bottom.inc' %] -- 2.39.5