mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-24 19:49:24 +02:00
89 lines
2.7 KiB
PHP
89 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\GraphQL\Policies\List;
|
|
|
|
use App\Enums\Auth\CrudPermission;
|
|
use App\Enums\Models\List\ExternalProfileVisibility;
|
|
use App\GraphQL\Mutations\List\ExternalProfileMutator;
|
|
use App\GraphQL\Policies\BasePolicy;
|
|
use App\Models\Auth\User;
|
|
use App\Models\List\ExternalProfile;
|
|
use Illuminate\Support\Arr;
|
|
|
|
/**
|
|
* Class ExternalProfilePolicy.
|
|
*/
|
|
class ExternalProfilePolicy extends BasePolicy
|
|
{
|
|
/**
|
|
* Determine whether the user can view the model.
|
|
*
|
|
* @param User|null $user
|
|
* @param array|null $injected
|
|
* @param string|null $keyName
|
|
* @return bool
|
|
*/
|
|
public function view(?User $user, ?array $injected = null, ?string $keyName = ExternalProfileMutator::ROUTE_SLUG): bool
|
|
{
|
|
/** @var ExternalProfile $profile */
|
|
$profile = Arr::get($injected, $keyName);
|
|
|
|
if ($user !== null) {
|
|
return ($profile->user()->is($user) || ExternalProfileVisibility::PRIVATE !== $profile->visibility)
|
|
&& $user->can(CrudPermission::VIEW->format(ExternalProfile::class));
|
|
}
|
|
|
|
return ExternalProfileVisibility::PRIVATE !== $profile->visibility;
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the model.
|
|
*
|
|
* @param User $user
|
|
* @param array $injected
|
|
* @param string|null $keyName
|
|
* @return bool
|
|
*/
|
|
public function update(User $user, array $injected, ?string $keyName = ExternalProfileMutator::ROUTE_SLUG): bool
|
|
{
|
|
/** @var ExternalProfile $profile */
|
|
$profile = Arr::get($injected, $keyName);
|
|
|
|
return $profile->user()->is($user) && parent::update($user, $injected, $keyName);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the model.
|
|
*
|
|
* @param User $user
|
|
* @param array $injected
|
|
* @param string|null $keyName
|
|
* @return bool
|
|
*/
|
|
public function delete(User $user, array $injected, ?string $keyName = ExternalProfileMutator::ROUTE_SLUG): bool
|
|
{
|
|
/** @var ExternalProfile $profile */
|
|
$profile = Arr::get($injected, $keyName);
|
|
|
|
return $profile->user()->is($user) && parent::update($user, $injected, $keyName);
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can restore the model.
|
|
*
|
|
* @param User $user
|
|
* @param array $injected
|
|
* @param string|null $keyName
|
|
* @return bool
|
|
*/
|
|
public function restore(User $user, array $injected, ?string $keyName = ExternalProfileMutator::ROUTE_SLUG): bool
|
|
{
|
|
/** @var ExternalProfile $profile */
|
|
$profile = Arr::get($injected, $keyName);
|
|
|
|
return $profile->user()->is($user) && parent::update($user, $injected, $keyName);
|
|
}
|
|
}
|