Groups.pm

filter: Statementstmt 22.9% 37 / 161 Branchbran 1.8% 2 / 108 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 45.4% 10 / 22 Podpod 100% 12 / 12 totaltotal 20.1% 61 / 303 CC 62 SCAR 43.4
CC
62
Cov
14%
Save
182.0
Edit
132.0
Admin
110.0
CRAP 76.9
« Hits.pm ↑ Summary Users/Info.pm »
1 package Labyrinth::Plugin::Groups;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 our $VERSION = '5.19';
7  
8 =head1 NAME
9  
10 Labyrinth::Plugin::Groups - handler for Labyrinth groups
11  
12 =head1 DESCRIPTION
13  
14 Contains all the group handling functionality for the Labyrinth
15 framework.
16  
17 =cut
18  
19 # type 1 - userid link to groupid
20 # type 2 - groupid link to groupid
21  
22 # -------------------------------------
23 # Library Modules
24  
25 4 ▶use base qw(Labyrinth::Plugin::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 4 ▶use Labyrinth::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 4 ▶use Labyrinth::DBUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 4 ▶use Labyrinth::Groups;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 4 ▶use Labyrinth::MLUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 4 ▶use Labyrinth::Support;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 4 ▶use Labyrinth::Users;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 4 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 # -------------------------------------
36 # Variables
37  
38 # html: 0 = none, 1 = text, 2 = textarea
39  
40 4 my %fields = (
41 groupid => { type => 0, html => 0 },
42 groupname => { type => 1, html => 1 },
43 );
44  
45 4 my (@mandatory, @allfields);
46 4 for(keys %fields) {
47 8 ▶ push @mandatory, $_ if($fields{$_}->{type});
Branch: 1 branch
BranchTrueFalseTotal
if $fields{$_}{"type"} 4 4 8
48 8 push @allfields, $_;
49 }
50  
51 # -------------------------------------
52 # The Subs
53  
54 =head1 PUBLIC INTERFACE METHODS
55  
56 =over 4
57  
58 =item GetUserGroup()
59  
60 For the current user login, set main group.
61  
62 =back
63  
64 =cut
65  
66 0 ▶sub GetUserGroup {
Subroutine GetUserGroup: not called CC=2 SCAR=17.9
Pod documented
67 0 my @rows = $dbi->GetQuery('hash','UserGroups',$tvars{loginid});
68 0 ▶ $tvars{user}{groupid} = $rows[0]->{groupid} if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
69 }
70  
71 =head1 ADMIN INTERFACE METHODS
72  
73 All action methods are only accessible by users with admin permission.
74  
75 =over 4
76  
77 =item Admin
78  
79 Provides List and Delete functionality for Group Admin.
80  
81 =item Add
82  
83 Creates a new group.
84  
85 =item AddLinkUser
86  
87 Links a given user to the given group.
88  
89 =item AddLinkGroup
90  
91 Links a given group to another, the latter becoming the parent of the former.
92  
93 =item Edit
94  
95 Provides group admin functionality for a given group.
96  
97 =item Save
98  
99 Saves the current settings for the given group.
100  
101 =item User
102  
103 Provides group admin functionality for a given user.
104  
105 =item UserSave
106  
107 Saves the current group settings for the given user.
108  
109 =item Delete
110  
111 Deletes a group. Called from within the Admin method above.
112  
113 =item DeleteLinkUser
114  
115 Removes the given user from the given group.
116  
117 =item DeleteLinkGroup
118  
119 Removes the given group from a nominated parent.
120  
121 =back
122  
123 =cut
124  
125 0 ▶sub Admin {
Subroutine Admin: not called CC=10 SCAR=47.0
Pod documented
126 0 ▶ return unless AccessUser(ADMIN);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(4) 0 0 0
127 0 ▶ if($cgiparams{doaction}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Groups::cgiparams{"doaction"}) 0 0 0
128 0 ▶ Delete() if($cgiparams{doaction} eq 'Delete');
Branch: 1 branch
BranchTrueFalseTotal
if $Labyrinth::Plugin::Groups::cgiparams{"doaction"} eq "Delete" 0 0 0
129 }
130 0 ▶ my @where = ($tvars{useraccess} == MASTER ? () : ('groupid!=9'));
Branch: 1 branch
BranchTrueFalseTotal
$Labyrinth::Plugin::Groups::tvars{'useraccess'} == 5 ? : 0 0 0
131 0 ▶ push @where, "groupname LIKE '%$cgiparams{'searchname'}%'" if($cgiparams{'searchname'});
Branch: 1 branch
BranchTrueFalseTotal
if $Labyrinth::Plugin::Groups::cgiparams{"searchname"} 0 0 0
132 0 ▶ my $where = @where ? 'WHERE '.join(' AND ',@where) : '';
Branch: 1 branch
BranchTrueFalseTotal
@where ? : 0 0 0
133 0 my @rows = $dbi->GetQuery('hash','AllGroups',{where=>$where});
134 0 for(@rows) {
135 0 my @cnt = $dbi->GetQuery('hash','GroupCount',$_->{groupid});
136 0 ▶ $_->{count} = @cnt ? $cnt[0]->{count} : 0;
Branch: 1 branch
BranchTrueFalseTotal
@cnt ? : 0 0 0
137 }
138 0 ▶ $tvars{data} = \@rows if(@rows);
Branch: 1 branch
BranchTrueFalseTotal
if @rows 0 0 0
139 }
140  
141 0 ▶sub Add {
Subroutine Add: not called CC=2 SCAR=17.9
Pod documented
142 0 ▶ return unless AccessUser(ADMIN);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(4) 0 0 0
143 0 $tvars{newgroup} = 1;
144 }
145  
146 0 ▶sub AddLinkUser {
Subroutine AddLinkUser: not called CC=4 SCAR=30.0
Pod documented
147 0 ▶ return unless AccessUser(ADMIN);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(4) 0 0 0
148 0 ▶ return unless $cgiparams{'groupid'};
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Groups::cgiparams{"groupid"} 0 0 0
149 0 ▶ return unless $cgiparams{'id'};
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Groups::cgiparams{"id"} 0 0 0
150 0 $dbi->DoQuery('AddLinkIndex',0,$cgiparams{'id'},$cgiparams{'groupid'});
151 }
152  
153 0 ▶sub AddLinkGroup {
Subroutine AddLinkGroup: not called CC=4 SCAR=30.0
Pod documented
154 0 ▶ return unless AccessUser(ADMIN);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(4) 0 0 0
155 0 ▶ return unless $cgiparams{'groupid'};
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Groups::cgiparams{"groupid"} 0 0 0
156 0 ▶ return unless $cgiparams{'id'};
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Groups::cgiparams{"id"} 0 0 0
157 0 $dbi->DoQuery('AddLinkIndex',1,$cgiparams{'id'},$cgiparams{'groupid'});
158 }
159  
160 0 ▶sub User {
Subroutine User: not called CC=9 SCAR=45.0
Pod documented
161 0 ▶ return unless AccessUser(ADMIN);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(4) 0 0 0
162 0 ▶ return unless $cgiparams{'userid'};
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Groups::cgiparams{"userid"} 0 0 0
163 0 my @rows = $dbi->GetQuery('hash','GetUserByID',$cgiparams{'userid'});
164 0 $tvars{data} = $rows[0];
165 0 my @urows = $dbi->GetQuery('hash','UserGroups',$cgiparams{'userid'});
166 0 ▶ $tvars{primary} = \@urows if(@urows);
Branch: 1 branch
BranchTrueFalseTotal
if @urows 0 0 0
167 0 my %groups;
168 0 my @arows = $dbi->GetQuery('hash','AllGroups');
169 0 my @irows = $dbi->GetQuery('hash','AllGroupIndex');
170 0 foreach (@irows) { push @{$groups{$_->{groupid}}}, $_->{linkid}; }
171 0 my @list;
172 0 my %grps = map {$_->{groupid} => 1} @urows;
173 0 my @grps = keys %grps;
174 0 ▶ while(@grps) {
Branch: 1 branch
BranchTrueFalseTotal
if (@grps) 0 0 0
175 0 my $g = shift @grps;
176 0 ▶ push @list, $g unless($grps{$g}); # not primary group
Branch: 1 branch
BranchTrueFalseTotal
unless $grps{$g} 0 0 0
177 0 ▶ next unless($groups{$g}); # not already seen
Branch: 1 branch
BranchTrueFalseTotal
unless $groups{$g} 0 0 0
178 0 push @grps, @{$groups{$g}};
179 0 delete $groups{$g};
180 }
181 0 my %list = map {$_->{groupid} => $_->{groupname}} @arows;
182 0 my @deps = sort map {$list{$_}} @list;
183 0 ▶ $tvars{secondary} = \@deps if(@deps);
Branch: 1 branch
BranchTrueFalseTotal
if @deps 0 0 0
184 0 $tvars{ddgroups} = GroupSelect();
185 }
186  
187 0 ▶sub Edit {
Subroutine Edit: not called CC=11 SCAR=48.8
Pod documented
188 0 ▶ return unless AccessUser(ADMIN);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(4) 0 0 0
189 0 ▶ return unless $cgiparams{'groupid'};
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Groups::cgiparams{"groupid"} 0 0 0
190 0 my @rows = $dbi->GetQuery('hash','GetGroup',$cgiparams{'groupid'});
191 0 ▶ return unless(@rows);
Branch: 1 branch
BranchTrueFalseTotal
unless @rows 0 0 0
192 0 $tvars{data} = $rows[0];
193 0 my @urows = $dbi->GetQuery('hash','LinkUsers',$cgiparams{'groupid'});
194 0 my @grows = $dbi->GetQuery('hash','LinkGroups',$cgiparams{'groupid'});
195 0 ▶ $tvars{groupusers} = \@urows if(@urows);
Branch: 1 branch
BranchTrueFalseTotal
if @urows 0 0 0
196 0 ▶ $tvars{primary} = \@grows if(@grows);
Branch: 1 branch
BranchTrueFalseTotal
if @grows 0 0 0
197 0 my %groups;
198 0 my @arows = $dbi->GetQuery('hash','AllGroups');
199 0 my @irows = $dbi->GetQuery('hash','AllGroupIndex');
200 0 foreach (@irows) { push @{$groups{$_->{groupid}}}, $_->{linkid}; }
201 0 my @list;
202 0 my %grps = map {$_->{linkid} => 1} @grows;
203 0 my @grps = keys %grps;
204 0 ▶ while(@grps) {
Branch: 1 branch
BranchTrueFalseTotal
if (@grps) 0 0 0
205 0 my $g = shift @grps;
206 0 ▶ push @list, $g unless($grps{$g}); # not primary group
Branch: 1 branch
BranchTrueFalseTotal
unless $grps{$g} 0 0 0
207 0 ▶ next unless($groups{$g}); # not already seen
Branch: 1 branch
BranchTrueFalseTotal
unless $groups{$g} 0 0 0
208 0 push @grps, @{$groups{$g}};
209 0 delete $groups{$g};
210 }
211 0 my %list = map {$_->{groupid} => $_->{groupname}} @arows;
212 0 my @deps = sort map {$list{$_}} @list;
213 0 ▶ $tvars{secondary} = \@deps if(@deps);
Branch: 1 branch
BranchTrueFalseTotal
if @deps 0 0 0
214 0 $tvars{ddusers} = UserSelect(undef,5);
215 0 $tvars{ddgroups} = GroupSelectMulti($cgiparams{'groupid'});
216 }
217  
218 0 ▶sub Save {
Subroutine Save: not called CC=13 SCAR=52.0
Pod documented
219 0 ▶ return unless AccessUser(ADMIN);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(4) 0 0 0
220 0 for(keys %fields) {
221 0 ▶ if($fields{$_}->{html} == 1) { $cgiparams{$_} = CleanHTML($cgiparams{$_}) }
Branch: 3 branches
BranchTrueFalseTotal
if ($fields{$_}{'html'} == 1) { } 0 0 0
elsif ($fields{$_}{'html'} == 2) { } 0 0 0
elsif ($fields{$_}{'html'} == 3) { } 0 0 0
222 0 elsif($fields{$_}->{html} == 2) { $cgiparams{$_} = CleanTags($cgiparams{$_}) }
223 0 elsif($fields{$_}->{html} == 3) { $cgiparams{$_} = CleanLink($cgiparams{$_}) }
224 }
225 0 ▶ return if FieldCheck(\@allfields,\@mandatory);
Branch: 1 branch
BranchTrueFalseTotal
if FieldCheck(\@allfields, \@mandatory) 0 0 0
226 # cannot change names of core groups
227 0 my @rows = $dbi->GetQuery('hash','GetGroup',$cgiparams{'groupid'});
228 0 ▶ unless($rows[0]->{master}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows[0]{"master"}) 0 0 0
229 0 ▶ if($cgiparams{'groupid'})
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Groups::cgiparams{'groupid'}) { } 0 0 0
230 0 { $dbi->DoQuery('SaveGroup',$cgiparams{'groupname'},$cgiparams{'groupid'}); }
231 0 else { $cgiparams{'groupid'} = $dbi->IDQuery('AddGroup',$cgiparams{'groupname'}); }
232 }
233 0 ▶ if($cgiparams{'users'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Groups::cgiparams{"users"}) 0 0 0
234 0 push my @ids, CGIArray('users');
235 0 $dbi->DoQuery('AddLinkIndex',1,$_,$cgiparams{'groupid'}) for @ids;
236 }
237 0 ▶ if($cgiparams{'groups'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Groups::cgiparams{"groups"}) 0 0 0
238 0 push my @ids, CGIArray('groups');
239 0 $dbi->DoQuery('AddLinkIndex',2,$_,$cgiparams{'groupid'}) for @ids;
240 }
241 }
242  
243 0 ▶sub UserSave {
Subroutine UserSave: not called CC=5 SCAR=34.0
Pod documented
244 0 ▶ return unless AccessUser(ADMIN);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(4) 0 0 0
245 0 ▶ return unless($cgiparams{'userid'});
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Groups::cgiparams{"userid"} 0 0 0
246 0 ▶ if($cgiparams{'groups'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Labyrinth::Plugin::Groups::cgiparams{"groups"}) 0 0 0
247 0 push my @ids, CGIArray('groups');
248 0 $dbi->DoQuery('AddLinkIndex',1,$cgiparams{'userid'},$_) for @ids;
249 }
250 }
251  
252 0 ▶sub Delete {
Subroutine Delete: not called CC=5 SCAR=34.0
Pod documented
253 0 ▶ return unless AccessUser(ADMIN);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(4) 0 0 0
254 0 my @ids = CGIArray('LISTED');
255 0 ▶ return unless @ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
256 0 for my $id (@ids) {
257 0 my @rows = $dbi->GetQuery('hash','GetGroup',$id);
258 0 ▶ next if($rows[0]->{master}); # cannot delete core groups
Branch: 1 branch
BranchTrueFalseTotal
if $rows[0]{"master"} 0 0 0
259 0 $dbi->DoQuery('DeleteGroupIndex',$id);
260 0 $dbi->DoQuery('DeleteGroup',$id);
261 }
262 }
263  
264 0 ▶sub DeleteLinkUser {
Subroutine DeleteLinkUser: not called CC=4 SCAR=30.0
Pod documented
265 0 ▶ return unless AccessUser(ADMIN);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(4) 0 0 0
266 0 ▶ return unless $cgiparams{'groupid'};
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Groups::cgiparams{"groupid"} 0 0 0
267 0 ▶ return unless $cgiparams{'userid'};
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Groups::cgiparams{"userid"} 0 0 0
268 0 $dbi->DoQuery('DeleteLinkIndex',1,$cgiparams{'userid'},$cgiparams{'groupid'});
269 }
270  
271 0 ▶sub DeleteLinkGroup {
Subroutine DeleteLinkGroup: not called CC=4 SCAR=30.0
Pod documented
272 0 ▶ return unless AccessUser(ADMIN);
Branch: 1 branch
BranchTrueFalseTotal
unless AccessUser(4) 0 0 0
273 0 ▶ return unless $cgiparams{'groupid'};
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Groups::cgiparams{"groupid"} 0 0 0
274 0 ▶ return unless $cgiparams{'id'};
Branch: 1 branch
BranchTrueFalseTotal
unless $Labyrinth::Plugin::Groups::cgiparams{"id"} 0 0 0
275 0 $dbi->DoQuery('DeleteLinkIndex',2,$cgiparams{'id'},$cgiparams{'groupid'});
276 }
277  
278 4 1;
279  
280 __END__
« Hits.pm ↑ Summary Users/Info.pm »