Skip to content

Commit

Permalink
Stacked 15: Show owner instead of just Shared albums (#2574)
Browse files Browse the repository at this point in the history
* Stacked 16: Composer update + fixing phpstan / Ts checker (#2580)
* Stacked 17: Various fixes. (#2581)

---------

Co-authored-by: Martin Stone <1611702+d7415@users.noreply.github.com>
  • Loading branch information
ildyria and d7415 authored Oct 25, 2024
1 parent 12b3e4d commit 8c3d8a3
Show file tree
Hide file tree
Showing 91 changed files with 791 additions and 595 deletions.
8 changes: 4 additions & 4 deletions app/Actions/Album/ListAlbums.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public function do(?int $lft, ?int $rgt, ?string $parent_id): array
$query = (new SortingDecorator($unfiltered))
->orderBy($sorting->column, $sorting->order);

/** @var NsCollection<int,string,Album> $albums */
/** @var NsCollection<Album> $albums */
$albums = $query->get();
/** @var NsCollection<int,string,Album> $tree */
/** @var NsCollection<Album> $tree */
$tree = $albums->toTree(null);

$flat_tree = $this->flatten($tree);
Expand All @@ -66,8 +66,8 @@ public function do(?int $lft, ?int $rgt, ?string $parent_id): array
/**
* Flatten the tree and create bread crumb paths.
*
* @param NsCollection<int,string,Album>|Collection<int,Album> $collection
* @param string $prefix
* @param NsCollection<Album>|Collection<int,Album> $collection
* @param string $prefix
*
* @return TAlbumSaved[]
*/
Expand Down
1 change: 1 addition & 0 deletions app/Actions/Album/PositionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function get(AbstractAlbum $album, bool $includeSubAlbums = false): Posit
$album->all_photos() :
$album->photos();

// @phpstan-ignore-next-line
$photoRelation
->with([
'album' => function (BelongsTo $b) {
Expand Down
3 changes: 2 additions & 1 deletion app/Contracts/Models/AbstractAlbum.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\Photo;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;

/**
Expand All @@ -31,7 +32,7 @@
interface AbstractAlbum
{
/**
* @return Relation<Photo>|Builder<Photo>
* @return Relation<Photo,AbstractAlbum&Model,Collection<int,Photo>>|Builder<Photo>
*/
public function photos(): Relation|Builder;

Expand Down
16 changes: 8 additions & 8 deletions app/Eloquent/FixedQueryBuilderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace App\Eloquent;

use App\Exceptions\Internal\QueryBuilderException;
use Illuminate\Contracts\Database\Query\Expression;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Query\Builder as BaseBuilder;
use Illuminate\Database\Query\Expression;

/**
* Fixed Eloquent query builder.
Expand Down Expand Up @@ -50,10 +50,10 @@ trait FixedQueryBuilderTrait
/**
* Add a basic where clause to the query.
*
* @param \Closure|string|array<string>|Expression $column
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @param \Closure|string|array<int|string,mixed>|Expression $column
* @param mixed $operator
* @param mixed $value
* @param string $boolean
*
* @return $this
*
Expand Down Expand Up @@ -268,9 +268,9 @@ public function addSelect($column): static
/**
* Add an "or where" clause to the query.
*
* @param \Closure|array<string>|string|Expression $column
* @param mixed $operator
* @param mixed $value
* @param \Closure|string|array<int|string,mixed>|Expression $column
* @param mixed $operator
* @param mixed $value
*
* @return $this
*
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Admin/Maintenance/Model/Album.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* This is necessary to fix the tree of the album model.
* We do not want to have to deal with the relationships here.
*
* @implements Node<string,Album>
* @implements Node<Album>
*/
class Album extends Model implements Node
{
/** @phpstan-use NodeTrait<string,Album> */
/** @phpstan-use NodeTrait<Album> */
use NodeTrait;
public $timestamps = false;
}
2 changes: 2 additions & 0 deletions app/Http/Resources/Models/ThumbAlbumResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ThumbAlbumResource extends Data
private ?string $min_taken_at = null;
private ?string $max_taken_at = null;
public ?string $formatted_min_max = null;
public ?string $owner = null;

public AlbumRightsResource $rights;

Expand All @@ -60,6 +61,7 @@ public function __construct(AbstractAlbum $data)
$this->created_at = $data->created_at->format($date_format);
$policy = AlbumProtectionPolicy::ofBaseAlbum($data);
$this->description = Str::limit($data->description, 100);
$this->owner = $data->owner->username;
}

if ($data instanceof Album) {
Expand Down
8 changes: 4 additions & 4 deletions app/Legacy/V1/Actions/Albums/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public function get(): AlbumForestResource
}
$query->orderBy($this->sorting->column, $this->sorting->order);

/** @var NsCollection<int,string,Album> $albums */
/** @var NsCollection<Album> $albums */
$albums = $query->get();
/** @var ?NsCollection<int,string,Album> $sharedAlbums */
/** @var ?NsCollection<Album> $sharedAlbums */
$sharedAlbums = null;
$userID = Auth::id();
if ($userID !== null) {
Expand All @@ -75,8 +75,8 @@ public function get(): AlbumForestResource
// (sub)-tree and then `toTree` will return garbage as it does
// not find connected paths within `$albums` or `$sharedAlbums`,
// resp.
/** @var NsCollection<int,string,Album> $albums */
/** @var ?NsCollection<int,string,Album> $sharedAlbums */
/** @var NsCollection<Album> $albums */
/** @var ?NsCollection<Album> $sharedAlbums */
list($albums, $sharedAlbums) = $albums->partition(fn (Album $album) => $album->owner_id === $userID);
}

Expand Down
15 changes: 14 additions & 1 deletion app/Legacy/V1/Controllers/Administration/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use App\SmartAlbums\BaseSmartAlbum;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;

Expand Down Expand Up @@ -403,6 +404,9 @@ public function getAll(GetSetAllSettingsRequest $request): Collection
return Configs::query()
->orderBy('cat')
->orderBy('id')
// Only display settings which are not part of SE
->where('level', '=', 0)
->whereNotIn('key', ['email'])
->get();
}

Expand All @@ -419,7 +423,16 @@ public function getAll(GetSetAllSettingsRequest $request): Collection
public function saveAll(GetSetAllSettingsRequest $request): void
{
$lastException = null;
foreach ($request->except(['_token', 'function', '/api/Settings::saveAll']) as $key => $value) {
// Select all the SE settings.
$except = DB::table('configs')
->select('key')
->where('level', '=', '1')
->pluck('key')
// Concat bunch of things coming from the POST request.
->concat(['_token', 'function', '/api/Settings::saveAll'])
// Convert to array.
->all();
foreach ($request->except($except) as $key => $value) {
$value ??= '';
try {
Configs::set($key, $value);
Expand Down
4 changes: 2 additions & 2 deletions app/Models/AccessPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function newEloquentBuilder($query): AccessPermissionBuilder
/**
* Returns the relationship between an AccessPermission and its associated album.
*
* @return BelongsTo<BaseAlbumImpl,AccessPermission>
* @return BelongsTo<BaseAlbumImpl,$this>
*/
public function album(): BelongsTo
{
Expand All @@ -114,7 +114,7 @@ public function album(): BelongsTo
/**
* Returns the relationship between an AccessPermission and its applied User.
*
* @return BelongsTo<User,AccessPermission>
* @return BelongsTo<User,$this>
*/
public function user(): BelongsTo
{
Expand Down
14 changes: 7 additions & 7 deletions app/Models/Album.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@
*
* // * @mixin \Eloquent
*
* @implements Node<string,Album>
* @implements Node<Album>
*/
class Album extends BaseAlbum implements Node
{
/** @phpstan-use NodeTrait<string,Album> */
/** @phpstan-use NodeTrait<Album> */
use NodeTrait;
use ToArrayThrowsNotImplemented;
/** @phpstan-use HasFactory<\Database\Factories\AlbumFactory> */
Expand Down Expand Up @@ -182,7 +182,7 @@ class Album extends BaseAlbum implements Node
*
* @return HasManyChildPhotos
*/
public function photos(): HasManyChildPhotos
public function photos(): HasManyChildPhotos // @phpstan-ignore-line
{
return new HasManyChildPhotos($this);
}
Expand Down Expand Up @@ -216,14 +216,14 @@ public function children(): HasManyChildAlbums
/**
* Get query for descendants of the node.
*
* @return DescendantsRelation<string,Album>
* @return DescendantsRelation<Album>
*
* @throws QueryBuilderException
*/
public function descendants(): DescendantsRelation
{
try {
/** @var DescendantsRelation<string,Album> */
/** @var DescendantsRelation<Album> */
return new DescendantsRelation($this->newQuery(), $this);
// @codeCoverageIgnoreStart
} catch (\Throwable $e) {
Expand All @@ -235,7 +235,7 @@ public function descendants(): DescendantsRelation
/**
* Return the relationship between an album and its cover.
*
* @return HasOne<Photo>
* @return HasOne<Photo,$this>
*/
public function cover(): HasOne
{
Expand All @@ -245,7 +245,7 @@ public function cover(): HasOne
/**
* Return the relationship between an album and its header.
*
* @return HasOne<Photo>
* @return HasOne<Photo,$this>
*/
public function header(): HasOne
{
Expand Down
6 changes: 3 additions & 3 deletions app/Models/BaseAlbumImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function newEloquentBuilder($query): BaseAlbumImplBuilder
/**
* Returns the relationship between an album and its owner.
*
* @return BelongsTo<User,BaseAlbumImpl>
* @return BelongsTo<User,$this>
*/
public function owner(): BelongsTo
{
Expand All @@ -225,7 +225,7 @@ public function owner(): BelongsTo
* Returns the relationship between an album and all users with whom
* this album is shared.
*
* @return BelongsToMany<User>
* @return BelongsToMany<User,$this>
*/
public function shared_with(): BelongsToMany
{
Expand All @@ -240,7 +240,7 @@ public function shared_with(): BelongsToMany
/**
* Returns the relationship between an album and its associated permissions.
*
* @return hasMany<AccessPermission>
* @return hasMany<AccessPermission,$this>
*/
public function access_permissions(): hasMany
{
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Builders/AlbumBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* @method $this whereNull(string|array $columns, string $boolean = 'and', bool $not = false)
* @method $this orderByDesc($column)
*
* @extends NSQueryBuilder<string,Album>
* @extends NSQueryBuilder<Album>
*/
class AlbumBuilder extends NSQueryBuilder
{
Expand All @@ -64,7 +64,7 @@ class AlbumBuilder extends NSQueryBuilder
*
* @param string[]|string $columns
*
* @return Album[]
* @return array<int,Album>
*
* @throws InternalLycheeException
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Builders/TagAlbumBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TagAlbumBuilder extends FixedQueryBuilder
*
* @param array<string>|string $columns
*
* @return TagAlbum[]
* @return array<int,TagAlbum>
*
* @throws QueryBuilderException
*/
Expand Down
8 changes: 4 additions & 4 deletions app/Models/Extensions/BaseAlbum.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ abstract class BaseAlbum extends Model implements AbstractAlbum, HasRandomID
public $incrementing = false;

/**
* @return BelongsTo<BaseAlbumImpl,self>
* @return BelongsTo<BaseAlbumImpl,$this>
*/
public function base_class(): BelongsTo
{
Expand All @@ -81,7 +81,7 @@ public function owner(): BelongsTo
* Returns the relationship between an album and all users with whom
* this album is shared.
*
* @return BelongsToMany<User>
* @return BelongsToMany<User,BaseAlbumImpl>
*/
public function shared_with(): BelongsToMany
{
Expand All @@ -91,7 +91,7 @@ public function shared_with(): BelongsToMany
/**
* Returns the relationship between an album and its associated permissions.
*
* @return HasMany<AccessPermission>
* @return HasMany<AccessPermission,BaseAlbumImpl>
*/
public function access_permissions(): HasMany
{
Expand Down Expand Up @@ -119,7 +119,7 @@ public function public_permissions(): AccessPermission|null
}

/**
* @return Relation<\App\Models\Photo>
* @return Relation<\App\Models\Photo,AbstractAlbum&Model,Collection<int,\App\Models\Photo>>
*/
abstract public function photos(): Relation;

Expand Down
2 changes: 1 addition & 1 deletion app/Models/Extensions/HasBidirectionalRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function getRelationshipFromMethod($method): mixed
* @param string|null $localKey
* @param string|null $foreignMethodName
*
* @return HasManyBidirectionally<TRelatedModel,self>
* @return HasManyBidirectionally<TRelatedModel,$this>
*/
public function hasManyBidirectionally(string $related, ?string $foreignKey = null, ?string $localKey = null, ?string $foreignMethodName = null): HasManyBidirectionally
{
Expand Down
Loading

0 comments on commit 8c3d8a3

Please sign in to comment.