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

    'filter:topic.create'
    

    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


  • Gamers

    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.

    The delete and purge functions for topics only take tid and 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 postData there, 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.can filter (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 privileges.can hook 🙂



  • @oplik0

    'privileges.can'
    

    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:

    1. reaches a certain number of answers.
    2. if it reaches a certain number of likes
    3. if it has existed for a certain period of time
    4. 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

    'action:topic.delete'
    

    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 filter:topic.delete then action:topic.delete shouldn't fire etc.



  • @baris
    i will do it! thanks you


Log in to reply
 

Suggested Topics

  • 4
  • 5
  • 7
  • 8
  • 3
| |