| 1 | package Authorization::RBAC::Backend::DBIx; | ||||||||||||||||||||||||||||
| 2 | 2 | $Authorization::RBAC::Backend::DBIx::VERSION = '0.12'; | |||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use FindBin '$Bin'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | require UNIVERSAL::require; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | has typeobjs => ( | ||||||||||||||||||||||||||||
| 11 | is => 'rw', | ||||||||||||||||||||||||||||
| 12 | 1 | ▶ | default => sub{ return shift->schema->resultset('Typeobj')->search; } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | has permissions => ( | ||||||||||||||||||||||||||||
| 16 | is => 'rw', | ||||||||||||||||||||||||||||
| 17 | 1 | ▶ | default => sub{ return shift->schema->resultset('Permission')->search; } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 2 | ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 43 | ▶ | sub get_operations{ | ||||||||||||||||||||||||||
|
Subroutine
get_operations: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 43 | my ($self, $operations) = @_; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 43 | my @ops; | |||||||||||||||||||||||||||
| 25 | 43 | foreach my $op ( @$operations ) { | |||||||||||||||||||||||||||
| 26 | 3 | my $op_rs = $self->schema->resultset('Operation')->search({ name => $op})->single; | |||||||||||||||||||||||||||
| 27 | 3 | ▶ | $self->_log("'$op' operation was not found in the database !!!") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | if ! $op_rs; | ||||||||||||||||||||||||||||
| 29 | 3 | ▶ | push( @ops, $op_rs ) if $op_rs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 43 | return @ops; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 64 | ▶ | sub get_permission{ | ||||||||||||||||||||||||||
|
Subroutine
get_permission: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 64 | my ($self, $role, $op, $obj) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 64 | my $typeobj = ref($obj); | |||||||||||||||||||||||||||
| 38 | 64 | $typeobj =~ s/.*:://; | |||||||||||||||||||||||||||
| 39 | 64 | my $typeobj_rs = $self->schema->resultset('Typeobj')->search({ name => $typeobj})->single; | |||||||||||||||||||||||||||
| 40 | 64 | ▶ | if ( ! $typeobj_rs ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | croak "'$typeobj' is unknown in the TypeObj table !"; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 64 | my $permission = $self->schema->resultset('Permission')->search({ role_id => $role->id, | |||||||||||||||||||||||||||
| 45 | typeobj_id => $typeobj_rs->id, | ||||||||||||||||||||||||||||
| 46 | obj_id => $obj->id, | ||||||||||||||||||||||||||||
| 47 | operation_id => $op->id | ||||||||||||||||||||||||||||
| 48 | })->single; | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 64 | ▶ | my $parent_field = $self->config->{typeobj}->{$typeobj}->{parent_field} || 'parent'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->config->{'typeobj'}{$typeobj}{'parent_field'} || 'parent'
MC/DC100%1/1
$self->config->{'typeobj'}{$typeobj}{'parent_field'} || 'parent'
$self->config->{'typeobj'}{$typeobj}{'parent_field'}
Truth table100%2/2
A
A= $self->config->{'typeobj'}{$typeobj}{'parent_field'}
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 64 | ▶ | if ( $permission ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 53 | 46 | return ($permission->value, $permission->inheritable); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | # Search permission on parents | ||||||||||||||||||||||||||||
| 56 | elsif ( $obj->can( $parent_field) ) { | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 17 | ▶ | if ( $obj->$parent_field ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 13 | my $typeobj_parent = ref($obj->$parent_field); | |||||||||||||||||||||||||||
| 61 | 13 | $typeobj_parent =~ s/.*:://; | |||||||||||||||||||||||||||
| 62 | 13 | $self->_log(" [??] Search inherited permissions on parents ${typeobj_parent}_" . $obj->$parent_field->id . "..."); | |||||||||||||||||||||||||||
| 63 | 13 | my ( $result, $inheritable) = $self->get_permission($role, $op, $obj->$parent_field); | |||||||||||||||||||||||||||
| 64 | 13 | ▶ | if ( $inheritable || ! $result ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$inheritable or not $result
MC/DC0%0/2
$inheritable or not $result
$inheritable
not $result
Truth table66%2/3
A or not(B)
A= $inheritableB= not $result
| |||||||||||||||||||||||||||||
| 65 | 13 | return ($result, $inheritable); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | # No permission and no parent => | ||||||||||||||||||||||||||||
| 70 | else { | ||||||||||||||||||||||||||||
| 71 | 1 | $self->_log(" No permission found :("); | |||||||||||||||||||||||||||
| 72 | 1 | return 0; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head1 NAME | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | Authorization::RBAC::Backend::DBIx - Backend 'DBIx' for Authorization::RBAC | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =head1 VERSION | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | version 0.12 | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | use Catalyst qw/ | ||||||||||||||||||||||||||||
| 88 | Authorization::Roles | ||||||||||||||||||||||||||||
| 89 | Authorization::RBAC | ||||||||||||||||||||||||||||
| 90 | /; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # in your config | ||||||||||||||||||||||||||||
| 93 | Authorization::RBAC: | ||||||||||||||||||||||||||||
| 94 | debug: 0 | ||||||||||||||||||||||||||||
| 95 | backend: | ||||||||||||||||||||||||||||
| 96 | name: DBIx | ||||||||||||||||||||||||||||
| 97 | model: Model::RBAC | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =head2 REQUIRED SCHEMA | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | See t/lib/Schema/RBAC/Result/ | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | User -> UserRole -> Role | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | Role -> Permission -> Object ( -> TypeObj ) | ||||||||||||||||||||||||||||
| 106 | -> Operation | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head1 PROVIDED METHODS | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head2 get_operations( $operations ) | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =head2 get_permission( $role, $op, $obj ) | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | Daniel Brosseau, C<< <dab at catapulse.org> >> | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | Copyright 2011 Daniel Brosseau. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 123 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||
| 124 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =cut | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 2 | 1; | |||||||||||||||||||||||||||