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

Ability to disable thread creation on certain categories #163

Closed gerbenjacobs closed 6 years ago

gerbenjacobs commented 7 years ago

The use case is for something like an 'announcement category'. A place where only admins/moderators can post new threads, but anyone can reply.

As far as I can see the only policy for thread creation is can('createThreads'). I thought I could change a category to 'private' so that only I can post threads, but this actually hides it from regular users.

Would it be an idea to add a boolean to categories named something like protected? (If so, I can create a pull request for this)

Riari commented 7 years ago

I'd prefer not to add another attribute like that because it's tied so closely with authorisation. The only reason the private one exists is because limiting visibility for unauthenticated users isn't possible with policies.

Just update the Category::createThreads policy method to check the category ID, or if you need it to be dynamic, create a migration of your own to add a column.