Skip to content

Commit 7d9c760

Browse files
authored
Merge pull request #16 from simbabque/result-source-only
Result set names are the only way to configure dbic
2 parents ec683a3 + 39cec35 commit 7d9c760

File tree

6 files changed

+146
-59
lines changed

6 files changed

+146
-59
lines changed

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ t/lib/Schema3.pm
2222
t/lib/Schema3/Result/Role.pm
2323
t/lib/Schema3/Result/User.pm
2424
t/lib/Schema3/Result/UserRole.pm
25+
t/deprecation.t
2526
t/manifest.t
2627
t/provider-dbic-user_as_object.t
2728
t/provider-dbic.t

Makefile.PL

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ WriteMakefile(
1111
? ('LICENSE'=> 'perl')
1212
: ()),
1313
BUILD_REQUIRES => {
14+
'Test::MockObject' => 0,
1415
'Test::More' => 0,
16+
'Test::Warn' => 0,
1517
'DateTime::Format::SQLite' => 0,
1618
},
1719
PREREQ_PM => {

lib/Dancer2/Plugin/Auth/Extensible/Provider/DBIC.pm

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,14 @@ A full example showing all options:
8080
# instead. This also affects what `logged_in_user` returns.
8181
user_as_object: 1
8282
83-
# Optionally specify the sources of the data if not the
84-
# defaults (as shown). See notes below for how these
85-
# generate the resultset names. If you use standard DBIC
86-
# resultset names, then these and the column names are the
87-
# only settings you might need. The relationships between
83+
# Optionally specify the DBIC resultset names if you don't
84+
# use the defaults (as shown). These and the column names are the
85+
# only settings you might need. The relationships between
8886
# these resultsets is automatically introspected by
8987
# inspection of the schema.
90-
users_source: 'user'
91-
roles_source: 'role'
92-
user_roles_source: 'user_role'
88+
users_resultset: User
89+
roles_resultset: Role
90+
user_roles_resultset: UserRole
9391
9492
# optionally set the column names
9593
users_username_column: username
@@ -127,23 +125,11 @@ A full example showing all options:
127125
# Optionally specify the algorithm when encrypting new passwords
128126
encryption_algorithm: SHA-512
129127
130-
# If you don't use standard DBIC resultset names, you might
131-
# need to configure these instead:
132-
users_resultset: User
133-
roles_resultset: Role
134-
user_roles_resultset: UserRole
135-
136128
# Optional: To validate passwords using a method called
137129
# 'check_password' in users_resultset result class
138130
# which takes the password to check as a single argument:
139131
users_password_check: check_password
140132
141-
# Deprecated settings. The following settings were renamed for clarity
142-
# to the *_source settings
143-
users_table:
144-
roles_table:
145-
user_roles_table:
146-
147133
148134
=over
149135
@@ -163,20 +149,32 @@ sub BUILDARGS {
163149

164150
# backwards compat
165151

152+
# deprecate the *_source settings, but don't change anything yet
153+
deprecated_setting('users_source', 'users_resultset')
154+
if $args{users_source};
155+
156+
deprecated_setting('roles_source', 'roles_resultset')
157+
if $args{roles_source};
158+
159+
deprecated_setting('user_roles_source', 'user_roles_resultset')
160+
if $args{user_roles_source};
161+
162+
# deprecate the *_table settings and move them into source, which
163+
# will be used in the lazy build for the correct *_resultset settings
166164
if ( $args{users_table} ) {
167-
deprecated_setting( 'users_table', 'users_source' );
165+
deprecated_setting( 'users_table', 'users_resultset' );
168166
$args{users_source} = delete $args{users_table}
169167
if !$args{users_source};
170168
}
171169

172170
if ( $args{roles_table} ) {
173-
deprecated_setting( 'roles_table', 'roles_source' );
171+
deprecated_setting( 'roles_table', 'roles_resultset' );
174172
$args{roles_source} = delete $args{roles_table}
175173
if !$args{roles_source};
176174
}
177175

178176
if ( $args{user_roles_table} ) {
179-
deprecated_setting( 'user_roles_table', 'user_roles_source' );
177+
deprecated_setting( 'user_roles_table', 'user_roles_resultset' );
180178
$args{user_roles_source} = delete $args{user_roles_table}
181179
if !$args{user_roles_source};
182180
}
@@ -192,23 +190,26 @@ By default a row object is returned as a simple hash reference using
192190
L<DBIx::Class::ResultClass::HashRefInflator>. Setting this to true
193191
causes normal row objects to be returned instead.
194192
195-
=item user_source
193+
=item users_resultset
196194
197-
Specifies the source name that contains the users. This will be camelized to generate
198-
the resultset name. The relationship to user_roles_source will be introspected from
199-
the schema.
195+
Defaults to C<User>.
200196
201-
=item role_source
197+
Specifies the L<DBIx::Class::ResultSet> that contains the users.
198+
The relationship to user_roles_source will be introspected from the schema.
202199
203-
Specifies the source name that contains the roles. This will be camelized to generate
204-
the resultset name. The relationship to user_roles_source will be introspected from
205-
the schema.
200+
=item roles_resultset
206201
207-
=item user_roles_source
202+
Defaults to C<Roles>.
208203
209-
Specifies the source name that contains the user_roles joining table. This will be
210-
camelized to generate the resultset name. The relationship to the user and role
211-
source will be introspected from the schema.
204+
Specifies the L<DBIx::Class::ResultSet> that contains the roles.
205+
The relationship to user_roles_source will be introspected from the schema.
206+
207+
=item user_roles_resultset
208+
209+
Defaults to C<User>.
210+
211+
Specifies the L<DBIx::Class::ResultSet> that contains the user_roles joining table.
212+
The relationship to the user and role source will be introspected from the schema.
212213
213214
=item users_username_column
214215
@@ -258,18 +259,38 @@ keyword. Instead it is intended to make it easier to access a user's roles if th
258259
user hash is being passed around (without requiring access to the user_has_role
259260
keyword in other modules).
260261
261-
=item users_resultset
262+
=back
262263
263-
=item roles_resultset
264+
=head1 DEPRECATED SETTINGS
264265
265-
=item user_roles_resultset
266+
=over
266267
267-
These configuration values are provided for fine-grain tuning of your DBIC
268-
resultset names. If you use standard DBIC naming practices, you will not need
269-
to configure these, and they will be generated internally automatically.
268+
=item user_source
269+
270+
=item user_table
271+
272+
Specifies the source name that contains the users. This will be camelized to generate
273+
the resultset name. The relationship to user_roles_source will be introspected from
274+
the schema.
275+
276+
=item role_source
277+
278+
=item role_table
279+
280+
Specifies the source name that contains the roles. This will be camelized to generate
281+
the resultset name. The relationship to user_roles_source will be introspected from
282+
the schema.
283+
284+
=item user_roles_source
285+
286+
=item user_roles_table
270287
271288
=back
272289
290+
Specifies the source name that contains the user_roles joining table. This will be
291+
camelized to generate the resultset name. The relationship to the user and role
292+
source will be introspected from the schema.
293+
273294
=head1 SUGGESTED SCHEMA
274295
275296
If you use a schema similar to the examples provided here, you should need minimal

t/deprecation.t

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use strict;
2+
use warnings;
3+
use Test::More;
4+
use Test::Warn;
5+
use Test::MockObject;
6+
use Dancer2::Plugin::Auth::Extensible::Provider::DBIC;
7+
8+
my $mock = Test::MockObject->new;
9+
$mock->set_true('app');
10+
11+
# instantiate with _source
12+
{
13+
my $plugin;
14+
warnings_like(
15+
sub {
16+
$plugin = Dancer2::Plugin::Auth::Extensible::Provider::DBIC->new(
17+
plugin => $mock,
18+
users_source => 'users',
19+
roles_source => 'roles',
20+
user_roles_source => 'user_roles',
21+
);
22+
},
23+
[
24+
qr/\Qconfig setting "users_source" is deprecated. Use "users_resultset" instead/,
25+
qr/\Qconfig setting "roles_source" is deprecated. Use "roles_resultset" instead/,
26+
qr/\Qconfig setting "user_roles_source" is deprecated. Use "user_roles_resultset" instead/,
27+
],
28+
"_source is deprecated"
29+
);
30+
isa_ok $plugin, 'Dancer2::Plugin::Auth::Extensible::Provider::DBIC',
31+
'object created with _source';
32+
is $plugin->users_resultset, 'Users', "... and users_resultset got set";
33+
is $plugin->roles_resultset, 'Roles', "... and roles_resultset got set";
34+
is $plugin->user_roles_resultset, 'UserRoles', "... and user_roles_resultset got set";
35+
}
36+
37+
# instantiate with _table
38+
{
39+
my $plugin;
40+
warnings_like(
41+
sub {
42+
$plugin = Dancer2::Plugin::Auth::Extensible::Provider::DBIC->new(
43+
plugin => $mock,
44+
users_table => 'users',
45+
roles_table => 'roles',
46+
user_roles_table => 'user_roles',
47+
);
48+
},
49+
[
50+
qr/\Qconfig setting "users_table" is deprecated. Use "users_resultset" instead/,
51+
qr/\Qconfig setting "roles_table" is deprecated. Use "roles_resultset" instead/,
52+
qr/\Qconfig setting "user_roles_table" is deprecated. Use "user_roles_resultset" instead/,
53+
],
54+
"_source is deprecated"
55+
);
56+
isa_ok $plugin, 'Dancer2::Plugin::Auth::Extensible::Provider::DBIC',
57+
'object created with _table';
58+
is $plugin->users_resultset, 'Users', "... and users_resultset got set";
59+
is $plugin->roles_resultset, 'Roles', "... and roles_resultset got set";
60+
is $plugin->user_roles_resultset, 'UserRoles', "... and user_roles_resultset got set";
61+
}
62+
63+
done_testing;

t/environments/hashref.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ plugins:
2222
provider: DBIC
2323
user_as_object: 0
2424
schema_name: schema1
25-
users_source: user
26-
roles_source: role
25+
users_resultset: User
26+
roles_resultset: Role
2727
roles_key: role
28-
user_roles_source: user_role
28+
user_roles_resultset: UserRole
2929
record_lastlogin: 1
3030
users_pwchanged_column: pw_changed
3131
password_expiry_days: 1
@@ -37,10 +37,10 @@ plugins:
3737
provider: DBIC
3838
user_as_object: 0
3939
schema_name: schema2
40-
users_source: myuser
41-
roles_source: myrole
40+
users_resultset: Myuser
41+
roles_resultset: Myrole
4242
roles_key: role
43-
user_roles_source: myuser_role
43+
user_roles_resultset: MyuserRole
4444
users_username_column: myusername
4545
users_password_column: mypassword
4646
roles_role_column: rolename
@@ -50,10 +50,10 @@ plugins:
5050
provider: DBIC
5151
user_as_object: 0
5252
schema_name: schema3
53-
users_source: user
54-
roles_source: role
53+
users_resultset: User
54+
roles_role_column: Role
5555
roles_key: role
56-
user_roles_source: user_role
56+
user_roles_resultset: UserRole
5757
record_lastlogin: 1
5858
users_pwchanged_column: pw_changed
5959
password_expiry_days: 1

t/environments/object.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ plugins:
2222
provider: DBIC
2323
user_as_object: 1
2424
schema_name: schema1
25-
users_source: user
26-
roles_source: role
25+
users_resultset: User
26+
roles_resultset: Role
2727
roles_key: role
28-
user_roles_source: user_role
28+
user_roles_resultset: UserRole
2929
record_lastlogin: 1
3030
users_pwchanged_column: pw_changed
3131
password_expiry_days: 1
@@ -37,10 +37,10 @@ plugins:
3737
provider: DBIC
3838
user_as_object: 1
3939
schema_name: schema2
40-
users_source: myuser
41-
roles_source: myrole
40+
users_resultset: Myuser
41+
roles_resultset: Myrole
4242
roles_key: role
43-
user_roles_source: myuser_role
43+
user_roles_resultset: MyuserRole
4444
users_username_column: myusername
4545
users_password_column: mypassword
4646
roles_role_column: rolename
@@ -50,10 +50,10 @@ plugins:
5050
provider: DBIC
5151
user_as_object: 1
5252
schema_name: schema3
53-
users_source: user
54-
roles_source: role
53+
users_resultset: User
54+
roles_resultset: Role
5555
roles_key: role
56-
user_roles_source: user_role
56+
user_roles_resultset: UserRole
5757
record_lastlogin: 1
5858
users_pwchanged_column: pw_changed
5959
password_expiry_days: 1

0 commit comments

Comments
 (0)