View | Details | Raw Unified | Return to bug 31378
Collapse All | Expand All

(-)a/admin/authentication_providers.pl (+299 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2022 Theke Solutions
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use CGI qw ( -utf8 );
23
use Scalar::Util qw( blessed );
24
use Try::Tiny qw( catch try );
25
26
use C4::Auth qw( get_template_and_user );
27
use C4::Output qw( output_html_with_http_headers );
28
29
use Koha::Auth::Providers;
30
31
my $input         = CGI->new;
32
my $op            = $input->param('op') || 'list';
33
my $domain_ops    = $input->param('domain_ops');
34
my $auth_provider_id = $input->param('auth_provider_id');
35
my $auth_provider;
36
37
$auth_provider = Koha::Auth::Providers->find($auth_provider_id)
38
    unless !$auth_provider_id;
39
40
my $template_name = $domain_ops ? 'admin/authentication_provider_domains.tt' : 'admin/authentication_providers.tt';
41
42
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
43
    {   template_name   => $template_name,
44
        query           => $input,
45
        type            => "intranet",
46
        flagsrequired   => { parameters => 'manage_authentication_providers' },
47
    }
48
);
49
50
my @messages;
51
52
if ( !$domain_ops && $op eq 'add' ) {
53
54
    my $code        = $input->param('code');
55
    my $config      = $input->param('config');
56
    my $description = $input->param('description');
57
    my $icon_url    = $input->param('icon_url');
58
    my $mapping     = $input->param('mapping');
59
    my $matchpoint  = $input->param('matchpoint'),
60
    my $protocol    = $input->param('protocol');
61
62
    try {
63
        my $provider = Koha::Auth::Provider->new(
64
            {   code        => $code,
65
                config      => $config,
66
                description => $description,
67
                icon_url    => $icon_url,
68
                mapping     => $mapping,
69
                matchpoint  => $matchpoint,
70
                protocol    => $protocol,
71
            }
72
        )->store;
73
74
        Koha::Auth::Provider::Domain->new(
75
            {
76
                auth_provider_id => $provider->auth_provider_id,
77
            }
78
        )->store;
79
80
        push @messages, { type => 'message', code => 'success_on_insert' };
81
    }
82
    catch {
83
        if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
84
            push @messages,
85
              {
86
                type   => 'alert',
87
                code   => 'error_on_insert',
88
                reason => 'duplicate_id'
89
              };
90
        }
91
    };
92
93
    # list servers after adding
94
    $op = 'list';
95
}
96
elsif ( $domain_ops && $op eq 'add' ) {
97
98
    my $allow_opac          = $input->param('allow_opac');
99
    my $allow_staff         = $input->param('allow_staff');
100
    my $auth_provider_id    = $input->param('auth_provider_id');
101
    my $auto_register       = $input->param('auto_register');
102
    my $default_category_id = $input->param('default_category_id');
103
    my $default_library_id  = $input->param('default_library_id');
104
    my $domain              = $input->param('domain');
105
    my $update_on_auth      = $input->param('update_on_auth');
106
107
    try {
108
109
        Koha::Auth::Provider::Domain->new(
110
            {
111
                allow_opac          => $allow_opac,
112
                allow_staff         => $allow_staff,
113
                auth_provider_id    => $auth_provider_id,
114
                auto_register       => $auto_register,
115
                default_category_id => $default_category_id,
116
                default_library_id  => $default_library_id,
117
                domain              => $domain,
118
                update_on_auth      => $update_on_auth,
119
            }
120
        )->store;
121
122
        push @messages, { type => 'message', code => 'success_on_insert' };
123
    }
124
    catch {
125
        if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
126
            push @messages,
127
              {
128
                type   => 'alert',
129
                code   => 'error_on_insert',
130
                reason => 'duplicate_id'
131
              };
132
        }
133
    };
134
135
    # list servers after adding
136
    $op = 'list';
137
}
138
elsif ( !$domain_ops && $op eq 'edit_form' ) {
139
140
    if ( $auth_provider ) {
141
        $template->param(
142
            auth_provider => $auth_provider
143
        );
144
    }
145
    else {
146
        push @messages,
147
            {
148
                type   => 'alert',
149
                code   => 'error_on_edit',
150
                reason => 'invalid_id'
151
            };
152
    }
153
}
154
elsif ( $domain_ops && $op eq 'edit_form' ) {
155
    my $auth_provider_domain_id = $input->param('auth_provider_domain_id');
156
    my $auth_provider_domain;
157
158
    $auth_provider_domain = Koha::Auth::Provider::Domains->find($auth_provider_domain_id)
159
        unless !$auth_provider_domain_id;
160
161
    if ( $auth_provider_domain ) {
162
        $template->param(
163
            auth_provider_domain => $auth_provider_domain
164
        );
165
    }
166
    else {
167
        push @messages,
168
            {
169
                type   => 'alert',
170
                code   => 'error_on_edit',
171
                reason => 'invalid_id'
172
            };
173
    }
174
}
175
elsif ( !$domain_ops && $op eq 'edit_save' ) {
176
177
    if ( $auth_provider ) {
178
179
        my $code        = $input->param('code');
180
        my $config      = $input->param('config');
181
        my $description = $input->param('description');
182
        my $icon_url    = $input->param('icon_url');
183
        my $mapping     = $input->param('mapping');
184
        my $matchpoint  = $input->param('matchpoint');
185
        my $protocol    = $input->param('protocol');
186
187
        try {
188
189
            $auth_provider->set(
190
                {   code        => $code,
191
                    config      => $config,
192
                    description => $description,
193
                    icon_url    => $icon_url,
194
                    mapping     => $mapping,
195
                    matchpoint  => $matchpoint,
196
                    protocol    => $protocol,
197
                }
198
            )->store;
199
200
            push @messages,
201
            {
202
                type => 'message',
203
                code => 'success_on_update'
204
            };
205
        }
206
        catch {
207
            push @messages,
208
            {
209
                type   => 'alert',
210
                code   => 'error_on_update'
211
            };
212
        };
213
214
        # list servers after adding
215
        $op = 'list';
216
    }
217
    else {
218
        push @messages,
219
            {
220
                type   => 'alert',
221
                code   => 'error_on_update',
222
                reason => 'invalid_id'
223
            };
224
    }
225
}
226
elsif ( $domain_ops && $op eq 'edit_save' ) {
227
228
    my $auth_provider_domain_id = $input->param('auth_provider_domain_id');
229
    my $auth_provider_domain;
230
231
    $auth_provider_domain = Koha::Auth::Provider::Domains->find($auth_provider_domain_id)
232
        unless !$auth_provider_domain_id;
233
234
    if ( $auth_provider_domain ) {
235
236
        my $auth_provider_id    = $input->param('auth_provider_id');
237
        my $domain              = $input->param('domain');
238
        my $auto_register       = $input->param('auto_register');
239
        my $update_on_auth      = $input->param('update_on_auth');
240
        my $default_library_id  = $input->param('default_library_id');
241
        my $default_category_id = $input->param('default_category_id');
242
        my $allow_opac          = $input->param('allow_opac');
243
        my $allow_staff         = $input->param('allow_staff');
244
245
        try {
246
247
            $auth_provider_domain->set(
248
                {
249
                    auth_provider_id    => $auth_provider_id,
250
                    domain              => $domain,
251
                    auto_register       => $auto_register,
252
                    update_on_auth      => $update_on_auth,
253
                    default_library_id  => $default_library_id,
254
                    default_category_id => $default_category_id,
255
                    allow_opac          => $allow_opac,
256
                    allow_staff         => $allow_staff,
257
                }
258
            )->store;
259
260
            push @messages,
261
            {
262
                type => 'message',
263
                code => 'success_on_update'
264
            };
265
        }
266
        catch {
267
            push @messages,
268
            {
269
                type   => 'alert',
270
                code   => 'error_on_update'
271
            };
272
        };
273
274
        # list servers after adding
275
        $op = 'list';
276
    }
277
    else {
278
        push @messages,
279
            {
280
                type   => 'alert',
281
                code   => 'error_on_update',
282
                reason => 'invalid_id'
283
            };
284
    }
285
}
286
287
if ( $domain_ops ) {
288
    $template->param(
289
        auth_provider_code => $auth_provider->code,
290
        auth_provider_id   => $auth_provider_id,
291
    );
292
}
293
294
$template->param(
295
    op       => $op,
296
    messages => \@messages,
297
);
298
299
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc (-1 / +4 lines)
Lines 141-149 Link Here
141
        </ul>
141
        </ul>
142
    [% END %]
142
    [% END %]
143
143
144
    [% IF ( CAN_user_parameters_manage_smtp_servers || CAN_user_parameters_manage_search_targets || CAN_user_parameters_manage_didyoumean || CAN_user_parameters_manage_column_config || CAN_user_parameters_manage_audio_alerts || ( CAN_user_parameters_manage_sms_providers && Koha.Preference('SMSSendDriver') == 'Email' ) || CAN_user_parameters_manage_usage_stats || CAN_user_parameters_manage_additional_fields || ( Koha.Preference('EnableAdvancedCatalogingEditor') && CAN_user_parameters_manage_keyboard_shortcuts ) ) %]
144
    [% IF ( CAN_user_parameters_manage_authentication_providers || CAN_user_parameters_manage_smtp_servers || CAN_user_parameters_manage_search_targets || CAN_user_parameters_manage_didyoumean || CAN_user_parameters_manage_column_config || CAN_user_parameters_manage_audio_alerts || ( CAN_user_parameters_manage_sms_providers && Koha.Preference('SMSSendDriver') == 'Email' ) || CAN_user_parameters_manage_usage_stats || CAN_user_parameters_manage_additional_fields || ( Koha.Preference('EnableAdvancedCatalogingEditor') && CAN_user_parameters_manage_keyboard_shortcuts ) ) %]
145
        <h5>Additional parameters</h5>
145
        <h5>Additional parameters</h5>
146
        <ul>
146
        <ul>
147
            [% IF ( CAN_user_parameters_manage_authentication_providers) %]
148
                <li><a href="/cgi-bin/koha/admin/authentication_providers.pl">Authentication providers</a></li>
149
            [% END %]
147
            [% IF ( CAN_user_parameters_manage_search_targets ) %]
150
            [% IF ( CAN_user_parameters_manage_search_targets ) %]
148
                <li><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50/SRU servers</a></li>
151
                <li><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50/SRU servers</a></li>
149
            [% END %]
152
            [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (-1 / +5 lines)
Lines 238-248 Link Here
238
                </dl>
238
                </dl>
239
            [% END %]
239
            [% END %]
240
240
241
            [% IF ( ( CAN_user_parameters_manage_smtp_servers || CAN_user_parameters_manage_search_targets || CAN_user_parameters_manage_didyoumean || CAN_user_parameters_manage_column_config || CAN_user_parameters_manage_audio_alerts || CAN_user_parameters_manage_sms_providers && Koha.Preference('SMSSendDriver') == 'Email' ) || CAN_user_parameters_manage_usage_stats || CAN_user_parameters_manage_additional_fields || CAN_user_parameters_manage_mana || (Koha.Preference('EnableAdvancedCatalogingEditor') && CAN_user_parameters_manage_keyboard_shortcuts) ) %]
241
            [% IF ( ( CAN_user_parameters_manage_authentication_providers || CAN_user_parameters_manage_smtp_servers || CAN_user_parameters_manage_search_targets || CAN_user_parameters_manage_didyoumean || CAN_user_parameters_manage_column_config || CAN_user_parameters_manage_audio_alerts || CAN_user_parameters_manage_sms_providers && Koha.Preference('SMSSendDriver') == 'Email' ) || CAN_user_parameters_manage_usage_stats || CAN_user_parameters_manage_additional_fields || CAN_user_parameters_manage_mana || (Koha.Preference('EnableAdvancedCatalogingEditor') && CAN_user_parameters_manage_keyboard_shortcuts) ) %]
242
                <h3>Additional parameters</h3>
242
                <h3>Additional parameters</h3>
243
                <dl>
243
                <dl>
244
                        <!-- <dt><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></dt>
244
                        <!-- <dt><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></dt>
245
                        <dd>Printers (UNIX paths).</dd> -->
245
                        <dd>Printers (UNIX paths).</dd> -->
246
                    [% IF ( CAN_user_parameters_manage_authentication_providers) %]
247
                        <dt><a href="/cgi-bin/koha/admin/authentication_providers.pl">Authentication providers</a></dt>
248
                        <dd>Define which external authentication providers to use</dd>
249
                    [% END %]
246
                    [% IF ( CAN_user_parameters_manage_search_targets ) %]
250
                    [% IF ( CAN_user_parameters_manage_search_targets ) %]
247
                        <dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50/SRU servers</a></dt>
251
                        <dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50/SRU servers</a></dt>
248
                        <dd>Define which external servers to query for MARC data</dd>
252
                        <dd>Define which external servers to query for MARC data</dd>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authentication_provider_domains.tt (+476 lines)
Line 0 Link Here
1
[% USE raw %]
2
[% USE Asset %]
3
[% USE Branches %]
4
[% USE Categories %]
5
[% SET footerjs = 1 %]
6
[% INCLUDE 'doc-head-open.inc' %]
7
<title>
8
    [% IF op == 'add_form' %]
9
        New authentication provider domain &rsaquo; [% ELSIF op == 'edit_form' %]
10
        Edit authentication provider domain &rsaquo; [% END %]
11
12
    Authentication providers &rsaquo; Administration &rsaquo; Koha
13
</title>
14
[% INCLUDE 'doc-head-close.inc' %]
15
</head>
16
17
<body id="admin_auth_provider_domains" class="admin">
18
[% INCLUDE 'header.inc' %]
19
[% INCLUDE 'prefs-admin-search.inc' %]
20
21
<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
22
    <ol>
23
        <li>
24
            <a href="/cgi-bin/koha/mainpage.pl">Home</a>
25
        </li>
26
        <li>
27
            <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
28
        </li>
29
30
        <li>
31
            <a href="/cgi-bin/koha/admin/authentication_providers.pl">Authentication providers</a>
32
        </li>
33
34
        [% IF op == 'add_form' %]
35
            <li>
36
                <a href="/cgi-bin/koha/admin/authentication_providers.pl?domain_ops=1&amp;auth_provider_id=[%- auth_provider_id | uri -%]">Domains for [%- auth_provider_name | html -%]</a>
37
            </li>
38
            <li>
39
                <a href="#" aria-current="page">
40
                    New Domain
41
                </a>
42
            </li>
43
44
        [% ELSIF op == 'edit_form' %]
45
            <li>
46
                <a href="/cgi-bin/koha/admin/authentication_providers.pl?domain_ops=1&amp;auth_provider_id=[%- auth_provider_id | uri -%]">Domains for [%- auth_provider_name | html -%]</a>
47
            </li>
48
            <li>
49
                <a href="#" aria-current="page">
50
                    Edit Domain
51
                </a>
52
            </li>
53
54
        [% ELSE %]
55
            <li>
56
                <a href="#" aria-current="page">
57
                    Domains for [%- auth_provider_code | html -%]
58
                </a>
59
            </li>
60
        [% END %]
61
    </ol>
62
</nav>
63
64
<div class="main container-fluid">
65
    <div class="row">
66
        <div class="col-sm-10 col-sm-push-2">
67
            <main>
68
69
[% FOREACH m IN messages %]
70
    <div class="dialog [% m.type | html %]" id="auth_provider_domain_action_result_dialog">
71
        [% SWITCH m.code %]
72
        [% CASE 'error_on_update' %]
73
            <span>An error occurred trying to open the authentication provider domain for editing. The passed id is invalid.</span>
74
        [% CASE 'error_on_insert' %]
75
            <span>An error occurred when adding a new authentication provider domain.</span>
76
        [% CASE 'success_on_update' %]
77
            <span>Authentication provider domain updated successfully.</span>
78
        [% CASE 'success_on_insert' %]
79
            <span>Authentication provider domain added successfully.</span>
80
        [% CASE %]
81
            <span>[% m.code | html %]</span>
82
        [% END %]
83
    </div>
84
[% END %]
85
86
    <div class="dialog message" id="auth_provider_domain_delete_success" style="display: none;"></div>
87
    <div class="dialog alert"   id="auth_provider_domain_delete_error"   style="display: none;"></div>
88
89
[% IF op == 'add_form' %]
90
    <h1>New authentication provider domain</h1>
91
    <form action="/cgi-bin/koha/admin/authentication_providers.pl" id="add" name="add" class="validated" method="post">
92
        <input type="hidden" name="op" value="add" />
93
        <input type="hidden" name="domain_ops" value="1" />
94
        <input type="hidden" name="auth_provider_id" value="[%- auth_provider_id | html -%]" />
95
        <fieldset class="rows">
96
            <ol>
97
                <li>
98
                    <label for="domain">Domain: </label>
99
                    <input type="text" name="domain" id="domain" size="60" />
100
                </li>
101
            </ol>
102
        </fieldset>
103
104
        <fieldset class="rows">
105
            <ol>
106
                <li>
107
                    <label for="update_on_auth">Update on login: </label>
108
                    <select name="update_on_auth" id="update_on_auth">
109
                        <option value="1">Update</option>
110
                        <option value="0" selected="selected">Don't update</option>
111
                    </select>
112
                    <span>user data on login</span>
113
                </li>
114
                <li>
115
                    <label for="auto_register">Auto register: </label>
116
                    <select name="auto_register" id="auto_register">
117
                        <option value="1">Allow</option>
118
                        <option value="0" selected="selected">Don't allow</option>
119
                    </select>
120
                    <span>users to auto register on login</span>
121
                </li>
122
                <li>
123
                    <label for="default_library_id">Default library: </label>
124
                    <select id="default_library_id" name="default_library_id">
125
                        [% PROCESS options_for_libraries libraries => Branches.all( unfiltered => 1, do_not_select_my_library => 1 ) %]
126
                    </select>
127
                </li>
128
                <li>
129
                    <label for="default_category_id">Default category: </label>
130
                    [% SET categories = Categories.all() %]
131
                    <select name="default_category_id" id="default_category_id">
132
                        [% FOREACH category IN categories %]
133
                            <option value="[% category.categorycode | html %]">[% category.description | html %]</option>
134
                        [% END %]
135
                    </select>
136
                </li>
137
                <li>
138
                    <label for="allow_opac">Allow opac: </label>
139
                    <select name="allow_opac" id="allow_opac">
140
                        <option value="1" selected="selected">Allow</option>
141
                        <option value="0">Don't allow</option>
142
                    </select>
143
                    <span>opac users of this domain to login with this authentication provider</span>
144
                </li>
145
                <li>
146
                    <label for="allow_opac">Allow staff: </label>
147
                    <select name="allow_staff" id="allow_staff">
148
                        <option value="1" selected="selected">Allow</option>
149
                        <option value="0">Don't allow</option>
150
                    </select>
151
                    <span>of this domain </span>
152
                </li>
153
            </ol>
154
        </fieldset>
155
        <fieldset class="action">
156
            <input type="submit" value="Submit" />
157
            <a class="cancel" href="/cgi-bin/koha/admin/authentication_providers.pl?domain_ops=1&amp;auth_provider_id=[%- auth_provider_id | html -%]">Cancel</a>
158
        </fieldset>
159
    </form>
160
[% END %]
161
162
[% IF op == 'edit_form' %]
163
    <h1>Edit authentication provider domain</h1>
164
    <form action="/cgi-bin/koha/admin/authentication_providers.pl" id="edit_save" name="edit_save" class="validated" method="post">
165
        <input type="hidden" name="op" value="edit_save" />
166
        <input type="hidden" name="domain_ops" value="1" />
167
        <input type="hidden" name="auth_provider_id" value="[%- auth_provider_id | html -%]" />
168
        <input type="hidden" name="auth_provider_domain_id" value="[%- auth_provider_domain.auth_provider_domain_id | html -%]" />
169
        <fieldset class="rows">
170
            <ol>
171
                <li>
172
                    <label for="domain">Domain: </label>
173
                    <input type="text" name="domain" id="domain" size="60" value="[%- auth_provider_domain.domain | html -%]"/>
174
                </li>
175
            </ol>
176
        </fieldset>
177
178
        <fieldset class="rows">
179
            <ol>
180
                <li>
181
                    <label for="update_on_auth">Update on login: </label>
182
                    <select name="update_on_auth" id="update_on_auth">
183
                    [% IF auth_provider_domain.update_on_auth == "1" %]
184
                        <option value="1" selected="selected">Update</option>
185
                        <option value="0">Don't update</option>
186
                    [% ELSE %]
187
                        <option value="1">Update</option>
188
                        <option value="0" selected="selected">Don't update</option>
189
                    [% END %]
190
                    </select>
191
                    <span>user data on login</span>
192
                </li>
193
                <li>
194
                    <label for="auto_register">Auto register: </label>
195
                    <select name="auto_register" id="auto_register">
196
                    [% IF auth_provider_domain.auto_register == "1" %]
197
                        <option value="1" selected="selected">Allow</option>
198
                        <option value="0">Don't allow</option>
199
                    [% ELSE %]
200
                        <option value="1">Allow</option>
201
                        <option value="0" selected="selected">Don't allow</option>
202
                    [% END %]
203
                    </select>
204
                    <span>users to auto register on login</span>
205
                </li>
206
                <li>
207
                    <label for="default_library_id">Default library: </label>
208
                    <select id="default_library_id" name="default_library_id">
209
                        [% PROCESS options_for_libraries libraries => Branches.all( selected => auth_provider_domain.default_library_id, unfiltered => 1, do_not_select_my_library => 1 ) %]
210
                    </select>
211
                </li>
212
                <li>
213
                    <label for="default_category_id">Default category: </label>
214
                    [% SET categories = Categories.all() %]
215
                    <select name="default_category_id" id="default_category_id">
216
                        [% FOREACH category IN categories %]
217
                            [% IF category.categorycode == auth_provider_domain.default_category_id %]
218
                                <option value="[% category.categorycode | html %]" selected="selected">[% category.description | html %]</option>
219
                            [% ELSE %]
220
                                <option value="[% category.categorycode | html %]">[% category.description | html %]</option>
221
                            [% END %]
222
                        [% END %]
223
                    </select>
224
                </li>
225
                <li>
226
                    <label for="allow_opac">Allow opac: </label>
227
                    <select name="allow_opac" id="allow_opac">
228
                    [% IF auth_provider_domain.allow_opac == "1" %]
229
                        <option value="1" selected="selected">Allow</option>
230
                        <option value="0">Don't allow</option>
231
                    [% ELSE %]
232
                        <option value="1">Allow</option>
233
                        <option value="0" selected="selected">Don't allow</option>
234
                    [% END %]
235
                    </select>
236
                    <span>opac users of this domain to login with this authentication provider</span>
237
                </li>
238
                <li>
239
                    <label for="allow_opac">Allow staff: </label>
240
                    <select name="allow_staff" id="allow_staff">
241
                    [% IF auth_provider_domain.allow_staff == "1" %]
242
                        <option value="1" selected="selected">Allow</option>
243
                        <option value="0">Don't allow</option>
244
                    [% ELSE %]
245
                        <option value="1">Allow</option>
246
                        <option value="0" selected="selected">Don't allow</option>
247
                    [% END %]
248
                    </select>
249
                    <span>staff users of this domain to login with this authentication provider</span>
250
                </li>
251
            </ol>
252
        </fieldset>
253
        <fieldset class="action">
254
            <input type="submit" value="Submit" />
255
            <a class="cancel" href="/cgi-bin/koha/admin/authentication_providers.pl?domain_ops=1&amp;auth_provider_id=[%- auth_provider_id | html -%]">Cancel</a>
256
        </fieldset>
257
    </form>
258
[% END %]
259
260
[% IF op == 'list' %]
261
262
    <div id="toolbar" class="btn-toolbar">
263
        <a class="btn btn-default" id="new_auth_provider_domain" href="/cgi-bin/koha/admin/authentication_providers.pl?domain_ops=1&amp;auth_provider_id=[%- auth_provider_id | html -%]&amp;op=add_form"><i class="fa fa-plus"></i> New authentication provider domain</a>
264
    </div>
265
266
    <h1>Authentication provider domains</h1>
267
268
    <table id="auth_provider_domains">
269
        <thead>
270
            <tr>
271
                <th>Domain</th>
272
                <th>Update on login</th>
273
                <th>Auto register</th>
274
                <th>Default library</th>
275
                <th>Default category</th>
276
                <th>Allow opac</th>
277
                <th>Allow staff</th>
278
                <th data-class-name="actions noExport">Actions</th>
279
            </tr>
280
        </thead>
281
    </table>
282
[% END %]
283
284
            <div id="delete_confirm_modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="delete_confirm_modal_label" aria-hidden="true">
285
                <div class="modal-dialog">
286
                    <div class="modal-content">
287
                        <div class="modal-header">
288
                            <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
289
                            <h3 id="delete_confirm_modal_label">Delete authentication provider domain</h3>
290
                        </div>
291
                        <div class="modal-body">
292
                            <div id="delete_confirm_dialog"></div>
293
                        </div>
294
                        <div class="modal-footer">
295
                            <a href="#" class="btn btn-default" id="delete_confirm_modal_button" role="button" data-toggle="modal">Delete</a>
296
                            <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
297
                        </div>
298
                    </div> <!-- /.modal-content -->
299
                </div> <!-- /.modal-dialog -->
300
            </div> <!-- #delete_confirm_modal -->
301
302
            </main>
303
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
304
305
        <div class="col-sm-2 col-sm-pull-10">
306
            <aside>
307
                [% INCLUDE 'admin-menu.inc' %]
308
            </aside>
309
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
310
     </div> <!-- /.row -->
311
312
313
[% MACRO jsinclude BLOCK %]
314
    [% Asset.js("js/admin-menu.js") | $raw %]
315
    [% INCLUDE 'datatables.inc' %]
316
    <script>
317
        $(document).ready(function() {
318
319
            var auth_provider_domains_url = '/api/v1/auth/providers/[%- auth_provider_id | html -%]/domains';
320
            [% SET categories = Categories.all() %]
321
            var categories = {
322
            [% FOREACH category IN categories %]
323
                "[% category.categorycode | html %]": "[% category.description | html %]",
324
            [% END %]
325
            };
326
            [% SET libraries = Branches.all() %]
327
            var libraries = {
328
            [% FOREACH library IN libraries %]
329
                "[% library.branchcode | html %]": "[% library.branchname | html %]",
330
            [% END %]
331
            };
332
            window.auth_provider_domains = $("#auth_provider_domains").kohaTable({
333
                "ajax": {
334
                    "url": auth_provider_domains_url
335
                },
336
                'language': {
337
                    'emptyTable': '<div class="dialog message">'+_("There are no authentication provider domains defined.")+'</div>'
338
                },
339
                "columnDefs": [ {
340
                    "targets": [1],
341
                    "render": function (data, type, row, meta) {
342
                        if ( type == 'display' ) {
343
                            if ( data != null ) {
344
                                return data.escapeHtml();
345
                            }
346
                            else {
347
                                return "";
348
                            }
349
                        }
350
                        return data;
351
                    }
352
                } ],
353
                "columns": [
354
                    {
355
                        "data": "domain",
356
                        "searchable": true,
357
                        "orderable": true,
358
                        "render": function(data, type, row, meta) {
359
                            if ( data != null ) {
360
                                return data.escapeHtml();
361
                            }
362
                            else {
363
                                return "*";
364
                            }
365
                        }
366
                    },
367
                    {
368
                        "data": function( row, type, val, meta ) {
369
                            if (row.update_on_auth) {
370
                                return _("Yes");
371
                            } else {
372
                                return _("No");
373
                            }
374
                        },
375
                        "searchable": true,
376
                        "orderable": true
377
                    },
378
                    {
379
                        "data": function( row, type, val, meta ) {
380
                            if (row.auto_register) {
381
                                return _("Yes");
382
                            } else {
383
                                return _("No");
384
                            }
385
                        },
386
                        "searchable": true,
387
                        "orderable": true
388
                    },
389
                    {
390
                        "data": function( row, type, val, meta ) {
391
                            return libraries[row.default_library_id] || "";
392
                        },
393
                        "searchable": true,
394
                        "orderable": true
395
                    },
396
                    {
397
                        "data": function( row, type, val, meta ) {
398
                            return categories[row.default_category_id] || "";
399
                        },
400
                        "searchable": true,
401
                        "orderable": true
402
                    },
403
                    {
404
                        "data": function( row, type, val, meta ) {
405
                            if (row.allow_opac) {
406
                                return _("Yes");
407
                            } else {
408
                                return _("No");
409
                            }
410
                        },
411
                        "searchable": true,
412
                        "orderable": true
413
                    },
414
                    {
415
                        "data": function( row, type, val, meta ) {
416
                            if (row.allow_staff) {
417
                                return _("Yes");
418
                            } else {
419
                                return _("No");
420
                            }
421
                        },
422
                        "searchable": true,
423
                        "orderable": true
424
                    },
425
                    {
426
                        "data": function( row, type, val, meta ) {
427
                            var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/authentication_providers.pl?domain_ops=1&amp;auth_provider_id=[%- auth_provider_id | html -%]&amp;op=edit_form&amp;auth_provider_domain_id='+ encodeURIComponent(row.auth_provider_domain_id) +'"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>'+"\n";
428
                            result += '<a class="btn btn-default btn-xs delete_auth_provider_domain" role="button" href="#" data-toggle="modal" data-target="#delete_confirm_modal" data-auth-provider-domain-id="'+ encodeURIComponent(row.auth_provider_domain_id) +'" data-auth-provider-domain="'+ encodeURIComponent((row.domain || '').escapeHtml()) +'"><i class="fa fa-trash" aria-hidden="true"></i> '+_("Delete")+'</a>';
429
                            return result;
430
                        },
431
                        "searchable": false,
432
                        "orderable": false
433
                    }
434
                ],
435
                createdRow: function (row, data, dataIndex) {
436
                    if ( data.debug ) {
437
                        $(row).addClass('debug');
438
                    }
439
                },
440
            });
441
442
            $('#auth_provider_domains').on( "click", '.delete_auth_provider_domain', function () {
443
                var auth_provider_domain_id   = $(this).data('auth-provider-domain-id');
444
                var auth_provider_domain = decodeURIComponent($(this).data('auth-provider-domain'));
445
446
                $("#delete_confirm_dialog").html(
447
                    _("You are about to delete the '%s' authentication provider domain.").format(auth_provider_domain)
448
                );
449
                $("#delete_confirm_modal_button").data('auth-provider-domain-id', auth_provider_domain_id);
450
                $("#delete_confirm_modal_button").data('auth-provider-domain', auth_provider_domain);
451
            });
452
453
            $("#delete_confirm_modal_button").on( "click", function () {
454
455
                var auth_provider_domain_id   = $(this).data('auth-provider-domain-id');
456
                var auth_provider_domain = $(this).data('auth-provider-domain');
457
458
                $.ajax({
459
                    method: "DELETE",
460
                    url: auth_provider_domains_url+"/"+auth_provider_domain_id
461
                }).success(function() {
462
                    window.auth_provider_domains.api().ajax.reload(function (data) {
463
                        $("#smtp_action_result_dialog").hide();
464
                        $("#smtp_delete_success").html(_("Server '%s' deleted successfully.").format(auth_provider_domain)).show();
465
                    });
466
                }).fail(function () {
467
                    $("#smtp_delete_error").html(_("Error deleting server '%s'. Check the logs.").format(auth_provider_domain)).show();
468
                }).done(function () {
469
                    $("#delete_confirm_modal").modal('hide');
470
                });
471
            });
472
        });
473
    </script>
474
[% END %]
475
476
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authentication_providers.tt (-1 / +466 lines)
Line 0 Link Here
0
- 
1
[% USE raw %]
2
[% USE Asset %]
3
[% SET footerjs = 1 %]
4
[% INCLUDE 'doc-head-open.inc' %]
5
<title>
6
    [% IF op == 'add_form' %]
7
        New authentication provider &rsaquo; [% ELSIF op == 'edit_form' %]
8
        Edit authentication provider &rsaquo; [% END %]
9
10
    Authentication providers &rsaquo; Administration &rsaquo; Koha
11
</title>
12
[% INCLUDE 'doc-head-close.inc' %]
13
</head>
14
15
<body id="admin_auth_providers" class="admin">
16
[% INCLUDE 'header.inc' %]
17
[% INCLUDE 'prefs-admin-search.inc' %]
18
19
<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
20
    <ol>
21
        <li>
22
            <a href="/cgi-bin/koha/mainpage.pl">Home</a>
23
        </li>
24
        <li>
25
            <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
26
        </li>
27
28
        [% IF op == 'add_form' %]
29
            <li>
30
                <a href="/cgi-bin/koha/admin/authentication_providers.pl">Authentication providers</a>
31
            </li>
32
            <li>
33
                <a href="#" aria-current="page">
34
                    New
35
                </a>
36
            </li>
37
38
        [% ELSIF op == 'edit_form' %]
39
            <li>
40
                <a href="/cgi-bin/koha/admin/authentication_providers.pl">Authentication providers</a>
41
            </li>
42
            <li>
43
                <a href="#" aria-current="page">
44
                    Edit
45
                </a>
46
            </li>
47
48
        [% ELSE %]
49
            <li>
50
                <a href="#" aria-current="page">
51
                    Authentication providers
52
                </a>
53
            </li>
54
        [% END %]
55
    </ol>
56
</nav>
57
58
<div class="main container-fluid">
59
    <div class="row">
60
        <div class="col-sm-10 col-sm-push-2">
61
            <main>
62
63
[% FOREACH m IN messages %]
64
    <div class="dialog [% m.type | html %]" id="auth_provider_action_result_dialog">
65
        [% SWITCH m.code %]
66
        [% CASE 'error_on_update' %]
67
            <span>An error occurred trying to open the authentication provider for editing. The passed id is invalid.</span>
68
        [% CASE 'error_on_insert' %]
69
            <span>An error occurred when adding a new authentication provider.</span>
70
        [% CASE 'success_on_update' %]
71
            <span>Authentication provider updated successfully.</span>
72
        [% CASE 'success_on_insert' %]
73
            <span>Authentication provider added successfully.</span>
74
        [% CASE %]
75
            <span>[% m.code | html %]</span>
76
        [% END %]
77
    </div>
78
[% END %]
79
80
    <div class="dialog message" id="auth_provider_delete_success" style="display: none;"></div>
81
    <div class="dialog alert"   id="auth_provider_delete_error"   style="display: none;"></div>
82
83
[% IF op == 'add_form' %]
84
    <h1>New authentication provider</h1>
85
    <form action="/cgi-bin/koha/admin/authentication_providers.pl" id="add" name="add" class="validated" method="post">
86
        <input type="hidden" name="op" value="add" />
87
        <fieldset class="rows">
88
            <ol>
89
                <li>
90
                    <label for="code" class="required">Code: </label>
91
                    <input type="text" name="code" id="code" size="60" class="required" required="required" />
92
                    <span class="required">Required</span>
93
                </li>
94
                <li>
95
                    <label for="description" class="required">Description: </label>
96
                    <input type="text" name="description" id="description" size="60" class="required" required="required" />
97
                    <span class="required">Required</span>
98
                </li>
99
                <li>
100
                    <label for="protocol">Protocol: </label>
101
                    <select name="protocol" id="protocol">
102
                        <option value="OAuth">OAuth</option>
103
                        <option value="OIDC">OIDC</option>
104
                        <!-- Not implemented yet
105
                        <option value="LDAP">LDAP</option>
106
                        <option value="CAS">CAS</option>
107
                        -->
108
                    </select>
109
                </li>
110
            </ol>
111
        </fieldset>
112
113
        <fieldset class="rows">
114
            <ol>
115
                <li>
116
                    <div>
117
                        <label for="config" class="required json">Configuration: </label>
118
                        <textarea name="config" id="config" class="required"></textarea>
119
                        <span class="required">Required</span>
120
                    </div>
121
                    <div>
122
                        <label></label>
123
                        <button class="btn btn-ligth defaults" data-default-target="config" id="default-config">Add default OAuth configuration</button>
124
                    </div>
125
                </li>
126
                <li>
127
                    <div>
128
                        <label for="mapping" class="required json">Mapping: </label>
129
                        <textarea name="mapping" id="mapping" class="required"></textarea>
130
                        <span class="required">Required</span>
131
                    </div>
132
                    <div>
133
                        <label></label>
134
                        <button class="btn btn-ligth defaults" data-default-target="mapping" id="default-mapping">Add default OAuth mapping</button>
135
                    </div>
136
                </li>
137
                <li>
138
                    <label for="matchpoint" class="required">Matchpoint: </label>
139
                    <select name="matchpoint" id="matchpoint" class="required">
140
                        <option value="email">Email</option>
141
                        <option value="userid">User id</option>
142
                        <option value="cardnumber">Card number</option>
143
                    </select>
144
                    <span class="required">Required</span>
145
                </li>
146
                <li>
147
                    <label for="icon_url">Icon URL: </label>
148
                    <input type="text" name="icon_url" id="icon_url" size="60" />
149
                </li>
150
            </ol>
151
        </fieldset>
152
        <fieldset class="action">
153
            <input type="submit" value="Submit" />
154
            <a class="cancel" href="/cgi-bin/koha/admin/authentication_providers.pl">Cancel</a>
155
        </fieldset>
156
    </form>
157
[% END %]
158
159
[% IF op == 'edit_form' %]
160
    <h1>Edit authentication provider</h1>
161
    <form action="/cgi-bin/koha/admin/authentication_providers.pl" id="edit_save" name="edit_save" class="validated" method="post">
162
        <input type="hidden" name="op" value="edit_save" />
163
        <input type="hidden" name="auth_provider_id" value="[%- auth_provider.auth_provider_id | html -%]" />
164
        <fieldset class="rows">
165
            <ol>
166
                <li>
167
                    <label for="code" class="required">Code: </label>
168
                    <input type="text" name="code" id="code" size="60" class="required" required="required" value="[%- auth_provider.code | html -%]"/>
169
                    <span class="required">Required</span>
170
                </li>
171
                <li>
172
                    <label for="description" class="required">Description: </label>
173
                    <input type="text" name="description" id="description" size="60" class="required" required="required" value="[%- auth_provider.description | html -%]"/>
174
                    <span class="required">Required</span>
175
                </li>
176
                <li>
177
                    <label for="protocol">Protocol: </label>
178
                    <select name="protocol" id="protocol">
179
                    [% IF auth_provider.protocol == 'OAuth' %]
180
                        <option value="OAuth" selected="selected">OAuth</option>
181
                        <option value="OIDC">OIDC</option>
182
                        <!-- Not implemented yet
183
                        <option value="LDAP">LDAP</option>
184
                        <option value="CAS">CAS</option>
185
                        -->
186
                    [% ELSE %]
187
                        <option value="OAuth">OAuth</option>
188
                        <option value="OIDC" selected="selected">OIDC</option>
189
                        <!-- Not implemented yet
190
                        <option value="LDAP">LDAP</option>
191
                        <option value="CAS">CAS</option>
192
                        -->
193
                    [% END %]
194
                    </select>
195
                </li>
196
            </ol>
197
        </fieldset>
198
199
        <fieldset class="rows">
200
            <ol>
201
                <li>
202
                    <div>
203
                        <label for="config" class="required json">Configuration: </label>
204
                        <textarea name="config" id="config" class="required">[%- auth_provider.config | html -%]</textarea>
205
                        <span class="required">Required</span>
206
                    </div>
207
                    <div>
208
                        <label></label>
209
                        <button class="btn btn-ligth defaults" data-default-target="config" id="default-config">Add default [%- auth_provider.protocol | html -%] configuration</button>
210
                    </div>
211
                </li>
212
                <li>
213
                    <div>
214
                        <label for="mapping" class="required json">Mapping: </label>
215
                        <textarea name="mapping" id="mapping" class="required">[%- auth_provider.mapping | html -%]</textarea>
216
                        <span class="required">Required</span>
217
                    </div>
218
                    <div>
219
                        <label></label>
220
                        <button class="btn btn-ligth defaults" data-default-target="mapping" id="default-mapping">Add default [%- auth_provider.protocol | html -%] mapping</button>
221
                    </div>
222
                </li>
223
                <li>
224
                    <label for="matchpoint" class="required">matchpoint: </label>
225
                    <select name="matchpoint" id="matchpoint" class="required">
226
                        [%- IF auth_provider.matchpoint == 'email'      -%]
227
                            <option value="email" selected="selected">Email</option>
228
                        [%- ELSE -%]
229
                            <option value="email">Email</option>
230
                        [%- END -%]
231
                        [%- IF auth_provider.matchpoint == 'userid'     -%]
232
                            <option value="userid" selected="selected">User id</option>
233
                        [%- ELSE -%]
234
                            <option value="userid">User id</option>
235
                        [%- END -%]
236
                        [%- IF auth_provider.matchpoint == 'cardnumber' -%]
237
                            <option value="cardnumber" selected="selected">Card number</option>
238
                        [%- ELSE -%]
239
                            <option value="cardnumber">Card number</option>
240
                        [%- END -%]
241
                    </select>
242
                    <span class="required">Required</span>
243
                </li>
244
                <li>
245
                    <label for="icon_url">Icon URL: </label>
246
                    <input type="text" name="icon_url" id="icon_url" size="60"  value="[%- auth_provider.icon_url | html -%]"/>
247
                </li>
248
            </ol>
249
        </fieldset>
250
        <fieldset class="action">
251
            <input type="submit" value="Submit" />
252
            <a class="cancel" href="/cgi-bin/koha/admin/authentication_providers.pl">Cancel</a>
253
        </fieldset>
254
    </form>
255
[% END %]
256
257
[% IF op == 'list' %]
258
259
    <div id="toolbar" class="btn-toolbar">
260
        <a class="btn btn-default" id="new_auth_provider" href="/cgi-bin/koha/admin/authentication_providers.pl?op=add_form"><i class="fa fa-plus"></i> New authentication provider</a>
261
    </div>
262
263
    <h1>Authentication providers</h1>
264
265
    <table id="auth_providers">
266
        <thead>
267
            <tr>
268
                <th>Code</th>
269
                <th>Description</th>
270
                <th>Protocol</th>
271
                <th data-class-name="actions noExport">Actions</th>
272
            </tr>
273
        </thead>
274
    </table>
275
[% END %]
276
277
            <div id="delete_confirm_modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="delete_confirm_modal_label" aria-hidden="true">
278
                <div class="modal-dialog">
279
                    <div class="modal-content">
280
                        <div class="modal-header">
281
                            <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
282
                            <h3 id="delete_confirm_modal_label">Delete authentication provider</h3>
283
                        </div>
284
                        <div class="modal-body">
285
                            <div id="delete_confirm_dialog"></div>
286
                        </div>
287
                        <div class="modal-footer">
288
                            <a href="#" class="btn btn-default" id="delete_confirm_modal_button" role="button" data-toggle="modal">Delete</a>
289
                            <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
290
                        </div>
291
                    </div> <!-- /.modal-content -->
292
                </div> <!-- /.modal-dialog -->
293
            </div> <!-- #delete_confirm_modal -->
294
295
            </main>
296
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
297
298
        <div class="col-sm-2 col-sm-pull-10">
299
            <aside>
300
                [% INCLUDE 'admin-menu.inc' %]
301
            </aside>
302
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
303
     </div> <!-- /.row -->
304
305
306
[% MACRO jsinclude BLOCK %]
307
    [% Asset.js("js/admin-menu.js") | $raw %]
308
    [% INCLUDE 'datatables.inc' %]
309
    <script>
310
        $(document).ready(function() {
311
312
            var auth_providers_url = '/api/v1/auth/providers';
313
            window.auth_providers = $("#auth_providers").kohaTable({
314
                "ajax": {
315
                    "url": auth_providers_url
316
                },
317
                'language': {
318
                    'emptyTable': '<div class="dialog message">'+_("There are no authentication providers defined.")+'</div>'
319
                },
320
                "columnDefs": [ {
321
                    "targets": [0,1,2],
322
                    "render": function (data, type, row, meta) {
323
                        if ( type == 'display' ) {
324
                            if ( data != null ) {
325
                                return data.escapeHtml();
326
                            }
327
                            else {
328
                                return "Default";
329
                            }
330
                        }
331
                        return data;
332
                    }
333
                } ],
334
                "columns": [
335
                    {
336
                        "data": "code",
337
                        "searchable": true,
338
                        "orderable": true
339
                    },
340
                    {
341
                        "data": "description",
342
                        "searchable": true,
343
                        "orderable": true
344
                    },
345
                    {
346
                        "data": "protocol",
347
                        "searchable": true,
348
                        "orderable": true
349
                    },
350
                    {
351
                        "data": function( row, type, val, meta ) {
352
                            var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/authentication_providers.pl?op=edit_form&amp;auth_provider_id='+ encodeURIComponent(row.auth_provider_id) +'"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>'+"\n";
353
                            result += '<a class="btn btn-default btn-xs delete_auth_provider" role="button" href="#" data-toggle="modal" data-target="#delete_confirm_modal" data-auth-provider-id="'+ encodeURIComponent(row.auth_provider_id) +'" data-auth-provider-code="'+ encodeURIComponent(row.code.escapeHtml()) +'"><i class="fa fa-trash" aria-hidden="true"></i> '+_("Delete")+'</a>'+"\n";
354
                            result += '<a class="btn btn-default btn-xs edit_domains" role="button" href="/cgi-bin/koha/admin/authentication_providers.pl?domain_ops=1&amp;auth_provider_id='+ encodeURIComponent(row.auth_provider_id) +'"><i class="fa fa-cog" aria-hidden="true"></i> '+_("Manage Domains")+'</a>';
355
                            return result;
356
                        },
357
                        "searchable": false,
358
                        "orderable": false
359
                    }
360
                ],
361
                createdRow: function (row, data, dataIndex) {
362
                    if ( data.debug ) {
363
                        $(row).addClass('debug');
364
                    }
365
                },
366
            });
367
368
            $('#auth_providers').on( "click", '.delete_auth_provider', function () {
369
                var auth_provider_id   = $(this).data('auth-provider-id');
370
                var auth_provider_code = decodeURIComponent($(this).data('auth-provider-code'));
371
372
                $("#delete_confirm_dialog").html(
373
                    _("You are about to delete the '%s' authentication provider.").format(auth_provider_code)
374
                );
375
                $("#delete_confirm_modal_button").data('auth-provider-id', auth_provider_id);
376
                $("#delete_confirm_modal_button").data('auth-provider-code', auth_provider_code);
377
            });
378
379
            $("#delete_confirm_modal_button").on( "click", function () {
380
381
                var auth_provider_id   = $(this).data('auth-provider-id');
382
                var auth_provider_code = $(this).data('auth-provider-code');
383
384
                $.ajax({
385
                    method: "DELETE",
386
                    url: auth_providers_url+"/"+auth_provider_id
387
                }).success(function() {
388
                    window.auth_providers.api().ajax.reload(function (data) {
389
                        $("#auth_provider_action_result_dialog").hide();
390
                        $("#auth_provider_delete_success").html(_("Server '%s' deleted successfully.").format(auth_provider_code)).show();
391
                    });
392
                }).fail(function () {
393
                    $("#auth_provider_delete_error").html(_("Error deleting server '%s'. Check the logs.").format(auth_provider_code)).show();
394
                }).done(function () {
395
                    $("#delete_confirm_modal").modal('hide');
396
                });
397
            });
398
399
            $.validator.addMethod('json', function(value, element) {
400
                if (this.optional(element)) return true;
401
                try {
402
                    JSON.parse(value)
403
                } catch (error) {
404
                    return false;
405
                }
406
                return true;
407
            }, _('Not a valid JSON'));
408
409
            $('#config, #mapping').each(function() {
410
                $(this).rules('add', {
411
                    required: true,
412
                    json: true
413
                });
414
            });
415
416
            var defaults = {
417
                OIDC: {
418
                    config: {
419
                        key: "<enter client id>",
420
                        secret: "<enter client secret>",
421
                        well_known_url: "<enter openid configuration endpoint>",
422
                        scope: "openid email"
423
                    },
424
                    mapping: {
425
                        email: "email",
426
                        given_name: "firstname",
427
	                    family_name: "surname"
428
                    }
429
                },
430
                OAuth: {
431
                    config: {
432
                        key: "<enter client id>",
433
                        secret: "<enter client secret>",
434
                        authorize_url: "<enter authorization endpoint>",
435
                        token_url: "<enter token endpoint>",
436
                        userinfo_url: "<enter user info endpoint (optional)>",
437
                        scope: "email"
438
                    },
439
                    mapping: {
440
                        email: "email",
441
                        given_name: "firstname",
442
	                    family_name: "surname"
443
                    }
444
                }
445
            };
446
447
            $('#protocol').on('change', function() {
448
                var protocol = $(this).val();
449
                $('#default-config').html(_('Add default %s configuration').format(protocol));
450
                $('#default-mapping').html(_('Add default %s mapping').format(protocol));
451
            });
452
453
            $('button.defaults').on('click', function(event) {
454
                event.preventDefault();
455
                var target = $(this).data('defaultTarget');
456
                if($('#'+target).html() !== '' && !confirm(_('Are you sure you want to replace current %s contents?').format(target))) {
457
                    return;
458
                }
459
                var protocol = $('#protocol').val();
460
                $('#'+target).html(JSON.stringify(defaults[protocol][target], null, 2));
461
            })
462
        });
463
    </script>
464
[% END %]
465
466
[% INCLUDE 'intranet-bottom.inc' %]

Return to bug 31378