Articulate/Authorisation.pm

filter: Statementstmt 90.6% 29 / 32 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 88.8% 40 / 45 SCAR 13.9
CC
4
Cov
89%
permitted
4.1
__ANON__
2.0
BEGIN
1.0
CRAP 4.0
« Articulate/Error.pm ↑ Summary Articulate/TestEnv.pm »
1 package Articulate::Authorisation;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 with 'Articulate::Role::Component';
7  
8 4 ▶use Articulate::Syntax qw(instantiate_array);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Articulate::Permission;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Articulate::Authorisation
14  
15 =cut
16  
17 =head1 CONFIGURATION
18  
19 plugins:
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 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 3 ▶ coerce => sub { instantiate_array(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
32  
33 =head3 permitted
34  
35 $self->permitted( $user_id, $permission, $location );
36  
37 Asks each of the rules in turn whether the user has the specified permission for that location.
38  
39 If so, returns the role under which they have that permission. Otherwise, returns undef. (Each provider should do likewise)
40  
41 =cut
42  
43 sub permitted {
44 4 ▶ my $self = shift;
Subroutine permitted: called CC=4 SCAR=14.1
Pod documented
45 4 my $user_id = shift;
46 4 my $verb = shift;
47 4 my $location = shift;
48 4 my $p = permission ($user_id, $verb, $location);
49 4 foreach my $rule ( @{ $self->rules } ) {
50 8 my $authed_role;
51 8 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($rule->permitted($p)) { } 4 4 8
elsif ($p->denied) { } 0 4 4
52 $rule->permitted( $p )
53 ) {
54 4 return $p;
55 }
56 elsif ( $p->denied ) {
57 0 return $p;
58 }
59 }
60 0 return ( $p->deny('No rule granted this permission') );
61 }
62  
63 =head1 SEE ALSO
64  
65 =over
66  
67 =item * L<Articulate::Authentication>
68  
69 =item * L<Articulate::Permission>
70  
71 =back
72  
73 =cut
74  
75  
76 4 1;
« Articulate/Error.pm ↑ Summary Articulate/TestEnv.pm »