Skip to content
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
6 changes: 2 additions & 4 deletions app/Http/Resources/CurrentUserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

namespace App\Http\Resources;

use App\Enums\Feature;
use App\Models\Organization;
use App\Models\User;
use App\Queries\ConversationsQuery;
use App\Services\Features;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

Expand All @@ -19,7 +17,7 @@
* was this version, so the app knows to ask. Their Remotes are `null` while turned off, as the web hides them, and
* otherwise say who can push to them, whether they share pulls, what the site lets them choose, and the unread count
* the web's nav shows. The organizations they are a member of, with their role in each, oldest membership first, and
* whether posting as one is switched on, which the web's Post as menu needs.
* whether they can post as one, which the web's Post as menu needs.
*
* @mixin User
*/
Expand Down Expand Up @@ -63,7 +61,7 @@ public function toArray(Request $request): array
...OrganizationResource::make($organization)->toArray($request),
])
->all(),
'can_post_as_organization' => resolve(Features::class)->enabled(Feature::OrganizationCommits),
'can_post_as_organization' => true,
];
}
}
2 changes: 1 addition & 1 deletion app/Queries/GitHubReadmeQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private function resolveRelativeImages(string $html, string $login): string
{
return preg_replace_callback(
'~<img\b[^>]*?\ssrc="\K(?![a-z][a-z0-9+.-]*:|//)[^"]+~i',
fn (array $match): string => "https://raw.githubusercontent.com/{$login}/{$login}/HEAD/".ltrim(preg_replace('~^(?:\./)+~', '', $match[0]) ?? $match[0], '/'),
fn (array $match): string => "https://raw.githubusercontent.com/{$login}/{$login}/HEAD/".mb_ltrim(preg_replace('~^(?:\./)+~', '', $match[0]) ?? $match[0], '/'),
$html,
) ?? $html;
}
Expand Down
19 changes: 1 addition & 18 deletions tests/Feature/Controllers/Api/CurrentUserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

declare(strict_types=1);

use App\Enums\Feature;
use App\Enums\OrganizationRole;
use App\Models\Commit;
use App\Models\Device;
use App\Models\Notification;
use App\Models\Organization;
use App\Models\User;
use App\Services\Features;

it('returns the signed-in user with their unread notifications and their pastéis', function (): void {
$this->travelTo(now()->setDate(2026, 10, 17)->setTime(9, 15));
Expand Down Expand Up @@ -76,7 +74,7 @@
'unread_count' => 0,
],
'organizations' => [],
'can_post_as_organization' => false,
'can_post_as_organization' => true,
],
'unread_notifications_count' => 1,
]);
Expand All @@ -103,8 +101,6 @@
});

it("returns the organizations the user can post as, oldest membership first, like the web's Post as menu", function (): void {
resolve(Features::class)->update(Feature::OrganizationCommits, true);

$user = User::factory()->create();
$keyPair = apiKeyPairFor($user);
$laravel = Organization::factory()->create(['handle' => 'laravel', 'name' => 'Laravel']);
Expand Down Expand Up @@ -139,19 +135,6 @@
->assertJsonCount(2, 'data.organizations');
});

it('says when posting as an organization is switched off, keeping the organizations', function (): void {
resolve(Features::class)->update(Feature::OrganizationCommits, false);

$user = User::factory()->create();
$keyPair = apiKeyPairFor($user);
Organization::factory()->create()->members()->attach($user->id, ['role' => OrganizationRole::Member]);

signedApiRequest($keyPair, 'GET', route('api-current-user.show'))
->assertOk()
->assertJsonPath('data.can_post_as_organization', false)
->assertJsonCount(1, 'data.organizations');
});

it('keeps those to the signed-in user, even on their own profile', function (): void {
$user = User::factory()->create(['preferred_lane' => 1]);
$keyPair = apiKeyPairFor($user);
Expand Down