Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Best way for an extension to selectively prohibit comment posting

edited August 2008 in Vanilla 1.0 Help
I see that CommentManager::SaveComment is the method that does the heavy lifting for adding and editing comments. What delegates or other things can I use to selectively (as in programmatically, based on an algorithm in my extension) prohibit SaveComment from going through with the Database::Insert or Database::Update that it is called to do? Thanks.

Comments

  • Add an error to the ErrorManager, and that will halt the post. This is also useful to display a message to the user.
  • Good idea. Now, which delegate or delegates do I need to hook into to accomplish this? CommentManager / PreInsertNewComment looks correct for adding a new comment, but I don't see one for editing existing comments.
  • Actually, I spoke too soon. There don't appear to be any opportunities for CommentManager::SaveComment to stop execution between that delegate and the database operation.
  • Incidentally, in case it helps or just in case anyone is curious, the reason I want to do this is as part of a Community Moderation extension I am working on. When a user's posts have been moderated down by the community too much, that user will have a negative score and will not be allowed to post or edit comments. (I will have other specific questions as I work on this extension, too. I am hoping to make it work smoothly and release it publicly as I think it is a useful feature that hardly any forum software has.)
  • I went (for now, at least) with adding an Error to the ErrorManager regardless of what's actually going on, if SelfUrl is post.php. Thanks for the suggestion. Others are still welcome if there is a more user-friendly way of doing this (a friendly way of prohibiting posting? :P)
  • I know new topics can be blocked that way because I did it--the forced category extension works that way. But your right that it isn't as easy for comments. You could attach to the DiscussionForm's PreSaveComment delegate, which is called right before the CommentManager is invoked. You could either halt the script there or another option is to toggle off the PERMISSION_ADD_COMMENTS setting (you can see it inside that SaveComment method) with your extension.
  • I didn't see that delegate. I'll check it out, although just erroring out post.php as a whole works fine. Thanks! :)
This discussion has been closed.