| 1 | package CGI::Lazy::Authz; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use CGI::Lazy::Globals; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | #------------------------------------------------------------------------------- | ||||||||||||
| 8 | 0 | ▶ | sub AUTOLOAD { | ||||||||||
|
Subroutine
AUTOLOAD: not called CC=4 SCAR=30.0
| |||||||||||||
| 9 | 0 | my $self = shift; | |||||||||||
| 10 | 0 | my $perm = shift; | |||||||||||
| 11 | |||||||||||||
| 12 | 0 | my $name = our $AUTOLOAD; | |||||||||||
| 13 | 0 | ▶ | return if $name =~ /::DESTROY$/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 14 | 0 | my @list = split "::", $name; | |||||||||||
| 15 | |||||||||||||
| 16 | 0 | my $groupName = pop @list; | |||||||||||
| 17 | 0 | my $userID = $self->q->session->data->authn->{id}; | |||||||||||
| 18 | 0 | my @binds = ($groupName, $userID); | |||||||||||
| 19 | |||||||||||||
| 20 | 0 | my $map = $self->_mapTable; | |||||||||||
| 21 | 0 | my $user = $self->_userTable; | |||||||||||
| 22 | 0 | my $group = $self->_groupTable; | |||||||||||
| 23 | 0 | my $flag = $self->_permFlag; | |||||||||||
| 24 | |||||||||||||
| 25 | 0 | my $query = "select * from $map->{name} inner join $group->{name} on $group->{primarykey} = $map->{groupField} where $group->{groupNameField} = ? and $map->{userField} = ?"; | |||||||||||
| 26 | |||||||||||||
| 27 | 0 | ▶ | if ($perm) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | 0 | $query .= " and $perm = ?"; | |||||||||||
| 29 | 0 | push @binds, $flag; | |||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | # $self->q->util->debug->edump($query, $groupName, $userID); | ||||||||||||
| 33 | |||||||||||||
| 34 | 0 | my $result = $self->q->db->get($query, @binds); | |||||||||||
| 35 | |||||||||||||
| 36 | 0 | ▶ | if ($result) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | 0 | return 1; | |||||||||||
| 38 | } else { | ||||||||||||
| 39 | 0 | return; | |||||||||||
| 40 | |||||||||||||
| 41 | } | ||||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | #---------------------------------------------------------------------------------------- | ||||||||||||
| 45 | 0 | ▶ | sub _groupTable { | ||||||||||
|
Subroutine
_groupTable: not called CC=1 SCAR=6.9
| |||||||||||||
| 46 | 0 | my $self = shift; | |||||||||||
| 47 | |||||||||||||
| 48 | 0 | return $self->{_groupTable}; | |||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | #---------------------------------------------------------------------------------------- | ||||||||||||
| 52 | 0 | ▶ | sub q { | ||||||||||
|
Subroutine
q: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 53 | 0 | my $self = shift; | |||||||||||
| 54 | |||||||||||||
| 55 | 0 | return $self->{_q}; | |||||||||||
| 56 | } | ||||||||||||
| 57 | |||||||||||||
| 58 | #---------------------------------------------------------------------------------------- | ||||||||||||
| 59 | 0 | ▶ | sub _mapTable { | ||||||||||
|
Subroutine
_mapTable: not called CC=1 SCAR=6.9
| |||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||
| 61 | |||||||||||||
| 62 | 0 | return $self->{_mapTable}; | |||||||||||
| 63 | } | ||||||||||||
| 64 | |||||||||||||
| 65 | #---------------------------------------------------------------------------------------- | ||||||||||||
| 66 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 67 | 0 | my $class = shift; | |||||||||||
| 68 | 0 | my $q = shift; | |||||||||||
| 69 | |||||||||||||
| 70 | my $self = { | ||||||||||||
| 71 | _q => $q, | ||||||||||||
| 72 | _userTable => $q->plugin->authz->{userTable}, | ||||||||||||
| 73 | _groupTable => $q->plugin->authz->{groupTable}, | ||||||||||||
| 74 | _mapTable => $q->plugin->authz->{mapTable}, | ||||||||||||
| 75 | 0 | ▶ | _permFlag => $q->plugin->authz->{permFlag} || 1, | ||||||||||
|
Condition0%0/2
$q->plugin->authz->{'permFlag'} || 1
MC/DC0%0/1
$q->plugin->authz->{'permFlag'} || 1
$q->plugin->authz->{'permFlag'}
Truth table0%0/2
A
A= $q->plugin->authz->{'permFlag'}
| |||||||||||||
| 76 | |||||||||||||
| 77 | }; | ||||||||||||
| 78 | |||||||||||||
| 79 | 0 | bless $self, $class; | |||||||||||
| 80 | |||||||||||||
| 81 | 0 | ▶ | die "Cannot use Authz without Authn. Please enable Authn plugin" unless $self->q->authn; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | |||||||||||||
| 83 | 0 | return $self; | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | #---------------------------------------------------------------------------------------- | ||||||||||||
| 87 | 0 | ▶ | sub _permFlag { | ||||||||||
|
Subroutine
_permFlag: not called CC=1 SCAR=6.9
| |||||||||||||
| 88 | 0 | my $self = shift; | |||||||||||
| 89 | |||||||||||||
| 90 | 0 | return $self->{_permFlag}; | |||||||||||
| 91 | } | ||||||||||||
| 92 | |||||||||||||
| 93 | #---------------------------------------------------------------------------------------- | ||||||||||||
| 94 | 0 | ▶ | sub _userTable { | ||||||||||
|
Subroutine
_userTable: not called CC=1 SCAR=6.9
| |||||||||||||
| 95 | 0 | my $self = shift; | |||||||||||
| 96 | |||||||||||||
| 97 | 0 | return $self->{_userTable}; | |||||||||||
| 98 | } | ||||||||||||
| 99 | 1 | 1 | |||||||||||
| 100 | |||||||||||||
| 101 | __END__ | ||||||||||||