line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Articulate::Authorisation; |
2
|
6
|
|
|
6
|
|
3835
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
237
|
|
3
|
6
|
|
|
6
|
|
28
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
145
|
|
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
29
|
use Moo; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
34
|
|
6
|
|
|
|
|
|
|
with 'Articulate::Role::Component'; |
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
1616
|
use Articulate::Syntax qw( new_permission instantiate_array ); |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
53
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Articulate::Authorisation |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 CONFIGURATION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
components: |
19
|
|
|
|
|
|
|
authorisation: |
20
|
|
|
|
|
|
|
Articulate::Authorisation: |
21
|
|
|
|
|
|
|
rules: |
22
|
|
|
|
|
|
|
- Articulate::Authorisation::OwnerOverride |
23
|
|
|
|
|
|
|
- Articulate::Authorisation::AlwaysAllow |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has rules => ( |
29
|
|
|
|
|
|
|
is => 'rw', |
30
|
|
|
|
|
|
|
default => sub { [] }, |
31
|
|
|
|
|
|
|
coerce => sub { instantiate_array(@_) } |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head3 permitted |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$self->permitted( $user_id, $permission, $location ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Asks each of the rules in turn whether the user has the specified |
39
|
|
|
|
|
|
|
permission for that location. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
If so, returns the role under which they have that permission. |
42
|
|
|
|
|
|
|
Otherwise, returns undef. (Each provider should do likewise) |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub permitted { |
47
|
4
|
|
|
4
|
1
|
306
|
my $self = shift; |
48
|
4
|
|
|
|
|
16
|
my $user_id = shift; |
49
|
4
|
|
|
|
|
9
|
my $verb = shift; |
50
|
4
|
|
|
|
|
11
|
my $location = shift; |
51
|
4
|
|
|
|
|
26
|
my $p = new_permission( $user_id, $verb, $location ); |
52
|
4
|
|
|
|
|
55
|
foreach my $rule ( @{ $self->rules } ) { |
|
4
|
|
|
|
|
85
|
|
53
|
8
|
|
|
|
|
732
|
my $authed_role; |
54
|
8
|
100
|
|
|
|
41
|
if ( $rule->permitted($p) ) { |
|
|
50
|
|
|
|
|
|
55
|
4
|
|
|
|
|
19
|
return $p; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ( $p->denied ) { |
58
|
0
|
|
|
|
|
|
return $p; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
return ( $p->deny('No rule granted this permission') ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 SEE ALSO |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=over |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item * L |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item * L |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=back |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |