<commit_before><?php

namespace Zeropingheroes\Lanager\Policies;

use Zeropingheroes\Lanager\User;
use Zeropingheroes\Lanager\LanGame;

class LanGamePolicy extends BasePolicy
{
    /**
     * Determine whether the user can view a given item.
     *
     * @param User $user
     * @param LanGame $lanGame
     * @return mixed
     */
    public function view(?User $authUser, LanGame $lanGame)
    {
        // Admins can view any
        if ($authUser && $authUser->hasRole('admin')) {
            return true;
        }
        // Non-admins can only view if the LAN has been published
        return $lanGame->lan->published;
    }

    /**
     * Determine whether the user can create an item.
     *
     * @param User $user
     * @return mixed
     */
    public function create(User $user)
    {
        return true;
    }

    /**
     * Determine whether the user can edit a given item.
     *
     * @param User $user
     * @param LanGame $lanGame
     * @return mixed
     */
    public function update(User $authUser, LanGame $lanGame)
    {
        return $authUser->id == $lanGame->user->id;
    }

    /**
     * Determine whether the user can delete a given item.
     *
     * @param User $user
     * @param LanGame $lanGame
     * @return mixed
     */
    public function delete(User $authUser, LanGame $lanGame)
    {
        return $authUser->id == $lanGame->user->id;
    }
}
<commit_msg>Prevent updating of LAN games if they have votes<commit_after><?php

namespace Zeropingheroes\Lanager\Policies;

use Zeropingheroes\Lanager\User;
use Zeropingheroes\Lanager\LanGame;

class LanGamePolicy extends BasePolicy
{
    /**
     * Determine whether the user can view a given item.
     *
     * @param User $user
     * @param LanGame $lanGame
     * @return mixed
     */
    public function view(?User $authUser, LanGame $lanGame)
    {
        // Admins can view any
        if ($authUser && $authUser->hasRole('admin')) {
            return true;
        }
        // Non-admins can only view if the LAN has been published
        return $lanGame->lan->published;
    }

    /**
     * Determine whether the user can create an item.
     *
     * @param User $user
     * @return mixed
     */
    public function create(User $user)
    {
        return true;
    }

    /**
     * Determine whether the user can edit a given item.
     *
     * @param User $authUser
     * @param LanGame $lanGame
     * @return mixed
     */
    public function update(User $authUser, LanGame $lanGame)
    {
        // Admins can update any
        if ($authUser && $authUser->hasRole('admin')) {
            return true;
        }
        // Non-admins can't update if game already voted for by others
        if ($lanGame->votes()->whereNotIn('user_id', [$authUser->id])->count() !== 0) {
            return false;
        }

        // Non-admins can update their own submissions
        return $authUser->id == $lanGame->user->id;
    }

    /**
     * Determine whether the user can delete a given item.
     *
     * @param User $user
     * @param LanGame $lanGame
     * @return mixed
     */
    public function delete(User $authUser, LanGame $lanGame)
    {
        return $authUser->id == $lanGame->user->id;
    }
}

{'fraction_non_alphanumeric': 0.11080246913580247, 'fraction_numerical': 0.00030864197530864197, 'mean_word_length': 2.0318054256314313, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '6413157', 'n_tokens_mistral': 994, 'n_tokens_neox': 969, 'n_words': 291}