PROD-10276: Show comments on public group activity to logged-in non-members - #5046
Open
rezwan-buddyboss wants to merge 1 commit into
Open
PROD-10276: Show comments on public group activity to logged-in non-members#5046rezwan-buddyboss wants to merge 1 commit into
rezwan-buddyboss wants to merge 1 commit into
Conversation
…embers Add bb_activity_can_view_comments()/bb_activity_can_view_comment_replies() view helpers and switch display gates to them; posting still requires group membership, now also enforced server-side in bp_activity_new_comment() and the REST comment endpoint. Mirror REST changes from buddyboss-platform-api. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PROD link: https://buddyboss.atlassian.net/browse/PROD-10276
Issue
A logged-in member who is not a member of a Public group cannot see existing comments on that group's activity posts — no comment list, no comment count, no Comment button — on any surface: News Feed, the poster's profile timeline, the group feed, or the single-activity permalink. The same post viewed logged-out shows the comments fine, which is the inconsistency: an anonymous visitor sees more than a signed-in member who simply hasn't joined the group.
Writing a comment is correctly members-only; this ticket is specifically about viewing existing comments, which should follow the same visibility as the post itself.
Root cause
bp_groups_filter_activity_can_comment()(src/bp-groups/bp-groups-activity.php:589, hooked tobp_activity_can_commentat priority 99, inherited from BuddyPress core) returns false for any group activity — public groups included — unless the viewer is a group member or hasbp_moderate. Critically, it bails out early when! is_user_logged_in()(:591), leaving the filter's incoming value untouched — which is what produces the inconsistency: a logged-out visitor never hits the membership veto at all, while a logged-in non-member always does.Every entry template then gates the entire comments block — the existing comment list, the count, and the write form — behind that single
bp_activity_can_comment()check, conflating two different permissions ("can I see what's already here" vs. "can I add to it") into one boolean.Fix
Split "can view" from "can write" instead of changing the membership check itself:
bb_activity_can_view_comments( $activity )and its reply counterpartbb_activity_can_view_comment_replies( $comment )(src/bp-activity/bp-activity-template.php). Each starts from the existingbp_activity_can_comment()/bp_activity_can_comment_reply()result, and only for a group activity that the viewer can already read (bp_activity_user_can_read()), temporarily unhooksbp_groups_filter_activity_can_comment[_reply]to recompute the value without the membership veto. The membership check itself is untouched — this only decides whether it gets applied to the view-permission question.bp_activity_can_comment()/bp_activity_can_comment_reply()call site to the newbb_activity_can_view_comments()/bb_activity_can_view_comment_replies()— the comments-block wrapper in both Nouveau templates (buddypress/activity/entry.php,readylaunch/activity/entry.php), the ReadyLaunch comment-reply block (readylaunch/activity/comment.php), thehas-commentsCSS class helper, the RSS feed's<slash:comments>output, and the ReadyLaunch activity-state helper class.bp_activity_can_comment()gate unchanged (in Nouveauentry.phpand ReadyLaunchentry.php, nowis_user_logged_in() && bp_activity_can_comment()), so posting still requires group membership through the UI.bb_activity_new_comment_validate_group_membershipfilter plus a group-membership check directly inbp_activity_new_comment()(src/bp-activity/bp-activity-functions.php), and the equivalent check inBP_REST_Activity_Comment_Endpoint::create_item_permissions_check()for the REST path — both reject with "You need to be a member of this group to comment." if the poster isn't a member (or is banned) and lacksbp_moderate.can_view_commentsfield to the REST activity response (class-bp-rest-activity-endpoint.php), separate from the existingcan_commentfield, wrapped infunction_exists( 'bb_activity_can_view_comments' )so older/mismatched builds degrade to the previouscan_commentvalue rather than fatal.Note: the commit message on this branch mentions mirroring the REST changes into
buddyboss-platform-api— that repo is out of scope for this PR and is not part of this fix.