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

Adding copyright to albums #1838 #1880

Merged
merged 17 commits into from
Apr 28, 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
11 changes: 11 additions & 0 deletions app/Contracts/Http/Requests/HasCopyright.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Contracts\Http\Requests;

interface HasCopyright
{
/**
* @return string|null
*/
public function copyright(): ?string;
}
2 changes: 2 additions & 0 deletions app/Contracts/Http/Requests/RequestAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,7 @@ class RequestAttribute
public const RESYNC_METADATA_ATTRIBUTE = 'resync_metadata';

public const FILE_LAST_MODIFIED_TIME = 'fileLastModifiedTime';

public const COPYRIGHT_ATTRIBUTE = 'copyright';
public const URLS_ATTRIBUTE = 'urls';
}
16 changes: 16 additions & 0 deletions app/Http/Controllers/AlbumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use App\Http\Requests\Album\GetAlbumRequest;
use App\Http\Requests\Album\MergeAlbumsRequest;
use App\Http\Requests\Album\MoveAlbumsRequest;
use App\Http\Requests\Album\SetAlbumCopyrightRequest;
use App\Http\Requests\Album\SetAlbumCoverRequest;
use App\Http\Requests\Album\SetAlbumDescriptionRequest;
use App\Http\Requests\Album\SetAlbumHeaderRequest;
Expand Down Expand Up @@ -187,6 +188,21 @@ public function setDescription(SetAlbumDescriptionRequest $request): void
$request->album()->save();
}

/**
* Change the copyright of the album.
*
* @param SetAlbumCopyrightRequest $request
*
* @return void
*
* @throws ModelDBException
*/
public function setCopyright(SetAlbumCopyrightRequest $request): void
{
$request->album()->copyright = $request->copyright();
ildyria marked this conversation as resolved.
Show resolved Hide resolved
$request->album()->save();
}

/**
* Change show tags of the tag album.
*
Expand Down
38 changes: 38 additions & 0 deletions app/Http/Requests/Album/SetAlbumCopyrightRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Http\Requests\Album;

use App\Contracts\Http\Requests\HasBaseAlbum;
use App\Contracts\Http\Requests\HasCopyright;
use App\Contracts\Http\Requests\RequestAttribute;
use App\Http\Requests\BaseApiRequest;
use App\Http\Requests\Traits\Authorize\AuthorizeCanEditAlbumTrait;
use App\Http\Requests\Traits\HasBaseAlbumTrait;
use App\Http\Requests\Traits\HasCopyrightTrait;
use App\Http\RuleSets\Album\SetAlbumCopyrightRuleSet;

class SetAlbumCopyrightRequest extends BaseApiRequest implements HasBaseAlbum, HasCopyright
{
use HasBaseAlbumTrait;
use HasCopyrightTrait;
use AuthorizeCanEditAlbumTrait;

/**
* {@inheritDoc}
*/
public function rules(): array
{
return SetAlbumCopyrightRuleSet::rules();
}

/**
* {@inheritDoc}
*/
protected function processValidatedValues(array $values, array $files): void
{
$this->album = $this->albumFactory->findBaseAlbumOrFail(
$values[RequestAttribute::ALBUM_ID_ATTRIBUTE], false
);
$this->copyright = $values[RequestAttribute::COPYRIGHT_ATTRIBUTE];
}
}
16 changes: 16 additions & 0 deletions app/Http/Requests/Traits/HasCopyrightTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Http\Requests\Traits;

trait HasCopyrightTrait
{
protected ?string $copyright = null;

/**
* @return string|null
*/
public function copyright(): ?string
{
return $this->copyright;
}
}
1 change: 1 addition & 0 deletions app/Http/Resources/Models/AlbumResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function toArray($request)
'id' => $this->resource->id,
'title' => $this->resource->title,
'owner_name' => $this->when(Auth::check(), $this->resource->owner->name),
'copyright' => $this->resource->copyright,

// attributes
'description' => $this->resource->description,
Expand Down
25 changes: 25 additions & 0 deletions app/Http/RuleSets/Album/SetAlbumCopyrightRuleSet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\RuleSets\Album;

use App\Contracts\Http\Requests\RequestAttribute;
use App\Contracts\Http\RuleSet;
use App\Rules\CopyrightRule;
use App\Rules\RandomIDRule;

/**
* Rules applied when updating the copyright of an album.
*/
class SetAlbumCopyrightRuleSet implements RuleSet
{
/**
* {@inheritDoc}
*/
public static function rules(): array
{
return [
RequestAttribute::ALBUM_ID_ATTRIBUTE => ['required', new RandomIDRule(false)],
RequestAttribute::COPYRIGHT_ATTRIBUTE => ['required', new CopyrightRule()],
];
}
}
9 changes: 9 additions & 0 deletions app/Livewire/Components/Forms/Album/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use App\Models\Album as ModelsAlbum;
use App\Models\Extensions\BaseAlbum;
use App\Policies\AlbumPolicy;
use App\Rules\CopyrightRule;
use App\Rules\TitleRule;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
Expand All @@ -44,6 +45,7 @@ class Properties extends Component
public string $album_sorting_order = ''; // ! wired
public string $album_aspect_ratio = ''; // ! wired
public string $license = 'none'; // ! wired
public string $copyright = ''; // ! wired

/**
* This is the equivalent of the constructor for Livewire Components.
Expand All @@ -63,6 +65,7 @@ public function mount(BaseAlbum $album): void
$this->description = $album->description ?? '';
$this->photo_sorting_column = $album->photo_sorting?->column->value ?? '';
$this->photo_sorting_order = $album->photo_sorting?->order->value ?? '';
$this->copyright = $album->copyright ?? '';
if ($this->is_model_album) {
/** @var ModelsAlbum $album */
$this->license = $album->license->value;
Expand Down Expand Up @@ -94,6 +97,7 @@ public function submit(AlbumFactory $albumFactory): void
...SetPhotoSortingRuleSet::rules(),
...SetAlbumSortingRuleSet::rules(),
RequestAttribute::ALBUM_ASPECT_RATIO_ATTRIBUTE => ['present', 'nullable', new Enum(AspectRatioType::class)],
RequestAttribute::COPYRIGHT_ATTRIBUTE => ['present', 'nullable', new CopyrightRule()],
];

if (!$this->areValid($rules)) {
Expand All @@ -106,12 +110,17 @@ public function submit(AlbumFactory $albumFactory): void
$baseAlbum->title = $this->title;
$baseAlbum->description = $this->description;

$this->copyright = trim($this->copyright);

// Not super pretty but whatever.
$column = ColumnSortingPhotoType::tryFrom($this->photo_sorting_column);
$order = OrderSortingType::tryFrom($this->photo_sorting_order);
$photoSortingCriterion = $column === null ? null : new PhotoSortingCriterion($column->toColumnSortingType(), $order);
$baseAlbum->photo_sorting = $photoSortingCriterion;

// If left empty, we set to null
$baseAlbum->copyright = $this->copyright === '' ? null : $this->copyright;

if ($this->is_model_album) {
/** @var ModelsAlbum $baseAlbum */
$baseAlbum->license = LicenseType::from($this->license);
Expand Down
2 changes: 2 additions & 0 deletions app/Livewire/DTO/AlbumFormatted.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class AlbumFormatted
public bool $can_download;
public ?string $created_at = null;
public ?string $description = null;
public ?string $copyright = null;

public function __construct(AbstractAlbum $album, ?string $url)
{
Expand All @@ -33,6 +34,7 @@ public function __construct(AbstractAlbum $album, ?string $url)
$this->max_taken_at = $album->max_taken_at?->format($min_max_date_format);
$this->created_at = $album->created_at->format($create_date_format);
$this->description = trim($album->description ?? '');
$this->copyright = $album->copyright;
}
if ($album instanceof Album) {
$this->num_children = $album->num_children;
Expand Down
2 changes: 2 additions & 0 deletions app/Models/BaseAlbumImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
* @property string|null $sorting_order
* @property Collection<int,AccessPermission> $access_permissions
* @property int|null $access_permissions_count
* @property string|null $copyright
*
* @method static BaseAlbumImplBuilder|BaseAlbumImpl addSelect($column)
* @method static BaseAlbumImplBuilder|BaseAlbumImpl join(string $table, string $first, string $operator = null, string $second = null, string $type = 'inner', string $where = false)
Expand Down Expand Up @@ -173,6 +174,7 @@ class BaseAlbumImpl extends Model implements HasRandomID
'owner_id' => 0,
'sorting_col' => null,
'sorting_order' => null,
'copyright' => null,
// Special visibility attributes
'is_nsfw' => false,
];
Expand Down
1 change: 1 addition & 0 deletions app/Models/Extensions/BaseAlbum.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @property Carbon $updated_at
* @property string|null $description
* @property bool $is_nsfw
* @property string|null $copyright
* @property int $owner_id
* @property User $owner
* @property Collection<int,AccessPermission> $access_permissions
Expand Down
11 changes: 11 additions & 0 deletions app/Rules/CopyrightRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Rules;

class CopyrightRule extends StringRule
{
public function __construct()
{
parent::__construct(true, 300);
}
}
30 changes: 30 additions & 0 deletions database/migrations/2024_04_28_172241_add_album_copyright.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
public const TABLE = 'base_albums';
public const COLUMN = 'copyright';

/**
* Run the migrations.
*/
public function up(): void
{
Schema::table(self::TABLE, function (Blueprint $table) {
$table->string(self::COLUMN, 300)->nullable()->default(null);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table(self::TABLE, function (Blueprint $table) {
$table->dropColumn(self::COLUMN);
});
}
};
2 changes: 2 additions & 0 deletions lang/cz/lychee.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
'ALBUM_ABOUT' => 'O albu',
'ALBUM_BASICS' => 'Základní informace',
'ALBUM_TITLE' => 'Název',
'ALBUM_COPYRIGHT' => 'Copyright',
'ALBUM_SET_COPYRIGHT' => 'Set copyright',
'ALBUM_NEW_TITLE' => 'Zadat nový název alba:',
'ALBUMS_NEW_TITLE' => 'Zadat nový název pro %d vybraná alba:',
'ALBUM_SET_TITLE' => 'Uložit název',
Expand Down
2 changes: 2 additions & 0 deletions lang/de/lychee.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
'ALBUM_ABOUT' => 'Über',
'ALBUM_BASICS' => 'Grundlegende Informationen',
'ALBUM_TITLE' => 'Titel',
'ALBUM_COPYRIGHT' => 'Copyright',
'ALBUM_SET_COPYRIGHT' => 'Set copyright',
'ALBUM_NEW_TITLE' => 'Geben Sie einen neuen Titel für dieses Album ein:',
'ALBUMS_NEW_TITLE' => 'Geben Sie einen Titel für alle %d ausgewählten Alben ein:',
'ALBUM_SET_TITLE' => 'Titel speichern',
Expand Down
2 changes: 2 additions & 0 deletions lang/el/lychee.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
'ALBUM_ABOUT' => 'Περί',
'ALBUM_BASICS' => 'Βασικές Πληροφορίες',
'ALBUM_TITLE' => 'Τίτλος',
'ALBUM_COPYRIGHT' => 'Πνευματική ιδιοκτησία',
'ALBUM_SET_COPYRIGHT' => 'Δήλωσε πνευματική ιδιοκτησία',
'ALBUM_NEW_TITLE' => 'Εισάγετε έναν νέο τίτλο για αυτό το Λεύκωμα:',
'ALBUMS_NEW_TITLE' => 'Εισάγετε νέο τίτλο για όλα %d τα επιλεγμένα λευκώματα:',
'ALBUM_SET_TITLE' => 'Ορίστε Τίτλο',
Expand Down
2 changes: 2 additions & 0 deletions lang/en/lychee.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
'ALBUM_ABOUT' => 'About',
'ALBUM_BASICS' => 'Basics',
'ALBUM_TITLE' => 'Title',
'ALBUM_COPYRIGHT' => 'Copyright',
'ALBUM_SET_COPYRIGHT' => 'Set copyright',
'ALBUM_NEW_TITLE' => 'Enter a new title for this album:',
'ALBUMS_NEW_TITLE' => 'Enter a title for all %d selected albums:',
'ALBUM_SET_TITLE' => 'Set Title',
Expand Down
2 changes: 2 additions & 0 deletions lang/es/lychee.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
'ALBUM_ABOUT' => 'Acerca de',
'ALBUM_BASICS' => 'Básico',
'ALBUM_TITLE' => 'Título',
'ALBUM_COPYRIGHT' => 'Copyright',
'ALBUM_SET_COPYRIGHT' => 'Set copyright',
'ALBUM_NEW_TITLE' => 'Ingrese un nuevo título para este álbum:',
'ALBUMS_NEW_TITLE' => 'Ingrese un título para todos %d álbumes seleccionados:',
'ALBUM_SET_TITLE' => 'Establecer Título',
Expand Down
2 changes: 2 additions & 0 deletions lang/fr/lychee.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
'ALBUM_ABOUT' => 'À propos',
'ALBUM_BASICS' => 'Informations de base',
'ALBUM_TITLE' => 'Titre',
'ALBUM_COPYRIGHT' => 'Droits d’auteur',
'ALBUM_SET_COPYRIGHT' => 'Définir les droits d’auteur',
'ALBUM_NEW_TITLE' => 'Entrez un nouveau titre pour cet album :',
'ALBUMS_NEW_TITLE' => 'Entrez un titre pour les %d albums sélectionnés :',
'ALBUM_SET_TITLE' => 'Enregistrer le titre',
Expand Down
2 changes: 2 additions & 0 deletions lang/hu/lychee.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
'ALBUM_ABOUT' => 'Névjegy',
'ALBUM_BASICS' => 'Alapok',
'ALBUM_TITLE' => 'Cím',
'ALBUM_COPYRIGHT' => 'Copyright',
'ALBUM_SET_COPYRIGHT' => 'Set copyright',
'ALBUM_NEW_TITLE' => 'Adjon meg egy új címet ennek az albumnak:',
'ALBUMS_NEW_TITLE' => 'Adjon meg címet az összes %d kiválasztott albumnak:',
'ALBUM_SET_TITLE' => 'Cím beállítása',
Expand Down
2 changes: 2 additions & 0 deletions lang/it/lychee.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
'ALBUM_ABOUT' => 'Informazioni',
'ALBUM_BASICS' => 'Base',
'ALBUM_TITLE' => 'Titolo',
'ALBUM_COPYRIGHT' => 'Copyright',
'ALBUM_SET_COPYRIGHT' => 'Set copyright',
'ALBUM_NEW_TITLE' => 'Inserire un nuovo titolo per questo album:',
'ALBUMS_NEW_TITLE' => 'Inserire un nuovo titolo per %d gli album selezionati:',
'ALBUM_SET_TITLE' => 'Imposta Titolo',
Expand Down
2 changes: 2 additions & 0 deletions lang/nl/lychee.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
'ALBUM_ABOUT' => 'Over',
'ALBUM_BASICS' => 'Basics',
'ALBUM_TITLE' => 'Titel',
'ALBUM_COPYRIGHT' => 'Copyright',
'ALBUM_SET_COPYRIGHT' => 'Set copyright',
'ALBUM_NEW_TITLE' => 'Geef dit album een nieuwe titel:',
'ALBUMS_NEW_TITLE' => 'Geef alle geselecteerde %d albums een nieuwe titel:',
'ALBUM_SET_TITLE' => 'Sla Titel op',
Expand Down
2 changes: 2 additions & 0 deletions lang/no/lychee.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
'ALBUM_ABOUT' => 'Om',
'ALBUM_BASICS' => 'Grunnleggende',
'ALBUM_TITLE' => 'Tittel',
'ALBUM_COPYRIGHT' => 'Copyright',
'ALBUM_SET_COPYRIGHT' => 'Set copyright',
'ALBUM_NEW_TITLE' => 'Legg inn en ny tittel for Albumet:',
'ALBUMS_NEW_TITLE' => 'Legg inn en ny tittel for %d valgte album:',
'ALBUM_SET_TITLE' => 'Lagre Tittel',
Expand Down
2 changes: 2 additions & 0 deletions lang/pl/lychee.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
'ALBUM_ABOUT' => 'Informacje o albumie',
'ALBUM_BASICS' => 'Informacje podstawowe',
'ALBUM_TITLE' => 'Tytuł',
'ALBUM_COPYRIGHT' => 'Copyright',
'ALBUM_SET_COPYRIGHT' => 'Set copyright',
'ALBUM_NEW_TITLE' => 'Edytuj tytuł albumu:',
'ALBUMS_NEW_TITLE' => 'Wpisz tytuł dla %d wybranych albumów:',
'ALBUM_SET_TITLE' => 'Zapisz',
Expand Down
2 changes: 2 additions & 0 deletions lang/pt/lychee.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
'ALBUM_ABOUT' => 'Acerca de',
'ALBUM_BASICS' => 'Básicos',
'ALBUM_TITLE' => 'Título',
'ALBUM_COPYRIGHT' => 'Copyright',
'ALBUM_SET_COPYRIGHT' => 'Set copyright',
'ALBUM_NEW_TITLE' => 'Inserir novo título para este álbum:',
'ALBUMS_NEW_TITLE' => 'Inserir um título para todos %d álbums selecionados:',
'ALBUM_SET_TITLE' => 'Escolher Título',
Expand Down
2 changes: 2 additions & 0 deletions lang/ru/lychee.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
'ALBUM_ABOUT' => 'Об альбоме',
'ALBUM_BASICS' => 'Основное',
'ALBUM_TITLE' => 'Заголовок',
'ALBUM_COPYRIGHT' => 'Copyright',
'ALBUM_SET_COPYRIGHT' => 'Set copyright',
'ALBUM_NEW_TITLE' => 'Новый заголовок альбома:',
'ALBUMS_NEW_TITLE' => 'Введите заголовок для всех %d выбранных альбомов:',
'ALBUM_SET_TITLE' => 'Сохранить заголовок',
Expand Down
2 changes: 2 additions & 0 deletions lang/sk/lychee.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
'ALBUM_ABOUT' => 'O albume',
'ALBUM_BASICS' => 'Základné informácie',
'ALBUM_TITLE' => 'Názov',
'ALBUM_COPYRIGHT' => 'Copyright',
'ALBUM_SET_COPYRIGHT' => 'Set copyright',
'ALBUM_NEW_TITLE' => 'Zadajte nový názov pre tento album:',
'ALBUMS_NEW_TITLE' => 'Zadajte názov pre všetky %d vybrané albumy:',
'ALBUM_SET_TITLE' => 'Názov uložiť',
Expand Down
Loading
Loading