From d41c2fa78ee3eec280fb04e638a4ab3976dfe8dd Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 8 Nov 2022 11:20:39 -0300 Subject: [PATCH] Bug 31378: Add domain settings to IdP add page This patch introduces a small form for an initial domain configuration to the 'New identity provider' page, to avoid confusion on testers about required settings for things to work. To test: 1. Apply this patch 2. Verify you are now offered a configuration section for domain settings. Fields like 'Default category' and 'Default library' are mandatory. 3. Choosing some values makes them get stored on 'Submit' Signed-off-by: Tomas Cohen Arazi --- admin/identity_providers.pl | 56 ++++++++++----- .../admin/identity_provider_domains.tt | 2 +- .../en/modules/admin/identity_providers.tt | 71 ++++++++++++++++++- 3 files changed, 108 insertions(+), 21 deletions(-) diff --git a/admin/identity_providers.pl b/admin/identity_providers.pl index 77d78c90f40..9a5f0cd786a 100644 --- a/admin/identity_providers.pl +++ b/admin/identity_providers.pl @@ -26,6 +26,7 @@ use Try::Tiny qw( catch try ); use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); +use Koha::Database; use Koha::Auth::Identity::Providers; my $input = CGI->new; @@ -51,33 +52,52 @@ my @messages; if ( !$domain_ops && $op eq 'add' ) { + # IdP configuration params my $code = $input->param('code'); my $config = $input->param('config'); my $description = $input->param('description'); my $icon_url = $input->param('icon_url'); my $mapping = $input->param('mapping'); - my $matchpoint = $input->param('matchpoint'), + my $matchpoint = $input->param('matchpoint'); my $protocol = $input->param('protocol'); + # Domain configuration params + my $allow_opac = $input->param('allow_opac') // 0; + my $allow_staff = $input->param('allow_staff') // 0; + my $auto_register = $input->param('auto_register') // 0; + my $default_category_id = $input->param('default_category_id'); + my $default_library_id = $input->param('default_library_id'); + my $domain = $input->param('domain'); + my $update_on_auth = $input->param('update_on_$update_on_auth'); try { - my $provider = Koha::Auth::Identity::Provider->new( - { code => $code, - config => $config, - description => $description, - icon_url => $icon_url, - mapping => $mapping, - matchpoint => $matchpoint, - protocol => $protocol, + Koha::Database->new->schema->txn_do( + sub { + my $provider = Koha::Auth::Identity::Provider->new( + { code => $code, + config => $config, + description => $description, + icon_url => $icon_url, + mapping => $mapping, + matchpoint => $matchpoint, + protocol => $protocol, + } + )->store; + + Koha::Auth::Identity::Provider::Domain->new( + { identity_provider_id => $provider->identity_provider_id, + allow_opac => $allow_opac, + allow_staff => $allow_staff, + auto_register => $auto_register, + default_category_id => $default_category_id, + default_library_id => $default_library_id, + domain => $domain, + update_on_auth => $update_on_auth, + } + )->store; + + push @messages, { type => 'message', code => 'success_on_insert' }; } - )->store; - - Koha::Auth::Identity::Provider::Domain->new( - { - identity_provider_id => $provider->identity_provider_id, - } - )->store; - - push @messages, { type => 'message', code => 'success_on_insert' }; + ); } catch { if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/identity_provider_domains.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/identity_provider_domains.tt index 3ad8593025d..c803404771f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/identity_provider_domains.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/identity_provider_domains.tt @@ -152,7 +152,7 @@ - opac users of this domain to login with this identity provider + OPAC users from this domain to login with this identity provider.
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/identity_providers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/identity_providers.tt index 7505e901f93..460f37ac403 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/identity_providers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/identity_providers.tt @@ -1,5 +1,7 @@ [% USE raw %] [% USE Asset %] +[% USE Branches %] +[% USE Categories %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] @@ -87,6 +89,7 @@ <form action="/cgi-bin/koha/admin/identity_providers.pl" id="add" name="add" class="validated" method="post"> <input type="hidden" name="op" value="add" /> <fieldset class="rows"> + <legend id="identity_provider_basic">Basic configuration</legend> <ol> <li> <label for="code" class="required">Code: </label> @@ -116,10 +119,11 @@ </fieldset> <fieldset class="rows"> + <legend id="identity_provider_advanced">Advanced configuration</legend> <ol> <li> <label for="config" class="required json">Configuration: </label> - <textarea name="config" id="config" class="required"></textarea> + <textarea name="config" id="config" class="required" cols="75" rows="10"></textarea> <span class="required">Required</span> <div class="hint">Provider's main configuration. <button class="more btn btn-ligth" data-target="config"><i class="fa fa-caret-down"></i> More</button></div> <div class="hint more-config" style="display: none"> @@ -132,7 +136,7 @@ </li> <li> <label for="mapping" class="required json">Mapping: </label> - <textarea name="mapping" id="mapping" class="required"></textarea> + <textarea name="mapping" id="mapping" class="required" cols="75" rows="10"></textarea> <span class="required">Required</span> <div class="hint">Map provider's result to Koha patron's fields. <button class="more btn btn-ligth" data-target="mapping"><i class="fa fa-caret-down"></i> More</button></div> <div class="hint more-mapping" style="display: none"> @@ -162,6 +166,69 @@ </li> </ol> </fieldset> + + <fieldset class="rows"> + <legend id="identity_provider_domain">Domain configuration</legend> + <ol> + <li> + <label for="domain" class="required">Domain: </label> + <input type="text" name="domain" id="domain" class="required" size="60" /> + <span class="required">Required</span> + <div class="hint">Use * for any domain. You can add new domains later on the dedicated admin page.</div> + </li> + <li> + <label for="default_library_id">Default library: </label> + <select id="default_library_id" name="default_library_id" class="mandatory"> + [% PROCESS options_for_libraries libraries => Branches.all( unfiltered => 1, do_not_select_my_library => 1 ) %] + </select> + <span class="required">Required</span> + <div class="hint">Use this library for the patron on auto register</div> + </li> + <li> + <label for="default_category_id">Default category: </label> + [% SET categories = Categories.all() %] + <select name="default_category_id" id="default_category_id" class="mandatory"> + [% FOREACH category IN categories %] + <option value="[% category.categorycode | html %]">[% category.description | html %]</option> + [% END %] + </select> + <span class="required">Required</span> + <div class="hint">Use this category for the patron on auto register</div> + </li> + <li> + <label for="allow_opac">Allow OPAC: </label> + <select name="allow_opac" id="allow_opac"> + <option value="1">Yes</option> + <option value="0" selected="selected">No</option> + </select> + <div class="hint">Allow OPAC access to users from this domain to login with this identity provider.</div> + </li> + <li> + <label for="allow_opac">Allow staff: </label> + <select name="allow_staff" id="allow_staff"> + <option value="1">Yes</option> + <option value="0" selected="selected">No</option> + </select> + <div class="hint">Allow staff access to users from this domain to login with this identity provider.</div> + </li> + <li> + <label for="auto_register">Auto register: </label> + <select name="auto_register" id="auto_register"> + <option value="1">Yes</option> + <option value="0" selected="selected">No</option> + </select> + <div class="hint">Allow users to auto register on login.</div> + </li> + <li> + <label for="update_on_auth">Update on login: </label> + <select name="update_on_auth" id="update_on_auth"> + <option value="1">Yes</option> + <option value="0" selected="selected">No</option> + </select> + <div class="hint">Update user data on login.</div> + </ol> + </fieldset> + <fieldset class="action"> <input type="submit" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/admin/identity_providers.pl">Cancel</a> -- 2.34.1