Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions app/Entities/Controllers/BookshelfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Exception;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Illuminate\Support\Facades\Auth;

class BookshelfController extends Controller
{
Expand Down Expand Up @@ -68,6 +69,13 @@ public function index(Request $request)
*/
public function create()
{
$user = Auth::user();
$roles = $user->roles;

// Check if the user has the "Admin" role
if (!$roles->contains('display_name', 'Admin')) {
return redirect()->back()->with('error', 'You do not have permission to create bookshelf.');
}
$this->checkPermission('bookshelf-create-all');
$books = $this->bookQueries->visibleForList()->orderBy('name')->get(['name', 'id', 'slug', 'created_at', 'updated_at']);
$this->setPageTitle(trans('entities.shelves_create'));
Expand All @@ -83,6 +91,13 @@ public function create()
*/
public function store(Request $request)
{
$user = Auth::user();
$roles = $user->roles;

// Check if the user has the "Admin" role
if (!$roles->contains('display_name', 'Admin')) {
return redirect()->back()->with('error', 'You do not have permission to store bookshelf.');
}
$this->checkPermission('bookshelf-create-all');
$validated = $this->validate($request, [
'name' => ['required', 'string', 'max:255'],
Expand Down Expand Up @@ -142,6 +157,13 @@ public function show(Request $request, ActivityQueries $activities, string $slug
*/
public function edit(string $slug)
{
$user = Auth::user();
$roles = $user->roles;

// Check if the user has the "Admin" role
if (!$roles->contains('display_name', 'Admin')) {
return redirect()->back()->with('error', 'You do not have permission to edit bookshelf.');
}
$shelf = $this->queries->findVisibleBySlugOrFail($slug);
$this->checkOwnablePermission('bookshelf-update', $shelf);

Expand All @@ -168,6 +190,13 @@ public function edit(string $slug)
*/
public function update(Request $request, string $slug)
{
$user = Auth::user();
$roles = $user->roles;

// Check if the user has the "Admin" role
if (!$roles->contains('display_name', 'Admin')) {
return redirect()->back()->with('error', 'You do not have permission to update bookshelf.');
}
$shelf = $this->queries->findVisibleBySlugOrFail($slug);
$this->checkOwnablePermission('bookshelf-update', $shelf);
$validated = $this->validate($request, [
Expand All @@ -194,6 +223,13 @@ public function update(Request $request, string $slug)
*/
public function showDelete(string $slug)
{
$user = Auth::user();
$roles = $user->roles;

// Check if the user has the "Admin" role
if (!$roles->contains('display_name', 'Admin')) {
return redirect()->back()->with('error', 'You do not have permission to delete bookshelf.');
}
$shelf = $this->queries->findVisibleBySlugOrFail($slug);
$this->checkOwnablePermission('bookshelf-delete', $shelf);

Expand All @@ -209,6 +245,13 @@ public function showDelete(string $slug)
*/
public function destroy(string $slug)
{
$user = Auth::user();
$roles = $user->roles;

// Check if the user has the "Admin" role
if (!$roles->contains('display_name', 'Admin')) {
return redirect()->back()->with('error', 'You do not have permission to destroy bookshelf.');
}
$shelf = $this->queries->findVisibleBySlugOrFail($slug);
$this->checkOwnablePermission('bookshelf-delete', $shelf);

Expand Down
Loading