Skip to content

Commit

Permalink
Grant view permission to CO Person for his/her own MVPA attributes li…
Browse files Browse the repository at this point in the history
…nked to OrgIdentities
  • Loading branch information
ioigoume committed Apr 23, 2021
1 parent 8637c0c commit 2f09acf
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/Controller/AdHocAttributesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ function isAuthorized() {
} elseif(!empty($aha['AdHocAttribute']['org_identity_id'])) {
$managed = $this->Role->isCoOrCouAdminForOrgidentity($roles['copersonid'],
$aha['AdHocAttribute']['org_identity_id']);
if(!empty($roles['orgidentities'])) {
$org_ids = Hash::extract($roles, 'orgidentities.{n}.org_id');
if(in_array($aha['AdHocAttribute']['org_identity_id'], $org_ids)) {
$self = true;
}
}
}
}
break;
Expand Down
6 changes: 6 additions & 0 deletions app/Controller/AddressesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ function isAuthorized() {
} elseif(!empty($address['Address']['org_identity_id'])) {
$managed = $this->Role->isCoOrCouAdminForOrgidentity($roles['copersonid'],
$address['Address']['org_identity_id']);
if(!empty($roles['orgidentities'])) {
$org_ids = Hash::extract($roles, 'orgidentities.{n}.org_id');
if(in_array($address['Address']['org_identity_id'], $org_ids)) {
$self = true;
}
}
}
}
break;
Expand Down
1 change: 1 addition & 0 deletions app/Controller/CoDepartmentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function isAuthorized() {
// View identifiers? This correlates with IdentifiersController
$p['identifiers'] = ($roles['cmadmin']
|| $roles['coadmin']
|| $self
|| ($managed && $roles['couadmin']));

$this->set('permissions', $p);
Expand Down
1 change: 1 addition & 0 deletions app/Controller/CoPeopleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ public function isAuthorized() {
// View identifiers? This correlates with IdentifiersController
$p['identifiers'] = ($roles['cmadmin']
|| $roles['coadmin']
|| $self
|| ($managed && $roles['couadmin']));

// View history? This correlates with HistoryRecordsController
Expand Down
6 changes: 6 additions & 0 deletions app/Controller/EmailAddressesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ function isAuthorized() {
} elseif(!empty($emailaddress['EmailAddress']['org_identity_id'])) {
$managed = $this->Role->isCoOrCouAdminForOrgidentity($roles['copersonid'],
$emailaddress['EmailAddress']['org_identity_id']);
if(!empty($roles['orgidentities'])) {
$org_ids = Hash::extract($roles, 'orgidentities.{n}.org_id');
if(in_array($emailaddress['EmailAddress']['org_identity_id'], $org_ids)) {
$self = true;
}
}
}
}
break;
Expand Down
13 changes: 12 additions & 1 deletion app/Controller/IdentifiersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ function isAuthorized() {
// the identifier passed in the URL, otherwise we lookup based on the record ID.

$managed = false;
$self = false;

if(!empty($roles['copersonid'])) {
switch($this->action) {
Expand Down Expand Up @@ -318,9 +319,18 @@ function isAuthorized() {
if(!empty($identifier['Identifier']['co_person_id'])) {
$managed = $this->Role->isCoOrCouAdminForCoPerson($roles['copersonid'],
$identifier['Identifier']['co_person_id']);
if($identifier['Identifier']['co_person_id'] == $roles['copersonid']) {
$self = true;
}
} elseif(!empty($identifier['Identifier']['org_identity_id'])) {
$managed = $this->Role->isCoOrCouAdminForOrgidentity($roles['copersonid'],
$identifier['Identifier']['org_identity_id']);
if(!empty($roles['orgidentities'])) {
$org_ids = Hash::extract($roles, 'orgidentities.{n}.org_id');
if(in_array($identifier['Identifier']['org_identity_id'], $org_ids)) {
$self = true;
}
}
}
}
break;
Expand Down Expand Up @@ -356,7 +366,8 @@ function isAuthorized() {

// View an existing Identifier?
$p['view'] = ($roles['cmadmin']
|| $roles['coadmin']
|| $roles['coadmin']
|| $self
|| ($managed && $roles['couadmin']));

$this->set('permissions', $p);
Expand Down
6 changes: 6 additions & 0 deletions app/Controller/NamesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ function isAuthorized() {
} elseif(!empty($name['Name']['org_identity_id'])) {
$managed = $this->Role->isCoOrCouAdminForOrgidentity($roles['copersonid'],
$name['Name']['org_identity_id']);
if(!empty($roles['orgidentities'])) {
$org_ids = Hash::extract($roles, 'orgidentities.{n}.org_id');
if(in_array($name['Name']['org_identity_id'], $org_ids)) {
$self = true;
}
}
}
}
break;
Expand Down
1 change: 1 addition & 0 deletions app/Controller/OrgIdentitiesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ function isAuthorized() {
// View identifiers? This correlates with IdentifiersController
$p['identifiers'] = ($roles['cmadmin']
|| $roles['coadmin']
|| $self
|| ($managed && $roles['couadmin']));

// View history? This correlates with HistoryRecordsController
Expand Down
6 changes: 6 additions & 0 deletions app/Controller/TelephoneNumbersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ function isAuthorized() {
} elseif(!empty($number['TelephoneNumber']['org_identity_id'])) {
$managed = $this->Role->isCoOrCouAdminForOrgidentity($roles['copersonid'],
$number['TelephoneNumber']['org_identity_id']);
if(!empty($roles['orgidentities'])) {
$org_ids = Hash::extract($roles, 'orgidentities.{n}.org_id');
if(in_array($number['TelephoneNumber']['org_identity_id'], $org_ids)) {
$self = true;
}
}
}
}
break;
Expand Down
6 changes: 6 additions & 0 deletions app/Controller/UrlsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ function isAuthorized() {
} elseif(!empty($url['Url']['org_identity_id'])) {
$managed = $this->Role->isCoOrCouAdminForOrgidentity($roles['copersonid'],
$url['Url']['org_identity_id']);
if(!empty($roles['orgidentities'])) {
$org_ids = Hash::extract($roles, 'orgidentities.{n}.org_id');
if(in_array($url['Url']['org_identity_id'], $org_ids)) {
$self = true;
}
}
}
}
break;
Expand Down

0 comments on commit 2f09acf

Please sign in to comment.