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

(-)a/Koha/Auth/Provider.pm (+58 lines)
Line 0 Link Here
1
package Koha::Auth::Provider;
2
3
# Copyright Theke Solutions 2022
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 base qw(Koha::Object);
23
24
use Koha::Auth::Provider::Domains;
25
26
=head1 NAME
27
28
Koha::Auth::Provider - Koha Auth Provider Object class
29
30
=head1 API
31
32
=head2 Class methods
33
34
=head3 domains
35
36
    my $domains = $provider->domains;
37
38
Returns the related I<Koha::Auth::Provider::Domains> iterator.
39
40
=cut
41
42
sub domains {
43
    my ($self) = @_;
44
45
    return Koha::Auth::Provider::Domains->_new_from_dbic( scalar $self->_result->domains );
46
}
47
48
=head2 Internal methods
49
50
=head3 _type
51
52
=cut
53
54
sub _type {
55
    return 'AuthProvider';
56
}
57
58
1;
(-)a/Koha/Auth/Providers.pm (+53 lines)
Line 0 Link Here
1
package Koha::Auth::Providers;
2
3
# Copyright Theke Solutions 2022
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 Koha::Database;
23
use Koha::Auth::Provider;
24
25
use base qw(Koha::Objects);
26
27
=head1 NAME
28
29
Koha::Auth::Providers - Koha Auth Provider Object class
30
31
=head1 API
32
33
=head2 Internal methods
34
35
=cut
36
37
=head3 _type
38
39
=cut
40
41
sub _type {
42
    return 'AuthProvider';
43
}
44
45
=head3 object_class
46
47
=cut
48
49
sub object_class {
50
    return 'Koha::Auth::Provider';
51
}
52
53
1;
(-)a/Koha/Schema/Result/AuthProvider.pm (+189 lines)
Line 0 Link Here
1
use utf8;
2
package Koha::Schema::Result::AuthProvider;
3
4
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7
=head1 NAME
8
9
Koha::Schema::Result::AuthProvider
10
11
=cut
12
13
use strict;
14
use warnings;
15
16
use base 'DBIx::Class::Core';
17
18
=head1 TABLE: C<auth_providers>
19
20
=cut
21
22
__PACKAGE__->table("auth_providers");
23
24
=head1 ACCESSORS
25
26
=head2 auth_provider_id
27
28
  data_type: 'integer'
29
  is_auto_increment: 1
30
  is_nullable: 0
31
32
unique key, used to identify the provider
33
34
=head2 code
35
36
  data_type: 'varchar'
37
  is_nullable: 0
38
  size: 20
39
40
Provider code
41
42
=head2 description
43
44
  data_type: 'varchar'
45
  is_nullable: 0
46
  size: 255
47
48
Description for the provider
49
50
=head2 protocol
51
52
  data_type: 'enum'
53
  extra: {list => ["OAuth","OIDC","LDAP","CAS"]}
54
  is_nullable: 0
55
56
Protocol provider speaks
57
58
=head2 config
59
60
  data_type: 'longtext'
61
  default_value: ''{}''
62
  is_nullable: 0
63
64
Configuration of the provider in JSON format
65
66
=head2 mapping
67
68
  data_type: 'longtext'
69
  default_value: ''{}''
70
  is_nullable: 0
71
72
Configuration to map provider data to Koha user
73
74
=head2 matchpoint
75
76
  data_type: 'enum'
77
  extra: {list => ["email","userid","cardnumber"]}
78
  is_nullable: 0
79
80
The patron attribute to be used as matchpoint
81
82
=head2 icon_url
83
84
  data_type: 'varchar'
85
  is_nullable: 1
86
  size: 255
87
88
Provider icon URL
89
90
=cut
91
92
__PACKAGE__->add_columns(
93
  "auth_provider_id",
94
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
95
  "code",
96
  { data_type => "varchar", is_nullable => 0, size => 20 },
97
  "description",
98
  { data_type => "varchar", is_nullable => 0, size => 255 },
99
  "protocol",
100
  {
101
    data_type => "enum",
102
    extra => { list => ["OAuth", "OIDC", "LDAP", "CAS"] },
103
    is_nullable => 0,
104
  },
105
  "config",
106
  { data_type => "longtext", default_value => "'{}'", is_nullable => 0 },
107
  "mapping",
108
  { data_type => "longtext", default_value => "'{}'", is_nullable => 0 },
109
  "matchpoint",
110
  {
111
    data_type => "enum",
112
    extra => { list => ["email", "userid", "cardnumber"] },
113
    is_nullable => 0,
114
  },
115
  "icon_url",
116
  { data_type => "varchar", is_nullable => 1, size => 255 },
117
);
118
119
=head1 PRIMARY KEY
120
121
=over 4
122
123
=item * L</auth_provider_id>
124
125
=back
126
127
=cut
128
129
__PACKAGE__->set_primary_key("auth_provider_id");
130
131
=head1 UNIQUE CONSTRAINTS
132
133
=head2 C<code>
134
135
=over 4
136
137
=item * L</code>
138
139
=back
140
141
=cut
142
143
__PACKAGE__->add_unique_constraint("code", ["code"]);
144
145
=head1 RELATIONS
146
147
=head2 auth_provider_domains
148
149
Type: has_many
150
151
Related object: L<Koha::Schema::Result::AuthProviderDomain>
152
153
=cut
154
155
__PACKAGE__->has_many(
156
  "auth_provider_domains",
157
  "Koha::Schema::Result::AuthProviderDomain",
158
  { "foreign.auth_provider_id" => "self.auth_provider_id" },
159
  { cascade_copy => 0, cascade_delete => 0 },
160
);
161
162
163
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-09-30 19:43:00
164
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZqUo3by0ZXca5RI3QFNypw
165
166
167
=head2 domains
168
169
Type: has_many
170
171
Related object: L<Koha::Schema::Result::AuthProviderDomain>
172
173
=cut
174
175
__PACKAGE__->has_many(
176
  "domains",
177
  "Koha::Schema::Result::AuthProviderDomain",
178
  { "foreign.auth_provider_id" => "self.auth_provider_id" },
179
  { cascade_copy => 0, cascade_delete => 0 },
180
);
181
182
sub koha_object_class {
183
    'Koha::Auth::Provider';
184
}
185
sub koha_objects_class {
186
    'Koha::Auth::Providers';
187
}
188
189
1;
(-)a/Koha/Schema/Result/AuthProviderDomain.pm (+226 lines)
Line 0 Link Here
1
use utf8;
2
package Koha::Schema::Result::AuthProviderDomain;
3
4
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7
=head1 NAME
8
9
Koha::Schema::Result::AuthProviderDomain
10
11
=cut
12
13
use strict;
14
use warnings;
15
16
use base 'DBIx::Class::Core';
17
18
=head1 TABLE: C<auth_provider_domains>
19
20
=cut
21
22
__PACKAGE__->table("auth_provider_domains");
23
24
=head1 ACCESSORS
25
26
=head2 auth_provider_domain_id
27
28
  data_type: 'integer'
29
  is_auto_increment: 1
30
  is_nullable: 0
31
32
unique key, used to identify providers domain
33
34
=head2 auth_provider_id
35
36
  data_type: 'integer'
37
  is_foreign_key: 1
38
  is_nullable: 0
39
40
Reference to provider
41
42
=head2 domain
43
44
  data_type: 'varchar'
45
  is_nullable: 1
46
  size: 100
47
48
Domain name. If null means all domains
49
50
=head2 auto_register
51
52
  data_type: 'tinyint'
53
  default_value: 0
54
  is_nullable: 0
55
56
Allow user auto register
57
58
=head2 update_on_auth
59
60
  data_type: 'tinyint'
61
  default_value: 0
62
  is_nullable: 0
63
64
Update user data on auth login
65
66
=head2 default_library_id
67
68
  data_type: 'varchar'
69
  is_foreign_key: 1
70
  is_nullable: 1
71
  size: 10
72
73
Default library to create user if auto register is enabled
74
75
=head2 default_category_id
76
77
  data_type: 'varchar'
78
  is_foreign_key: 1
79
  is_nullable: 1
80
  size: 10
81
82
Default category to create user if auto register is enabled
83
84
=head2 allow_opac
85
86
  data_type: 'tinyint'
87
  default_value: 1
88
  is_nullable: 0
89
90
Allow provider from opac interface
91
92
=head2 allow_staff
93
94
  data_type: 'tinyint'
95
  default_value: 1
96
  is_nullable: 0
97
98
Allow provider from staff interface
99
100
=cut
101
102
__PACKAGE__->add_columns(
103
  "auth_provider_domain_id",
104
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
105
  "auth_provider_id",
106
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
107
  "domain",
108
  { data_type => "varchar", is_nullable => 1, size => 100 },
109
  "auto_register",
110
  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
111
  "update_on_auth",
112
  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
113
  "default_library_id",
114
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
115
  "default_category_id",
116
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
117
  "allow_opac",
118
  { data_type => "tinyint", default_value => 1, is_nullable => 0 },
119
  "allow_staff",
120
  { data_type => "tinyint", default_value => 1, is_nullable => 0 },
121
);
122
123
=head1 PRIMARY KEY
124
125
=over 4
126
127
=item * L</auth_provider_domain_id>
128
129
=back
130
131
=cut
132
133
__PACKAGE__->set_primary_key("auth_provider_domain_id");
134
135
=head1 UNIQUE CONSTRAINTS
136
137
=head2 C<auth_provider_id>
138
139
=over 4
140
141
=item * L</auth_provider_id>
142
143
=item * L</domain>
144
145
=back
146
147
=cut
148
149
__PACKAGE__->add_unique_constraint("auth_provider_id", ["auth_provider_id", "domain"]);
150
151
=head1 RELATIONS
152
153
=head2 auth_provider
154
155
Type: belongs_to
156
157
Related object: L<Koha::Schema::Result::AuthProvider>
158
159
=cut
160
161
__PACKAGE__->belongs_to(
162
  "auth_provider",
163
  "Koha::Schema::Result::AuthProvider",
164
  { auth_provider_id => "auth_provider_id" },
165
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
166
);
167
168
=head2 default_category
169
170
Type: belongs_to
171
172
Related object: L<Koha::Schema::Result::Category>
173
174
=cut
175
176
__PACKAGE__->belongs_to(
177
  "default_category",
178
  "Koha::Schema::Result::Category",
179
  { categorycode => "default_category_id" },
180
  {
181
    is_deferrable => 1,
182
    join_type     => "LEFT",
183
    on_delete     => "CASCADE",
184
    on_update     => "RESTRICT",
185
  },
186
);
187
188
=head2 default_library
189
190
Type: belongs_to
191
192
Related object: L<Koha::Schema::Result::Branch>
193
194
=cut
195
196
__PACKAGE__->belongs_to(
197
  "default_library",
198
  "Koha::Schema::Result::Branch",
199
  { branchcode => "default_library_id" },
200
  {
201
    is_deferrable => 1,
202
    join_type     => "LEFT",
203
    on_delete     => "CASCADE",
204
    on_update     => "RESTRICT",
205
  },
206
);
207
208
209
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-08-24 15:03:07
210
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1b0q+e8Ym8icJ6bYAY/Mbw
211
212
sub koha_object_class {
213
    'Koha::Auth::Provider::Domain';
214
}
215
sub koha_objects_class {
216
    'Koha::Auth::Providers::Domains';
217
}
218
219
__PACKAGE__->add_columns(
220
    '+auto_register'  => { is_boolean => 1 },
221
    '+update_on_auth' => { is_boolean => 1 },
222
    '+allow_opac'     => { is_boolean => 1 },
223
    '+allow_staff'    => { is_boolean => 1 },
224
);
225
226
1;
(-)a/t/db_dependent/Koha/Auth/Provider.t (-1 / +50 lines)
Line 0 Link Here
0
- 
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 Test::More tests => 1;
23
24
use Koha::Auth::Providers;
25
26
use t::lib::TestBuilder;
27
use t::lib::Mocks;
28
29
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
32
subtest 'domains() tests' => sub {
33
34
    plan tests => 3;
35
36
    $schema->storage->txn_begin;
37
38
    my $provider = $builder->build_object({ class => 'Koha::Auth::Providers' });
39
    my $domains  = $provider->domains;
40
41
    is( ref($domains), 'Koha::Auth::Provider::Domains', 'Type is correct' );
42
    is( $domains->count, 0, 'No domains defined' );
43
44
    $builder->build_object({ class => 'Koha::Auth::Provider::Domains', value => { auth_provider_id => $provider->id } });
45
    $builder->build_object({ class => 'Koha::Auth::Provider::Domains', value => { auth_provider_id => $provider->id } });
46
47
    is( $provider->domains->count, 2, 'The provider has 2 domains defined' );
48
49
    $schema->storage->txn_rollback;
50
};

Return to bug 31378