HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How to Disable Commenting on Custom Activity Types?

I would like to disable commenting on Article and ArticleComment activity types.

I have defined those activity types in the Article app's structure.php file with:

$ActivityModel = new ActivityModel();
$ActivityModel->DefineType('Article');
$ActivityModel->DefineType('ArticleComment');

This creates two new rows in the GDN_ActivityType table with the AllowComments field set to the default of 0 (false).

When I insert a new activity with either the Article or the ArticleComment activity type, I can still leave a comment on the activities when comments shouldn't be allowed. It's the same on both an admin account and a normal user account.

I see that the comments link for activities doesn't have any logic to hide the link if AllowComments is set to false. Reference: https://github.com/vanilla/vanilla/blob/master/applications/dashboard/views/activity/helper_functions.php#L82

Is the AllowComments property being ignored and simply not used in the code, or is there another way to do this?

Add Pages to Vanilla with the Basic Pages app

Comments

  • LincLinc Admin

    Wow, yeah, looks like AllowComments is a dummy db field that either didn't get implemented or got supplanted by a calculated value. I don't have a good suggestion on this one.

  • Huh, I didn't even think about this when I was creating new activity types. Good find @Shadowdare.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Possible trick: implement a handler for ActivityController_AfterActivityBody. In it, set the following:

    // Keep $ID empty (line 75)
    $Sender->EventArguments['Activity']->SharedNotifyUserID = null;
    // Keep $ID empty (line 77)
    $Sender->EventArguments['Activity']->CommentNotifyUserID = null;
    // At this point $SharedString should be empty as well. Set $Activity->NotifyUserID to 
    // any value greater than zero
    $Sender->EventArguments['Activity']->NotifyUserID = 12345;
    
    // Now $AllowComments = $Activity->NotifyUserID < 0 || $SharedString; should 
    // always return false, disabling comments
    
Sign In or Register to comment.