Inheritance: extends Illuminate\Database\Eloquent\Model
 protected function getViewer()
 {
     $role = \BookStack\Role::getRole('viewer');
     $viewer = $this->getNewBlankUser();
     $viewer->attachRole($role);
     return $viewer;
 }
Example #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $user = factory(BookStack\User::class, 1)->create();
     $role = \BookStack\Role::where('name', '=', 'admin')->first();
     $user->attachRole($role);
     $books = factory(BookStack\Book::class, 20)->create(['created_by' => $user->id, 'updated_by' => $user->id])->each(function ($book) use($user) {
         $chapters = factory(BookStack\Chapter::class, 5)->create(['created_by' => $user->id, 'updated_by' => $user->id])->each(function ($chapter) use($user, $book) {
             $pages = factory(\BookStack\Page::class, 10)->make(['created_by' => $user->id, 'updated_by' => $user->id, 'book_id' => $book->id]);
             $chapter->pages()->saveMany($pages);
         });
         $pages = factory(\BookStack\Page::class, 3)->make(['created_by' => $user->id, 'updated_by' => $user->id]);
         $book->chapters()->saveMany($chapters);
         $book->pages()->saveMany($pages);
     });
 }
 public function test_public_page_creation()
 {
     $this->setSettings(['app-public' => 'true']);
     $publicRole = \BookStack\Role::getSystemRole('public');
     // Grant all permissions to public
     $publicRole->permissions()->detach();
     foreach (\BookStack\RolePermission::all() as $perm) {
         $publicRole->attachPermission($perm);
     }
     $this->app[\BookStack\Services\PermissionService::class]->buildJointPermissionForRole($publicRole);
     $chapter = \BookStack\Chapter::first();
     $this->visit($chapter->book->getUrl());
     $this->visit($chapter->getUrl())->click('New Page')->see('Create Page')->seePageIs($chapter->getUrl('/create-page'));
     $this->submitForm('Continue', ['name' => 'My guest page'])->seePageIs($chapter->book->getUrl('/page/my-guest-page/edit'));
     $user = \BookStack\User::getDefault();
     $this->seeInDatabase('pages', ['name' => 'My guest page', 'chapter_id' => $chapter->id, 'created_by' => $user->id, 'updated_by' => $user->id]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $user = factory(BookStack\User::class, 1)->create();
     $role = \BookStack\Role::getRole('editor');
     $user->attachRole($role);
     $books = factory(BookStack\Book::class, 20)->create(['created_by' => $user->id, 'updated_by' => $user->id])->each(function ($book) use($user) {
         $chapters = factory(BookStack\Chapter::class, 5)->create(['created_by' => $user->id, 'updated_by' => $user->id])->each(function ($chapter) use($user, $book) {
             $pages = factory(\BookStack\Page::class, 5)->make(['created_by' => $user->id, 'updated_by' => $user->id, 'book_id' => $book->id]);
             $chapter->pages()->saveMany($pages);
         });
         $pages = factory(\BookStack\Page::class, 3)->make(['created_by' => $user->id, 'updated_by' => $user->id]);
         $book->chapters()->saveMany($chapters);
         $book->pages()->saveMany($pages);
     });
     $restrictionService = app(\BookStack\Services\PermissionService::class);
     $restrictionService->buildJointPermissions();
 }
Example #5
0
 /**
  * Assign an list of permission names to an role.
  * @param Role $role
  * @param array $permissionNameArray
  */
 public function assignRolePermissions(Role $role, $permissionNameArray = [])
 {
     $permissions = [];
     $permissionNameArray = array_values($permissionNameArray);
     if ($permissionNameArray && count($permissionNameArray) > 0) {
         $permissions = $this->permission->whereIn('name', $permissionNameArray)->pluck('id')->toArray();
     }
     $role->permissions()->sync($permissions);
 }
Example #6
0
 public function test_user_cannot_be_deleted_if_last_admin()
 {
     $adminRole = \BookStack\Role::getRole('admin');
     // Ensure we currently only have 1 admin user
     $this->assertEquals(1, $adminRole->users()->count());
     $user = $adminRole->users->first();
     $this->asAdmin()->visit('/users/' . $user->id)->click('Delete User')->press('Confirm')->seePageIs('/users/' . $user->id)->see('You cannot delete the only admin');
 }
Example #7
0
 /**
  * Create an array of data with the information of an entity jointPermissions.
  * Used to build data for bulk insertion.
  * @param Entity $entity
  * @param Role $role
  * @param $action
  * @param $permissionAll
  * @param $permissionOwn
  * @return array
  */
 protected function createJointPermissionDataArray(Entity $entity, Role $role, $action, $permissionAll, $permissionOwn)
 {
     $entityClass = get_class($entity);
     return ['role_id' => $role->getRawAttribute('id'), 'entity_id' => $entity->getRawAttribute('id'), 'entity_type' => $entityClass, 'action' => $action, 'has_permission' => $permissionAll, 'has_permission_own' => $permissionOwn, 'created_by' => $entity->getRawAttribute('created_by')];
 }
Example #8
0
 public function test_cannot_delete_admin_role()
 {
     $adminRole = \BookStack\Role::getRole('admin');
     $deletePageUrl = '/settings/roles/delete/' . $adminRole->id;
     $this->asAdmin()->visit($deletePageUrl)->press('Confirm')->seePageIs($deletePageUrl)->see('cannot be deleted');
 }
Example #9
0
 /**
  * Quick way to create a new user
  * @param array $attributes
  * @return mixed
  */
 protected function getEditor($attributes = [])
 {
     $user = factory(\BookStack\User::class)->create($attributes);
     $role = \BookStack\Role::getRole('editor');
     $user->attachRole($role);
     return $user;
 }