Skip to content

Commit

Permalink
Fix share button always visible (LycheeOrg#2346)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Apr 6, 2024
1 parent e5404bc commit d0fee60
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 44 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Sync extends Command
* @var string
*/
protected $signature =
'lychee:sync ' .
'lychee:sync ' .
'{dir* : directory to sync} ' . // string[]
'{--album_id= : Album ID to import to} ' . // string or null
'{--owner_id=1 : Owner ID of imported photos} ' . // string
Expand Down
14 changes: 8 additions & 6 deletions app/Livewire/DTO/AlbumRights.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AlbumRights implements Wireable

public function __construct(
public bool $can_edit = false,
public bool $can_share = false,
public bool $can_share_with_users = false,
public bool $can_download = false,
public bool $can_upload = false,
Expand All @@ -32,12 +33,13 @@ public function __construct(
public static function make(?AbstractAlbum $abstractAlbum): AlbumRights
{
return new self(
Gate::check(AlbumPolicy::CAN_EDIT, [AbstractAlbum::class, $abstractAlbum]),
Gate::check(AlbumPolicy::CAN_SHARE_WITH_USERS, [AbstractAlbum::class, $abstractAlbum]),
Gate::check(AlbumPolicy::CAN_DOWNLOAD, [AbstractAlbum::class, $abstractAlbum]),
Gate::check(AlbumPolicy::CAN_UPLOAD, [AbstractAlbum::class, $abstractAlbum]),
Gate::check(AlbumPolicy::CAN_DELETE, [AbstractAlbum::class, $abstractAlbum]),
Gate::check(AlbumPolicy::CAN_ACCESS_FULL_PHOTO, [AbstractAlbum::class, $abstractAlbum]),
can_edit: Gate::check(AlbumPolicy::CAN_EDIT, [AbstractAlbum::class, $abstractAlbum]),
can_share: Gate::check(AlbumPolicy::CAN_SHARE, [AbstractAlbum::class, $abstractAlbum]),
can_share_with_users: Gate::check(AlbumPolicy::CAN_SHARE_WITH_USERS, [AbstractAlbum::class, $abstractAlbum]),
can_download: Gate::check(AlbumPolicy::CAN_DOWNLOAD, [AbstractAlbum::class, $abstractAlbum]),
can_upload: Gate::check(AlbumPolicy::CAN_UPLOAD, [AbstractAlbum::class, $abstractAlbum]),
can_delete: Gate::check(AlbumPolicy::CAN_DELETE, [AbstractAlbum::class, $abstractAlbum]),
can_access_original: Gate::check(AlbumPolicy::CAN_ACCESS_FULL_PHOTO, [AbstractAlbum::class, $abstractAlbum]),
);
}
}
31 changes: 29 additions & 2 deletions app/Policies/AlbumPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class AlbumPolicy extends BasePolicy
public const CAN_EDIT = 'canEdit';
public const CAN_EDIT_ID = 'canEditById';
public const CAN_DELETE_ID = 'canDeleteById';
public const CAN_SHARE = 'canShare';
public const CAN_SHARE_WITH_USERS = 'canShareWithUsers';
public const CAN_IMPORT_FROM_SERVER = 'canImportFromServer';
public const CAN_SHARE_ID = 'canShareById';
Expand Down Expand Up @@ -399,11 +400,37 @@ public function canDeleteById(User $user, array $albumIDs): bool
return false;
}

/**
* Check if user can share selected album with to public.
*
* @param User $user
* @param ?AbstractAlbum $abstractAlbum
*
* @return bool
*/
public function canShare(?User $user, ?AbstractAlbum $abstractAlbum): bool
{
// should not be the case, but well.
if ($abstractAlbum === null) {
return true;
}

if (Configs::getValueAsBool('share_button_visible')) {
return true;
}

if (!$abstractAlbum instanceof BaseAlbum) {
return false;
}

return $this->isOwner($user, $abstractAlbum);
}

/**
* Check if user can share selected album with another user.
*
* @param User $user
* @param AbstractAlbum $abstractAlbum
* @param User $user
* @param AbstractAlbum|BaseAlbumImpl|null $abstractAlbum
*
* @return bool
*/
Expand Down
70 changes: 35 additions & 35 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,47 +51,47 @@ class AppServiceProvider extends ServiceProvider
* @var array<int,string>
*/
private array $ignore_log_SQL =
[
'information_schema', // Not interesting
'migrations',
[
'information_schema', // Not interesting
'migrations',

// We do not want infinite loops
'EXPLAIN',
// We do not want infinite loops
'EXPLAIN',

// Way too noisy
'configs',
];
// Way too noisy
'configs',
];

public array $singletons =
[
SymLinkFunctions::class => SymLinkFunctions::class,
Helpers::class => Helpers::class,
CheckUpdate::class => CheckUpdate::class,
AlbumFactory::class => AlbumFactory::class,
AlbumQueryPolicy::class => AlbumQueryPolicy::class,
PhotoQueryPolicy::class => PhotoQueryPolicy::class,

// Versioning
InstalledVersion::class => InstalledVersion::class,
GitHubVersion::class => GitHubVersion::class,
FileVersion::class => FileVersion::class,

// Json requests.
CommitsRequest::class => CommitsRequest::class,
UpdateRequest::class => UpdateRequest::class,

// JsonParsers
GitCommits::class => GitCommits::class,
GitTags::class => GitTags::class,
];
[
SymLinkFunctions::class => SymLinkFunctions::class,
Helpers::class => Helpers::class,
CheckUpdate::class => CheckUpdate::class,
AlbumFactory::class => AlbumFactory::class,
AlbumQueryPolicy::class => AlbumQueryPolicy::class,
PhotoQueryPolicy::class => PhotoQueryPolicy::class,

// Versioning
InstalledVersion::class => InstalledVersion::class,
GitHubVersion::class => GitHubVersion::class,
FileVersion::class => FileVersion::class,

// Json requests.
CommitsRequest::class => CommitsRequest::class,
UpdateRequest::class => UpdateRequest::class,

// JsonParsers
GitCommits::class => GitCommits::class,
GitTags::class => GitTags::class,
];

private array $livewireSynth =
[
AlbumSynth::class,
PhotoSynth::class,
SessionFlagsSynth::class,
AlbumFlagsSynth::class,
];
[
AlbumSynth::class,
PhotoSynth::class,
SessionFlagsSynth::class,
AlbumFlagsSynth::class,
];

/**
* Bootstrap any application services.
Expand Down
2 changes: 2 additions & 0 deletions resources/views/components/gallery/album/details.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
<x-icons.iconic class="my-0 w-4 h-4 mr-0 ml-0" icon="cloud-download" />
</a>
@endif
@if($this->rights->can_share)
<a class="flex-shrink-0 px-3 cursor-pointer" title={{ __('lychee.SHARE_ALBUM') }} x-on:click="albumFlags.isSharingLinksOpen = true">
<x-icons.iconic class="my-0 w-4 h-4 mr-0 ml-0" icon="share-ion" />
</a>
@endif
</div>
@if($this->AlbumFormatted->description !== null)
<div class="w-full px-7 my-4 text-justify text-text-main-200 prose prose-invert prose-sm" {{ $attributes }} >
Expand Down

0 comments on commit d0fee60

Please sign in to comment.