-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(admin): settings ui #4866
Open
alexevladgabriel
wants to merge
16
commits into
pterodactyl:develop
Choose a base branch
from
alexevladgabriel:feat/settings-ui
base: develop
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(admin): settings ui #4866
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c4559a6
fix: solved routing handler for admin settings
alexevladgabriel 088af0d
feat(settings-ui): Added security container & added default recaptcha…
alexevladgabriel 240e1e3
feat(settings-ui): added controller for settings
alexevladgabriel f71a626
fix: remove Google Analytics
alexevladgabriel 4fa832b
ui(admin): added advanced settings, settings service/transformer & fi…
alexevladgabriel 2e2007e
ui(admin): glueing backend and frontend
alexevladgabriel d2a3511
fix: created store for settings page
alexevladgabriel 47d4bda
Merge branch 'develop' into feat/settings-ui
alexevladgabriel 4a5747c
Merge branch 'develop' into feat/settings-ui
alexevladgabriel 8056d0a
fix buttons
alexevladgabriel 39dbbcf
work on settings ui
alexevladgabriel f2521d1
fix: gravatar url
alexevladgabriel a9f7c5f
Merge branch 'fix/gravatar' into feat/settings-ui
alexevladgabriel 8609ccc
add handlers for mail & security
alexevladgabriel 4c9dbbc
fix request security
alexevladgabriel 70032c1
revert relative paths
alexevladgabriel File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
app/Http/Controllers/Api/Application/SettingsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Pterodactyl\Http\Controllers\Api\Application; | ||
|
||
use Illuminate\Http\Response; | ||
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface; | ||
use Pterodactyl\Exceptions\Model\DataValidationException; | ||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException; | ||
use Illuminate\Contracts\Console\Kernel; | ||
use Pterodactyl\Http\Requests\Api\Application\Settings\UpdateSettingsRequest; | ||
use Pterodactyl\Services\Helpers\SettingsService; | ||
use Pterodactyl\Traits\Helpers\AvailableLanguages; | ||
use Pterodactyl\Transformers\Api\Application\SettingsTransformer; | ||
|
||
class SettingsController extends ApplicationApiController | ||
{ | ||
use AvailableLanguages; | ||
|
||
/** | ||
* VersionController constructor. | ||
* | ||
* @param Kernel $kernel | ||
* @param SettingsService $settingsService | ||
* @param SettingsRepositoryInterface $settingsRepository | ||
*/ | ||
public function __construct( | ||
private readonly Kernel $kernel, | ||
private readonly SettingsService $settingsService, | ||
private readonly SettingsRepositoryInterface $settingsRepository | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Returns current settings of panel. | ||
*/ | ||
public function index(): array | ||
{ | ||
return $this->fractal->item($this->settingsService->getCurrentSettings())->transformWith(SettingsTransformer::class)->toArray(); | ||
} | ||
|
||
/** | ||
* Handle settings update. | ||
* | ||
* @throws DataValidationException | ||
* @throws RecordNotFoundException | ||
*/ | ||
public function update(UpdateSettingsRequest $request): Response | ||
{ | ||
$data = $request->validated(); | ||
|
||
foreach($data as $key => $value) { | ||
$this->settingsRepository->set($key, $value); | ||
} | ||
|
||
$this->kernel->call('queue:clear'); | ||
return response()->noContent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/Http/Requests/Api/Application/Settings/UpdateSettingsRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Pterodactyl\Http\Requests\Api\Application\Settings; | ||
|
||
use Illuminate\Validation\Rule; | ||
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest; | ||
use Pterodactyl\Traits\Helpers\AvailableLanguages; | ||
|
||
class UpdateSettingsRequest extends ApplicationApiRequest | ||
{ | ||
use AvailableLanguages; | ||
|
||
public function rules(): array | ||
{ | ||
return [ | ||
// General | ||
'appName' => 'sometimes|required|string|max:191', | ||
'language' => ['sometimes', 'required', 'string', Rule::in(array_keys($this->getAvailableLanguages()))], | ||
|
||
'smtpHost' => 'sometimes|required|string', | ||
'smtpPort' => 'sometimes|required|integer|between:1,65535', | ||
'smtpEncryption' => ['sometimes', 'present', Rule::in([null, 'tls', 'ssl'])], | ||
'smtpUsername' => 'sometimes|nullable|string|max:191', | ||
'smtpPassword' => 'sometimes|nullable|string|max:191', | ||
'smtpMailFrom' => 'sometimes|required|string|email', | ||
'smtpMailFromName' => 'sometimes|nullable|string|max:191', | ||
|
||
// Security | ||
'recaptchaEnabled' => 'sometimes|required|boolean', | ||
'recaptchaSiteKey' => 'sometimes|required_if:recaptchaEnabled,true|string|max:191', | ||
'recaptchaSecretKey' => 'sometimes|required_if:recaptchaEnabled,true|string|max:191', | ||
'sfaEnabled' => 'sometimes|required|integer|between:0,2', | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Pterodactyl\Services\Helpers; | ||
|
||
use Pterodactyl\Repositories\Eloquent\SettingsRepository; | ||
use Pterodactyl\Traits\Helpers\AvailableLanguages; | ||
use Pterodactyl\Models\Setting; | ||
|
||
class SettingsService | ||
{ | ||
use AvailableLanguages; | ||
|
||
public function __construct(private readonly SettingsRepository $repository) {} | ||
|
||
/** | ||
* Return the current version of the panel that is being used. | ||
*/ | ||
public function getCurrentSettings(): array | ||
{ | ||
return array( | ||
'general' => [ | ||
'name' => $this->repository->get('appName', config('app.name')), | ||
'language' => $this->repository->get('language', config('app.locale')), | ||
'languages' => $this->getAvailableLanguages(true), | ||
], | ||
'mail' => [ | ||
'host' => $this->repository->get('smtpHost', config('mail.mailers.smtp.host')), | ||
'port' => $this->repository->get('smtpPort', config('mail.mailers.smtp.port')), | ||
'encryption' => $this->repository->get('smtpEncryption', config('mail.mailers.smtp.encryption')), | ||
'username' => $this->repository->get('smtpUsername', config('mail.mailers.smtp.username')), | ||
'password' => $this->repository->get('smtpPassword', config('mail.mailers.smtp.password')), | ||
'from_address' => $this->repository->get('smtpMailFrom', config('mail.from.address')), | ||
'from_name' => $this->repository->get('smtpMailFromName', config('mail.from.name')), | ||
], | ||
'security' => [ | ||
'recaptcha' => [ | ||
'enabled' => $this->repository->get('recaptchaEnabled' , config('recaptcha.enabled')), | ||
'site_key' => $this->repository->get('recaptchaSiteKey', config('recaptcha.website_key')), | ||
'secret_key' => $this->repository->get('recaptchaSecretKey', config('recaptcha.secret_key')), | ||
], | ||
'2fa_enabled' => $this->repository->get('sfaEnabled', config('pterodactyl.auth.2fa_required')), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Pterodactyl\Transformers\Api\Application; | ||
|
||
use Pterodactyl\Models\Setting; | ||
use Pterodactyl\Transformers\Api\Transformer; | ||
|
||
class SettingsTransformer extends Transformer | ||
{ | ||
/** | ||
* Return the resource name for the JSONAPI output. | ||
*/ | ||
public function getResourceName(): string | ||
{ | ||
return Setting::RESOURCE_NAME; | ||
} | ||
|
||
/** | ||
* Return a generic transformed server variable array. | ||
*/ | ||
public function transform(array $model): array | ||
{ | ||
return [ | ||
'general' => [ | ||
'name' => $model['general']['name'], | ||
'language' => $model['general']['language'], | ||
'languages' => $model['general']['languages'], | ||
], | ||
'mail' => [ | ||
'host' => $model['mail']['host'], | ||
'port' => $model['mail']['port'], | ||
'from_address' => $model['mail']['from_address'], | ||
'from_name' => $model['mail']['from_name'], | ||
'encryption' => $model['mail']['encryption'], | ||
'username' => $model['mail']['username'], | ||
'password' => $model['mail']['password'], | ||
], | ||
'security' => [ | ||
'recaptcha' => [ | ||
'enabled' => $model['security']['recaptcha']['enabled'], | ||
'site_key' => $model['security']['recaptcha']['site_key'], | ||
'secret_key' => $model['security']['recaptcha']['secret_key'], | ||
], | ||
'2fa_enabled' => $model['security']['2fa_enabled'], | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Model } from '@/api/admin/index'; | ||
import http from '@/api/http'; | ||
import Transformers from '../definitions/admin/transformers'; | ||
|
||
export interface Settings { | ||
general: GeneralSettings; | ||
mail: MailSettings; | ||
security: SecuritySettings; | ||
} | ||
|
||
export interface GeneralSettings { | ||
name: string; | ||
language: LanguageKey; | ||
languages: Record<LanguageKey, 'string'>; | ||
} | ||
|
||
export type LanguageKey = 'en' | 'es' | 'ro'; | ||
|
||
export interface MailSettings { | ||
host: string; | ||
port: number; | ||
username: string; | ||
password: string; | ||
encryption: string; | ||
fromAddress: string; | ||
fromName: string; | ||
} | ||
|
||
export interface SecuritySettings { | ||
recaptcha: { | ||
enabled: boolean; | ||
siteKey: string; | ||
secretKey: string; | ||
}; | ||
'2faEnabled': boolean; | ||
} | ||
|
||
// export const getSettings = () => { | ||
// return useSWR<Settings>('settings', async () => { | ||
// const { data } = await http.get(`/api/application/settings`); | ||
|
||
// return Transformers.toSettings(data); | ||
// }); | ||
// }; | ||
|
||
export const getSettings = (): Promise<Settings> => { | ||
return new Promise((resolve, reject) => { | ||
http.get('/api/application/settings') | ||
.then(({ data }) => resolve(Transformers.toSettings(data))) | ||
.catch(reject); | ||
}); | ||
}; | ||
|
||
export const updateSetting = <Type>(values: Type): Promise<void> => { | ||
return new Promise((resolve, reject) => { | ||
http.patch('/api/application/settings', { ...values }) | ||
.then(() => resolve()) | ||
.catch(reject); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewpi is a good idea to use transformers for settings page, for me at least it seems more boilerplate code?