This commit is contained in:
Vehikl 2025-06-05 17:10:42 -04:00
parent 2ba50e616c
commit 53599feff9
10 changed files with 67 additions and 33 deletions

View File

@ -44,4 +44,10 @@ class AvatarService
$this->schemas[$schema->getId()] = $schema;
}
/** @return array<string, string> */
public function getMapping(): array
{
return collect($this->schemas)->mapWithKeys(fn ($schema) => [$schema->getId() => $schema->getName()])->all();
}
}

View File

@ -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<string, array<string>> */
public function getMappings(Server $server): array
{
return collect($this->get($server->egg->features))->mapWithKeys(fn (FeatureSchemaInterface $schema) => [
$schema->getId() => $schema->getListeners(),
])->all();
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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),
]);

View File

@ -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());

View File

@ -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());

View File

@ -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<int>,
* },
* 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),
],
];

View File

@ -17,5 +17,6 @@
"prettier": "^3.4.2",
"tailwindcss": "^3.4.13",
"vite": "^6.0"
}
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}