RBAC/Backend/DBIx.pm

filter: Statementstmt 97.6% 41 / 42 Branchbran 71.4% 10 / 14 Conditioncond 80.0% 4 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 89.0% 65 / 73 CC 11 SCAR 16.2
CC
11
Cov
90%
get_permission
8.1
get_operations
4.1
BEGIN
1.0
CRAP 5.1
« RBAC.pm ↑ Summary
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
BranchTrueFalseTotal
unless $op_rs 0 3 3
28 if ! $op_rs;
29 3 ▶ push( @ops, $op_rs ) if $op_rs;
Branch: 1 branch
BranchTrueFalseTotal
if $op_rs 3 0 3
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
BranchTrueFalseTotal
unless ($typeobj_rs) 0 64 64
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'
l!l
622
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'}
Aresult
11
00
51  
52 64 ▶ if ( $permission ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($permission) { } 46 18 64
elsif ($obj->can($parent_field)) { } 17 1 18
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
BranchTrueFalseTotal
if ($obj->$parent_field) 13 4 17
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
BranchTrueFalseTotal
if ($inheritable or not $result) 13 0 13
Condition66%2/3
$inheritable or not $result
l!l&&r!l&&!r
850
MC/DC0%0/2
$inheritable or not $result
$inheritable not $result
Truth table66%2/3
A or not(B)
A= $inheritableB= not $result
ABresult
1X1
011
000
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;
« RBAC.pm ↑ Summary