function testSucceedsToUseUserAndAdminAllowedMethod() { $accessRights = new AccessRights(new MockAnyClass()); $accessRights->allow("User", "definedMethod"); $accessRights->allow("Admin", "definedMethod"); $accessRights->loggedAsA("User"); $this->assertTrue($accessRights->definedMethod()); }
public static function getInstance() { if (empty(self::$accessrights)) { self::$accessrights = new AccessRights(); } return self::$accessrights; }
/** * Converts user rights array into it's object representation * * @param array $raw_config Raw config * @param array $options Associative array of options * @return \ConfigContainer Config object */ public function objectify(array $raw_config = array(), array $options = array()) { $config = new ConfigContainer(); $rights = $raw_config[0]; $access = AccessRights::getInstance(); $variables = array(); foreach ($rights as $right) { if ($right === 'full_access') { $variables[] = new ConfigVariable('superuser', true); } if ($access->checkPrivilege($right)) { $variables[] = new ConfigVariable($right, true); } } $section = new ConfigSection('privileges'); $section->addVariables($variables); $config->addSection($section); return $config; }
} $SESSION->redirect('?m=userinfo&id=' . $userinfo['id']); } else { $userinfo['selected'] = array(); if (isset($_POST['selected'])) { foreach ($_POST['selected'] as $idx => $name) { $userinfo['selected'][$idx]['id'] = $idx; $userinfo['selected'][$idx]['name'] = $name; } } $access = AccessRights::getInstance(); $accesslist = $access->getArray(array_keys($acl)); } } else { $rights = $LMS->GetUserRights($id); $access = AccessRights::getInstance(); $accesslist = $access->getArray($rights); } foreach ($LMS->GetUserInfo($id) as $key => $value) { if (!isset($userinfo[$key])) { $userinfo[$key] = $value; } } if (!isset($userinfo['selected'])) { $userinfo['selected'] = $DB->GetAllByKey('SELECT g.id, g.name FROM customergroups g, excludedgroups WHERE customergroupid = g.id AND userid = ? ORDER BY name', 'id', array($userinfo['id'])); } $layout['pagetitle'] = trans('User Edit: $a', $userinfo['login']); $SESSION->save('backto', $_SERVER['QUERY_STRING']);