<commit_before><?php

namespace LiddleDev\LiddleForum\Policies;

use Illuminate\Database\Eloquent\Model;
use LiddleDev\LiddleForum\Models\Post;

class PostPolicy
{
    /**
     * Used to determine whether the user can perform any displayable actions on the post
     * @param Model $user
     * @param Post $post
     * @return bool
     */
    final public function update(Model $user, Post $post)
    {
        return $this->edit($user, $post) || $this->delete($user, $post);
    }

    public function edit(Model $user, Post $post)
    {
        if ($post->thread->locked) {
            return false;
        }
        return $user->getKey() === $post->user_id;
    }

    public function delete(Model $user, Post $post)
    {
        if ($post->thread->locked) {
            return false;
        }
        return $user->getKey() === $post->user_id;
    }
}<commit_msg>can't delete op on threads<commit_after><?php

namespace LiddleDev\LiddleForum\Policies;

use Illuminate\Database\Eloquent\Model;
use LiddleDev\LiddleForum\Models\Post;

class PostPolicy
{
    /**
     * Used to determine whether the user can perform any displayable actions on the post
     * @param Model $user
     * @param Post $post
     * @return bool
     */
    final public function update(Model $user, Post $post)
    {
        return $this->edit($user, $post) || $this->delete($user, $post);
    }

    public function edit(Model $user, Post $post)
    {
        if ($post->thread->locked) {
            return false;
        }
        return $user->getKey() === $post->user_id;
    }

    public function delete(Model $user, Post $post)
    {
        if ($user->getKey() !== $post->user_id) {
            return false;
        }

        if ($post->thread->locked) {
            return false;
        }
        // Don't let users delete the original post of a thread. Instead, they should delete the whole thread
        if ($post->thread->getOriginalPost()->id === $post->id) {
            return false;
        }

        return true;
    }
}
{'fraction_non_alphanumeric': 0.12962050271069492, 'fraction_numerical': 0.0, 'mean_word_length': 2.232484076433121, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '5080643', 'n_tokens_mistral': 605, 'n_tokens_neox': 607, 'n_words': 168}