| 1 | package Articulate::Authorisation; | ||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 6 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 6 | with 'Articulate::Role::Component'; | |||||||||||||
| 7 | |||||||||||||||
| 8 | 6 | ▶ | use Articulate::Syntax qw( new_permission instantiate_array ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 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 | 0 | ▶ | default => sub { [] }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 31 | 5 | ▶ | coerce => sub { instantiate_array(@_) } | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 32 | 6 | ); | |||||||||||||
| 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 | 4 | ▶ | sub permitted { | ||||||||||||
|
Subroutine
permitted: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||
| 47 | 4 | my $self = shift; | |||||||||||||
| 48 | 4 | my $user_id = shift; | |||||||||||||
| 49 | 4 | my $verb = shift; | |||||||||||||
| 50 | 4 | my $location = shift; | |||||||||||||
| 51 | 4 | my $p = new_permission( $user_id, $verb, $location ); | |||||||||||||
| 52 | 4 | foreach my $rule ( @{ $self->rules } ) { | |||||||||||||
| 53 | 8 | my $authed_role; | |||||||||||||
| 54 | 8 | ▶ | if ( $rule->permitted($p) ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 55 | 4 | 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<Articulate::Authentication> | ||||||||||||||
| 69 | |||||||||||||||
| 70 | =item * L<Articulate::Permission> | ||||||||||||||
| 71 | |||||||||||||||
| 72 | =back | ||||||||||||||
| 73 | |||||||||||||||
| 74 | =cut | ||||||||||||||
| 75 | |||||||||||||||
| 76 | 6 | 1; | |||||||||||||