/** * @covers ::createPermission * @covers ::grantUserPermission * @covers ::grantGroupPermission * @covers ::grantRolePermission * @covers ::grantGroupRole * @covers ::grantUserRole * @covers ::collectPermissions * @covers ::collectUserPermissions * @covers ::collectGroupPermissions * @covers ::collectRolePermission * @covers ::parseSpecialRoles * @covers ::parsePermissions * @covers ::__prepareResource * @covers ::__compareResourceWithPermissions * @covers ::isAllow */ public function testAclAreaPermission() { $group = new Group(); $group->setName('TestGroup')->save(); $role1 = new Role(); $role1->setName('TestRole1')->save(); $role2 = new Role(); $role2->setName('TestRole2')->save(); $role3 = new Role(); $role3->setName('TestRole3')->setFilter('R')->save(); $permission1 = $this->acl->createPermission('zone1', 'access1', ['act1', 'act2', 'act3'], 'Zone 1'); $permission2 = $this->acl->createPermission('zone2', 'access2', ['act1', 'act2', 'act3'], 'Zone 2'); $permission3 = $this->acl->createPermission('zone3', 'access3', ['act1', 'act2', 'act3'], 'Zone 3'); $user = new User(); $user->login = '******'; $user->password = '******'; $user->setGroup($group); $user->save(); // Connect user with permissions $this->acl->grantUserPermission($permission1, $user, ['act1'], true); $this->acl->grantUserPermission($permission2, $user, ['act1', 'act2', 'act3'], true); // Connect group with permissions $this->acl->grantGroupPermission($permission1, $group, ['act3'], true); // Connect roles with permissions $this->acl->grantRolePermission($permission3, $role1, ['act1'], true); $this->acl->grantRolePermission($permission1, $role2, ['act2'], true); $this->acl->grantRolePermission($permission2, $role3, ['act2'], true); // Connect user with roles $this->acl->grantUserRole($role2, $user, true); $this->acl->grantUserRole($role3, $user, true); // Connect group with roles $this->acl->grantGroupRole($role1, $group, true); $this->acl->grantGroupRole($role2, $group, true); $this->assertTrue($this->acl->isAllow('zone1.access1|act1.act2.act3', $user)); $this->assertTrue($this->acl->isAllow('zone2.access2|act1.act3', $user)); $this->assertTrue($this->acl->isAllow('zone3.access3|act1', $user)); // because act2 was revoked (R) $this->assertFalse($this->acl->isAllow('zone2.access2|act1.act2.act3', $user)); }
/** * @covers ::grantUserRole * @covers ::revokeUserRole * @throws \Signes\Acl\Exception\DuplicateEntry * @expectedException \Signes\Acl\Exception\DuplicateEntry */ public function testUserRoleGrantDuplicate() { $user = new User(); $user->login = '******'; $user->password = '******'; $user->group_id = '2'; $user->save(); $role = new Role(); $role->setName('TestRole')->save(); $this->repository->grantUserRole($role, $user); $this->repository->grantUserRole($role, $user); }
public function add() { $this->checkPageAction($this->page_id, Action::$Add); if (Request::ajax()) { if (Input::has('actionType')) { switch (Input::get('actionType')) { case 'groupList': $group_list = array(); if (Input::has('company_id')) { $user = User::find(Auth::id()); if ($user->group->group_name != 'Admin') { $groups[] = $user->group; } else { $company_id = Input::get('company_id'); $groups = Group::where('company_id', $company_id)->get(); } foreach ($groups as $group) { $group_list[] = array('id' => $group->group_id, 'text' => $group->group_name); } } return json_encode($group_list); break; case 'checkUsername': if (Input::has('username')) { $user = User::where(array('username' => Input::get('username')))->where('remove_status', '<>', 'Active')->get(); if (count($user) > 0) { return 'false'; } } return 'true'; break; case 'addUser': if (Request::isMethod('post') && Input::has('user') && Input::has('userinfo')) { $user_detail = json_decode(Input::get('user'), TRUE); $userInfo = json_decode(Input::get('userinfo'), TRUE); $user = User::where(array('username' => $user_detail['username']))->where('remove_status', '<>', 'Active')->get(); if (count($user) > 0) { return json_encode(array('msg' => 'Unable to add user, Please try again later!')); } else { $user = new User(); $user->fill($user_detail); $user->password = Hash::make(User::$DefaultPassword); if ($user->save()) { $userInfo['user_id'] = $user->user_id; if ($user->userinfo()->insert($userInfo)) { return json_encode(array('status' => 'true', 'msg' => 'Successfully Added User!')); } else { $user->delete(); return json_encode(array('status' => 'false', 'msg' => 'Unable To Add User!')); } } return json_encode(array('status' => 'false', 'msg' => 'Unable To Add User!')); } } return json_encode(array('status' => 'false', 'msg' => 'Invalid Request!')); break; } } } $user = User::find(Auth::id()); $company_id = $user->group->company_id; return view('content.setting.users.form.user_form', array('company_id' => $company_id)); }