Team-Tea-Time / laravel-forum

A slim, lean forum package designed for quick and easy integration in Laravel projects
https://laravel-forum.teamteatime.net/
MIT License
601 stars 165 forks source link

Policy "markThreadsAsRead" doesn't get called no matter what #358

Closed fseesys closed 8 months ago

fseesys commented 8 months ago
namespace TeamTeaTime\Forum\Policies;

use TeamTeaTime\Forum\Models\Category;

class CategoryPolicy {

    public function markThreadsAsRead($user, Category $category): bool
    {
        clock($category);
        return true;
    }
}

I've tried putting a breakpoint insider, or a clockwork dump, it just doesn't get called, while others checks got called normally.

I'm using active template & the forum package is vanilla v5.4.3.

namespace App\Policies;

use Illuminate\Support\Facades\DB;
use TeamTeaTime\Forum\Models\Category;
use TeamTeaTime\Forum\Models\Thread;
use TeamTeaTime\Forum\Policies\CategoryPolicy as ForumCategoryPolicy;

class CategoryPolicy extends ForumCategoryPolicy
{
    public function viewThread($user, Thread $thread): bool
    {
        clock($thread);
        return true;
    }
}

I've also added a custom policy check, it also doesn't get called, please kindly help.

Thanks very much.

Riari commented 8 months ago

Hi,

I think CategoryPolicy::markThreadsAsRead isn't actually used anywhere in the code - it will only be called if you pass along a category instance. There is also ForumPolicy::markThreadsAsRead, which doesn't take any model instances (only the user) and is used in a few places.

This is an oversight on my part and I'll most likely remove CategoryPolicy::markThreadsAsRead as I don't think it makes sense for a user to be able to access a category but not mark threads in it as read. If you do need that specific behaviour, you can extend any of the policies to add your own methods and specify your policy namespaces in the integration.policies config option: https://github.com/Team-Tea-Time/laravel-forum/blob/5.0/config/integration.php#L15-L22

Let me know if you need any further help with that.