[buddypress-trac] [BuddyPress Trac] #8728: Group Moderator Unable Delete Group Posts

buddypress-trac noreply at wordpress.org
Wed Apr 17 03:13:22 UTC 2024


#8728: Group Moderator Unable Delete Group Posts
--------------------------------------+------------------------
 Reporter:  kainelabsteam             |       Owner:  emaralive
     Type:  enhancement               |      Status:  assigned
 Priority:  normal                    |   Milestone:  14.0.0
Component:  Groups                    |     Version:  10.3.0
 Severity:  normal                    |  Resolution:
 Keywords:  needs-patch dev-feedback  |
--------------------------------------+------------------------

Comment (by emaralive):

 @imath,

 Thanks for the enlightenment and I've managed to come up with
 8728.03.patch that is a hybrid of the 8728.01.patch and the 8728.02.patch,
 that looks like the following:
 {{{
 function bp_groups_filter_activity_user_can_delete( $retval, $activity ) {
         // Bail if no current user.
         // Todo: add second conditional statement to check the state to
 allow group activity deletions.
         // e.g., "|| ! bp_enable_group_activity_deletions()".
         if ( ! is_user_logged_in() ) {
                 return $retval;
         }

         if ( isset( $activity->component ) && 'groups' !==
 $activity->component ) {
                 return $retval;
         }

         // The second conditional statement does not allow "site admin"
 activity posts to be deleted by "non site admins".
         if ( bp_current_user_can( 'bp_moderate' ) || bp_user_can(
 $activity->user_id, 'bp_moderate' ) ) {
                 return $retval;
         }

         $group_id = $activity->item_id;

         // Group creator, administrators or moderators can delete content
 in which deletions are allowed for that group.
         // Todo: break this out into additional conditionals that provide
 granularity as to who can to what, when.
         if ( groups_is_user_creator( bp_loggedin_user_id(), $group_id ) ||
 groups_is_user_admin( bp_loggedin_user_id(), $group_id ) ||
 groups_is_user_mod( bp_loggedin_user_id(), $group_id ) ) {
                 $retval = true;
         }

         return $retval;
 }
 }}}

 @espellcaste,

 8728.03.patch to be uploaded shortly to replace 8728.02.patch.

 Next is for the both of you, when testing the **REST API** for activity
 deletion, I'm receiving  the following error notices with successful
 deletions:


 {{{
 Notice: Trying to get property 'is_spam' of non-object in /wp-
 content/plugins/buddypress/src/bp-activity/bp-activity-functions.php on
 line 3376

 Notice: Trying to get property 'component' of non-object in /wp-
 content/plugins/buddypress/src/bp-activity/bp-activity-functions.php on
 line 3357
 }}}

 [https://github.com/buddypress/buddypress/blob/ef9fde9191b87a2f6a4027f2ecc75cfc1c616090/src
 /bp-activity/bp-activity-functions.php#L3376 Line 3376] and
 [https://github.com/buddypress/buddypress/blob/ef9fde9191b87a2f6a4027f2ecc75cfc1c616090/src
 /bp-activity/bp-activity-functions.php#L3357 line 3357]

 == Scenario
 WP 6.5.2
 BP 14.0.0-alpha and BP 12.4.0
 PHP 7.4.33
 !BuddyPress Nouveau template pack
 BP Rewrites API
 Plugin: JSON Basic Authentication

 Curl statement on the command line:

 {{{
 curl -X DELETE --user <user>:<password> -i site.url/wp-
 json/buddypress/v1/activity/<id>
 }}}

 Is it just me or are these valid error notices?

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/8728#comment:13>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list