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