diff --git a/app/Actions/Statistics/Spaces.php b/app/Actions/Statistics/Spaces.php index c812443b5cc..82df2af7cab 100644 --- a/app/Actions/Statistics/Spaces.php +++ b/app/Actions/Statistics/Spaces.php @@ -146,7 +146,18 @@ public function getSpacePerSizeVariantTypePerAlbum(string $album_id): Collection public function getSpacePerAlbum(?string $album_id = null, ?int $owner_id = null) { $query = DB::table('albums') - ->when($album_id !== null, fn ($query) => $query->where('albums.id', '=', $album_id)) + ->when($album_id !== null, + fn ($query) => $query + ->joinSub( + query: DB::table('albums', 'parent')->select('parent.id', 'parent._lft', 'parent._rgt'), + as: 'parent', + first: function (JoinClause $join) { + $join->on('albums._lft', '>=', 'parent._lft') + ->on('albums._rgt', '<=', 'parent._rgt'); + } + ) + ->where('parent.id', '=', $album_id) + ) ->when($owner_id !== null, fn ($query) => $query->joinSub( query: DB::table('base_albums')->select(['base_albums.id', 'base_albums.owner_id']), as: 'base_albums', @@ -258,7 +269,18 @@ public function getTotalSpacePerAlbum(?string $album_id = null, ?int $owner_id = public function getPhotoCountPerAlbum(?string $album_id = null, ?int $owner_id = null) { $query = DB::table('albums') - ->when($album_id !== null, fn ($query) => $query->where('albums.id', '=', $album_id)) + ->when($album_id !== null, + fn ($query) => $query + ->joinSub( + query: DB::table('albums', 'parent')->select('parent.id', 'parent._lft', 'parent._rgt'), + as: 'parent', + first: function (JoinClause $join) { + $join->on('albums._lft', '>=', 'parent._lft') + ->on('albums._rgt', '<=', 'parent._rgt'); + } + ) + ->where('parent.id', '=', $album_id) + ) ->joinSub( query: DB::table('base_albums')->select(['base_albums.id', 'base_albums.owner_id', 'base_albums.title', 'base_albums.is_nsfw']), as: 'base_albums', diff --git a/app/Http/Requests/Statistics/SpacePerAlbumRequest.php b/app/Http/Requests/Statistics/SpacePerAlbumRequest.php index cd583a4d493..b24802f9a79 100644 --- a/app/Http/Requests/Statistics/SpacePerAlbumRequest.php +++ b/app/Http/Requests/Statistics/SpacePerAlbumRequest.php @@ -30,7 +30,7 @@ public function authorize(): bool return Gate::check(SettingsPolicy::CAN_SEE_STATISTICS, [Configs::class]); } - return Gate::check(AlbumPolicy::CAN_ACCESS, [AbstractAlbum::class, $this->album]); + return Auth::check() && Gate::check(AlbumPolicy::CAN_ACCESS, [AbstractAlbum::class, $this->album]); } /** diff --git a/app/Http/Requests/Statistics/SpaceSizeVariantRequest.php b/app/Http/Requests/Statistics/SpaceSizeVariantRequest.php index b85c18d3ac1..30918f4d6fc 100644 --- a/app/Http/Requests/Statistics/SpaceSizeVariantRequest.php +++ b/app/Http/Requests/Statistics/SpaceSizeVariantRequest.php @@ -30,7 +30,7 @@ public function authorize(): bool return Gate::check(UserPolicy::CAN_EDIT, [User::class]); } - return Gate::check(AlbumPolicy::CAN_ACCESS, [AbstractAlbum::class, $this->album]); + return Auth::check() && Gate::check(AlbumPolicy::CAN_ACCESS, [AbstractAlbum::class, $this->album]); } /** diff --git a/resources/js/components/drawers/AlbumStatistics.vue b/resources/js/components/drawers/AlbumStatistics.vue index f567852a51d..0105a31848b 100644 --- a/resources/js/components/drawers/AlbumStatistics.vue +++ b/resources/js/components/drawers/AlbumStatistics.vue @@ -1,91 +1,82 @@ diff --git a/resources/js/components/gallery/AlbumHero.vue b/resources/js/components/gallery/AlbumHero.vue index 0238a5e8faa..b69a2b57ac3 100644 --- a/resources/js/components/gallery/AlbumHero.vue +++ b/resources/js/components/gallery/AlbumHero.vue @@ -46,14 +46,14 @@ @@ -70,12 +70,15 @@