Skip to content
Open
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
2 changes: 1 addition & 1 deletion KNOWLEDGE_BASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Requests/ListApiCommitStarsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
}

/**
Expand Down
37 changes: 37 additions & 0 deletions tests/Feature/Controllers/Api/CommitStarControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();

Expand Down