Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix smart album not having visibilty option #2470

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
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
45 changes: 43 additions & 2 deletions app/Livewire/Components/Forms/Album/Visibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Livewire\Components\Forms\Album;

use App\Actions\Album\SetProtectionPolicy;
use App\Contracts\Http\Requests\RequestAttribute;
use App\Contracts\Models\AbstractAlbum;
use App\DTO\AlbumProtectionPolicy;
use App\Factories\AlbumFactory;
Expand Down Expand Up @@ -31,19 +32,21 @@ class Visibility extends Component
public ?string $password = null; // ! wired

#[Locked] public string $albumID;
#[Locked] public bool $is_base_album;
/**
* This is the equivalent of the constructor for Livewire Components.
*
* @param BaseAlbum $album to update the visibility of
*
* @return void
*/
public function mount(BaseAlbum $album): void
public function mount(AbstractAlbum $album): void
{
Gate::authorize(AlbumPolicy::CAN_EDIT, [AbstractAlbum::class, $album]);

$this->albumID = $album->id;
$this->is_nsfw = $album->is_nsfw;
$this->is_base_album = $album instanceof BaseAlbum;
$this->is_nsfw = $this->is_base_album ? $album->is_nsfw : false;

/** @var AccessPermission $perm */
$perm = $album->public_permissions();
Expand Down Expand Up @@ -101,6 +104,20 @@ public function render(): View
* @return void
*/
public function updated()
{
if ($this->is_base_album) {
$this->updatedAsBaseAlbum();
} else {
$this->updatedAsSmartAlbum();
}
}

/**
* Update the policy for a base album.
*
* @return void
*/
private function updatedAsBaseAlbum()
{
$albumFactory = resolve(AlbumFactory::class);
$baseAlbum = $albumFactory->findBaseAlbumOrFail($this->albumID, false);
Expand Down Expand Up @@ -144,4 +161,28 @@ public function updated()
);
$this->notify(__('lychee.CHANGE_SUCCESS'));
}

/**
* Update policy for a smart album.
*
* @return void
*/
private function updatedAsSmartAlbum(): void
{
$albumFactory = resolve(AlbumFactory::class);
/** @var \App\SmartAlbums\BaseSmartAlbum */
$smartAlbum = $albumFactory->findAbstractAlbumOrFail($this->albumID, false);

$this->validate([
RequestAttribute::IS_PUBLIC_ATTRIBUTE => 'required|boolean',
]);

Gate::authorize(AlbumPolicy::CAN_EDIT, [AbstractAlbum::class, $smartAlbum]);

if ($this->is_public) {
$smartAlbum->setPublic();
} else {
$smartAlbum->setPrivate();
}
}
}
33 changes: 19 additions & 14 deletions resources/views/components/gallery/album/menu/menu.blade.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
@props(['album', 'rights', 'userCount' => 0])
<div class="w-full flex justify-center flex-wrap flex-row-reverse" x-cloak x-show="albumFlags.isDetailsOpen" x-collapse.duration.300ms >
@if($this->flags->is_base_album)
<ul class="
sm:mt-7 sm:px-7 mb-4
text-text-main-200 text-sm w-full xl:w-1/6 xl:px-9
max-xl:w-full max-xl:flex max-xl:justify-center
">
<x-gallery.album.menu.item tab='0' >{{ __('lychee.ABOUT_ALBUM') }}</x-gallery.album.menu.item>
@if ($rights->can_share_with_users === true && $userCount > 1 && ($album instanceof \App\Models\Album))
@if ($this->rights->can_share_with_users === true && $this->num_users > 1)
<x-gallery.album.menu.item tab='1' >{{ __('lychee.SHARE_ALBUM') }}</x-gallery.album.menu.item>
@endif
@if($album instanceof \App\Models\Album && $rights->can_delete === true)
@if($this->rights->can_delete === true)
<x-gallery.album.menu.item tab='2' >{{ __('lychee.MOVE_ALBUM') }}</x-gallery.album.menu.item>
@endif
@if($rights->can_delete === true)
@if($this->rights->can_delete === true)
<x-gallery.album.menu.danger tab='3' >{{ "DANGER ZONE" }}</x-gallery.album.menu.danger>
@endif
</ul>
@endif
<div class="w-full xl:w-5/6 flex justify-center flex-wrap mb-4 sm:mt-7 pl-7" x-cloak x-show="albumFlags.activeTab === 0">
<livewire:forms.album.properties :album="$album" />
<livewire:forms.album.visibility :album="$album" />
@if($this->flags->is_base_album)
<livewire:forms.album.properties :album="$this->album" />
@endif
<livewire:forms.album.visibility :album="$this->album" />
</div>
@if ($rights->can_share_with_users === true && $userCount > 1 && ($album instanceof \App\Models\Album))
@if($this->flags->is_base_album)
@if ($this->rights->can_share_with_users === true && $this->num_users > 1)
<div class="w-full xl:w-5/6 flex justify-center flex-wrap mb-4 sm:mt-7 pl-7" x-cloak x-show="albumFlags.activeTab === 1">
<livewire:forms.album.share-with :album="$album" />
<livewire:forms.album.share-with :album="$this->album" />
</div>
@endif
@if($album instanceof \App\Models\Album && $rights->can_delete === true)
@if($this->rights->can_delete === true)
<div class="w-full xl:w-5/6 flex justify-center flex-wrap mb-4 sm:mt-7 pl-7" x-cloak x-show="albumFlags.activeTab === 2">
<livewire:forms.album.move-panel :album="$album" />
<livewire:forms.album.move-panel :album="$this->album" />
</div>
@endif
@if($rights->can_delete === true)
@if($this->rights->can_delete === true)
<div class="w-full xl:w-5/6 flex justify-center flex-wrap mb-4 sm:mt-7 pl-7" x-cloak x-show="albumFlags.activeTab === 3">
{{-- We only display this menu if there are more than 1 user, it does not make sense otherwise --}}
@if ($userCount > 1)
<livewire:forms.album.transfer :album="$album" lazy />
@if ($this->num_users > 1)
<livewire:forms.album.transfer :album="$this->album" lazy />
@endif
<livewire:forms.album.delete-panel :album="$album" />
<livewire:forms.album.delete-panel :album="$this->album" />
</div>
@endif
@endif
</div>
4 changes: 4 additions & 0 deletions resources/views/livewire/forms/album/visibility.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<x-forms.toggle id="pp_dialog_public_check" wire:model.live="is_public" />
<p class="my-1.5">{{ __('lychee.ALBUM_PUBLIC_EXPL') }}</p>
</div>
@if($is_base_album)
<div @class(['relative h-12 my-4 pl-9 transition-color duration-300',
'text-text-main-400'=> !$is_public,
'text-text-main-200' => $is_public ])>
Expand Down Expand Up @@ -36,7 +37,9 @@
<x-forms.inputs.text wire:model.live.debounce.500ms='password' placeholder="{{ __('lychee.ALBUM_PASSWORD') }}" />
</div>
</div>
@endif
</form>
@if($is_base_album)
<hr class="block my-6 w-full border-t border-solid border-black/30">
<form>
<div class="relative h-12 my-4 transition-color duration-300">
Expand All @@ -45,4 +48,5 @@
<p class="my-1.5">{{ __('lychee.ALBUM_NSFW_EXPL') }}</p>
</div>
</form>
@endif
</div>
8 changes: 4 additions & 4 deletions resources/views/livewire/pages/gallery/album.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@entangle('sessionFlags.nsfwAlbumsVisible'),
@entangle('sessionFlags.is_fullscreen'),
@entangle('sessionFlags.are_photo_details_open'),
@js($rights),
@js($this->rights),
@js($album->id),
@js($this->albumIDs),
@js($this->photosResource),
Expand All @@ -19,7 +19,7 @@
<x-header.button class="flex flex-grow justify-end" href="{{ route('livewire-search', ['albumId' => $this->album->id]) }}" wire:navigate icon="magnifying-glass" />
@endif
<x-header.actions-menus />
@if ($rights->can_edit && $flags->is_base_album)
@if ($this->rights->can_edit)
<x-header.button x-on:click="toggleDetails" icon="chevron-top" fill="fill-primary-500" x-cloak
x-show="albumFlags.isDetailsOpen" />
<x-header.button x-on:click="toggleDetails" icon="chevron-bottom" x-cloak
Expand All @@ -34,8 +34,8 @@
<div id="lychee_view_content"
class="relative flex flex-wrap content-start w-full justify-start overflow-y-auto"
x-bind:class="isFullscreen ? 'h-[calc(100vh-3px)]' : 'h-[calc(100vh-56px)]'">
@if ($rights->can_edit && $flags->is_base_album)
<x-gallery.album.menu.menu :album="$this->album" :rights="$this->rights" :user-count="$this->num_users" />
@if ($this->rights->can_edit)
<x-gallery.album.menu.menu />
@endif
@if ($this->albumFormatted !== null && ($num_albums > 0 || $num_photos > 0))
<x-gallery.album.hero x-show="! albumFlags.isDetailsOpen" />
Expand Down
Loading