diff --git a/.idea/deployment.xml b/.idea/deployment.xml index 981e50c..02a52c6 100644 --- a/.idea/deployment.xml +++ b/.idea/deployment.xml @@ -1,6 +1,6 @@ - + @@ -10,5 +10,6 @@ + \ No newline at end of file diff --git a/app/Helpers/DbHelper.php b/app/Helpers/DbHelper.php index 89c5f53..9df062e 100644 --- a/app/Helpers/DbHelper.php +++ b/app/Helpers/DbHelper.php @@ -66,10 +66,8 @@ class DbHelper ->withCount('photos'); } - public static function getAlbumByAliasForCurrentUser($urlAlias) + public static function getAlbumByAlias($urlAlias) { - $album = Album::where('url_alias', $urlAlias)->first(); - - return $album; + return Album::where('url_alias', $urlAlias)->first(); } } \ No newline at end of file diff --git a/app/Http/Controllers/Gallery/AlbumController.php b/app/Http/Controllers/Gallery/AlbumController.php index 85246b1..fef5ec2 100644 --- a/app/Http/Controllers/Gallery/AlbumController.php +++ b/app/Http/Controllers/Gallery/AlbumController.php @@ -17,13 +17,15 @@ class AlbumController extends Controller { public function index(Request $request, $albumUrlAlias) { - $album = DbHelper::getAlbumByAliasForCurrentUser($albumUrlAlias); + $album = DbHelper::getAlbumByAlias($albumUrlAlias); if (is_null($album)) { App::abort(404); return null; } + $this->authorizeForUser($this->getUser(), 'view', $album); + $validViews = UserConfig::allowedAlbumViews(); $requestedView = strtolower($request->get('view')); if (!in_array($requestedView, $validViews)) @@ -36,8 +38,6 @@ class AlbumController extends Controller } } - $this->authorizeForUser($this->getUser(), 'album.view', $album); - if ($album->photos()->count() == 0) { $requestedView = 'empty'; diff --git a/app/Http/Controllers/Gallery/PhotoController.php b/app/Http/Controllers/Gallery/PhotoController.php index 03d8e25..858fd97 100644 --- a/app/Http/Controllers/Gallery/PhotoController.php +++ b/app/Http/Controllers/Gallery/PhotoController.php @@ -20,14 +20,14 @@ class PhotoController extends Controller { public function download(Request $request, $albumUrlAlias, $photoFilename) { - $album = DbHelper::getAlbumByAliasForCurrentUser($albumUrlAlias); + $album = DbHelper::getAlbumByAlias($albumUrlAlias); if (is_null($album)) { App::abort(404); return null; } - $this->authorizeForUser($this->getUser(), 'album.view', $album); + $this->authorizeForUser($this->getUser(), 'view', $album); if (UserConfig::get('hotlink_protection')) { @@ -75,14 +75,14 @@ class PhotoController extends Controller public function show(Request $request, $albumUrlAlias, $photoFilename) { - $album = DbHelper::getAlbumByAliasForCurrentUser($albumUrlAlias); + $album = DbHelper::getAlbumByAlias($albumUrlAlias); if (is_null($album)) { App::abort(404); return null; } - $this->authorizeForUser($this->getUser(), 'album.view', $album); + $this->authorizeForUser($this->getUser(), 'view', $album); $photo = PhotoController::loadPhotoByAlbumAndFilename($album, $photoFilename); diff --git a/app/Policies/AlbumPolicy.php b/app/Policies/AlbumPolicy.php index 8adef65..815521b 100644 --- a/app/Policies/AlbumPolicy.php +++ b/app/Policies/AlbumPolicy.php @@ -45,6 +45,37 @@ class AlbumPolicy 'description' => 'edit' ])->first(); + return $this->userHasPermission($user, $album, $permission); + } + + public function view(User $user, Album $album) + { + if ($user->id == $album->user_id) + { + // The album's owner and can do everything + return true; + } + + // Get the edit permission + $permission = Permission::where([ + 'section' => 'album', + 'description' => 'view' + ])->first(); + + return $this->userHasPermission($user, $album, $permission); + } + + private function userHasPermission(User $user, Album $album, Permission $permission) + { + if ($user->isAnonymous()) + { + $query = Album::query()->join('album_anonymous_permissions', 'album_anonymous_permissions.album_id', '=', 'albums.id') + ->join('permissions', 'permissions.id', '=', 'album_anonymous_permissions.permission_id') + ->where('permissions.id', $permission->id); + + return $query->count() > 0; + } + // If any of the user's groups are granted the permission /** @var Group $group */ foreach ($user->groups as $group) diff --git a/app/User.php b/app/User.php index 5035918..a1abcc2 100644 --- a/app/User.php +++ b/app/User.php @@ -45,4 +45,9 @@ class User extends Authenticatable { return $this->belongsToMany(Group::class, 'user_groups'); } + + public function isAnonymous() + { + return $this->id == -1 && $this->name == 'Anonymous'; + } } diff --git a/resources/views/themes/base/gallery/album_default.blade.php b/resources/views/themes/base/gallery/album_default.blade.php index 38b0bfd..c639f49 100644 --- a/resources/views/themes/base/gallery/album_default.blade.php +++ b/resources/views/themes/base/gallery/album_default.blade.php @@ -35,7 +35,7 @@

{{ $photo->name }}

diff --git a/resources/views/themes/base/gallery/photo.blade.php b/resources/views/themes/base/gallery/photo.blade.php index d455c83..cd0726c 100644 --- a/resources/views/themes/base/gallery/photo.blade.php +++ b/resources/views/themes/base/gallery/photo.blade.php @@ -2,21 +2,15 @@ @section('title', $photo->name) @section('breadcrumb') - + + + @endsection @section('content')
-
+

{{ $photo->name }}

@if (strlen($photo->description) > 0)

{{ $photo->description }}

@@ -25,7 +19,7 @@
-
+
@if ($is_original_allowed) @endif @@ -35,11 +29,11 @@ @endif
-
-
-
Information about this photo:
-
- +
+
+
Information about this photo:
+
+
@@ -87,8 +81,8 @@ diff --git a/resources/views/themes/base/partials/album_permissions.blade.php b/resources/views/themes/base/partials/album_permissions.blade.php index e893465..a9d89ae 100644 --- a/resources/views/themes/base/partials/album_permissions.blade.php +++ b/resources/views/themes/base/partials/album_permissions.blade.php @@ -12,12 +12,8 @@
Album Permissions
- @php ($permission = Theme::getPermission($all_permissions, 'album', 'list')) -
- -
+ @include(Theme::viewName('partials.permission_checkbox'), ['permission' => Theme::getPermission($all_permissions, 'album', 'list')]) + @include(Theme::viewName('partials.permission_checkbox'), ['permission' => Theme::getPermission($all_permissions, 'album', 'view')])
diff --git a/resources/views/themes/base/partials/permission_checkbox.blade.php b/resources/views/themes/base/partials/permission_checkbox.blade.php new file mode 100644 index 0000000..51a00fb --- /dev/null +++ b/resources/views/themes/base/partials/permission_checkbox.blade.php @@ -0,0 +1,5 @@ +
+ +
\ No newline at end of file