<commit_before><?php

/** Created by PhpStorm,  User: jonphipps,  Date: 2017-05-30,  Time: 11:57 AM */

namespace App\Http\Traits;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

trait UsesPolicies
{
    public function create()
    {
        $this->policyAuthorize('create', $this->crud->getModel());

        return parent::create();
    }

    public function destroy($id)
    {
        $this->policyAuthorize('delete', $this->crud->getModel(), $id);

        return parent::destroy($id);
    }

    public function edit($id)
    {
        $this->policyAuthorize('update', $this->crud->getModel(), $id);

        return parent::edit($id);
    }

    public function index()
    {
        $this->policyAuthorize('index', $this->crud->getModel());

        return parent::index();
    }

    public function show($id)
    {
        $this->policyAuthorize('show', $this->crud->getModel(), $id);

        return parent::show($id);
    }

    /**
     * Determines the access to allow based on policy
     *
     * @param string   $ability The ability to validate
     * @param Model    $class   The instance of a Model class to check against
     * @param int|null $id      The id of the individual to check against
     *
     * @return void
     */
    protected function policyAuthorize($ability, $class, $id = null)
    {
        $model = $id !== null ? $class::findOrFail($id) : $class;

        if (Auth::check() && Auth::user()->can($ability, $model)) {
            $this->crud->allowAccess([ $ability ]);
        }
    }
}<commit_msg>update uses policies to use correct trait and auto deny<commit_after><?php

/** Created by PhpStorm,  User: jonphipps,  Date: 2017-05-30,  Time: 11:57 AM */

namespace App\Http\Traits;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

trait UsesPolicies
{
    use AuthorizesRequests;

    public function create()
    {
        $this->policyAuthorize('create', $this->crud->getModel());

        return parent::create();
    }

    public function destroy($id)
    {
        $this->policyAuthorize('delete', $this->crud->getModel(), $id);

        return parent::destroy($id);
    }

    public function edit($id)
    {
        $this->policyAuthorize('update', $this->crud->getModel(), $id);

        return parent::edit($id);
    }

    public function index()
    {
        $this->policyAuthorize('index', $this->crud->getModel());

        return parent::index();
    }

    public function show($id)
    {
        $this->policyAuthorize('show', $this->crud->getModel(), $id);

        return parent::show($id);
    }

    /**
     * Determines the access to allow based on policy
     *
     * @param string   $ability The ability to validate
     * @param Model    $class   The instance of a Model class to check against
     * @param int|null $id      The id of the individual to check against
     *
     * @return void
     */
    protected function policyAuthorize($ability, $class, $id = null)
    {
        $model = $id !== null ? $class::findOrFail($id) : $class;

        $this->crud->denyAccess([ $ability ]);
        $this->authorize($ability, $model);
        $this->crud->allowAccess([ $ability ]);
    }
}
{'fraction_non_alphanumeric': 0.15254237288135594, 'fraction_numerical': 0.007395993836671803, 'mean_word_length': 2.622767857142857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '2468129', 'n_tokens_mistral': 1016, 'n_tokens_neox': 985, 'n_words': 239}