Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/20/2025 07:10:28 PM (11 months ago)
Author:
dcavins
Message:

Restrict bulk notification management to owner (14.0 branch).

When attempting to manage notifications in bulk, ensure that the current user is either a site admin or owns all of the notifications specified.

Many thanks to Brian Mungah for responsibly reporting the problem.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/12.0/tests/phpunit/testcases/notifications/functions.php

    r13414 r14107  
    502502        $this->assertTrue( 1 === (int) $n_obj->is_new );
    503503    }
     504
     505    /**
     506     * @group bulk_manage_notifications
     507     */
     508    public function test_bp_notifications_bulk_manage_notifications_user_must_own_items() {
     509        $u1 = self::factory()->user->create();
     510        $u2 = self::factory()->user->create();
     511
     512        // Create notifications
     513        $n1 = self::factory()->notification->create( array(
     514            'component_name'    => 'messages',
     515            'component_action'  => 'new_message',
     516            'item_id'           => 99,
     517            'user_id'           => $u1,
     518        ) );
     519        $n2 = self::factory()->notification->create( array(
     520            'component_name'    => 'messages',
     521            'component_action'  => 'new_message',
     522            'item_id'           => 100,
     523            'user_id'           => $u1,
     524        ) );
     525        $n3 = self::factory()->notification->create( array(
     526            'component_name'    => 'messages',
     527            'component_action'  => 'new_message',
     528            'item_id'           => 101,
     529            'user_id'           => $u2,
     530        ) );
     531
     532        wp_set_current_user( $u2 );
     533        // Attempt to mark all as read.
     534        bp_notifications_bulk_manage_notifications( 'read', array( $n1, $n2, $n3 ) );
     535
     536        // Check status of $n2 (which shouldn't be affected).
     537        $n_get = BP_Notifications_Notification::get(
     538            array(
     539                'id'               => $n2,
     540                'component_name'   => 'messages',
     541                'component_action' => 'new_message',
     542                'is_new'           => 'both',
     543            )
     544        );
     545        $n_obj = reset( $n_get );
     546        $this->assertTrue( 1 === (int) $n_obj->is_new );
     547
     548        // Check status of $n3 (which should be affected).
     549        $n_get = BP_Notifications_Notification::get(
     550            array(
     551                'id'               => $n3,
     552                'component_name'   => 'messages',
     553                'component_action' => 'new_message',
     554                'is_new'           => 'both',
     555            )
     556        );
     557        $n_obj = reset( $n_get );
     558        $this->assertTrue( 0 === (int) $n_obj->is_new );
     559    }
     560
    504561}
Note: See TracChangeset for help on using the changeset viewer.