From 964359d6c21424d1b5920df38977c9bb7c3b06aa Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 18 Nov 2026 15:12:32 +0000 Subject: [PATCH] fix: let every member of an organization see who starred its commits through the API --- KNOWLEDGE_BASE.md | 2 +- .../Requests/ListApiCommitStarsRequest.php | 5 ++- .../Api/CommitStarControllerTest.php | 37 +++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index 4ef8bf678..d7d8b1518 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -594,7 +594,7 @@ A signed request sees what the web shows you, such as your own pending commits a - read who to follow, also as it is suggested beside a profile or a commit, and mark a suggestion not interested; - read the hot topics, and each one's commits from the past week with its recap; - list guilds as the Guilds page does, 24 a page, searched by name, handle or description, with whether you joined or muted each one and whether it is paused, while guilds are available to you; -- star or unstar, and list who starred your own commit, newest first, 20 a page; +- star or unstar, and list who starred your own commits and your organizations', newest first, 20 a page; - create polls on commits that are neither replies nor quotes, and vote on polls; - change Remotes settings, read and send messages with images, link cards, and voice notes in conversations and orgs, mark them pulled, react to messages and list your reactions, pin and unpin org messages as a maintainer, find people, and start orgs; - rename orgs, add people to them, change their roles, remove them, and leave an org, with the same maintainer rules as the web; diff --git a/app/Http/Requests/ListApiCommitStarsRequest.php b/app/Http/Requests/ListApiCommitStarsRequest.php index c8679a2bd..403fba09a 100644 --- a/app/Http/Requests/ListApiCommitStarsRequest.php +++ b/app/Http/Requests/ListApiCommitStarsRequest.php @@ -12,7 +12,8 @@ final class ListApiCommitStarsRequest extends FormRequest { /** - * Only authors see who starred their commit, as on the web. Everyone else only sees how many did. + * Only authors see who starred their commit, as on the web, so every member of an organization sees who starred its + * commits. Everyone else only sees how many did. */ public function authorize(): Response { @@ -22,7 +23,7 @@ public function authorize(): Response $commit = $this->route('commit'); assert($commit instanceof Commit); - return $commit->user_id === $user->id ? Response::allow() : Response::denyAsNotFound(); + return $commit->isOwnedBy($user) ? Response::allow() : Response::denyAsNotFound(); } /** diff --git a/tests/Feature/Controllers/Api/CommitStarControllerTest.php b/tests/Feature/Controllers/Api/CommitStarControllerTest.php index 13c9df7ea..2fadb465f 100644 --- a/tests/Feature/Controllers/Api/CommitStarControllerTest.php +++ b/tests/Feature/Controllers/Api/CommitStarControllerTest.php @@ -4,7 +4,9 @@ use App\Enums\CommitStatus; use App\Enums\NotificationType; +use App\Enums\OrganizationRole; use App\Models\Commit; +use App\Models\Organization; use App\Models\User; beforeEach(function (): void { @@ -243,6 +245,41 @@ ->assertNotFound(); }); +it('lists who starred a commit of their organization to every member, as the web does', function (bool $posted): void { + $organization = Organization::factory()->create(); + $teammate = User::factory()->create(); + $organization->members()->attach([$this->user->id, $teammate->id], ['role' => OrganizationRole::Member]); + + $commit = Commit::factory()->for($posted ? $this->user : $teammate)->create(['author_id' => $organization->id]); + $stargazer = User::factory()->create(); + $stargazer->starredCommits()->attach($commit); + + signedApiRequest($this->keyPair, 'GET', route('api-commit-star.index', $commit)) + ->assertOk() + ->assertJsonPath('data.*.id', [$stargazer->id]); +})->with([ + 'the member who posted it' => true, + 'another member' => false, +]); + +it('may not list who starred a commit of an organization the user is not a member of', function (Closure $commit): void { + $organization = Organization::factory()->create(); + $commit = $commit($this->user, $organization); + + User::factory()->create()->starredCommits()->attach($commit); + + signedApiRequest($this->keyPair, 'GET', route('api-commit-star.index', $commit)) + ->assertNotFound(); +})->with([ + 'someone outside it' => fn (User $user, Organization $organization): Commit => Commit::factory()->create(['author_id' => $organization->id]), + 'a site admin outside it' => function (User $user, Organization $organization): Commit { + config(['app.admins' => [$user->handle]]); + + return Commit::factory()->create(['author_id' => $organization->id]); + }, + 'the member who posted it, after leaving' => fn (User $user, Organization $organization): Commit => Commit::factory()->for($user)->create(['author_id' => $organization->id]), +]); + it('requires a signed request to list who starred a commit', function (): void { $commit = Commit::factory()->for($this->user)->create();