addRole() public method

Add roles.
public addRole ( Sulu\Component\Security\Authentication\RoleInterface $roles ) : Group
$roles Sulu\Component\Security\Authentication\RoleInterface
return Group
 public function setUp()
 {
     $this->user = new User();
     $this->userRole = new UserRole();
     $this->role = new Role();
     $this->permission = new Permission();
     $this->permission->setPermissions(122);
     $this->permission->setContext('sulu.security.roles');
     $this->role->addPermission($this->permission);
     $this->userRole->setRole($this->role);
     $this->user->addUserRole($this->userRole);
     $this->userGroup = new UserGroup();
     $this->group = new Group();
     $this->role = new Role();
     $this->permission = new Permission();
     $this->permission->setPermissions(122);
     $this->permission->setContext('sulu.security.groups');
     $this->role->addPermission($this->permission);
     $this->group->addRole($this->role);
     $this->userGroup->setGroup($this->group);
     $this->nestedGroup = new Group();
     $this->role = new Role();
     $this->permission = new Permission();
     $this->permission->setPermissions(122);
     $this->permission->setContext('sulu.security.groups.nested');
     $this->role->addPermission($this->permission);
     $this->nestedGroup->addRole($this->role);
     $this->group->addChildren($this->nestedGroup);
     $this->user->addUserGroup($this->userGroup);
     $this->token = $this->prophesize(TokenInterface::class);
     $this->token->getUser()->willReturn($this->user);
     $this->aclProvider = $this->prophesize(AclProviderInterface::class);
     $this->aclProvider->findAcl(Argument::any())->willReturn(true);
     $this->voter = new SecurityContextVoter($this->permissions, $this->aclProvider->reveal());
 }
Beispiel #2
0
 public function setUp()
 {
     $this->em = $this->db('ORM')->getOm();
     $this->purgeDatabase();
     $datetime = new \DateTime();
     $role1 = new Role();
     $role1->setName('Sulu Administrator');
     $role1->setSystem('Sulu');
     $this->em->persist($role1);
     $this->role1 = $role1;
     $role2 = new Role();
     $role2->setName('Sulu Manager');
     $role2->setSystem('Sulu');
     $this->em->persist($role2);
     $this->role2 = $role2;
     $group1 = new Group();
     $group1->setName('Group1');
     $group1->addRole($role1);
     $group1->addRole($role2);
     $this->em->persist($group1);
     $this->group1 = $group1;
     $group2 = new Group();
     $group2->setName('Group2');
     $group2->addRole($role1);
     $this->em->persist($group2);
     $this->group2 = $group2;
     $this->em->flush();
 }
Beispiel #3
0
 /**
  * Adds the given role to the group.
  *
  * @param Group $group
  * @param array $roleData
  *
  * @return bool
  *
  * @throws \Sulu\Component\Rest\Exception\EntityNotFoundException
  */
 private function addRole(Group $group, $roleData)
 {
     if (isset($roleData['id'])) {
         $role = $this->get('sulu.repository.role')->findRoleById($roleData['id']);
         if (!$role) {
             throw new EntityNotFoundException($this->get('sulu.repository.role')->getClassName(), $roleData['id']);
         }
         if (!$group->getRoles()->contains($role)) {
             $group->addRole($role);
         }
     }
     return true;
 }