custom logic before topic delete
Hello. I see there is a hook that allow you to accept or reject a new topic. its name is
But the same thing dont exist for topic delete. At moment there is only a action hook to call after a topic is deleted.
Is possible to have a filter also for delete and purge? But i think is sufficent only for delete actions
oplik0 last edited by oplik0
So... You just want a filter for weather or not user can delete/Purge the topic?
If not, then how would that filter work?
Deleting just changes one attribute of a topic, and purging deletes it from database.
purgefunctions for topics only take
uid(of the caller), so I don't really know what a filter could do here. Unlike on deleting a post there is no equivalent to
postDatathere, so unless you want to delete different topic than you were trying to or make it seem like a different user did it, I don't know in what way that would be useful.
Before the actual delete function is called, there is a check for wether or not user has the right privileges, but I think a more general
privileges.canfilter (or probably 2: one for category and one for global privileges) would be better than a dedicated filter for topic deletion privileges.
Edit: Ah, I misunderstood. You want a filter that will allow you to reject topic deletion and I didn't even think of that. This post isn't really relevant here then, but I'll still leave it for the part with
NoduleJS last edited by NoduleJS
Is a good idea if this action depend exclusively from user privileges. Can be good also a filter if the action depend exclusively from the topic category. But i think is good also a hook dedicated for a single topic.
for example, maybe I want to make that a topic cannot be deleted if:
- reaches a certain number of answers.
- if it reaches a certain number of likes
- if it has existed for a certain period of time
- met certain criteria saved in another database.
they are all things that concern the single topic. Even if, thinking of it better, these cancellation criteria should belong to a category, (there are no topics without category). So in most cases, even a hook for each category would suffice.
But, seeing the structure of nodebb, there are no hooks by category but only during the creation or modification of topics and posts. Perhaps it is easier to continue following this structure
If someone is interested at moment there is a ugly way to avoid a delete.
you can add your logic here
restore the topic if the caller is not the admin and the topic is part of a specific category
Feel free to open an issue on our github, this needs to be implemented properly so canceling a topic delete doesn't execute all the code that comes after. For example if you cancel topic delete in
action:topic.deleteshouldn't fire etc.
i will do it! thanks you