Skip to content

Commit

Permalink
Update menu calculations in RegistryAuthComponent (CFM-30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Jul 9, 2022
1 parent 11c6188 commit ac83f41
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function beforeRender(\Cake\Event\EventInterface $event) {

if(isset($this->RegistryAuth)) {
// Components might not be loaded on error, so check
$this->set('vv_menu_permissions', $this->RegistryAuth->getMenuPermissions());
$this->set('vv_menu_permissions', $this->RegistryAuth->getMenuPermissions($this->getCOID()));
}

// For breadcrumbs, do we have a target model, and if so is it a configuration
Expand Down
25 changes: 14 additions & 11 deletions app/src/Controller/Component/RegistryAuthComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,23 +287,26 @@ public function getAuthenticatedUser(): ?string {
* templates/element/menuMain.php.
*
* @since COmanage Registry v5.0.0
* @return array Array of permissions
* @param int $coId Current CO ID, if known
* @return array Array of permissions
*/

public function getMenuPermissions() {
public function getMenuPermissions(?int $coId): array {
$permissions = [];

// XXX need to set permissions according to current user's roles
$permissions['platform'] = true;
$permissions['platform'] = $this->isPlatformAdmin();

// Can access the Configuration Dashboard for the current CO
$permissions['configuration'] = true;
$permissions['configuration'] = $this->isPlatformAdmin()
|| $this->isCoAdmin($coId);

// Can manage Groups in the current CO
$permissions['groups'] = true;
$permissions['groups'] = $this->isPlatformAdmin()
|| $this->isCoAdmin($coId);

// Can manage People in the current CO
$permissions['people'] = true;
$permissions['people'] = $this->isPlatformAdmin()
|| $this->isCoAdmin($coId);

return $permissions;
}
Expand Down Expand Up @@ -336,22 +339,22 @@ public function isCoAdmin(?int $coId): bool {
}

if(!isset($this->cache['isCoAdmin'])) {
$this->cache['isCoAdmin'] = false;
$this->cache['isCoAdmin'][$coId] = false;

if($this->authenticatedApiUser) {
$ApiUsers = TableRegistry::getTableLocator()->get('ApiUsers');

$priv = $ApiUsers->getUserPrivilege($this->authenticatedUser);

$this->cache['isCoAdmin'] = ($priv === true || $priv === $coId);
$this->cache['isCoAdmin'][$coId] = ($priv === true || $priv === $coId);
} else {
if(!empty($this->authenticatedUser)) {
$this->cache['isCoAdmin'] = $this->isIdentifierAdmin(identifier: $this->authenticatedUser, coId: $coId);
$this->cache['isCoAdmin'][$coId] = $this->isIdentifierAdmin(identifier: $this->authenticatedUser, coId: $coId);
}
}
}

return $this->cache['isCoAdmin'];
return $this->cache['isCoAdmin'][$coId];
}

/**
Expand Down

0 comments on commit ac83f41

Please sign in to comment.