%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /www/loslex/test/app/Policies/
Upload File :
Create Path :
Current File : //www/loslex/test/app/Policies/ContestPolicy.php

<?php

namespace App\Policies;

use App\Enums\ContestPublicationStatusEnum;
use App\Models\Contest;
use App\Models\User;
use Illuminate\Auth\Access\Response;
use Illuminate\Support\Facades\Log;

class ContestPolicy
{
    public function before(User $user, string $ability): bool|null
    {
        if ($user->is_admin) return true;
        return null;
    }

    /**
     * Determine whether the user can view any models.
     */
    public function viewAny(?User $user): bool
    {
        return true;
    }

    /**
     * Determine whether the user can view the model.
     */
    public function view(?User $user, Contest $contest): bool
    {
        if ($contest->published == ContestPublicationStatusEnum::PUBLISHED) return true;    // published contest is ok for all

        if (is_null($user)) return false;                                                   // no visitors for rest
        if ($user->is_organizer_member($contest->organizer_group_id)) return true;          // maybe if user is organizer

        if ($contest->published == ContestPublicationStatusEnum::HIDDEN                     // users registered to (so far) contests
            && $contest->registrations->where('user_id', $user?->id)->count() > 0) return true;

        return false;
    }

    /**
     * Determine whether the user can create models.
     */
    public function create(User $user): bool
    {
        return $user->organizer_groups->isNotEmpty();
    }

    /**
     * Determine whether the user can update the model.
     */
    public function update(User $user, Contest $contest): bool
    {
        return $user->organizer_groups->pluck('id')->contains($contest->organizer_group_id);
    }

    /**
     * Determine whether the user can delete the model.
     */
    public function delete(User $user, Contest $contest): bool
    {
        return $user->organizer_groups->pluck('id')->contains($contest->organizer_group_id);
    }

    /**
     * Determine whether the user can restore the model.
     */
    public function restore(User $user, Contest $contest): bool
    {
        return $user->organizer_groups->pluck('id')->contains($contest->organizer_group_id);
    }

    /**
     * Determine whether the user can permanently delete the model.
     */
    public function forceDelete(User $user, Contest $contest): bool
    {
        return $user->is_admin;
    }

    public function fileManage(User $user, Contest $contest): bool
    {
        return $user->is_admin;
    }
}

Zerion Mini Shell 1.0