1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Rolled out new permissions system throughout application

This commit is contained in:
Dan Brown
2016-04-24 16:54:20 +01:00
parent ada7c83e96
commit a81a56706e
18 changed files with 295 additions and 95 deletions

View File

@ -1,5 +1,6 @@
<?php namespace BookStack\Repos;
use Alpha\B;
use BookStack\Exceptions\NotFoundException;
use Illuminate\Support\Str;
use BookStack\Book;
@ -123,21 +124,43 @@ class BookRepo extends EntityRepo
/**
* Get a new book instance from request input.
* @param $input
* @param array $input
* @return Book
*/
public function newFromInput($input)
public function createFromInput($input)
{
return $this->book->newInstance($input);
$book = $this->book->newInstance($input);
$book->slug = $this->findSuitableSlug($book->name);
$book->created_by = auth()->user()->id;
$book->updated_by = auth()->user()->id;
$book->save();
$this->restrictionService->buildEntityPermissionsForEntity($book);
return $book;
}
/**
* Destroy a book identified by the given slug.
* @param $bookSlug
* Update the given book from user input.
* @param Book $book
* @param $input
* @return Book
*/
public function destroyBySlug($bookSlug)
public function updateFromInput(Book $book, $input)
{
$book->fill($input);
$book->slug = $this->findSuitableSlug($book->name, $book->id);
$book->updated_by = auth()->user()->id;
$book->save();
$this->restrictionService->buildEntityPermissionsForEntity($book);
return $book;
}
/**
* Destroy the given book.
* @param Book $book
* @throws \Exception
*/
public function destroy(Book $book)
{
$book = $this->getBySlug($bookSlug);
foreach ($book->pages as $page) {
$this->pageRepo->destroy($page);
}
@ -146,9 +169,19 @@ class BookRepo extends EntityRepo
}
$book->views()->delete();
$book->restrictions()->delete();
$this->restrictionService->deleteEntityPermissionsForEntity($book);
$book->delete();
}
/**
* Alias method to update the book permissions in the RestrictionService.
* @param Book $book
*/
public function updateBookPermissions(Book $book)
{
$this->restrictionService->buildEntityPermissionsForEntity($book);
}
/**
* Get the next child element priority.
* @param Book $book

View File

@ -2,6 +2,7 @@
use Activity;
use BookStack\Book;
use BookStack\Exceptions\NotFoundException;
use Illuminate\Support\Str;
use BookStack\Chapter;
@ -78,11 +79,18 @@ class ChapterRepo extends EntityRepo
/**
* Create a new chapter from request input.
* @param $input
* @return $this
* @param Book $book
* @return Chapter
*/
public function newFromInput($input)
public function createFromInput($input, Book $book)
{
return $this->chapter->fill($input);
$chapter = $this->chapter->newInstance($input);
$chapter->slug = $this->findSuitableSlug($chapter->name, $book->id);
$chapter->created_by = auth()->user()->id;
$chapter->updated_by = auth()->user()->id;
$chapter = $book->chapters()->save($chapter);
$this->restrictionService->buildEntityPermissionsForEntity($chapter);
return $chapter;
}
/**
@ -100,6 +108,7 @@ class ChapterRepo extends EntityRepo
Activity::removeEntity($chapter);
$chapter->views()->delete();
$chapter->restrictions()->delete();
$this->restrictionService->deleteEntityPermissionsForEntity($chapter);
$chapter->delete();
}

View File

@ -151,6 +151,7 @@ class EntityRepo
}
}
$entity->save();
$this->restrictionService->buildEntityPermissionsForEntity($entity);
}
/**

View File

@ -168,6 +168,7 @@ class PageRepo extends EntityRepo
if ($chapter) $page->chapter_id = $chapter->id;
$book->pages()->save($page);
$this->restrictionService->buildEntityPermissionsForEntity($page);
return $page;
}
@ -583,6 +584,7 @@ class PageRepo extends EntityRepo
$page->views()->delete();
$page->revisions()->delete();
$page->restrictions()->delete();
$this->restrictionService->deleteEntityPermissionsForEntity($page);
$page->delete();
}

View File

@ -4,6 +4,7 @@
use BookStack\Exceptions\PermissionsException;
use BookStack\Permission;
use BookStack\Role;
use BookStack\Services\RestrictionService;
use Setting;
class PermissionsRepo
@ -11,16 +12,19 @@ class PermissionsRepo
protected $permission;
protected $role;
protected $restrictionService;
/**
* PermissionsRepo constructor.
* @param $permission
* @param $role
* @param Permission $permission
* @param Role $role
* @param RestrictionService $restrictionService
*/
public function __construct(Permission $permission, Role $role)
public function __construct(Permission $permission, Role $role, RestrictionService $restrictionService)
{
$this->permission = $permission;
$this->role = $role;
$this->restrictionService = $restrictionService;
}
/**
@ -69,6 +73,7 @@ class PermissionsRepo
$permissions = isset($roleData['permissions']) ? array_keys($roleData['permissions']) : [];
$this->assignRolePermissions($role, $permissions);
$this->restrictionService->buildEntityPermissionForRole($role);
return $role;
}
@ -91,6 +96,7 @@ class PermissionsRepo
$role->fill($roleData);
$role->save();
$this->restrictionService->buildEntityPermissionForRole($role);
}
/**
@ -136,6 +142,7 @@ class PermissionsRepo
}
}
$this->restrictionService->deleteEntityPermissionsForRole($role);
$role->delete();
}