Changed the sort view to only show books to which we have an update permission.

Signed-off-by: Abijeet <abijeetpatro@gmail.com>
This commit is contained in:
Abijeet 2017-12-31 16:44:46 +05:30
parent 4a24d1c31b
commit e13e71cbe0
2 changed files with 8 additions and 9 deletions

View file

@ -155,7 +155,7 @@ class BookController extends Controller
$book = $this->entityRepo->getBySlug('book', $bookSlug); $book = $this->entityRepo->getBySlug('book', $bookSlug);
$this->checkOwnablePermission('book-update', $book); $this->checkOwnablePermission('book-update', $book);
$bookChildren = $this->entityRepo->getBookChildren($book, true); $bookChildren = $this->entityRepo->getBookChildren($book, true);
$books = $this->entityRepo->getAll('book', false); $books = $this->entityRepo->getAll('book', false, 'update');
$this->setPageTitle(trans('entities.books_sort_named', ['bookName'=>$book->getShortName()])); $this->setPageTitle(trans('entities.books_sort_named', ['bookName'=>$book->getShortName()]));
return view('books/sort', ['book' => $book, 'current' => $book, 'books' => $books, 'bookChildren' => $bookChildren]); return view('books/sort', ['book' => $book, 'current' => $book, 'books' => $books, 'bookChildren' => $bookChildren]);
} }
@ -229,9 +229,7 @@ class BookController extends Controller
if ($model->priority !== $priority || $model->book_id !== $bookId || ($isPage && $model->chapter_id !== $chapterId)) { if ($model->priority !== $priority || $model->book_id !== $bookId || ($isPage && $model->chapter_id !== $chapterId)) {
$this->entityRepo->changeBook($isPage?'page':'chapter', $bookId, $model); $this->entityRepo->changeBook($isPage?'page':'chapter', $bookId, $model);
$model->priority = $priority; $model->priority = $priority;
if ($isPage) { if ($isPage) $model->chapter_id = $chapterId;
$model->chapter_id = $chapterId;
}
$model->save(); $model->save();
$updatedModels->push($model); $updatedModels->push($model);
} }

View file

@ -113,9 +113,9 @@ class EntityRepo
* @param bool $allowDrafts * @param bool $allowDrafts
* @return \Illuminate\Database\Query\Builder * @return \Illuminate\Database\Query\Builder
*/ */
protected function entityQuery($type, $allowDrafts = false) protected function entityQuery($type, $allowDrafts = false, $permission = 'view')
{ {
$q = $this->permissionService->enforceEntityRestrictions($type, $this->getEntity($type), 'view'); $q = $this->permissionService->enforceEntityRestrictions($type, $this->getEntity($type), $permission);
if (strtolower($type) === 'page' && !$allowDrafts) { if (strtolower($type) === 'page' && !$allowDrafts) {
$q = $q->where('draft', '=', false); $q = $q->where('draft', '=', false);
} }
@ -196,14 +196,15 @@ class EntityRepo
} }
/** /**
* Get all entities of a type limited by count unless count if false. * Get all entities of a type with the given permission, limited by count unless count is false.
* @param string $type * @param string $type
* @param integer|bool $count * @param integer|bool $count
* @param string $permission
* @return Collection * @return Collection
*/ */
public function getAll($type, $count = 20) public function getAll($type, $count = 20, $permission = 'view')
{ {
$q = $this->entityQuery($type)->orderBy('name', 'asc'); $q = $this->entityQuery($type, false, $permission)->orderBy('name', 'asc');
if ($count !== false) $q = $q->take($count); if ($count !== false) $q = $q->take($count);
return $q->get(); return $q->get();
} }