File Coverage

blib/lib/Articulate/Authorisation.pm
Criterion Covered Total %
statement 25 27 92.5
branch 3 4 75.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 35 38 92.1


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