Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Store masks in roles.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Sep 18, 2015
1 parent 5ee3a12 commit 671d728
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions core/src/core/classes/class.AJXP_Role.php
Expand Up @@ -58,6 +58,10 @@ class AJXP_Role implements AjxpGroupPathProvider
* @var array Automatically applies to a given list of profiles
*/
protected $autoApplies = array();
/**
* @var AJXP_PermissionMask[]
*/
protected $masks = array();

static $cypheredPassPrefix = '$pydio_password$';

Expand Down Expand Up @@ -162,6 +166,46 @@ public function clearAcls()
$this->acls = array();
}

/**
* @param String $repositoryId
* @param AJXP_PermissionMask $mask
*/
public function setMask($repositoryId, $mask){
$this->masks[$repositoryId] = $mask;
}

/**
* @param string $repositoryId
*/
public function clearMask($repositoryId){
if(isSet($this->masks[$repositoryId])){
unset($this->masks[$repositoryId]);
}
}

/**
* @param string $repositoryId
* @return bool
*/
public function hasMask($repositoryId){
return isSet($this->masks[$repositoryId]);
}

/**
* @param $repositoryId
* @return AJXP_PermissionMask|null
*/
public function getMask($repositoryId){
return (isSet($this->masks[$repositoryId]) ? $this->masks[$repositoryId] : null);
}

/**
* @return AJXP_PermissionMask[]
*/
public function listMasks(){
return $this->masks;
}

/**
* Send all role informations as an associative array
* @param bool $blurPasswords
Expand All @@ -171,6 +215,7 @@ public function getDataArray($blurPasswords = false)
{
$roleData = array();
$roleData["ACL"] = $this->listAcls();
$roleData["MASKS"] = $this->listMasks();
$roleData["ACTIONS"] = $this->listActionsStates();
$roleData["PARAMETERS"] = $this->listParameters(false, $blurPasswords);
$roleData["APPLIES"] = $this->listAutoApplies();
Expand All @@ -188,6 +233,9 @@ public function bunchUpdate($roleData)
$this->actions = $roleData["ACTIONS"];
$this->parameters = $roleData["PARAMETERS"];
$this->autoApplies = $roleData["APPLIES"];
if(isSet($roleData["MASKS"])){
$this->masks = $roleData["MASKS"];
}

}

Expand Down Expand Up @@ -372,6 +420,18 @@ public function override(AJXP_Role $role)
}
}

$roleMasks = $role->listMasks();
$allKeys = array_merge(array_keys($this->masks), array_keys($roleMasks));
foreach($allKeys as $repoId){
if(isSet($roleMasks[$repoId]) && isSet($this->masks[$repoId])){
$newRole->setMask($repoId, $this->masks[$repoId]->override($roleMasks[$repoId]));
}else if(isSet($roleMasks[$repoId])){
$newRole->setMask($repoId, $roleMasks[$repoId]);
}else{
$newRole->setMask($repoId, $this->masks[$repoId]);
}
}

return $newRole;
}

Expand Down

0 comments on commit 671d728

Please sign in to comment.