diff --git a/app/Extensions/Avatar/AvatarService.php b/app/Extensions/Avatar/AvatarService.php index 8eabdf93c..06dee6af4 100644 --- a/app/Extensions/Avatar/AvatarService.php +++ b/app/Extensions/Avatar/AvatarService.php @@ -44,4 +44,10 @@ class AvatarService $this->schemas[$schema->getId()] = $schema; } + + /** @return array */ + public function getMapping(): array + { + return collect($this->schemas)->mapWithKeys(fn ($schema) => [$schema->getId() => $schema->getName()])->all(); + } } diff --git a/app/Extensions/Features/FeatureService.php b/app/Extensions/Features/FeatureService.php index b252fe4f0..57ba6f1b1 100644 --- a/app/Extensions/Features/FeatureService.php +++ b/app/Extensions/Features/FeatureService.php @@ -2,6 +2,8 @@ namespace App\Extensions\Features; +use App\Models\Server; + class FeatureService { /** @var FeatureSchemaInterface[] */ @@ -28,4 +30,12 @@ class FeatureService $this->schemas[$schema->getId()] = $schema; } + + /** @return array> */ + public function getMappings(Server $server): array + { + return collect($this->get($server->egg->features))->mapWithKeys(fn (FeatureSchemaInterface $schema) => [ + $schema->getId() => $schema->getListeners(), + ])->all(); + } } diff --git a/app/Extensions/OAuth/OAuthSchemaInterface.php b/app/Extensions/OAuth/OAuthSchemaInterface.php index 6c5e0ebd0..837705888 100644 --- a/app/Extensions/OAuth/OAuthSchemaInterface.php +++ b/app/Extensions/OAuth/OAuthSchemaInterface.php @@ -9,6 +9,10 @@ interface OAuthSchemaInterface { public function getId(): string; + public function getName(): string; + + public function getConfigKey(): string; + /** @return ?class-string */ public function getSocialiteProvider(): ?string; @@ -23,8 +27,6 @@ interface OAuthSchemaInterface /** @return Step[] */ public function getSetupSteps(): array; - public function getName(): string; - public function getIcon(): ?string; public function getHexColor(): ?string; diff --git a/app/Extensions/OAuth/Schemas/CommonSchema.php b/app/Extensions/OAuth/Schemas/CommonSchema.php index cdc1764b4..ad42041ab 100644 --- a/app/Extensions/OAuth/Schemas/CommonSchema.php +++ b/app/Extensions/OAuth/Schemas/CommonSchema.php @@ -6,8 +6,10 @@ final class CommonSchema extends OAuthSchema { public function __construct( private readonly string $id, - private readonly ?string $icon, - private readonly ?string $hexColor + private readonly ?string $name = null, + private readonly ?string $configName = null, + private readonly ?string $icon = null, + private readonly ?string $hexColor = null ) {} public function getId(): string @@ -15,6 +17,16 @@ final class CommonSchema extends OAuthSchema return $this->id; } + public function getName(): string + { + return $this->name ?? parent::getName(); + } + + public function getConfigKey(): string + { + return $this->configName ?? parent::getConfigKey(); + } + public function getIcon(): ?string { return $this->icon; diff --git a/app/Extensions/OAuth/Schemas/OAuthSchema.php b/app/Extensions/OAuth/Schemas/OAuthSchema.php index 5ed1a1596..f849fe097 100644 --- a/app/Extensions/OAuth/Schemas/OAuthSchema.php +++ b/app/Extensions/OAuth/Schemas/OAuthSchema.php @@ -76,6 +76,13 @@ abstract class OAuthSchema implements OAuthSchemaInterface return Str::title($this->getId()); } + public function getConfigKey(): string + { + $id = Str::upper($this->getId()); + + return "OAUTH_{$id}_ENABLED"; + } + public function getIcon(): ?string { return null; diff --git a/app/Filament/Admin/Pages/Settings.php b/app/Filament/Admin/Pages/Settings.php index 53ecf4447..c39e32663 100644 --- a/app/Filament/Admin/Pages/Settings.php +++ b/app/Filament/Admin/Pages/Settings.php @@ -180,7 +180,7 @@ class Settings extends Page implements HasForms Select::make('FILAMENT_AVATAR_PROVIDER') ->label(trans('admin/setting.general.avatar_provider')) ->native(false) - ->options(collect($this->avatarService->get())->mapWithKeys(fn ($schema) => [$schema->getId() => $schema->getName()])) + ->options($this->avatarService->getMapping()) ->selectablePlaceholder(false) ->default(env('FILAMENT_AVATAR_PROVIDER', config('panel.filament.avatar-provider'))), Toggle::make('FILAMENT_UPLOADABLE_AVATARS') @@ -535,36 +535,34 @@ class Settings extends Page implements HasForms $oauthSchemas = $this->oauthService->get(); foreach ($oauthSchemas as $schema) { $id = Str::upper($schema->getId()); - $name = Str::title($schema->getId()); + $key = $schema->getConfigKey(); - $formFields[] = Section::make($name) + $formFields[] = Section::make($schema->getName()) ->columns(5) ->icon($schema->getIcon() ?? 'tabler-brand-oauth') - ->collapsed(fn () => !env("OAUTH_{$id}_ENABLED", false)) + ->collapsed(fn () => !env($key, false)) ->collapsible() ->schema([ - Hidden::make("OAUTH_{$id}_ENABLED") + Hidden::make($key) ->live() - ->default(env("OAUTH_{$id}_ENABLED")), + ->default(env($key)), Actions::make([ FormAction::make("disable_oauth_$id") - ->visible(fn (Get $get) => $get("OAUTH_{$id}_ENABLED")) + ->visible(fn (Get $get) => $get($key)) ->label(trans('admin/setting.oauth.disable')) ->color('danger') - ->action(function (Set $set) use ($id) { - $set("OAUTH_{$id}_ENABLED", false); - }), + ->action(fn (Set $set) => $set($key, false)), FormAction::make("enable_oauth_$id") - ->visible(fn (Get $get) => !$get("OAUTH_{$id}_ENABLED")) + ->visible(fn (Get $get) => !$get($key)) ->label(trans('admin/setting.oauth.enable')) ->color('success') ->steps($schema->getSetupSteps()) - ->modalHeading(trans('admin/setting.oauth.enable') . ' ' . $name) + ->modalHeading(trans('admin/setting.oauth.enable') . ' ' . $schema->getName()) ->modalSubmitActionLabel(trans('admin/setting.oauth.enable')) ->modalCancelAction(false) - ->action(function ($data, Set $set) use ($id) { + ->action(function ($data, Set $set) use ($key) { $data = array_merge([ - "OAUTH_{$id}_ENABLED" => 'true', + $key => 'true', ], $data); foreach ($data as $key => $value) { @@ -573,7 +571,7 @@ class Settings extends Page implements HasForms }), ])->columnSpan(1), Group::make($schema->getSettingsForm()) - ->visible(fn (Get $get) => $get("OAUTH_{$id}_ENABLED")) + ->visible(fn (Get $get) => $get($key)) ->columns(4) ->columnSpan(4), ]); diff --git a/app/Filament/Server/Pages/Console.php b/app/Filament/Server/Pages/Console.php index d830ae881..cb8bb6339 100644 --- a/app/Filament/Server/Pages/Console.php +++ b/app/Filament/Server/Pages/Console.php @@ -69,10 +69,11 @@ class Console extends Page public function mountFeature(string $data): void { $data = json_decode($data); - $feature = data_get($data, 'key'); + //$feature = data_get($data, 'key'); + $feature = 'test'; $feature = $this->featureService->get($feature); - if ($this->getMountedAction()) { + if (/*!$feature || */ $this->getMountedAction()) { return; } $this->mountAction($feature->getId()); diff --git a/app/Providers/Extensions/OAuthServiceProvider.php b/app/Providers/Extensions/OAuthServiceProvider.php index aa5d03bc0..b021e5050 100644 --- a/app/Providers/Extensions/OAuthServiceProvider.php +++ b/app/Providers/Extensions/OAuthServiceProvider.php @@ -18,14 +18,14 @@ class OAuthServiceProvider extends ServiceProvider $this->app->singleton(OAuthService::class, function ($app) { $service = new OAuthService(); // Default OAuth providers included with Socialite - $service->register(new CommonSchema('facebook', 'tabler-brand-facebook-f', '#1877f2')); - $service->register(new CommonSchema('x', 'tabler-brand-x-f', '#1da1f2')); - $service->register(new CommonSchema('linkedin', 'tabler-brand-linkedin-f', '#0a66c2')); - $service->register(new CommonSchema('google', 'tabler-brand-google-f', '#4285f4')); + $service->register(new CommonSchema('facebook', icon: 'tabler-brand-facebook-f', hexColor: '#1877f2')); + $service->register(new CommonSchema('x', icon: 'tabler-brand-x-f', hexColor: '#1da1f2')); + $service->register(new CommonSchema('linkedin', icon: 'tabler-brand-linkedin-f', hexColor: '#0a66c2')); + $service->register(new CommonSchema('google', icon: 'tabler-brand-google-f', hexColor: '#4285f4')); $service->register(new GithubSchema()); $service->register(new GitlabSchema()); - $service->register(new CommonSchema('bitbucket', 'tabler-brand-bitbucket-f', '#205081')); - $service->register(new CommonSchema('slack', 'tabler-brand-slack', '#6ecadc')); + $service->register(new CommonSchema('bitbucket', icon: 'tabler-brand-bitbucket-f', hexColor: '#205081')); + $service->register(new CommonSchema('slack', icon: 'tabler-brand-slack', hexColor: '#6ecadc')); // Additional OAuth providers from socialiteproviders.com $service->register(new AuthentikSchema()); diff --git a/app/Services/Servers/ServerConfigurationStructureService.php b/app/Services/Servers/ServerConfigurationStructureService.php index 4a4662c6f..9190cb16c 100644 --- a/app/Services/Servers/ServerConfigurationStructureService.php +++ b/app/Services/Servers/ServerConfigurationStructureService.php @@ -3,7 +3,6 @@ namespace App\Services\Servers; use App\Extensions\Features\FeatureService; -use App\Extensions\Features\FeatureSchemaInterface; use App\Models\Egg; use App\Models\Mount; use App\Models\Server; @@ -61,7 +60,7 @@ class ServerConfigurationStructureService * default: array{ip: string, port: int}, * mappings: array, * }, - * egg: array{id: string, file_denylist: string[]}, + * egg: array{id: string, file_denylist: string[], features: string[][]}, * labels?: string[], * mounts: array{source: string, target: string, read_only: bool}, * } @@ -104,9 +103,7 @@ class ServerConfigurationStructureService 'egg' => [ 'id' => $server->egg->uuid, 'file_denylist' => $server->egg->inherit_file_denylist, - 'features' => collect($this->featureService->get($server->egg->features))->mapWithKeys(fn (FeatureSchemaInterface $feature) => [ - $feature->getId() => $feature->getListeners(), - ])->all(), + 'features' => $this->featureService->getMappings($server), ], ]; diff --git a/package.json b/package.json index e4cbee185..13053bf2c 100644 --- a/package.json +++ b/package.json @@ -17,5 +17,6 @@ "prettier": "^3.4.2", "tailwindcss": "^3.4.13", "vite": "^6.0" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" }