feat: theming
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
74
core/lib/Controllers/TenantSettingsController.php
Normal file
74
core/lib/Controllers/TenantSettingsController.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace KTXC\Controllers;
|
||||
|
||||
use KTXC\Http\Response\JsonResponse;
|
||||
use KTXC\Service\TenantService;
|
||||
use KTXC\SessionTenant;
|
||||
use KTXF\Controller\ControllerAbstract;
|
||||
use KTXF\Routing\Attributes\AuthenticatedRoute;
|
||||
|
||||
/**
|
||||
* Tenant-scoped settings controller.
|
||||
*
|
||||
* Mirrors UserSettingsController but operates on the current tenant record
|
||||
* rather than the current user. Write access is guarded by the
|
||||
* `tenant.settings.update` permission so only administrators can mutate
|
||||
* tenant-wide configuration.
|
||||
*/
|
||||
class TenantSettingsController extends ControllerAbstract
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SessionTenant $tenantIdentity,
|
||||
private readonly TenantService $tenantService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Retrieve all settings for the current tenant.
|
||||
*
|
||||
* @return JsonResponse Settings data as key-value pairs
|
||||
*/
|
||||
#[AuthenticatedRoute(
|
||||
'/tenant/settings',
|
||||
name: 'tenant.settings.read',
|
||||
methods: ['GET'],
|
||||
permissions: ['tenant.settings.read'],
|
||||
)]
|
||||
public function read(): JsonResponse
|
||||
{
|
||||
$settings = $this->tenantService->fetchSettings($this->tenantIdentity->identifier());
|
||||
|
||||
return new JsonResponse($settings, JsonResponse::HTTP_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update one or more settings for the current tenant.
|
||||
*
|
||||
* @param array $data Key-value pairs to persist
|
||||
*
|
||||
* @example request body:
|
||||
* {
|
||||
* "data": {
|
||||
* "default_mode": "dark",
|
||||
* "primary_color": "#6366F1",
|
||||
* "lock_user_colors": true
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @return JsonResponse The updated values that were written
|
||||
*/
|
||||
#[AuthenticatedRoute(
|
||||
'/tenant/settings',
|
||||
name: 'tenant.settings.update',
|
||||
methods: ['PUT', 'PATCH'],
|
||||
permissions: ['tenant.settings.update'],
|
||||
)]
|
||||
public function update(array $data): JsonResponse
|
||||
{
|
||||
$this->tenantService->storeSettings($this->tenantIdentity->identifier(), $data);
|
||||
|
||||
$updatedSettings = $this->tenantService->fetchSettings($this->tenantIdentity->identifier(), array_keys($data));
|
||||
|
||||
return new JsonResponse($updatedSettings, JsonResponse::HTTP_OK);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user