Skip to content

Commit d75529b

Browse files
committed
Fix null safety in Horizon gate, GitHub callback route, plugin name handling
- Handle null user in HorizonServiceProvider gate to prevent crash on unauthenticated Horizon requests - Fix undefined route 'customer.licenses' to 'customer.licenses.list' in GitHub OAuth callback - Add null safety to Plugin::routeParams() for plugins without a name set - Check for duplicate plugin name before updating in PluginSyncService to avoid unique constraint violation
1 parent b2be39d commit d75529b

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

app/Http/Controllers/GitHubIntegrationController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function handleCallback(): RedirectResponse
5757
'trace' => $e->getTraceAsString(),
5858
]);
5959

60-
$route = Auth::check() ? 'customer.licenses' : 'customer.login';
60+
$route = Auth::check() ? 'customer.licenses.list' : 'customer.login';
6161

6262
return to_route($route)
6363
->with('error', 'GitHub authentication failed. Please try again.');

app/Models/Plugin.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ public static function findByVendorPackageOrFail(string $vendor, string $package
4747
*/
4848
public function routeParams(): array
4949
{
50-
[$vendor, $package] = explode('/', $this->name);
50+
$parts = explode('/', $this->name ?? '');
5151

52-
return ['vendor' => $vendor, 'package' => $package];
52+
return [
53+
'vendor' => $parts[0] ?? '',
54+
'package' => $parts[1] ?? '',
55+
];
5356
}
5457

5558
protected $guarded = [];

app/Providers/HorizonServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function boot(): void
2828
protected function gate(): void
2929
{
3030
Gate::define('viewHorizon', function ($user = null) {
31-
return $user->isAdmin();
31+
return $user?->isAdmin() ?? false;
3232
});
3333
}
3434
}

app/Services/PluginSyncService.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,18 @@ public function sync(Plugin $plugin): bool
6565

6666
if ($composerData) {
6767
if (isset($composerData['name']) && ! $plugin->name) {
68-
$updateData['name'] = $composerData['name'];
68+
$existing = Plugin::where('name', $composerData['name'])
69+
->where('id', '!=', $plugin->id)
70+
->exists();
71+
72+
if (! $existing) {
73+
$updateData['name'] = $composerData['name'];
74+
} else {
75+
Log::warning('[PluginSync] Plugin name already taken', [
76+
'plugin_id' => $plugin->id,
77+
'name' => $composerData['name'],
78+
]);
79+
}
6980
}
7081

7182
if (isset($composerData['description'])) {

0 commit comments

Comments
 (0)