Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROD-8149 #4583

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ public function get_items_permissions_check( $request ) {
);
}

if ( true === $retval && ! $this->can_see( $request ) ) {
$retval = new WP_Error(
'bp_rest_authorization_required',
__( 'Sorry, you cannot view the activity comment.', 'buddyboss' ),
array(
'status' => rest_authorization_required_code(),
)
);
}

/**
* Filter the activity comment permissions check.
*
Expand Down Expand Up @@ -1151,6 +1161,22 @@ public function validate_activity_comment_request( $request ) {
* @since 0.1.0
*/
protected function can_see( $request ) {

// Check if the user can read the activity as per privacy settings.
if ( ! empty( $request['id'] ) && function_exists( 'bb_validate_activity_privacy' ) ) {
$privacy_check = bb_validate_activity_privacy(
array(
'activity_id' => $request['id'],
'validate_action' => 'view_activity',
'user_id' => bp_loggedin_user_id(),
)
);

if ( is_wp_error( $privacy_check ) ) {
return false;
}
}

$activity_comment = $this->get_activity_comment_object( $request );

return ( ! empty( $activity_comment ) && bp_activity_user_can_read( $activity_comment, bp_loggedin_user_id() ) );
Expand Down
15 changes: 15 additions & 0 deletions src/bp-activity/classes/class-bp-rest-activity-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -2540,6 +2540,21 @@ protected function prepare_links( $activity ) {
* @since 0.1.0
*/
protected function can_see( $request ) {
// Check if the user can read the activity as per privacy settings.
if ( ! empty( $request['id'] ) && function_exists( 'bb_validate_activity_privacy' ) ) {
$privacy_check = bb_validate_activity_privacy(
array(
'activity_id' => $request['id'],
'validate_action' => 'view_activity',
'user_id' => bp_loggedin_user_id(),
)
);

if ( is_wp_error( $privacy_check ) ) {
return false;
}
}

$activity = $this->get_activity_object( $request );

return ( ! empty( $activity ) ? bp_activity_user_can_read( $activity, bp_loggedin_user_id() ) : false );
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/api_project.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ define({
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2024-11-22T13:04:15.023Z",
"time": "2024-12-17T13:06:44.549Z",
"url": "http://apidocjs.com",
"version": "0.22.1"
}
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/api_project.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2024-11-22T13:04:15.023Z",
"time": "2024-12-17T13:06:44.549Z",
"url": "http://apidocjs.com",
"version": "0.22.1"
}
Expand Down
Loading