/** * Set the parent role * * @param Role $parent * @return Role */ public function setParent(Role $parent) { if ($parent->getName() !== $this->getName()) { $this->parent = $parent; $this->parent->addChild($this); } return $this; }
/** * {@inheritdoc} * @param \Role $role */ public function fill($form, $role) { $form->get('name')->setData($role->getName()); $form->get('display_as_leader')->setData($role->displayAsLeader()); $form->get('display_icon')->setData($role->getDisplayIcon()); $form->get('display_color')->setData($role->getDisplayColor()); $form->get('display_name')->setData($role->getDisplayName()); $form->get('display_order')->setData($role->getDisplayOrder()); $form->get('permissions')->setData($role->getPermObjects()); }
/** * Check owing Role & Resource and match its with $roleName & $resourceName; * if match was found depending on action allow or deny access to $resourceName for $roleName. * * @param string $needRuleName * @param string $needRoleName * @param string $needResourceName * * @return RuleResult|null null is returned if there is no matched Role & Resource in this rule. * RuleResult otherwise. */ public function isAllowed($needRuleName, $needRoleName, $needResourceName) { static $roleCache = array(); static $resourceCache = array(); if ($needRuleName != 'RuleWide' && $this->name === $needRuleName || $this->isRuleMatched($needRuleName)) { if (null !== $this->role) { $roleNameTmp = $this->role->getName(); if (!isset($roleCache[$roleNameTmp])) { $roles = iterator_to_array($this->role); $roleCache[$roleNameTmp] = $roles; } else { $roles = $roleCache[$roleNameTmp]; } } else { $roles = array(null); } if (null !== $this->resource) { $resourceNameTmp = $this->resource->getName(); if (!isset($resourceCache[$resourceNameTmp])) { $resources = iterator_to_array($this->resource); $resourceCache[$resourceNameTmp] = $resources; } else { $resources = $resourceCache[$resourceNameTmp]; } } else { $resources = array(null); } foreach ($roles as $role) { if (null === $role || $role && $role->name === $needRoleName) { $roleNameMatched = true; } else { $roleNameMatched = false; } foreach ($resources as $resource) { if (null === $resource || $resource && $resource->name === $needResourceName) { $resourceNameMatched = true; } else { $resourceNameMatched = false; } // Check if $role and $resource match to need role and resource. $ruleResult = null; if ($roleNameMatched === true && $resourceNameMatched === true) { $ruleResult = new RuleResult($this, $needRoleName, $needResourceName); } if ($ruleResult) { return $ruleResult; } } } } return null; }
public function testCreateRoleWithProjectReference() { $xml = simplexml_load_file($this->roleProjectFile); $expectedId = 'RELATED_PROJECT'; $expectedUrl = 'http://example.com/youtrack/rest/admin/project/' . $expectedId; $role = new Role($xml); $this->assertEquals('Developer', $role->getName()); $this->assertNotEmpty($role->getProjectRefs()); $this->assertCount(1, $role->getProjectRefs()); $refs = $role->getProjectRefs(); $ref0 = $refs[0]; $this->assertEquals($expectedId, $ref0->getId()); $this->assertEquals($expectedUrl, $ref0->getUrl()); }
public function testNormalRole() { $role = new Role($this->normalRole->getId()); $this->player_b->addRole($role->getId()); $this->assertFalse($role->displayAsLeader()); $this->assertFalse($role->isProtected()); $this->assertEquals("Sample Normal Role", $role->getName()); $this->assertNull($role->getDisplayIcon()); $this->assertNull($role->getDisplayColor()); $this->assertEquals("Sample Normal Role", $role->getDisplayName()); $this->assertEquals(-1, $role->getDisplayOrder()); $this->assertArrayContainsModel($role, Role::getRoles($this->player_b->getId())); $this->wipe($role); }
/** * Set specific role as default role * * @param void * @return null */ function set_as_default() { if ($this->request->isSubmitted()) { if ($this->active_role->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if ($this->active_role->getType() == ROLE_TYPE_PROJECT) { $this->httpError(HTTP_ERR_INVALID_PROPERTIES); } // if ConfigOptions::setValue('default_role', $this->active_role->getId()); flash_success(':name role has been set as default', array('name' => $this->active_role->getName())); $this->redirectTo('admin_roles'); } else { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if }
public function getName() { $this->_load(); return parent::getName(); }
/** * Return display name property. (readonly) * * @author KnowledgeTree Team * @access public * @return string */ public function getName() { return $this->role->getName(); }
public function deleteRole(Role $roleToDelete) { // check permissions if (!PermissionEngine::getInstance()->currentUserCanDo('userCanDeleteRoles')) { return false; } $db = Database::getInstance(); if (!$db->isConnected()) { return false; } $roleID = $db->escapeString($roleToDelete->getID()); $roleName = $db->escapeString($roleToDelete->getName()); $results = $db->removeData('role', 'roleID = ' . $roleID . ' AND roleName = \'' . $roleName . '\''); if (!$results) { return false; } return true; }
/** * @param Role|string $role * * @throws \InvalidArgumentException * * @return bool */ public function has($role) { if (is_scalar($role)) { $role = new Role($role); } elseif (!$role instanceof Role) { throw new \InvalidArgumentException('$role is expected to be of type string or Gobline\\Acl\\Role'); } $roleName = $role->getName(); return isset($this->roles[$roleName]); }
/** * TODO: Enter description here ... * @param Role $a * @param Role $b * @return number */ function CompareNoRef($a, $b) { $ap = $a->getHomeProject(); $bp = $b->getHomeProject(); if ($ap == NULL && $bp != NULL) { return 1; } elseif ($ap != NULL && $bp == NULL) { return -1; } elseif ($ap == NULL && $bp == NULL) { $tmp = strcoll($a->getName(), $b->getName()); return $tmp; } else { $projcmp = new ProjectComparator(); $projcmp->criterion = 'name'; $tmp = $projcmp->Compare($ap, $bp); if ($tmp) { /* Different projects, sort accordingly */ return $tmp; } return strcoll($a->getName(), $b->getName()); } }
/** * 添加一个角色,如果角色名已经存在,则替换老值 * @param Role $role * @return \tfc\auth\Authoriz */ public function addRole(Role $role) { $name = $role->getName(); $this->_roles[$name] = $role; return $this; }
public function testGetName() { $role = new Role('admin'); $this->assertEquals('admin', $role->getName()); }