1 package Koha::REST::V1::Auth::Provider::Domains;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Mojo::Base 'Mojolicious::Controller';
22 use Koha::Auth::Provider::Domains;
23 use Koha::Auth::Providers;
27 use Scalar::Util qw(blessed);
32 Koha::REST::V1::Auth::Provider::Domains - Controller library for handling
33 authentication provider domains routes.
39 Controller method for listing authentication provider domains.
44 my $c = shift->openapi->valid_input or return;
47 my $auth_provider_id = $c->validation->param('auth_provider_id');
48 my $provider = Koha::Auth::Providers->find($auth_provider_id);
54 error => 'Object not found',
55 error_code => 'not_found',
60 my $domains_rs = $provider->domains;
63 openapi => $c->objects->search($domains_rs)
66 $c->unhandled_exception($_);
72 Controller method for retrieving an authentication provider domain.
77 my $c = shift->openapi->valid_input or return;
81 my $auth_provider_id = $c->validation->param('auth_provider_id');
82 my $provider = Koha::Auth::Providers->find($auth_provider_id);
88 error => 'Object not found',
89 error_code => 'not_found',
94 my $domains_rs = $provider->domains;
96 my $auth_provider_domain_id = $c->validation->param('auth_provider_domain_id');
97 my $domain = $c->objects->find( $domains_rs, $auth_provider_domain_id );
103 error => 'Object not found',
104 error_code => 'not_found',
109 return $c->render( status => 200, openapi => $domain );
111 $c->unhandled_exception($_);
117 Controller method for adding an authentication provider.
122 my $c = shift->openapi->valid_input or return;
126 Koha::Database->new->schema->txn_do(
128 my $domain = Koha::Auth::Provider::Domain->new_from_api( $c->validation->param('body') );
131 $c->res->headers->location( $c->req->url->to_string . '/' . $domain->id );
134 openapi => $domain->to_api
139 if ( blessed($_) and $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
143 error => 'Object not found',
144 error_code => 'not_found',
149 $c->unhandled_exception($_);
155 Controller method for updating an authentication provider domain.
160 my $c = shift->openapi->valid_input or return;
162 my $auth_provider_id = $c->validation->param('auth_provider_id');
163 my $auth_provider_domain_id = $c->validation->param('auth_provider_domain_id');
165 my $domain = Koha::Auth::Provider::Domains->find(
166 { auth_provider_id => $auth_provider_id, auth_provider_domain_id => $auth_provider_domain_id } );
172 error => 'Object not found',
173 error_code => 'not_found',
180 Koha::Database->new->schema->txn_do(
183 $domain->set_from_api( $c->validation->param('body') );
184 $domain->store->discard_changes;
188 openapi => $domain->to_api
193 $c->unhandled_exception($_);
199 Controller method for deleting an authentication provider.
204 my $c = shift->openapi->valid_input or return;
206 my $auth_provider_id = $c->validation->param('auth_provider_id');
207 my $auth_provider_domain_id = $c->validation->param('auth_provider_domain_id');
209 my $domain = Koha::Auth::Provider::Domains->find(
210 { auth_provider_id => $auth_provider_id, auth_provider_domain_id => $auth_provider_domain_id } );
216 error => 'Object not found',
217 error_code => 'not_found',
229 $c->unhandled_exception($_);