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

Require viewUserList to get user by ID #2573

Closed
Closed
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
1 change: 1 addition & 0 deletions src/Api/Controller/ShowUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected function data(ServerRequestInterface $request, Document $document)
if (Arr::get($request->getQueryParams(), 'bySlug', false)) {
$user = $this->slugManager->forResource(User::class)->fromSlug($id, $actor);
} else {
$actor->assertCan('viewUserList');
$user = $this->users->findOrFail($id, $actor);
}

Expand Down
14 changes: 9 additions & 5 deletions tests/integration/api/users/ShowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public function admin_can_see_user_via_slug()
/**
* @test
*/
public function guest_can_see_user_by_default()
public function guest_cant_see_user_by_id_default()
{
$response = $this->send(
$this->request('GET', '/api/users/2')
);

$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals(403, $response->getStatusCode());
}

/**
Expand All @@ -99,15 +99,19 @@ public function guest_can_see_user_by_slug_by_default()
/**
* @test
*/
public function guest_cant_see_user_if_blocked()
public function guest_can_see_user_by_id_if_allowed()
{
$this->forbidGuestsFromSeeingForum();
$this->prepareDatabase([
'group_permission' => [
['permission' => 'viewUserList', 'group_id' => 2],
]
]);

$response = $this->send(
$this->request('GET', '/api/users/2')
);

$this->assertEquals(404, $response->getStatusCode());
$this->assertEquals(200, $response->getStatusCode());
}

/**
Expand Down