| 1 | package Labyrinth::Groups; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use vars qw($VERSION @ISA %EXPORT_TAGS @EXPORT @EXPORT_OK); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 12 | $VERSION = '5.32'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Labyrinth::Groups - User Group Manager for Labyrinth | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | This package provides group management for user access. Groups can be used to | ||||||||||||||||||||||||||||
| 16 | set permissions for a set of users, without setting individual user | ||||||||||||||||||||||||||||
| 17 | permissions. | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # ------------------------------------- | ||||||||||||||||||||||||||||
| 22 | # Export Details | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 12 | require Exporter; | |||||||||||||||||||||||||||
| 25 | 12 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 12 | %EXPORT_TAGS = ( | |||||||||||||||||||||||||||
| 28 | 'all' => [ qw( GetGroupID UserInGroup UserGroups GroupSelect GroupSelectMulti ) ] | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 12 | @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||
| 32 | 12 | @EXPORT = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # ------------------------------------- | ||||||||||||||||||||||||||||
| 35 | # Library Modules | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 12 | ▶ | use Labyrinth::Audit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 12 | ▶ | use Labyrinth::Globals; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 12 | ▶ | use Labyrinth::DBUtils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 12 | ▶ | use Labyrinth::MLUtils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 12 | ▶ | use Labyrinth::Session; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 12 | ▶ | use Labyrinth::Support; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 12 | ▶ | use Labyrinth::Variables; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # ------------------------------------- | ||||||||||||||||||||||||||||
| 46 | # Variables | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 12 | my %InGroup; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # ------------------------------------- | ||||||||||||||||||||||||||||
| 51 | # The Subs | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =over 4 | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =item GetGroupID | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | Returns the ID of the specific group. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =item UserInGroup | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Checks whether the specified user (or current user) is in the specified group | ||||||||||||||||||||||||||||
| 64 | Returns 1 if true, otherwise 0 for false. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =item UserGroups() | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | For the current user login, return the list of groups they are associated with. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =item GroupSelect([$opt]) | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | Provides the XHTML code for a single select dropdown box. Pass the id of a | ||||||||||||||||||||||||||||
| 73 | group to pre-select that group. | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =item GroupSelectMulti([$opt[,$rows]]) | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Provides the XHTML code for a multiple select dropdown box. Pass the group id | ||||||||||||||||||||||||||||
| 78 | or an arrayref to a list of group ids to pre-select those groups. By default | ||||||||||||||||||||||||||||
| 79 | the number of rows displayed is 5, although this can be changed by passing the | ||||||||||||||||||||||||||||
| 80 | number of rows you require. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =cut | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub GetGroupID { | ||||||||||||||||||||||||||
|
Subroutine
GetGroupID: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my $name = shift || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 86 | 0 | my @rows = $dbi->GetQuery('array','GetGroupID',$name); | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | return unless(@rows); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | return $rows[0]->[0]; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub UserInGroup { | ||||||||||||||||||||||||||
|
Subroutine
UserInGroup: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $groupid = shift || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | my $userid = shift || $tvars{loginid}; | ||||||||||||||||||||||||||
|
Condition0%0/3
shift() || $Labyrinth::Groups::tvars{'loginid'}
MC/DC0%0/2
shift() || $Labyrinth::Groups::tvars{'loginid'}
shift()
$Labyrinth::Groups::tvars{'loginid'}
Truth table0%0/3
A || B
A= shift()B= $Labyrinth::Groups::tvars{'loginid'}
| |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | return 0 unless($groupid && $userid); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$groupid and $userid
MC/DC0%0/2
$groupid and $userid
$groupid
$userid
Truth table0%0/3
A and B
A= $groupidB= $userid
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | $InGroup{$userid} ||= do { UserGroups($userid) }; | ||||||||||||||||||||||||||
|
Condition0%0/3
$InGroup{$userid} ||= do {
UserGroups($userid)
}
MC/DC0%0/2
$InGroup{$userid} ||= do {
UserGroups($userid)
}
$InGroup{$userid}
do {
UserGroups($userid)
}
Truth table0%0/3
A ||= B
A= $InGroup{$userid}B= do {
UserGroups($userid)
}
| |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | return 1 if($InGroup{$userid} =~ /\b$groupid\b/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | return 0; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub UserGroups { | ||||||||||||||||||||||||||
|
Subroutine
UserGroups: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $userid = shift || $tvars{loginid}; | ||||||||||||||||||||||||||
|
Condition0%0/3
shift() || $Labyrinth::Groups::tvars{'loginid'}
MC/DC0%0/2
shift() || $Labyrinth::Groups::tvars{'loginid'}
shift()
$Labyrinth::Groups::tvars{'loginid'}
Truth table0%0/3
A || B
A= shift()B= $Labyrinth::Groups::tvars{'loginid'}
| |||||||||||||||||||||||||||||
| 103 | 0 | my (%groups,@grps); | |||||||||||||||||||||||||||
| 104 | 0 | my @rows = $dbi->GetQuery('hash','AllGroupIndex'); | |||||||||||||||||||||||||||
| 105 | 0 | foreach (@rows) { | |||||||||||||||||||||||||||
| 106 | # a user link, but not our user | ||||||||||||||||||||||||||||
| 107 | 0 | ▶ | next if($_->{type} == 1 && $_->{linkid} ne $userid); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_->{"type"} == 1 and $_->{"linkid"} ne $userid
MC/DC0%0/2
$_->{"type"} == 1 and $_->{"linkid"} ne $userid
$_->{"type"} == 1
$_->{"linkid"} ne $userid
Truth table0%0/3
A and B
A= $_->{"type"} == 1B= $_->{"linkid"} ne $userid
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if($_->{type} == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | push @grps, $_->{groupid}; | |||||||||||||||||||||||||||
| 111 | } else { | ||||||||||||||||||||||||||||
| 112 | 0 | push @{$groups{$_->{linkid}}}, $_->{groupid}; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 0 | my @list = (); | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | while(@grps) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | my $g = shift @grps; | |||||||||||||||||||||||||||
| 118 | 0 | push @list, $g; | |||||||||||||||||||||||||||
| 119 | 0 | ▶ | next unless($groups{$g}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | push @grps, @{$groups{$g}}; | |||||||||||||||||||||||||||
| 121 | 0 | delete $groups{$g}; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | 0 | my %hash = map {$_ => 1} @list; | |||||||||||||||||||||||||||
| 124 | 0 | my $grps = join(",",keys %hash); | |||||||||||||||||||||||||||
| 125 | 0 | return $grps; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub GroupSelect { | ||||||||||||||||||||||||||
|
Subroutine
GroupSelect: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 129 | 0 | my $opt = shift; | |||||||||||||||||||||||||||
| 130 | 0 | my @rows = $dbi->GetQuery('hash','AllGroups'); | |||||||||||||||||||||||||||
| 131 | 0 | unshift @rows, {groupid => 0, groupname => 'Select A Group' }; | |||||||||||||||||||||||||||
| 132 | 0 | return DropDownRows($opt,'groups','groupid','groupname',@rows); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub GroupSelectMulti { | ||||||||||||||||||||||||||
|
Subroutine
GroupSelectMulti: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 136 | 0 | my $opt = shift; | |||||||||||||||||||||||||||
| 137 | 0 | ▶ | my $multi = shift || 5; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 5
MC/DC0%0/1
shift() || 5
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 138 | 0 | my @rows = $dbi->GetQuery('hash','AllGroups'); | |||||||||||||||||||||||||||
| 139 | 0 | unshift @rows, {groupid => 0, groupname => 'Select A Group' }; | |||||||||||||||||||||||||||
| 140 | 0 | return DropDownMultiRows($opt,'groups','groupid','groupname',$multi,@rows); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 12 | 1; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | __END__ | ||||||||||||||||||||||||||||