Skip to content

Beautiful Open-Source Form Builder

1.1 KB
Raw Blame
<?php

namespace App\Policies;

use App\Models\Forms\FormSubmission;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class FormSubmissionPolicy
{
    use HandlesAuthorization;

    /**
     * Determine whether the user can view the form submission.
     */
    public function view(User $user, FormSubmission $submission)
    {
        $form = $submission->form;

        if ($token = $user->currentAccessToken()) {
            $canAccess = $token->can('forms-read') || $token->can('manage-integrations');
            return $canAccess && $user->ownsForm($form);
        }

        return $user->ownsForm($form);
    }

    /**
     * Determine whether the user can update the form submission.
     */
    public function update(User $user, FormSubmission $submission)
    {
        $form = $submission->form;

        $ownsAndWritable = $user->ownsForm($form) && !$form->workspace->isReadonlyUser($user);

        if ($token = $user->currentAccessToken()) {
            return $token->can('forms-write') && $ownsAndWritable;
        }

        return $ownsAndWritable;
    }
}