/** * @inheritdoc */ public function isValid($data, $field = '', array $extra = []) { if (is_array($data) && array_key_exists($field, $data)) { return $this->isValid($data[$field], $field, $extra); } return $this->privilegeRepository->privilegeExists($data); }
/** * @param int $privilegeId * @return array */ protected function fetchPrivileges($privilegeId) { $privileges = $this->privilegeRepository->getAllPrivileges(); $cPrivileges = count($privileges); for ($i = 0; $i < $cPrivileges; ++$i) { $privileges[$i]['selected'] = $this->formsHelper->selectEntry('privileges', $privileges[$i]['id'], $privilegeId); } return $privileges; }
/** * Überprüft, ob die übergebenen Privilegien existieren und * plausible Werte enthalten * * @param array $privilegeIds * * @return boolean */ public function privilegesExist(array $privilegeIds) { $valid = false; foreach ($this->privilegeRepository->getAllPrivileges() as $privilege) { $valid = false; foreach ($privilegeIds as $module) { foreach ($module as $privilegeId => $permission) { if ($this->isValidPrivilege($privilegeId, $privilege, $permission)) { $valid = true; break 2; } } } } return $valid; }
/** * Insert new acl user rules * * @param string $moduleName */ protected function insertAclRules($moduleName) { $roles = $this->roleRepository->getAllRoles(); $privileges = $this->privilegeRepository->getAllPrivilegeIds(); $moduleId = $this->schemaHelper->getModuleId($moduleName); foreach ($roles as $role) { foreach ($privileges as $privilege) { $insertValues = ['id' => '', 'role_id' => $role['id'], 'module_id' => $moduleId, 'privilege_id' => $privilege['id'], 'permission' => $this->getDefaultAclRulePermission($role, $privilege)]; $this->ruleRepository->insert($insertValues); } } }
/** * @param int $roleId * @param int $defaultValue * * @return array */ protected function fetchModulePermissions($roleId, $defaultValue = 0) { $rules = $this->permissionsCache->getRulesCache([$roleId]); $modules = $this->modules->getActiveModules(); $privileges = $this->privilegeRepository->getAllPrivileges(); $cPrivileges = count($privileges); foreach ($modules as $name => $moduleInfo) { $moduleDir = strtolower($moduleInfo['dir']); for ($j = 0; $j < $cPrivileges; ++$j) { $privileges[$j]['select'] = $this->generatePrivilegeCheckboxes($roleId, $moduleInfo['id'], $privileges[$j]['id'], isset($rules[$moduleDir][$privileges[$j]['key']]['permission']) ? (int) $rules[$moduleDir][$privileges[$j]['key']]['permission'] : $defaultValue); if ($roleId !== 0) { $privileges[$j]['calculated'] = $this->calculatePermission($rules, $moduleDir, $privileges[$j]['key']); } } $modules[$name]['privileges'] = $privileges; } return $modules; }