Skip to content

Commit afb8fe5

Browse files
authored
Outbox: Properly handle username requests (#1559)
* Add failing test * Add changelog * Make tests pass
1 parent 3e4cab6 commit afb8fe5

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Outbox endpoint bug where non-numeric usernames caused errors when querying Outbox data.

includes/rest/class-outbox-controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public function validate_user_id( $user_id ) {
9999
* @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
100100
*/
101101
public function get_items( $request ) {
102-
$user_id = $request->get_param( 'user_id' );
103102
$page = $request->get_param( 'page' ) ?? 1;
104-
$user = Actors::get_by_various( $user_id );
103+
$user = Actors::get_by_various( $request->get_param( 'user_id' ) );
104+
$user_id = $user->get__id();
105105

106106
/**
107107
* Action triggered prior to the ActivityPub profile being created and sent to the client.

tests/includes/rest/class-test-outbox-controller.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ public function test_get_items() {
111111
$this->assertEquals( 200, $response->get_status() );
112112
}
113113

114+
/**
115+
* Test getting items by passing the username instead of the user ID.
116+
*
117+
* @covers ::get_items
118+
*/
119+
public function test_get_items_with_username() {
120+
$request = new \WP_REST_Request( 'GET', sprintf( '/%s/actors/%s/outbox', ACTIVITYPUB_REST_NAMESPACE, get_userdata( self::$user_id )->user_nicename ) );
121+
$response = \rest_get_server()->dispatch( $request );
122+
$data = $response->get_data();
123+
124+
$this->assertEquals( 10, $data['totalItems'] );
125+
}
126+
114127
/**
115128
* Test schema.
116129
*

0 commit comments

Comments
 (0)