From 4d9ed4b897e8a95cc18bc2dbcc6ccd34bff211e9 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 28 Oct 2022 22:15:10 +0000 Subject: [PATCH] Bug 32030: Add users to licenses Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/ERM/License.pm | 26 ++++++++++++++++ Koha/REST/V1/ERM/Licenses.pm | 4 +++ .../js/vue/components/ERM/LicensesFormAdd.vue | 16 +++++++++- .../js/vue/components/ERM/LicensesShow.vue | 30 +++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/Koha/ERM/License.pm b/Koha/ERM/License.pm index 9dd22991d2..412dd9da3a 100644 --- a/Koha/ERM/License.pm +++ b/Koha/ERM/License.pm @@ -22,6 +22,7 @@ use Koha::Database; use base qw(Koha::Object); use Koha::Acquisition::Bookseller; +use Koha::ERM::UserRoles; use Koha::ERM::Documents; =head1 NAME @@ -34,6 +35,31 @@ Koha::ERM::License - Koha ERM License Object class =cut +=head3 user_roles + +Returns the user roles for this license + +=cut + +sub user_roles { + my ( $self, $user_roles ) = @_; + + if ( $user_roles ) { + my $schema = $self->_result->result_source->schema; + $schema->txn_do( + sub { + $self->user_roles->delete; + + for my $user_role (@$user_roles) { + $self->_result->add_to_erm_user_roles($user_role); + } + } + ); + } + my $user_roles_rs = $self->_result->erm_user_roles; + return Koha::ERM::UserRoles->_new_from_dbic($user_roles_rs); +} + =head3 documents Returns or updates the documents for this license diff --git a/Koha/REST/V1/ERM/Licenses.pm b/Koha/REST/V1/ERM/Licenses.pm index 15a40ef7e2..f3e19a697c 100644 --- a/Koha/REST/V1/ERM/Licenses.pm +++ b/Koha/REST/V1/ERM/Licenses.pm @@ -91,9 +91,11 @@ sub add { my $body = $c->validation->param('body'); + my $user_roles = delete $body->{user_roles} // []; my $documents = delete $body->{documents} // []; my $license = Koha::ERM::License->new_from_api($body)->store; + $license->user_roles($user_roles); $license->documents($documents); $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id); @@ -172,9 +174,11 @@ sub update { my $body = $c->validation->param('body'); + my $user_roles = delete $body->{user_roles} // []; my $documents = delete $body->{documents} // []; $license->set_from_api($body)->store; + $license->user_roles($user_roles); $license->documents($documents); $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id); diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue index c3f45c6df5..b5034591e2 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue @@ -124,6 +124,11 @@ +
@@ -142,6 +147,7 @@