line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Articulate::Permission; |
2
|
13
|
|
|
13
|
|
1108
|
use strict; |
|
13
|
|
|
|
|
17
|
|
|
13
|
|
|
|
|
445
|
|
3
|
13
|
|
|
13
|
|
56
|
use warnings; |
|
13
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
368
|
|
4
|
|
|
|
|
|
|
|
5
|
13
|
|
|
13
|
|
51
|
use Moo; |
|
13
|
|
|
|
|
14
|
|
|
13
|
|
|
|
|
66
|
|
6
|
13
|
|
|
13
|
|
4532
|
use Devel::StackTrace; |
|
13
|
|
|
|
|
9235
|
|
|
13
|
|
|
|
|
697
|
|
7
|
|
|
|
|
|
|
|
8
|
13
|
|
|
13
|
|
62
|
use overload bool => sub { shift->granted }, '0+' => sub { shift->granted }; |
|
13
|
|
|
0
|
|
16
|
|
|
13
|
|
|
|
|
106
|
|
|
27
|
|
|
|
|
1951
|
|
|
0
|
|
|
|
|
0
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Articulate::Permission - represent a permission request/response |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 FUNCTIONS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head3 new_permission |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $permission = new_permission $user, verb => $location; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Creates a new permission request, using the user, verb and location |
23
|
|
|
|
|
|
|
supplied as the respective arguments. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
13
|
|
|
13
|
|
2096
|
use Exporter::Declare; |
|
13
|
|
|
|
|
48313
|
|
|
13
|
|
|
|
|
78
|
|
28
|
|
|
|
|
|
|
default_exports qw(new_permission); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new_permission { |
31
|
7
|
|
100
|
7
|
1
|
2464
|
__PACKAGE__->new( |
32
|
|
|
|
|
|
|
{ |
33
|
|
|
|
|
|
|
user_id => shift // '[guest]', |
34
|
|
|
|
|
|
|
verb => shift, |
35
|
|
|
|
|
|
|
location => shift |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 METHODS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head3 new |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
An unremarkable Moo constructor. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head3 grant |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$permission->grant('Anybody can do that!'); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Declares that the user has that permission, for the reason given; sets |
53
|
|
|
|
|
|
|
C and C and populates the stack trace. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub grant { |
58
|
6
|
|
|
6
|
1
|
10
|
my $self = shift; |
59
|
6
|
|
|
|
|
15
|
my $reason = shift; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# die if granted or denied are already set? |
62
|
6
|
|
|
|
|
27
|
$self->granted(1); |
63
|
6
|
|
|
|
|
24
|
$self->reason($reason); |
64
|
6
|
|
|
|
|
56
|
$self->stack_trace( Devel::StackTrace->new ); |
65
|
6
|
|
|
|
|
1819
|
return $self; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head3 deny |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$permission->deny('Don\t touch that!'); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Declares that the user does not have that permission, for the reason |
73
|
|
|
|
|
|
|
given; sets C and C and populates the stack trace. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub deny { |
78
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
79
|
0
|
|
|
|
|
|
my $reason = shift; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# die if granted or denied are already set? |
82
|
0
|
|
|
|
|
|
$self->granted(0); |
83
|
0
|
|
|
|
|
|
$self->denied(1); |
84
|
0
|
|
|
|
|
|
$self->reason($reason); |
85
|
0
|
|
|
|
|
|
$self->stack_trace( Devel::StackTrace->new ); |
86
|
0
|
|
|
|
|
|
return $self; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head3 user_id |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
The user_id requesting permission to access the resource. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
has user_id => ( |
98
|
|
|
|
|
|
|
is => 'rw', |
99
|
|
|
|
|
|
|
default => sub { undef }, |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head3 verb |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
The action being performed, e.g. C, C, etc. The verbs |
105
|
|
|
|
|
|
|
available are entirely dependant on the application. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
A permission request will be granted or denied by an authorisation rule |
108
|
|
|
|
|
|
|
(see Articulate::Authorisation), who will typically implement verbs |
109
|
|
|
|
|
|
|
that bay be different from but are either a) broader than, or b) |
110
|
|
|
|
|
|
|
equally broad as, the verbs used by the Articulate::Service. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
has verb => ( |
115
|
|
|
|
|
|
|
is => 'rw', |
116
|
|
|
|
|
|
|
default => sub { 'error' }, |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head3 location |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
The location of the resource for which permission is requested. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
has location => ( |
126
|
|
|
|
|
|
|
is => 'rw', |
127
|
|
|
|
|
|
|
default => sub { [] }, |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head3 granted |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Whether or not the permission has been explicitly granted. The value of |
133
|
|
|
|
|
|
|
this is used for overload behaviour. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Please do not explicitly set this. Use C instead. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
has granted => ( |
140
|
|
|
|
|
|
|
is => 'rw', |
141
|
|
|
|
|
|
|
default => sub { 0 }, |
142
|
|
|
|
|
|
|
); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head3 denied |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Whether the permission has been explicitly denied. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Please do not explicitly set this. Use C instead. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
has denied => ( |
153
|
|
|
|
|
|
|
is => 'rw', |
154
|
|
|
|
|
|
|
default => sub { 0 } |
155
|
|
|
|
|
|
|
); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head3 reason |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
The reason for the grant or denial of permission. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Please do not explicitly set this. Use C or C instead. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
has reason => ( |
166
|
|
|
|
|
|
|
is => 'rw', |
167
|
|
|
|
|
|
|
default => sub { '' } |
168
|
|
|
|
|
|
|
); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head3 stack_trace |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
The stack trace at the point of grant or denial of permission. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Please do not explicitly set this. Use C or C instead. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
has stack_trace => ( |
179
|
|
|
|
|
|
|
is => 'rw', |
180
|
|
|
|
|
|
|
default => sub { '' } |
181
|
|
|
|
|
|
|
); |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 SEE ALSO |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=over |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item * L |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item * L (which performs a similar function for L) |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=back |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1; |