Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
render action sidebar if the user belongs to the appropriate group
Showing
5 changed files
with
193 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<?php | ||
|
||
App::uses('Validator', 'Vendor/cakephp/Validation'); | ||
App::uses('CoGrouperLite', 'GrouperLiteWidget.Model/'); | ||
App::uses('GrouperGroup', 'GrouperLiteWidget.Model/'); | ||
|
||
App::uses('Identifier', 'Model'); | ||
|
||
class GrouperLiteActAsPeopleController extends StandardController | ||
{ | ||
public $helpers = ['Html', 'Form', 'Flash']; | ||
|
||
// Dynamic properties are deprecated, so we will define the property here | ||
private $userId; | ||
|
||
public $uses = [ | ||
'GrouperLiteWidget.GrouperLiteActAsPerson', | ||
'GrouperLiteWidget.CoGrouperLiteWidget', | ||
'GrouperLiteWidget.GrouperGroup', | ||
'Identifier', | ||
'CoPerson' | ||
]; | ||
|
||
public $components = [ | ||
'Flash', | ||
'RequestHandler', | ||
'Security' => [ | ||
'validatePost' => false, | ||
'csrfUseOnce' => false | ||
] | ||
]; | ||
|
||
|
||
public $name = 'GrouperLiteActAsPeople'; | ||
|
||
/** | ||
* Overrides parent beforeFilter to verify that Session contains the correct API settings. | ||
* | ||
* @return void | ||
*/ | ||
public function beforeFilter() | ||
{ | ||
parent::beforeFilter(); | ||
|
||
if(empty($this->request->params['named']['glid'])) { | ||
throw new InvalidArgumentException(_txt('er.grouperlite.glid'), | ||
HttpStatusCodesEnum::HTTP_BAD_REQUEST); | ||
} | ||
$this->response->disableCache(); | ||
$this->RequestHandler->addInputType('json', ['json_decode', true]); | ||
|
||
$this->Security->unlockedActions = [ | ||
'add', | ||
'edit', | ||
'delete' | ||
]; | ||
|
||
// Get the config | ||
$args = array(); | ||
$args['conditions']['CoGrouperLiteWidget.id'] = $this->request->params['named']['glid']; | ||
$args['contain'] = false; | ||
$cfg = $this->CoGrouperLiteWidget->find('first', $args); | ||
// Set the config so that everybody can access it | ||
$this->CoGrouperLiteWidget->setConfig($cfg); | ||
} | ||
|
||
/** | ||
* NOTE: All permissions will be done on the Grouper side. All Authenticated users will be able to | ||
* use this plugin for self-admin of groups. | ||
* | ||
* Authorization for this Controller, called by Auth component | ||
* - precondition: Session.Auth holds data used for authz decisions | ||
* - postcondition: $permissions set with calculated permissions | ||
* | ||
* @return array|bool Permissions | ||
* @since COmanage Registry v4.4.0 | ||
*/ | ||
public function isAuthorized(): array|bool | ||
{ | ||
$roles = $this->Role->calculateCMRoles(); | ||
$cfg = $this->CoGrouperLiteWidget->getConfig(); | ||
// Find the identifier | ||
$args = array(); | ||
$args['conditions']['Identifier.type'] = $cfg['CoGrouperLiteWidget']['identifier_type']; | ||
$args['conditions']['Identifier.status'] = SuspendableStatusEnum::Active; | ||
$args['conditions']['Identifier.co_person_id'] = $roles['copersonid']; | ||
$args['contain'] = false; | ||
|
||
$identifiers = $this->Identifier->find('first', $args); | ||
if(!empty($identifiers) | ||
&& is_array($identifiers) | ||
&& isset($identifiers['Identifier']['identifier']) | ||
) { | ||
$this->setUserId($identifiers['Identifier']['identifier']); | ||
} | ||
|
||
// Find if the user belongs to Group | ||
$eligibleGroup = $cfg['CoGrouperLiteWidget']['act_as_grp_name']; | ||
$isActAsEligibilityGroupmember = false; | ||
|
||
if(!empty($eligibleGroup)) { | ||
$isActAsEligibilityGroupmember = $this->GrouperGroup->isGroupMember($this->getUserId(), $eligibleGroup, $cfg); | ||
} | ||
|
||
// Determine what operations this user can perform | ||
// Construct the permission set for this user, which will also be passed to the view. | ||
$p = []; | ||
|
||
$p['add'] = $isActAsEligibilityGroupmember; | ||
$p['delete'] = $isActAsEligibilityGroupmember; | ||
$p['edit'] = $isActAsEligibilityGroupmember; | ||
$p['update'] = $isActAsEligibilityGroupmember; | ||
|
||
$this->set('permissions', $p); | ||
|
||
return ($p[$this->action]); | ||
} | ||
|
||
/** | ||
* @return null | ||
*/ | ||
public function getUserId() | ||
{ | ||
return $this->userId; | ||
} | ||
|
||
|
||
/** | ||
* @param null $userId | ||
*/ | ||
private function setUserId($userId): void | ||
{ | ||
$this->userId = $userId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters