1 package Koha::REST::V1::Auth::Identity::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::Identity::Provider::Domains;
23 use Koha::Auth::Identity::Providers;
27 use Scalar::Util qw(blessed);
32 Koha::REST::V1::Auth::Identity::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 $identity_provider_id = $c->validation->param('identity_provider_id');
48 my $provider = Koha::Auth::Identity::Providers->find($identity_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 $identity_provider_id = $c->validation->param('identity_provider_id');
82 my $provider = Koha::Auth::Identity::Providers->find($identity_provider_id);
88 error => 'Object not found',
89 error_code => 'not_found',
94 my $domains_rs = $provider->domains;
96 my $identity_provider_domain_id = $c->validation->param('identity_provider_domain_id');
97 my $domain = $c->objects->find( $domains_rs, $identity_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;
125 my $params = $c->validation->param('body');
126 $params->{identity_provider_id} = $c->validation->param('identity_provider_id');
127 Koha::Database->new->schema->txn_do(
129 my $domain = Koha::Auth::Identity::Provider::Domain->new_from_api( $params );
132 $c->res->headers->location( $c->req->url->to_string . '/' . $domain->id );
135 openapi => $domain->to_api
140 if ( blessed($_) and $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
144 error => 'Object not found',
145 error_code => 'not_found',
150 $c->unhandled_exception($_);
156 Controller method for updating an authentication provider domain.
161 my $c = shift->openapi->valid_input or return;
163 my $identity_provider_id = $c->validation->param('identity_provider_id');
164 my $identity_provider_domain_id = $c->validation->param('identity_provider_domain_id');
166 my $domain = Koha::Auth::Identity::Provider::Domains->find(
167 { identity_provider_id => $identity_provider_id, identity_provider_domain_id => $identity_provider_domain_id } );
173 error => 'Object not found',
174 error_code => 'not_found',
181 Koha::Database->new->schema->txn_do(
184 $domain->set_from_api( $c->validation->param('body') );
185 $domain->store->discard_changes;
189 openapi => $domain->to_api
194 $c->unhandled_exception($_);
200 Controller method for deleting an authentication provider.
205 my $c = shift->openapi->valid_input or return;
207 my $identity_provider_id = $c->validation->param('identity_provider_id');
208 my $identity_provider_domain_id = $c->validation->param('identity_provider_domain_id');
210 my $domain = Koha::Auth::Identity::Provider::Domains->find(
211 { identity_provider_id => $identity_provider_id, identity_provider_domain_id => $identity_provider_domain_id } );
217 error => 'Object not found',
218 error_code => 'not_found',
230 $c->unhandled_exception($_);