public function setPermissions() { $permissionFiledName = $this->getPermission(); $permissions = json_decode($this->{$permissionFiledName}); if ($permissions === null) { return $this; } if (isset($permissions->permissions) && is_array($permissions->permissions)) { foreach ($permissions->permissions as $permission) { $this->permissionGroup->add(new Permission($permission->name, $permission->status)); } } return $this; }
public function test_it_can_find_permission_in_permissions_and_subGroups_of_a_permissionGroup_if_its_not_baned() { $permission0 = new Permission("comment-edit", 1); $permission12 = new Permission("comment-delete", -1); $this->group->add($permission0); $this->group->add($permission12); $permission = new Permission("comment-delete", -1); $group1 = new PermissionGroup(); $group1->add(new Permission("comment-edit", 0)); $group2 = new PermissionGroup(); $group2->add(new Permission("feed", 1)); $group3 = new PermissionGroup(); $group3->add($permission); $this->group->addGroup($group1); $this->group->addGroup($group2); $this->group->addGroup($group3); $this->assertTrue($this->group->has(new Permission("feed"))); $this->assertFalse($this->group->has(new Permission("comment-delete"))); $this->assertFalse($this->group->has(new Permission("comment-edit"))); }
public function setPermissions() { $permissionFiledName = $this->getPermission(); $permissions = json_decode($this->{$permissionFiledName}); if ($permissions === null) { return $this->permissionGroup; } if (isset($permissions->permissions) && is_array($permissions->permissions)) { foreach ($permissions->permissions as $permission) { $this->permissionGroup->add(new PermissionModel($permission->name, $permission->status)); } } if (isset($permissions->groups) && is_array($permissions->groups)) { $model = App::make($this->groupModel); if ($model instanceof PermissionGroupContract === false) { throw new GroupModelNotFoundException("you must define your Group model full class name in your User model with the help of protected property named groupModel :)"); } foreach ($permissions->groups as $group) { $group = $model->find($group->id)->getPermissionGroup(); $this->permissionGroup->addGroup($group); } } return $this; }
public function removeGroup(PermissionGroup $group) { if (isset($this->groups[$group->getId()])) { unset($this->groups[$group->getId()]); } }