| 1 | package SIAM::User; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use base 'SIAM::Object'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use SIAM::Privilege; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use SIAM::AccessScope; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | =head1 NAME | ||||||||||
| 12 | |||||||||||
| 13 | SIAM::User - User object class | ||||||||||
| 14 | |||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||
| 16 | |||||||||||
| 17 | my $user = $siam->get_user($uid); | ||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | =head1 METHODS | ||||||||||
| 21 | |||||||||||
| 22 | =head2 has_privilege | ||||||||||
| 23 | |||||||||||
| 24 | $user->has_privilege('ViewContract', $contract) | ||||||||||
| 25 | |||||||||||
| 26 | Expects a privilege string and an object. Returns true if the object matches | ||||||||||
| 27 | the privilege | ||||||||||
| 28 | |||||||||||
| 29 | =cut | ||||||||||
| 30 | |||||||||||
| 31 | sub has_privilege | ||||||||||
| 32 | 6 | ▶ | { | ||||||||
|
Subroutine
has_privilege: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 33 | 6 | my $self = shift; | |||||||||
| 34 | 6 | my $priv = shift; | |||||||||
| 35 | 6 | my $obj = shift; | |||||||||
| 36 | |||||||||||
| 37 | 6 | my $privileges = $self->get_contained_objects | |||||||||
| 38 | ('SIAM::Privilege', | ||||||||||
| 39 | {'match_attribute' => ['siam.privilege.type', [$priv]]}); | ||||||||||
| 40 | |||||||||||
| 41 | 6 | foreach my $privilege (@{$privileges}) | |||||||||
| 42 | { | ||||||||||
| 43 | 6 | ▶ | if( $privilege->match_object($obj) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | { | ||||||||||
| 45 | 4 | return 1; | |||||||||
| 46 | } | ||||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 2 | return undef; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | |||||||||||
| 53 | |||||||||||
| 54 | =head2 get_objects_by_privilege | ||||||||||
| 55 | |||||||||||
| 56 | $user->get_objects_by_privilege('ViewContract', 'SIAM::Contract', $siam) | ||||||||||
| 57 | |||||||||||
| 58 | Expects 3 arguments: privilege string; object class; and a container object. | ||||||||||
| 59 | Returns arrayref with all matching objects. | ||||||||||
| 60 | |||||||||||
| 61 | =cut | ||||||||||
| 62 | |||||||||||
| 63 | sub get_objects_by_privilege | ||||||||||
| 64 | 3 | ▶ | { | ||||||||
|
Subroutine
get_objects_by_privilege: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||
| 65 | 3 | my $self = shift; | |||||||||
| 66 | 3 | my $priv = shift; | |||||||||
| 67 | 3 | my $objclass = shift; | |||||||||
| 68 | 3 | my $objcontainer = shift; | |||||||||
| 69 | |||||||||||
| 70 | 3 | my $privileges = $self->get_contained_objects | |||||||||
| 71 | ('SIAM::Privilege', | ||||||||||
| 72 | {'match_attribute' => ['siam.privilege.type', [$priv]]}); | ||||||||||
| 73 | |||||||||||
| 74 | # Driver may return the same scope twice, so we keep track of which scopes | ||||||||||
| 75 | # we've already seen | ||||||||||
| 76 | |||||||||||
| 77 | 3 | my @scopes; | |||||||||
| 78 | my %scopes_seen; | ||||||||||
| 79 | |||||||||||
| 80 | 3 | foreach my $privilege (@{$privileges}) | |||||||||
| 81 | { | ||||||||||
| 82 | 3 | ▶ | if( $privilege->matches_all($objclass) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | { | ||||||||||
| 84 | 1 | return $objcontainer->get_contained_objects($objclass); | |||||||||
| 85 | } | ||||||||||
| 86 | else | ||||||||||
| 87 | { | ||||||||||
| 88 | 2 | my $id = $privilege->scope_id; | |||||||||
| 89 | 2 | ▶ | if( not $scopes_seen{$id} ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | { | ||||||||||
| 91 | 2 | push(@scopes, | |||||||||
| 92 | new SIAM::AccessScope($self->_driver, $id)); | ||||||||||
| 93 | } | ||||||||||
| 94 | } | ||||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | # Scopes may overlap, so we put the object IDs in a hash | ||||||||||
| 98 | 2 | my %object_ids; | |||||||||
| 99 | 2 | foreach my $scope (@scopes) | |||||||||
| 100 | { | ||||||||||
| 101 | 2 | my $ids = $scope->get_object_ids(); | |||||||||
| 102 | 2 | foreach my $id (@{$ids}) | |||||||||
| 103 | { | ||||||||||
| 104 | 2 | $object_ids{$id} = 1; | |||||||||
| 105 | } | ||||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | # Retrieve the matching objects | ||||||||||
| 109 | |||||||||||
| 110 | 2 | my $ret = []; | |||||||||
| 111 | 2 | foreach my $id ( keys %object_ids ) | |||||||||
| 112 | { | ||||||||||
| 113 | 2 | push(@{$ret}, $self->instantiate_object($objclass, $id)); | |||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | 2 | return $ret; | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | |||||||||||
| 120 | |||||||||||
| 121 | |||||||||||
| 122 | |||||||||||
| 123 | |||||||||||
| 124 | |||||||||||
| 125 | |||||||||||
| 126 | # mandatory attributes | ||||||||||
| 127 | |||||||||||
| 128 | 3 | my $mandatory_attributes = | |||||||||
| 129 | [ 'siam.user.uid' ]; | ||||||||||
| 130 | |||||||||||
| 131 | sub _mandatory_attributes | ||||||||||
| 132 | 6 | ▶ | { | ||||||||
|
Subroutine
_mandatory_attributes: called CC=1 SCAR=0.0
| |||||||||||
| 133 | 6 | return $mandatory_attributes; | |||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | |||||||||||
| 137 | sub _manifest_attributes | ||||||||||
| 138 | 1 | ▶ | { | ||||||||
|
Subroutine
_manifest_attributes: called CC=1 SCAR=0.0
| |||||||||||
| 139 | 1 | my $ret = []; | |||||||||
| 140 | 1 | push(@{$ret}, @{$mandatory_attributes}, | |||||||||
| 141 | 1 | @{ SIAM::Privilege->_manifest_attributes() }); | |||||||||
| 142 | |||||||||||
| 143 | 1 | return $ret; | |||||||||
| 144 | } | ||||||||||
| 145 | |||||||||||
| 146 | 3 | 1; | |||||||||
| 147 | |||||||||||
| 148 | # Local Variables: | ||||||||||
| 149 | # mode: cperl | ||||||||||
| 150 | # indent-tabs-mode: nil | ||||||||||
| 151 | # cperl-indent-level: 4 | ||||||||||
| 152 | # cperl-continued-statement-offset: 4 | ||||||||||
| 153 | # cperl-continued-brace-offset: -4 | ||||||||||
| 154 | # cperl-brace-offset: 0 | ||||||||||
| 155 | # cperl-label-offset: -2 | ||||||||||
| 156 | # End: | ||||||||||