<commit_before><?php

namespace App\Http\Requests;

use App\Http\Requests\Request;
use Illuminate\Http\Request as HttpRequest;
use App\Repositories\FindRepository;
use Illuminate\Support\Facades\Auth;
use App\Models\Person;

class EditFindRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize(HttpRequest $request, FindRepository $finds)
    {
        if (!Auth::check()) {
            return redirect('/finds/' . $request->finds);
        }

        // The edit can only be shown if the find if the status is "in bewerking"
        // or the user is an admin
        $user = $request->user();

        $findId = $request->finds;

        $this->find = $finds->expandValues($findId);

        if ($user->hasRole('administrator')) {
            return true;
        }

        return ($this->find['object']['objectValidationStatus'] == 'revisie nodig'
           && $user->id == $this->find['person']['identifier']);
    }

    public function getFind()
    {
        return $this->find;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            //
        ];
    }
}<commit_msg>Let validator edit request if the find is in the state that allows validator changes<commit_after><?php

namespace App\Http\Requests;

use App\Http\Requests\Request;
use Illuminate\Http\Request as HttpRequest;
use App\Repositories\FindRepository;
use Illuminate\Support\Facades\Auth;
use App\Models\Person;

class EditFindRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize(HttpRequest $request, FindRepository $finds)
    {
        if (!Auth::check()) {
            return redirect('/finds/' . $request->finds);
        }

        // The edit can only be shown if the find if the status is "in bewerking"
        // or the user is an admin
        $user = $request->user();

        $findId = $request->finds;

        $this->find = $finds->expandValues($findId);

        if ($user->hasRole('administrator')) {
            return true;
        }

        return ($this->find['object']['objectValidationStatus'] == 'revisie nodig'
            && $user->id == $this->find['person']['identifier']
           || $this->find['object']['objectValidationStatus'] == 'in bewerking' && $user->hasRole('validator'));
    }

    public function getFind()
    {
        return $this->find;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            //
        ];
    }
}
{'fraction_non_alphanumeric': 0.1312298314808175, 'fraction_numerical': 0.0, 'mean_word_length': 2.2142857142857144, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2475836', 'n_tokens_mistral': 789, 'n_tokens_neox': 784, 'n_words': 216}