Skip to content

Commit

Permalink
Upgrade to Laravel 9 + switch to Laragear/WebAuthn (#1469)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria authored Oct 21, 2022
1 parent 80bbd41 commit 3872691
Show file tree
Hide file tree
Showing 120 changed files with 3,501 additions and 5,459 deletions.
2,167 changes: 1,023 additions & 1,144 deletions .phpstorm.meta.php

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion app/Actions/Album/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Safe\Exceptions\ArrayException;
use function Safe\usort;

/**
* Deletes the albums with the designated IDs **efficiently**.
Expand Down Expand Up @@ -101,6 +100,8 @@ public function do(array $albumIDs): FileDeleter
$recursiveAlbumIDs = array_merge($recursiveAlbumIDs, $subAlbums->pluck('id')->all());
$recursiveAlbumTracks = $recursiveAlbumTracks->merge($subAlbums->pluck('track_short_path'));
}
// prune the null values
$recursiveAlbumTracks = $recursiveAlbumTracks->filter(fn ($val) => $val !== null);

// Delete the photos from DB and obtain the list of files which need
// to be deleted later
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Albums/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function get(): AlbumTree
// (sub)-tree and then `toTree` will return garbage as it does
// not find connected paths within `$albums` or `$sharedAlbums`,
// resp.
list($albums, $sharedAlbums) = $albums->partition(fn ($album) => $album->owner_id === $userID);
list($albums, $sharedAlbums) = $albums->partition(fn (Album $album) => $album->owner_id === $userID);
}

// We must explicitly pass `null` as the ID of the root album
Expand Down
38 changes: 27 additions & 11 deletions app/Actions/Diagnostics/Checks/BasicPermissionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Adapter\Local as LocalFlysystem;
use League\Flysystem\Local\LocalFilesystemAdapter;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use function Safe\sprintf;
use Safe\Exceptions\FilesystemException;
use Safe\Exceptions\PosixException;
use function Safe\fileperms;
use function Safe\posix_getgrgid;
use function Safe\posix_getgroups;

class BasicPermissionCheck implements DiagnosticCheckInterface
{
Expand Down Expand Up @@ -62,8 +66,9 @@ public function folders(array &$errors): void
$this->numOwnerIssues = 0;
$this->numPermissionIssues = 0;
$this->numAccessIssues = 0;
$groupIDsOrFalse = posix_getgroups();
if ($groupIDsOrFalse === false) {
try {
$groupIDsOrFalse = posix_getgroups();
} catch (PosixException) {
$errors[] = 'Error: Could not determine groups of process';

return;
Expand All @@ -74,9 +79,11 @@ public function folders(array &$errors): void
$this->groupIDs = array_unique($this->groupIDs);
$this->groupNames = implode(', ', array_map(
function (int $gid): string {
$groupNameOrFalse = posix_getgrgid($gid);

return $groupNameOrFalse === false ? '<unknown>' : $groupNameOrFalse['name'];
try {
return posix_getgrgid($gid)['name'];
} catch (PosixException) {
return '<unknown>';
}
},
$this->groupIDs
));
Expand All @@ -88,7 +95,7 @@ function (int $gid): string {
];

foreach ($disks as $disk) {
if ($disk->getDriver()->getAdapter() instanceof LocalFlysystem) {
if ($disk->getAdapter() instanceof LocalFilesystemAdapter) {
$this->checkDirectoryPermissionsRecursively($disk->path(''), $errors);
}
}
Expand Down Expand Up @@ -134,8 +141,9 @@ private function checkDirectoryPermissionsRecursively(string $path, array &$erro
return;
}

$actualPerm = fileperms($path);
if ($actualPerm === false) {
try {
$actualPerm = fileperms($path);
} catch (FilesystemException) {
$errors[] = sprintf('Warning: Unable to determine permissions for %s' . PHP_EOL, $path);

return;
Expand All @@ -146,7 +154,15 @@ private function checkDirectoryPermissionsRecursively(string $path, array &$erro
// interested in
$actualPerm &= 07777;
$owningGroupIdOrFalse = filegroup($path);
$owningGroupNameOrFalse = $owningGroupIdOrFalse === false ? false : posix_getgrgid($owningGroupIdOrFalse);
if ($owningGroupIdOrFalse !== false) {
try {
$owningGroupNameOrFalse = posix_getgrgid($owningGroupIdOrFalse);
} catch (PosixException) {
$owningGroupNameOrFalse = false;
}
} else {
$owningGroupNameOrFalse = false;
}
$owningGroupName = $owningGroupNameOrFalse === false ? '<unknown>' : $owningGroupNameOrFalse['name'];
$expectedPerm = self::getConfiguredDirectoryPerm();

Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Diagnostics/Checks/ImageOptCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Contracts\DiagnosticCheckInterface;
use App\Facades\Helpers;
use App\Models\Configs;
use function Safe\substr;
use function Safe\exec;
use Spatie\ImageOptimizer\Optimizers\Cwebp;
use Spatie\ImageOptimizer\Optimizers\Gifsicle;
use Spatie\ImageOptimizer\Optimizers\Jpegoptim;
Expand Down
2 changes: 0 additions & 2 deletions app/Actions/Diagnostics/Diagnostics.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Actions\Diagnostics;

use function Safe\sprintf;

abstract class Diagnostics
{
/**
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Import/Exec.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
use function Safe\file;
use function Safe\glob;
use function Safe\ini_get;
use function Safe\ob_flush;
use function Safe\preg_match;
use function Safe\realpath;
use function Safe\set_time_limit;
use function Safe\substr;
use Symfony\Component\HttpFoundation\StreamedResponse;

class Exec
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Import/FromUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function do(array $urls, ?Album $album): Collection
// Silently do nothing, if `set_time_limit` is denied.
}

// If the component parameter is specified, this function returns a string (or int in case of PHP_URL_PORT)
/** @var string $path */
$path = parse_url($url, PHP_URL_PATH);
$extension = '.' . pathinfo($path, PATHINFO_EXTENSION);

Expand Down
1 change: 0 additions & 1 deletion app/Actions/Install/PermissionsChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Actions\Install;

use function Safe\preg_match;
use function Safe\substr;

class PermissionsChecker
{
Expand Down
1 change: 0 additions & 1 deletion app/Actions/Photo/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use App\SmartAlbums\PublicAlbum;
use App\SmartAlbums\StarredAlbum;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use function Safe\substr;

class Create
{
Expand Down
1 change: 0 additions & 1 deletion app/Actions/Photo/Strategies/AddVideoPartnerStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use App\Image\NativeLocalFile;
use App\Image\StreamStat;
use App\Models\Photo;
use function Safe\substr;

/**
* Adds a video as partner to an existing photo.
Expand Down
1 change: 1 addition & 0 deletions app/Actions/RSS/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function do(): Collection
throw new FrameworkException('Date/Time component (Carbon)', $e);
}

/** @var Collection<int,Photo> $photos */
$photos = $this->photoQueryPolicy
->applySearchabilityFilter(
Photo::with(['album', 'owner', 'size_variants', 'size_variants.sym_links'])
Expand Down
1 change: 1 addition & 0 deletions app/Actions/Update/Apply.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Config;
use function Safe\chdir;
use function Safe\exec;
use function Safe\preg_replace;
use function Safe\putenv;

Expand Down
1 change: 1 addition & 0 deletions app/Actions/Update/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Metadata\GitRequest;
use App\Metadata\LycheeVersion;
use App\Models\Configs;
use function Safe\exec;

class Check
{
Expand Down
23 changes: 20 additions & 3 deletions app/Actions/User/Notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,44 @@

namespace App\Actions\User;

use App\Exceptions\ConfigurationKeyMissingException;
use App\Exceptions\Internal\QueryBuilderException;
use App\Models\Configs;
use App\Models\Photo;
use App\Models\User;
use App\Notifications\PhotoAdded;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\MultipleRecordsFoundException;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Notification;

class Notify
{
/**
* Notify users that a new photo has been uploaded.
*
* @param Photo $photo
*
* @return void
*
* @throws ConfigurationKeyMissingException
* @throws QueryBuilderException
* @throws ModelNotFoundException
* @throws MultipleRecordsFoundException
*/
public function do(Photo $photo): void
{
if (!Configs::getValueAsBool('new_photos_notification')) {
return;
}

// The admin is always informed
$users = new Collection([User::query()->find(0)]);
// Admin user is always notified
$users = new Collection([User::find(0)]);

$album = $photo->album;
if ($album !== null) {
$users->push($album->shared_with);
$users = $users->concat($album->shared_with);
$users->push($album->owner);
}

Expand Down
20 changes: 0 additions & 20 deletions app/Actions/WebAuth/Delete.php

This file was deleted.

18 changes: 0 additions & 18 deletions app/Actions/WebAuth/GenerateAuthentication.php

This file was deleted.

22 changes: 0 additions & 22 deletions app/Actions/WebAuth/GenerateRegistration.php

This file was deleted.

21 changes: 0 additions & 21 deletions app/Actions/WebAuth/Lists.php

This file was deleted.

Loading

0 comments on commit 3872691

Please sign in to comment.