/** * @param AJXP_Role $roleObject */ public function addRole($roleObject) { if (isset($this->roles[$roleObject->getId()])) { // NOTHING SPECIAL TO DO ! return; } if (!isset($this->rights["ajxp.roles"])) { $this->rights["ajxp.roles"] = array(); } $this->rights["ajxp.roles"][$roleObject->getId()] = true; if (!isset($this->rights["ajxp.roles.order"])) { $this->rights["ajxp.roles.order"] = array(); } $this->rights["ajxp.roles.order"][$roleObject->getId()] = count($this->rights["ajxp.roles"]); if ($roleObject->alwaysOverrides()) { if (!isset($this->rights["ajxp.roles.sticky"])) { $this->rights["ajxp.roles.sticky"] = array(); } $this->rights["ajxp.roles.sticky"][$roleObject->getId()] = true; } uksort($this->rights["ajxp.roles"], array($this, "orderRoles")); $this->roles[$roleObject->getId()] = $roleObject; $this->recomputeMergedRole(); }
/** * @param AJXP_Role $role * @param AbstractAjxpUser|null $userObject */ public function updateRole($role, $userObject = null) { if ($userObject != null) { // This a personal role, save differently $userObject->personalRole = $role; $userObject->save("superuser"); } else { $all = AJXP_Utils::loadSerialFile($this->rolesSerialFile); $all[$role->getId()] = $role; AJXP_Utils::saveSerialFile($this->rolesSerialFile, $all); } }
/** * @param AJXP_Role $role */ public function updateRole($role, $userObject = null) { // if role is not existed => insert into switch ($this->sqlDriver["driver"]) { case "sqlite": case "sqlite3": case "postgre": $row = dibi::query("SELECT [role_id] FROM [ajxp_roles] WHERE [role_id]=%s", $role->getId()); $res = $row->fetchSingle(); if ($res != null) { dibi::query("UPDATE [ajxp_roles] SET [serial_role]=%bin,[searchable_repositories]=%s WHERE [role_id]=%s", serialize($role), serialize($role->listAcls()), $role->getId()); } else { dibi::query("INSERT INTO [ajxp_roles] ([role_id],[serial_role],[searchable_repositories]) VALUES (%s, %bin,%s)", $role->getId(), serialize($role), serialize($role->listAcls())); } break; case "mysql": dibi::query("INSERT INTO [ajxp_roles] ([role_id],[serial_role]) VALUES (%s, %s) ON DUPLICATE KEY UPDATE [serial_role]=VALUES([serial_role])", $role->getId(), serialize($role)); break; default: return "ERROR!, DB driver " . $this->sqlDriver["driver"] . " not supported yet in __FUNCTION__"; } }
/** * @param AJXP_Role $role * @return AJXP_Role */ public function override(AJXP_Role $role) { $newRole = new AJXP_Role($role->getId()); $roleAcl = $role->listAcls(); $newAcls = $this->array_merge_recursive2($roleAcl, $this->listAcls()); foreach ($newAcls as $repoId => $rightString) { //if($rightString == AJXP_VALUE_CLEAR) continue; if (empty($rightString) && !empty($roleAcl[$repoId])) { $rightString = $roleAcl[$repoId]; } $newRole->setAcl($repoId, $rightString); } $roleParameters = $role->listParameters(true); $newParams = $this->array_merge_recursive2($roleParameters, $this->listParameters(true)); foreach ($newParams as $repoId => $data) { foreach ($data as $pluginId => $param) { foreach ($param as $parameterName => $parameterValue) { if ($parameterValue === true || $parameterValue === false) { $newRole->setParameterValue($pluginId, $parameterName, $parameterValue, $repoId); continue; } if ($parameterValue == AJXP_VALUE_CLEAR) { continue; } if ($parameterValue === "" && !empty($roleParameters[$repoId][$pluginId][$parameterName])) { $parameterValue = $newParams[$repoId][$pluginId][$parameterName]; } $newRole->setParameterValue($pluginId, $parameterName, $parameterValue, $repoId); } } } $newActions = $this->array_merge_recursive2($role->listActionsStates(), $this->listActionsStates()); foreach ($newActions as $repoId => $data) { foreach ($data as $pluginId => $action) { foreach ($action as $actionName => $actionState) { $newRole->setActionState($pluginId, $actionName, $repoId, $actionState); } } } $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, $roleMasks[$repoId]->override($this->masks[$repoId])); } else { if (isset($roleMasks[$repoId])) { $newRole->setMask($repoId, $roleMasks[$repoId]); } else { $newRole->setMask($repoId, $this->masks[$repoId]); } } } return $newRole; }
/** * @param AJXP_Role $role * @return AJXP_Role */ public function override(AJXP_Role $role) { $newRole = new AJXP_Role($role->getId()); $newAcls = $this->array_merge_recursive2($role->listAcls(), $this->listAcls()); foreach ($newAcls as $repoId => $rightString) { if ($rightString == AJXP_VALUE_CLEAR) { continue; } $newRole->setAcl($repoId, $rightString); } $newParams = $this->array_merge_recursive2($role->listParameters(true), $this->listParameters(true)); foreach ($newParams as $repoId => $data) { foreach ($data as $pluginId => $param) { foreach ($param as $parameterName => $parameterValue) { if ($parameterValue === true || $parameterValue === false) { $newRole->setParameterValue($pluginId, $parameterName, $parameterValue, $repoId); continue; } if ($parameterValue == AJXP_VALUE_CLEAR) { continue; } $newRole->setParameterValue($pluginId, $parameterName, $parameterValue, $repoId); } } } $newActions = $this->array_merge_recursive2($role->listActionsStates(), $this->listActionsStates()); foreach ($newActions as $repoId => $data) { foreach ($data as $pluginId => $action) { foreach ($action as $actionName => $actionState) { $newRole->setActionState($pluginId, $actionName, $repoId, $actionState); } } } return $newRole; }
/** * @param AJXP_Role $roleObject */ public function addRole($roleObject) { if (isset($this->roles[$roleObject->getId()])) { // NOTHING SPECIAL TO DO ! return; } if (!isset($this->rights["ajxp.roles"])) { $this->rights["ajxp.roles"] = array(); } $this->rights["ajxp.roles"][$roleObject->getId()] = true; uksort($this->rights["ajxp.roles"], array($this, "orderRoles")); $this->roles[$roleObject->getId()] = $roleObject; $this->recomputeMergedRole(); }
/** * @param AJXP_Role $role */ public function updateRole($role, $userObject = null) { dibi::query("DELETE FROM [ajxp_roles] WHERE [role_id]=%s", $role->getId()); switch ($this->sqlDriver["driver"]) { case "sqlite": case "sqlite3": case "postgre": dibi::query("INSERT INTO [ajxp_roles] ([role_id],[serial_role],[searchable_repositories]) VALUES (%s, %bin,%s)", $role->getId(), serialize($role), serialize($role->listAcls())); break; case "mysql": dibi::query("INSERT INTO [ajxp_roles] ([role_id],[serial_role]) VALUES (%s, %s)", $role->getId(), serialize($role)); break; default: return "ERROR!, DB driver " + $this->sqlDriver["driver"] + " not supported yet in __FUNCTION__"; } }