blib/lib/OpusVL/AppKit/Plugin/AppKit/FeatureList.pm

filter: Statementstmt 100% 59 / 59 Branchbran 91.6% 11 / 12 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 94.7% 90 / 95 CC 11 SCAR 10.3
CC
11
Cov
96%
add_action
4.0
feature_list
4.0
roles_allowed_for_action
3.0
CRAP 2.8
« blib/lib/OpusVL/AppKit/RolesFor/Model/LDAPAuth.pm ↑ Summary lib/OpusVL/AppKit/RolesFor/Schema/AppKitAuthDB/Result/Role.pm »
1 package OpusVL::AppKit::Plugin::AppKit::FeatureList;
2  
3  
4 15 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶has _features => ( is => 'rw' , isa => 'HashRef', default => sub { {}; } );
Subroutine __ANON__: called CC=1 SCAR=0.0
7 8 ▶has _path_to_feature => ( is => 'rw' , isa => 'HashRef', default => sub { {}; } );
Subroutine __ANON__: called CC=1 SCAR=0.0
8  
9 sub add_action
10 {
11 346 ▶ my $self = shift;
Subroutine add_action: called CC=4 SCAR=13.9
Pod documented
12 346 my $app = shift;
13 346 my $action = shift;
14  
15 346 my $features = $action->attributes->{AppKitFeature};
16 346 ▶ return if !$features || !@$features;
Branch: 1 branch
BranchTrueFalseTotal
unless $features and @$features 98 248 346
Condition66%2/3
$features and @$features
!ll&&!rl&&r
980248
MC/DC50%1/2
$features and @$features
$features @$features
Truth table66%2/3
A and B
A= $featuresB= @$features
ABresult
0X0
100
111
17 248 my $list = $features->[0];
18 248 my @features = split /,/, $list;
19 248 for my $feature (@features)
20 {
21 269 $self->_add_to_feature($app .'/'. $feature, $action->reverse);
22 }
23 248 my @app_and_feature = map { $app .'/'. $_ } @features;
24 248 $self->_path_to_feature->{$action->reverse} = \@app_and_feature;
25 }
26  
27 sub _add_to_feature
28 {
29 269 ▶ my ($self, $feature, $action) = @_;
Subroutine _add_to_feature: called CC=2 SCAR=6.9
30  
31 269 ▶ if(!defined $self->_features->{$feature})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->_features->{$feature}) 79 190 269
32 {
33 79 $self->_features->{$feature} = { actions => [], roles_allowed => [] };
34 }
35 269 push @{$self->_features->{$feature}->{actions}}, $action;
36 }
37  
38 sub set_roles_allowed
39 {
40 76 ▶ my ($self, $feature, $roles) = @_;
Subroutine set_roles_allowed: called CC=2 SCAR=7.1
Pod documented
41  
42 76 my $f = $self->_features->{$feature};
43 76 ▶ $f->{roles_allowed} = $roles if $f;
Branch: 1 branch
BranchTrueFalseTotal
if $f 76 0 76
44 }
45  
46 sub roles_allowed_for_action
47 {
48 460 ▶ my $self = shift;
Subroutine roles_allowed_for_action: called CC=3 SCAR=11.0
Pod documented
49 460 my $action_path = shift;
50  
51 460 my $features = $self->_path_to_feature->{$action_path};
52 460 ▶ return [] if !$features || !@$features;
Branch: 1 branch
BranchTrueFalseTotal
unless $features and @$features 119 341 460
Condition66%2/3
$features and @$features
!ll&&!rl&&r
1190341
MC/DC50%1/2
$features and @$features
$features @$features
Truth table66%2/3
A and B
A= $featuresB= @$features
ABresult
0X0
100
111
53 341 my @roles = map { @{$self->_features->{$_}->{roles_allowed} } } @$features;
54 341 return \@roles;
55 }
56  
57 sub feature_list
58 {
59 13 ▶ my $self = shift;
Subroutine feature_list: called CC=4 SCAR=13.9
Pod documented
60 13 my $current_role = shift;
61  
62 # return a list of Feature name -> [roles allowed]
63 13 my %map;
64 13 my @keys = keys %{$self->_features};
65 13 ▶ if($current_role)
Branch: 1 branch
BranchTrueFalseTotal
if ($current_role) { } 8 5 13
66 {
67 # filter it down to a yes/no type deal.
68 8 %map = map { $_ => scalar grep { $current_role eq $_ } @{$self->_features->{$_}->{roles_allowed}} } @keys;
69 }
70 else
71 {
72 5 %map = map { $_ => $self->_features->{$_}->{roles_allowed} } @keys;
73 }
74 # now split the map up some more.
75 13 my %apps;
76 13 for my $key (sort keys %map)
77 {
78 74 $key =~ q|^(.*)/(.*)$|;
79 74 ▶ $apps{$1} = {} if !defined $apps{$1};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $apps{$1} 31 43 74
80 74 $apps{$1}->{$2} = $map{$key};
81 }
82 13 return \%apps;
83 }
84  
85 sub feature_names_with_app
86 {
87 7 ▶ my $self = shift;
Subroutine feature_names_with_app: called CC=1 SCAR=0.0
Pod documented
88 7 my %map;
89 7 my @keys = keys %{$self->_features};
90 7 return \@keys;
91 }
92  
93 15 1;
94  
95 __END__
96  
97 =pod
98  
99 =encoding UTF-8
100  
101 =head1 NAME
102  
103 OpusVL::AppKit::Plugin::AppKit::FeatureList
104  
105 =head1 VERSION
106  
107 version 2.22
108  
109 =head1 SYNOPSIS
110  
111 my $features = OpusVL::AppKit::Plugin::AppKit::FeatureList->new;
112  
113 =head1 DESCRIPTION
114  
115 Object to manage the features in AppKit to provide a less granular view of our access control
116 system.
117  
118 =head1 NAME
119  
120 OpusVL::AppKit::Plugin::AppKit::FeatureList;
121  
122 =head1 METHODS
123  
124 =head2 add_action
125  
126 Pass it an action from the controller and it will read the features it is part of and store
127 the details.
128  
129 =head2 set_roles_allowed
130  
131 Allows you to set the roles allowed to access a feature.
132  
133 =head2 roles_allowed_for_action
134  
135 Returns a list of roles allow to access an action path.
136  
137 =head2 feature_list
138  
139 Returns a hash containing the feature names and their allowed roles.
140  
141 =head2 feature_names_with_app
142  
143 Returns a flat list of features. These feature names have the app name encoded in.
144  
145 This is used by code that talks to the database since that's the format we store the features in.
146  
147 =head1 AUTHOR
148  
149 OpusVL - www.opusvl.com
150  
151 =head1 COPYRIGHT AND LICENSE
152  
153 This software is copyright (c) 2010 by OpusVL - www.opusvl.com.
154  
155 This is free software; you can redistribute it and/or modify it under
156 the same terms as the Perl 5 programming language system itself.
157  
158 =cut
« blib/lib/OpusVL/AppKit/RolesFor/Model/LDAPAuth.pm ↑ Summary lib/OpusVL/AppKit/RolesFor/Schema/AppKitAuthDB/Result/Role.pm »