added role self_check and self_check_any to User store
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / t / lib / TestApp / Schema / User.pm
CommitLineData
ad93b3e9 1package TestApp::Schema::User;
2
3use strict;
4use warnings;
5use base 'DBIx::Class';
6
7__PACKAGE__->load_components(qw/ Core /);
8
9__PACKAGE__->table( 'user' );
6d4bea88 10
11__PACKAGE__->add_columns( qw/id username email status role_text session_data/ );
12
13__PACKAGE__->add_column(password => { accessor => 'password_accessor' });
14
ad93b3e9 15__PACKAGE__->set_primary_key( 'id' );
16
17__PACKAGE__->has_many( 'map_user_role' => 'TestApp::Schema::UserRole' => 'user' );
18
19__PACKAGE__->many_to_many( roles => 'map_user_role', 'role');
20
b3c995e9 21use Set::Object;
22
23sub t_check_roles {
24 my ( $self, $roles, $wanted_roles ) = @_;
25
26 if ( grep { $_ eq 'superadmin' } @$roles ) {
27 return 1;
28 }
29
30 my $have = Set::Object->new(@$roles);
31 my $need = Set::Object->new(@$wanted_roles);
32
33 if ( $have->superset($need) ) {
34 return 1;
35 }
36}
37
38sub t_check_roles_any {
39 my ( $self, $roles, $wanted_roles ) = @_;
40
41 if ( grep { $_ eq 'superadmin' } @$roles ) {
42 return 1;
43 }
44
45 my $have = Set::Object->new(@$roles);
46 my $need = Set::Object->new(@$wanted_roles);
47
48 if ( $have->intersection($need)->size > 0 ) {
49 return 1;
50 }
51}
52
ad93b3e9 531;