Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Sep 26, 2022
1 parent f8fa88b commit 16c9949
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 60 deletions.
11 changes: 9 additions & 2 deletions app/Actions/Album/SetProtectionPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@ class SetProtectionPolicy extends Action
*/
public function do(BaseAlbum $album, AlbumProtectionPolicy $protectionPolicy, bool $shallSetPassword, ?string $password): void
{
// Security attributes of the album itself independent of a particular user
// Note: The first one (`is_public`) will become implicit in the future when the following three attributes are
// move to a separate table for sharing albums with anonymous users
$album->is_public = $protectionPolicy->is_public;
$album->is_link_required = $protectionPolicy->is_link_required;
$album->is_nsfw = $protectionPolicy->is_nsfw;
$album->is_share_button_visible = $protectionPolicy->is_share_button_visible;
$album->grant_download = $protectionPolicy->grants_download;
$album->grant_access_full_photo = $protectionPolicy->grants_access_full_photo;

// (Future) permissions on an album-user relation.
// Note: For the time being these are still "globally" defined on the album for all users, but they will be
// moved to a separate table for sharing albums with users.
$album->grants_download = $protectionPolicy->grants_download;
$album->grants_access_full_photo = $protectionPolicy->grants_access_full_photo;

// Set password if provided
if ($shallSetPassword) {
Expand Down
4 changes: 2 additions & 2 deletions app/DTO/AlbumProtectionPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public static function ofAlbum(AbstractAlbum $abstractAlbum): AlbumProtectionPol
is_link_required: $abstractAlbum->is_link_required,
is_nsfw: $abstractAlbum->is_nsfw,
is_share_button_visible: $abstractAlbum->is_share_button_visible,
grants_access_full_photo: $abstractAlbum->grant_access_full_photo,
grants_download: $abstractAlbum->grant_download,
grants_access_full_photo: $abstractAlbum->grants_access_full_photo,
grants_download: $abstractAlbum->grants_download,
is_password_required: $abstractAlbum->password !== null && $abstractAlbum->password !== '',
);
}
Expand Down
6 changes: 3 additions & 3 deletions app/DTO/TopAlbums.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function __construct(
public function toArray(): array
{
return [
'smart_albums' => $this->smartAlbums->toArray(),
'tag_albums' => $this->tagAlbums->map(fn ($a) => self::toAlbumDTOArray($a))->toArray(),
'smart_albums' => $this->smart_albums->toArray(),
'tag_albums' => $this->tag_albums->map(fn ($a) => self::toAlbumDTOArray($a))->toArray(),
'albums' => $this->albums->map(fn ($a) => self::toAlbumDTOArray($a))->toArray(),
'shared_albums' => $this->sharedAlbums->map(fn ($a) => self::toAlbumDTOArray($a))->toArray(),
'shared_albums' => $this->shared_albums->map(fn ($a) => self::toAlbumDTOArray($a))->toArray(),
];
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Livewire/Sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function generateAlbumStructure()
$share = new \stdClass();
$share->title = Lang::get('ALBUM_SHARING');
$_public = $this->album->is_public ? Lang::get('ALBUM_SHR_YES') : Lang::get('ALBUM_SHR_NO');
$_hidden = $this->album->is_link_required ? Lang::get('ALBUM_SHR_YES') : Lang::get('ALBUM_SHR_NO');
$_hidden = $this->album->is_link_required ? Lang::get('ALBUM_SHR_YES') : Lang::get('ALBUM_SHR_NO'); // TODO : double check;
$_downloadable = $this->album->grants_download ? Lang::get('ALBUM_SHR_YES') : Lang::get('ALBUM_SHR_NO');
$_share_button_visible = $this->album->is_share_button_visible ? Lang::get('ALBUM_SHR_YES') : Lang::get('ALBUM_SHR_NO');
$_password = $this->album->has_password ? Lang::get('ALBUM_SHR_YES') : Lang::get('ALBUM_SHR_NO');
Expand Down
14 changes: 7 additions & 7 deletions app/Http/Requests/Album/SetAlbumProtectionPolicyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class SetAlbumProtectionPolicyRequest extends BaseApiRequest implements HasBaseA
public const IS_PUBLIC_ATTRIBUTE = 'is_public';
public const IS_LINK_REQUIRED_ATTRIBUTE = 'is_link_required';
public const IS_SHARE_BUTTON_VISIBLE_ATTRIBUTE = 'is_share_button_visible';
public const GRANT_DOWNLOAD_ATTRIBUTE = 'grant_download';
public const GRANT_ACCESS_FULL_PHOTO_ATTRIBUTE = 'grant_access_full_photo';
public const GRANTS_DOWNLOAD_ATTRIBUTE = 'grants_download';
public const GRANTS_ACCESS_FULL_PHOTO_ATTRIBUTE = 'grants_access_full_photo';

protected bool $isPasswordProvided;
protected AlbumProtectionPolicy $albumAccessSettings;
Expand All @@ -40,9 +40,9 @@ public function rules(): array
self::IS_PUBLIC_ATTRIBUTE => 'required|boolean',
self::IS_LINK_REQUIRED_ATTRIBUTE => 'required|boolean',
self::IS_NSFW_ATTRIBUTE => 'required|boolean',
self::GRANT_DOWNLOAD_ATTRIBUTE => 'required|boolean',
self::GRANTS_DOWNLOAD_ATTRIBUTE => 'required|boolean',
self::IS_SHARE_BUTTON_VISIBLE_ATTRIBUTE => 'required|boolean',
self::GRANT_ACCESS_FULL_PHOTO_ATTRIBUTE => 'required|boolean',
self::GRANTS_ACCESS_FULL_PHOTO_ATTRIBUTE => 'required|boolean',
];
}

Expand All @@ -57,10 +57,10 @@ protected function processValidatedValues(array $values, array $files): void
$this->albumAccessSettings = new AlbumProtectionPolicy(
is_public: static::toBoolean($values[self::IS_PUBLIC_ATTRIBUTE]),
is_link_required: static::toBoolean($values[self::IS_LINK_REQUIRED_ATTRIBUTE]),
is_share_button_visible: static::toBoolean($values[self::IS_SHARE_BUTTON_VISIBLE_ATTRIBUTE]),
is_nsfw: static::toBoolean($values[self::IS_NSFW_ATTRIBUTE]),
grants_download: static::toBoolean($values[self::GRANT_DOWNLOAD_ATTRIBUTE]),
grants_access_full_photo: static::toBoolean($values[self::GRANT_ACCESS_FULL_PHOTO_ATTRIBUTE]),
is_share_button_visible: static::toBoolean($values[self::IS_SHARE_BUTTON_VISIBLE_ATTRIBUTE]),
grants_access_full_photo: static::toBoolean($values[self::GRANTS_ACCESS_FULL_PHOTO_ATTRIBUTE]),
grants_download: static::toBoolean($values[self::GRANTS_DOWNLOAD_ATTRIBUTE]),
);
$this->isPasswordProvided = array_key_exists(HasPassword::PASSWORD_ATTRIBUTE, $values);
$this->password = $this->isPasswordProvided ? $values[HasPassword::PASSWORD_ATTRIBUTE] : null;
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Extensions/BaseAlbum.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @property Carbon $updated_at
* @property string|null $description
* @property bool $is_nsfw
* @property bool $grant_access_full_photo
* @property bool $grants_access_full_photo
* @property int $owner_id
* @property User $owner
* @property Collection $shared_with
Expand Down
2 changes: 1 addition & 1 deletion app/Policies/AlbumPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function canDownload(?User $user, ?AbstractAlbum $abstractAlbum): bool
return ($abstractAlbum instanceof BaseSmartAlbum && $user !== null) ||
($abstractAlbum instanceof BaseAlbum && $this->isOwner($user, $abstractAlbum) ||
($abstractAlbum instanceof BaseAlbum && $abstractAlbum->shared_with()->where('user_id', '=', $user?->id)->count() > 0 && $default) ||
$abstractAlbum->grant_download);
$abstractAlbum->grants_download);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/SmartAlbums/BaseSmartAlbum.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class BaseSmartAlbum implements AbstractAlbum
protected PhotoQueryPolicy $photoQueryPolicy;
protected string $id;
protected string $title;
protected bool $grant_download;
protected bool $grants_download;
protected bool $is_public;
protected bool $is_share_button_visible;
protected ?Thumb $thumb;
Expand All @@ -58,7 +58,7 @@ protected function __construct(string $id, string $title, bool $is_public, \Clos
$this->id = $id;
$this->title = $title;
$this->is_public = $is_public;
$this->grant_download = Configs::getValueAsBool('downloadable');
$this->grants_download = Configs::getValueAsBool('downloadable');
$this->is_share_button_visible = Configs::getValueAsBool('share_button_visible');
$this->thumb = null;
$this->smartPhotoCondition = $smartCondition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public function up()
$table->renameColumn('requires_link', 'is_link_required');
});
Schema::table('base_albums', function (Blueprint $table) {
$table->renameColumn('is_downloadable', 'grant_download');
$table->renameColumn('is_downloadable', 'grants_download');
});
Schema::table('base_albums', function (Blueprint $table) {
$table->renameColumn('grants_full_photo', 'grant_access_full_photo');
$table->renameColumn('grants_full_photo', 'grants_access_full_photo');
});
if (Schema::connection(null)->getConnection()->getDriverName() === 'sqlite') {
Schema::enableForeignKeyConstraints();
Expand All @@ -44,10 +44,10 @@ public function down()
$table->renameColumn('is_link_required', 'requires_link');
});
Schema::table('base_albums', function (Blueprint $table) {
$table->renameColumn('grant_download', 'is_downloadable');
$table->renameColumn('grants_download', 'is_downloadable');
});
Schema::table('base_albums', function (Blueprint $table) {
$table->renameColumn('grant_access_full_photo', 'grants_full_photo');
$table->renameColumn('grants_access_full_photo', 'grants_full_photo');
});
if (Schema::connection(null)->getConnection()->getDriverName() === 'sqlite') {
Schema::enableForeignKeyConstraints();
Expand Down
2 changes: 1 addition & 1 deletion public/Lychee-front
6 changes: 3 additions & 3 deletions public/dist/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ $(function () {
* @property {string} [owner_name] optional, only shown in authenticated mode
* @property {boolean} is_nsfw
* @property {{can_edit: boolean, can_share_with_users: boolean, can_download: boolean, can_upload: boolean, can_share_by_link: boolean}} rights
* @property {?{is_nsfw: boolean, is_public: boolean, is_link_required: boolean, is_share_button_visible: boolean, is_password_required: boolean, grant_access_full_photo: boolean, grant_download: boolean}} policies
* @property {?{is_nsfw: boolean, is_public: boolean, is_link_required: boolean, is_share_button_visible: boolean, is_password_required: boolean, grants_access_full_photo: boolean, grants_download: boolean}} policies
* @property {boolean} has_albums
* @property {boolean} has_password
* @property {?string} min_taken_at
Expand All @@ -1468,7 +1468,7 @@ $(function () {
* @property {string} [owner_name] optional, only shown in authenticated mode
* @property {boolean} is_nsfw
* @property {{can_edit: boolean, can_share_with_users: boolean, can_download: boolean, can_upload: boolean, can_share_by_link: boolean}} rights
* @property {?{is_nsfw: boolean, is_public: boolean, is_link_required: boolean, is_share_button_visible: boolean, is_password_required: boolean, grant_access_full_photo: boolean, grant_download: boolean}} policies
* @property {?{is_nsfw: boolean, is_public: boolean, is_link_required: boolean, is_share_button_visible: boolean, is_password_required: boolean, grants_access_full_photo: boolean, grants_download: boolean}} policies
* @property {?string} min_taken_at
* @property {?string} max_taken_at
* @property {?SortingCriterion} sorting
Expand All @@ -1483,7 +1483,7 @@ $(function () {
* @property {Photo[]} [photos]
* @property {?Thumb} thumb
* @property {{can_edit: boolean, can_share: boolean, can_download: boolean, can_upload: boolean, can_share_by_link: boolean}} rights
* @property {?{is_nsfw: boolean, is_public: boolean, is_link_required: boolean, is_share_button_visible: boolean, is_password_required: boolean, grant_access_full_photo: boolean, grant_download: boolean}} policies
* @property {?{is_nsfw: boolean, is_public: boolean, is_link_required: boolean, is_share_button_visible: boolean, is_password_required: boolean, grants_access_full_photo: boolean, grants_download: boolean}} policies
*/

/**
Expand Down
Loading

0 comments on commit 16c9949

Please sign in to comment.