From 56e9bcb8346a6b8c63301abb08ad5b85959db63d Mon Sep 17 00:00:00 2001 From: antoine Date: Thu, 7 May 2026 11:47:17 +0200 Subject: [PATCH 1/4] add sharp_auth middleware to routes and refactor authentication handling --- src/Http/Controllers/SharpProtectedController.php | 3 --- src/Http/Middleware/SharpAuthenticate.php | 4 ++++ src/routes/api.php | 2 +- src/routes/web.php | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Http/Controllers/SharpProtectedController.php b/src/Http/Controllers/SharpProtectedController.php index 234240925..84cf2c786 100644 --- a/src/Http/Controllers/SharpProtectedController.php +++ b/src/Http/Controllers/SharpProtectedController.php @@ -15,8 +15,5 @@ public function __construct() { $this->entityManager = app(SharpEntityManager::class); $this->authorizationManager = app(SharpAuthorizationManager::class); - - $guardSuffix = sharp()->config()->get('auth.guard') ? ':'.sharp()->config()->get('auth.guard') : ''; - $this->middleware('sharp_auth'.$guardSuffix); } } diff --git a/src/Http/Middleware/SharpAuthenticate.php b/src/Http/Middleware/SharpAuthenticate.php index 31a0316c2..62dc2e54f 100644 --- a/src/Http/Middleware/SharpAuthenticate.php +++ b/src/Http/Middleware/SharpAuthenticate.php @@ -13,6 +13,10 @@ class SharpAuthenticate extends BaseAuthenticate { public function handle($request, Closure $next, ...$guards) { + $guards = empty($guards) && sharp()->config()->get('auth.guard') + ? [sharp()->config()->get('auth.guard')] + : $guards; + $this->authenticate($request, $guards); if (Gate::has('viewSharp')) { diff --git a/src/routes/api.php b/src/routes/api.php index 65993f5f0..8a8ca7ba0 100644 --- a/src/routes/api.php +++ b/src/routes/api.php @@ -24,7 +24,7 @@ Route::group([ 'prefix' => '/'.sharp()->config()->get('custom_url_segment').'/api', - 'middleware' => ['sharp_common', 'sharp_api'], + 'middleware' => ['sharp_common', 'sharp_api', 'sharp_auth'], ], function () { Route::get('/{globalFilter}/dashboard/{dashboardKey}/command/{commandKey}/form', [ApiDashboardCommandController::class, 'show']) ->name('code16.sharp.api.dashboard.command.form'); diff --git a/src/routes/web.php b/src/routes/web.php index 65d4aeeb2..d5b778a38 100644 --- a/src/routes/web.php +++ b/src/routes/web.php @@ -15,7 +15,7 @@ Route::group([ 'prefix' => '/'.sharp()->config()->get('custom_url_segment'), - 'middleware' => ['sharp_common', 'sharp_web'], + 'middleware' => ['sharp_common', 'sharp_web', 'sharp_auth'], ], function () { // Redirect GET routes without globalFilter Route::get('/', fn () => redirect( From 8ddd25e7a832e653a77f9f8c05a297ac4e39b267 Mon Sep 17 00:00:00 2001 From: antoine Date: Thu, 7 May 2026 12:37:26 +0200 Subject: [PATCH 2/4] Fix wrong redirection to 'login' --- src/Http/Middleware/SharpAuthenticate.php | 11 ++++++----- src/SharpInternalServiceProvider.php | 14 -------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/Http/Middleware/SharpAuthenticate.php b/src/Http/Middleware/SharpAuthenticate.php index 62dc2e54f..917ddefe3 100644 --- a/src/Http/Middleware/SharpAuthenticate.php +++ b/src/Http/Middleware/SharpAuthenticate.php @@ -4,6 +4,7 @@ use Closure; use Code16\Sharp\Auth\Impersonate\SharpImpersonationHandler; +use Code16\Sharp\Exceptions\SharpAuthenticationException; use Code16\Sharp\Exceptions\SharpTokenMismatchException; use Illuminate\Auth\Middleware\Authenticate as BaseAuthenticate; use Illuminate\Http\Request; @@ -37,15 +38,15 @@ protected function unauthenticated($request, array $guards) /** reflash status flashed in @see SharpTokenMismatchException::render */ session()->reflash(); - parent::unauthenticated($request, $guards); + throw new SharpAuthenticationException( + 'Unauthenticated.', + $guards, + $this->redirectTo($request) + ); } protected function redirectTo(Request $request) { - if ($loginPageUrl = sharp()->config()->get('auth.login_page_url')) { - return $loginPageUrl; - } - if (app(SharpImpersonationHandler::class)?->enabled()) { return route('code16.sharp.impersonate'); } diff --git a/src/SharpInternalServiceProvider.php b/src/SharpInternalServiceProvider.php index 31ed8b1f8..ec54685a1 100644 --- a/src/SharpInternalServiceProvider.php +++ b/src/SharpInternalServiceProvider.php @@ -28,7 +28,6 @@ use Code16\Sharp\Console\ReorderHandlerMakeCommand; use Code16\Sharp\Console\ServiceProviderMakeCommand; use Code16\Sharp\Console\ShowPageMakeCommand; -use Code16\Sharp\Exceptions\SharpAuthenticationException; use Code16\Sharp\Exceptions\SharpTokenMismatchException; use Code16\Sharp\Form\Eloquent\Uploads\Migration\CreateUploadsMigration; use Code16\Sharp\Form\Eloquent\Uploads\Thumbnails\SharpImageManager; @@ -42,7 +41,6 @@ use Code16\Sharp\View\Components\Content; use Code16\Sharp\View\Components\File as FileComponent; use Code16\Sharp\View\Components\Image; -use Illuminate\Auth\AuthenticationException; use Illuminate\Auth\Notifications\ResetPassword; use Illuminate\Console\Events\CommandStarting; use Illuminate\Contracts\Debug\ExceptionHandler; @@ -194,18 +192,6 @@ protected function registerViewExceptionMapper(): void return $exception; }); - - $handler->map(function (AuthenticationException $exception) { - if (request()->routeIs('code16.sharp.*')) { - return new SharpAuthenticationException( - $exception->getMessage(), - $exception->guards(), - $exception->redirectTo(request()) - ); - } - - return $exception; - }); } protected function clearAssetsPublicDirectoryOnPublish(): void From 13cc7e722573723cf27556eec929c0ac41e43c63 Mon Sep 17 00:00:00 2001 From: antoine Date: Thu, 7 May 2026 12:39:24 +0200 Subject: [PATCH 3/4] Refactor route definitions and middleware configurations for improved clarity and consistency --- .../Auth/ImpersonateController.php | 6 - src/Http/Controllers/Auth/LoginController.php | 7 - .../SharpRedirectIfAuthenticated.php | 2 + src/routes/api.php | 141 +++++++------- src/routes/auth/forgotten_password.php | 25 ++- src/routes/auth/impersonate.php | 17 +- src/routes/auth/login.php | 32 ++-- src/routes/auth/passkeys.php | 25 ++- src/routes/web.php | 177 +++++++++--------- 9 files changed, 209 insertions(+), 223 deletions(-) diff --git a/src/Http/Controllers/Auth/ImpersonateController.php b/src/Http/Controllers/Auth/ImpersonateController.php index 5b3efabf1..62711228b 100644 --- a/src/Http/Controllers/Auth/ImpersonateController.php +++ b/src/Http/Controllers/Auth/ImpersonateController.php @@ -11,12 +11,6 @@ class ImpersonateController extends Controller { - public function __construct() - { - $guardSuffix = sharp()->config()->get('auth.guard') ? ':'.sharp()->config()->get('auth.guard') : ''; - $this->middleware('sharp_guest'.$guardSuffix); - } - public function create(?SharpImpersonationHandler $impersonationHandler): RedirectResponse|Response { return Inertia::render('Auth/Impersonate', [ diff --git a/src/Http/Controllers/Auth/LoginController.php b/src/Http/Controllers/Auth/LoginController.php index 54c2cc883..62390b255 100644 --- a/src/Http/Controllers/Auth/LoginController.php +++ b/src/Http/Controllers/Auth/LoginController.php @@ -15,13 +15,6 @@ class LoginController extends Controller { - public function __construct() - { - $guardSuffix = sharp()->config()->get('auth.guard') ? ':'.sharp()->config()->get('auth.guard') : ''; - $this->middleware('sharp_guest'.$guardSuffix)->only(['create', 'store']); - $this->middleware('sharp_auth'.$guardSuffix)->only('destroy'); - } - public function create(): RedirectResponse|Response { if ($loginPageUrl = sharp()->config()->get('auth.login_page_url')) { diff --git a/src/Http/Middleware/SharpRedirectIfAuthenticated.php b/src/Http/Middleware/SharpRedirectIfAuthenticated.php index c8abb524a..d32578167 100644 --- a/src/Http/Middleware/SharpRedirectIfAuthenticated.php +++ b/src/Http/Middleware/SharpRedirectIfAuthenticated.php @@ -9,6 +9,8 @@ class SharpRedirectIfAuthenticated { public function handle($request, Closure $next, $guard = null) { + $guard = $guard ?: sharp()->config()->get('auth.guard'); + if ($this->checkSharpUserAuthenticated($guard)) { return redirect(route('code16.sharp.home')); } diff --git a/src/routes/api.php b/src/routes/api.php index 8a8ca7ba0..5bf42bbe1 100644 --- a/src/routes/api.php +++ b/src/routes/api.php @@ -22,103 +22,102 @@ use Code16\Sharp\Http\Controllers\EntityListController; use Illuminate\Support\Facades\Route; -Route::group([ - 'prefix' => '/'.sharp()->config()->get('custom_url_segment').'/api', - 'middleware' => ['sharp_common', 'sharp_api', 'sharp_auth'], -], function () { - Route::get('/{globalFilter}/dashboard/{dashboardKey}/command/{commandKey}/form', [ApiDashboardCommandController::class, 'show']) - ->name('code16.sharp.api.dashboard.command.form'); +Route::middleware(['sharp_common', 'sharp_api', 'sharp_auth']) + ->prefix('/'.sharp()->config()->get('custom_url_segment').'/api') + ->group(function () { + Route::get('/{globalFilter}/dashboard/{dashboardKey}/command/{commandKey}/form', [ApiDashboardCommandController::class, 'show']) + ->name('code16.sharp.api.dashboard.command.form'); - Route::post('/{globalFilter}/dashboard/{dashboardKey}/command/{commandKey}', [ApiDashboardCommandController::class, 'update']) - ->name('code16.sharp.api.dashboard.command'); + Route::post('/{globalFilter}/dashboard/{dashboardKey}/command/{commandKey}', [ApiDashboardCommandController::class, 'update']) + ->name('code16.sharp.api.dashboard.command'); - Route::get('/{globalFilter}/list/{entityKey}/form/{formEntityKey}/create', [ApiEntityListQuickCreationCommandController::class, 'create']) - ->name('code16.sharp.api.list.command.quick-creation-form.create'); + Route::get('/{globalFilter}/list/{entityKey}/form/{formEntityKey}/create', [ApiEntityListQuickCreationCommandController::class, 'create']) + ->name('code16.sharp.api.list.command.quick-creation-form.create'); - Route::post('/{globalFilter}/list/{entityKey}/form/{formEntityKey}/create', [ApiEntityListQuickCreationCommandController::class, 'store']) - ->name('code16.sharp.api.list.command.quick-creation-form.store'); + Route::post('/{globalFilter}/list/{entityKey}/form/{formEntityKey}/create', [ApiEntityListQuickCreationCommandController::class, 'store']) + ->name('code16.sharp.api.list.command.quick-creation-form.store'); - // EmbeddedEntityLists - Route::get('/{globalFilter}/list/{entityKey}', [EntityListController::class, 'show']) - ->name('code16.sharp.api.list') - ->middleware('cache.headers:no_store'); + // EmbeddedEntityLists + Route::get('/{globalFilter}/list/{entityKey}', [EntityListController::class, 'show']) + ->name('code16.sharp.api.list') + ->middleware('cache.headers:no_store'); - Route::post('/{globalFilter}/list/{entityKey}/filters', [ApiEntityListFiltersController::class, 'store']) - ->name('code16.sharp.api.list.filters.store'); + Route::post('/{globalFilter}/list/{entityKey}/filters', [ApiEntityListFiltersController::class, 'store']) + ->name('code16.sharp.api.list.filters.store'); - Route::post('/{globalFilter}/list/{entityKey}/reorder', [ApiEntityListController::class, 'update']) - ->name('code16.sharp.api.list.reorder'); + Route::post('/{globalFilter}/list/{entityKey}/reorder', [ApiEntityListController::class, 'update']) + ->name('code16.sharp.api.list.reorder'); - Route::delete('/{globalFilter}/list/{entityKey}/{instanceId}', [ApiEntityListController::class, 'delete']) - ->name('code16.sharp.api.list.delete'); + Route::delete('/{globalFilter}/list/{entityKey}/{instanceId}', [ApiEntityListController::class, 'delete']) + ->name('code16.sharp.api.list.delete'); - Route::post('/{globalFilter}/list/{entityKey}/state/{instanceId}', [ApiEntityListEntityStateController::class, 'update']) - ->name('code16.sharp.api.list.state'); + Route::post('/{globalFilter}/list/{entityKey}/state/{instanceId}', [ApiEntityListEntityStateController::class, 'update']) + ->name('code16.sharp.api.list.state'); - Route::post('/{globalFilter}/list/{entityKey}/command/{commandKey}', [ApiEntityListEntityCommandController::class, 'update']) - ->name('code16.sharp.api.list.command.entity'); + Route::post('/{globalFilter}/list/{entityKey}/command/{commandKey}', [ApiEntityListEntityCommandController::class, 'update']) + ->name('code16.sharp.api.list.command.entity'); - Route::get('/{globalFilter}/list/{entityKey}/command/{commandKey}/form', [ApiEntityListEntityCommandController::class, 'show']) - ->name('code16.sharp.api.list.command.entity.form'); + Route::get('/{globalFilter}/list/{entityKey}/command/{commandKey}/form', [ApiEntityListEntityCommandController::class, 'show']) + ->name('code16.sharp.api.list.command.entity.form'); - Route::post('/{globalFilter}/list/{entityKey}/command/{commandKey}/{instanceId}', [ApiEntityListInstanceCommandController::class, 'update']) - ->name('code16.sharp.api.list.command.instance'); + Route::post('/{globalFilter}/list/{entityKey}/command/{commandKey}/{instanceId}', [ApiEntityListInstanceCommandController::class, 'update']) + ->name('code16.sharp.api.list.command.instance'); - Route::get('/{globalFilter}/list/{entityKey}/command/{commandKey}/{instanceId}/form', [ApiEntityListInstanceCommandController::class, 'show']) - ->name('code16.sharp.api.list.command.instance.form'); + Route::get('/{globalFilter}/list/{entityKey}/command/{commandKey}/{instanceId}/form', [ApiEntityListInstanceCommandController::class, 'show']) + ->name('code16.sharp.api.list.command.instance.form'); - // EmbeddedDashboards - Route::get('/{globalFilter}/dashboard/{dashboardKey}', [DashboardController::class, 'show']) - ->name('code16.sharp.api.dashboard') - ->middleware('cache.headers:no_store'); + // EmbeddedDashboards + Route::get('/{globalFilter}/dashboard/{dashboardKey}', [DashboardController::class, 'show']) + ->name('code16.sharp.api.dashboard') + ->middleware('cache.headers:no_store'); - Route::post('/{globalFilter}/dashboard/{dashboardKey}/filters', [ApiDashboardFiltersController::class, 'store']) - ->name('code16.sharp.api.dashboard.filters.store'); + Route::post('/{globalFilter}/dashboard/{dashboardKey}/filters', [ApiDashboardFiltersController::class, 'store']) + ->name('code16.sharp.api.dashboard.filters.store'); - Route::post('/{globalFilter}/show/{entityKey}/command/{commandKey}/{instanceId?}', [ApiShowInstanceCommandController::class, 'update']) - ->name('code16.sharp.api.show.command.instance'); + Route::post('/{globalFilter}/show/{entityKey}/command/{commandKey}/{instanceId?}', [ApiShowInstanceCommandController::class, 'update']) + ->name('code16.sharp.api.show.command.instance'); - Route::get('/{globalFilter}/show/{entityKey}/command/{commandKey}/{instanceId}/form', [ApiShowInstanceCommandController::class, 'show']) - ->name('code16.sharp.api.show.command.instance.form'); + Route::get('/{globalFilter}/show/{entityKey}/command/{commandKey}/{instanceId}/form', [ApiShowInstanceCommandController::class, 'show']) + ->name('code16.sharp.api.show.command.instance.form'); - // Specific route for single shows, because /show/{entityKey}/command/{commandKey}/{instanceId?}/data - // does not work since instanceId is optional but not the last segment. - Route::get('/{globalFilter}/show/{entityKey}/command/{commandKey}/form', [ApiShowInstanceCommandController::class, 'show']) - ->name('code16.sharp.api.show.command.singleInstance.form'); + // Specific route for single shows, because /show/{entityKey}/command/{commandKey}/{instanceId?}/data + // does not work since instanceId is optional but not the last segment. + Route::get('/{globalFilter}/show/{entityKey}/command/{commandKey}/form', [ApiShowInstanceCommandController::class, 'show']) + ->name('code16.sharp.api.show.command.singleInstance.form'); - Route::post('/{globalFilter}/show/{entityKey}/state/{instanceId?}', [ApiShowEntityStateController::class, 'update']) - ->name('code16.sharp.api.show.state'); + Route::post('/{globalFilter}/show/{entityKey}/state/{instanceId?}', [ApiShowEntityStateController::class, 'update']) + ->name('code16.sharp.api.show.state'); - Route::get('/{globalFilter}/search', [ApiSearchController::class, 'index']) - ->name('code16.sharp.api.search.index'); + Route::get('/{globalFilter}/search', [ApiSearchController::class, 'index']) + ->name('code16.sharp.api.search.index'); - Route::post('/{globalFilter}/embeds/{embedKey}/{entityKey}/form/init', [ApiEmbedsFormController::class, 'show']) - ->name('code16.sharp.api.embed.form.show'); + Route::post('/{globalFilter}/embeds/{embedKey}/{entityKey}/form/init', [ApiEmbedsFormController::class, 'show']) + ->name('code16.sharp.api.embed.form.show'); - Route::post('/{globalFilter}/embeds/{embedKey}/{entityKey}/form', [ApiEmbedsFormController::class, 'update']) - ->name('code16.sharp.api.embed.form.update'); + Route::post('/{globalFilter}/embeds/{embedKey}/{entityKey}/form', [ApiEmbedsFormController::class, 'update']) + ->name('code16.sharp.api.embed.form.update'); - Route::post('/{globalFilter}/embeds/{embedKey}/{entityKey}/{instanceId}/form/init', [ApiEmbedsFormController::class, 'show']) - ->name('code16.sharp.api.embed.instance.form.show'); + Route::post('/{globalFilter}/embeds/{embedKey}/{entityKey}/{instanceId}/form/init', [ApiEmbedsFormController::class, 'show']) + ->name('code16.sharp.api.embed.instance.form.show'); - Route::post('/{globalFilter}/embeds/{embedKey}/{entityKey}/{instanceId}/form', [ApiEmbedsFormController::class, 'update']) - ->name('code16.sharp.api.embed.instance.form.update'); + Route::post('/{globalFilter}/embeds/{embedKey}/{entityKey}/{instanceId}/form', [ApiEmbedsFormController::class, 'update']) + ->name('code16.sharp.api.embed.instance.form.update'); - Route::post('/{globalFilter}/form/editors/upload/form/{entityKey}/{instanceId?}', [ApiFormEditorUploadFormController::class, 'update']) - ->name('code16.sharp.api.form.editor.upload.form.update'); + Route::post('/{globalFilter}/form/editors/upload/form/{entityKey}/{instanceId?}', [ApiFormEditorUploadFormController::class, 'update']) + ->name('code16.sharp.api.form.editor.upload.form.update'); - Route::post('/{globalFilter}/upload/thumbnail/{entityKey}/{instanceId?}', [ApiFormUploadThumbnailController::class, 'show']) - ->name('code16.sharp.api.form.upload.thumbnail.show'); + Route::post('/{globalFilter}/upload/thumbnail/{entityKey}/{instanceId?}', [ApiFormUploadThumbnailController::class, 'show']) + ->name('code16.sharp.api.form.upload.thumbnail.show'); - Route::post('/{globalFilter}/upload/{entityKey}/{uploadFieldKey}', [ApiFormUploadController::class, 'store']) - ->name('code16.sharp.api.form.upload'); + Route::post('/{globalFilter}/upload/{entityKey}/{uploadFieldKey}', [ApiFormUploadController::class, 'store']) + ->name('code16.sharp.api.form.upload'); - Route::post('/{globalFilter}/form/autocomplete/{entityKey}/{autocompleteFieldKey}', [ApiFormAutocompleteController::class, 'index']) - ->name('code16.sharp.api.form.autocomplete.index'); + Route::post('/{globalFilter}/form/autocomplete/{entityKey}/{autocompleteFieldKey}', [ApiFormAutocompleteController::class, 'index']) + ->name('code16.sharp.api.form.autocomplete.index'); - Route::post('/{globalFilter}/form/refresh/{entityKey}', [ApiFormRefreshController::class, 'update']) - ->name('code16.sharp.api.form.refresh.update'); + Route::post('/{globalFilter}/form/refresh/{entityKey}', [ApiFormRefreshController::class, 'update']) + ->name('code16.sharp.api.form.refresh.update'); - Route::post('/{globalFilter}/filters/autocomplete/{entityKey}/{filterHandlerKey}', [ApiFilterAutocompleteController::class, 'index']) - ->name('code16.sharp.api.filters.autocomplete.index'); -}); + Route::post('/{globalFilter}/filters/autocomplete/{entityKey}/{filterHandlerKey}', [ApiFilterAutocompleteController::class, 'index']) + ->name('code16.sharp.api.filters.autocomplete.index'); + }); diff --git a/src/routes/auth/forgotten_password.php b/src/routes/auth/forgotten_password.php index 381ff7b81..2f958c04e 100644 --- a/src/routes/auth/forgotten_password.php +++ b/src/routes/auth/forgotten_password.php @@ -4,19 +4,18 @@ use Code16\Sharp\Http\Controllers\Auth\PasswordResetController; use Illuminate\Support\Facades\Route; -Route::group([ - 'prefix' => '/'.sharp()->config()->get('custom_url_segment'), - 'middleware' => ['sharp_common', 'sharp_web', 'sharp_guest'], -], function () { - Route::get('/forgot-password', [ForgotPasswordController::class, 'create']) - ->name('code16.sharp.password.request'); +Route::middleware(['sharp_common', 'sharp_web', 'sharp_guest']) + ->prefix('/'.sharp()->config()->get('custom_url_segment')) + ->group(function () { + Route::get('/forgot-password', [ForgotPasswordController::class, 'create']) + ->name('code16.sharp.password.request'); - Route::post('/forgot-password', [ForgotPasswordController::class, 'store']) - ->name('code16.sharp.password.request.post'); + Route::post('/forgot-password', [ForgotPasswordController::class, 'store']) + ->name('code16.sharp.password.request.post'); - Route::get('/reset-password/{token}', [PasswordResetController::class, 'create']) - ->name('code16.sharp.password.reset'); + Route::get('/reset-password/{token}', [PasswordResetController::class, 'create']) + ->name('code16.sharp.password.reset'); - Route::post('/reset-password', [PasswordResetController::class, 'store']) - ->name('code16.sharp.password.reset.post'); -}); + Route::post('/reset-password', [PasswordResetController::class, 'store']) + ->name('code16.sharp.password.reset.post'); + }); diff --git a/src/routes/auth/impersonate.php b/src/routes/auth/impersonate.php index 9414431e5..884d12137 100644 --- a/src/routes/auth/impersonate.php +++ b/src/routes/auth/impersonate.php @@ -3,13 +3,12 @@ use Code16\Sharp\Http\Controllers\Auth\ImpersonateController; use Illuminate\Support\Facades\Route; -Route::group([ - 'prefix' => '/'.sharp()->config()->get('custom_url_segment'), - 'middleware' => ['sharp_common', 'sharp_web', 'sharp_guest'], -], function () { - Route::get('/impersonate', [ImpersonateController::class, 'create']) - ->name('code16.sharp.impersonate'); +Route::middleware(['sharp_common', 'sharp_web', 'sharp_guest']) + ->prefix('/'.sharp()->config()->get('custom_url_segment')) + ->group(function () { + Route::get('/impersonate', [ImpersonateController::class, 'create']) + ->name('code16.sharp.impersonate'); - Route::post('/impersonate', [ImpersonateController::class, 'store']) - ->name('code16.sharp.impersonate.post'); -}); + Route::post('/impersonate', [ImpersonateController::class, 'store']) + ->name('code16.sharp.impersonate.post'); + }); diff --git a/src/routes/auth/login.php b/src/routes/auth/login.php index 15bb66d3c..eef994290 100644 --- a/src/routes/auth/login.php +++ b/src/routes/auth/login.php @@ -4,22 +4,24 @@ use Code16\Sharp\Http\Controllers\Auth\LoginController; use Illuminate\Support\Facades\Route; -Route::group([ - 'prefix' => '/'.sharp()->config()->get('custom_url_segment'), - 'middleware' => ['sharp_common', 'sharp_web'], -], function () { - Route::get('/login', [LoginController::class, 'create']) - ->name('code16.sharp.login'); +Route::middleware(['sharp_common', 'sharp_web']) + ->prefix('/'.sharp()->config()->get('custom_url_segment')) + ->group(function () { + Route::get('/login', [LoginController::class, 'create']) + ->middleware('sharp_guest') + ->name('code16.sharp.login'); - Route::post('/login', [LoginController::class, 'store']) - ->name('code16.sharp.login.post'); + Route::post('/login', [LoginController::class, 'store']) + ->middleware('sharp_guest') + ->name('code16.sharp.login.post'); - Route::get('/login/2fa', [Login2faController::class, 'create']) - ->name('code16.sharp.login.2fa'); + Route::get('/login/2fa', [Login2faController::class, 'create']) + ->name('code16.sharp.login.2fa'); - Route::post('/login/2fa', [Login2faController::class, 'store']) - ->name('code16.sharp.login.2fa.post'); + Route::post('/login/2fa', [Login2faController::class, 'store']) + ->name('code16.sharp.login.2fa.post'); - Route::post('/logout', [LoginController::class, 'destroy']) - ->name('code16.sharp.logout'); -}); + Route::post('/logout', [LoginController::class, 'destroy']) + ->middleware('sharp_auth') + ->name('code16.sharp.logout'); + }); diff --git a/src/routes/auth/passkeys.php b/src/routes/auth/passkeys.php index ab0985144..41ded79c8 100644 --- a/src/routes/auth/passkeys.php +++ b/src/routes/auth/passkeys.php @@ -4,19 +4,18 @@ use Code16\Sharp\Http\Controllers\Auth\Passkeys\PasskeySkipPromptController; use Illuminate\Support\Facades\Route; -Route::group([ - 'prefix' => '/'.sharp()->config()->get('custom_url_segment'), - 'middleware' => ['sharp_common', 'sharp_web', 'sharp_auth'], -], function () { - Route::get('/passkeys/create', [PasskeyController::class, 'create']) - ->name('code16.sharp.passkeys.create'); +Route::middleware(['sharp_common', 'sharp_web', 'sharp_auth']) + ->prefix('/'.sharp()->config()->get('custom_url_segment')) + ->group(function () { + Route::get('/passkeys/create', [PasskeyController::class, 'create']) + ->name('code16.sharp.passkeys.create'); - Route::post('/passkeys/validate', [PasskeyController::class, 'validate']) - ->name('code16.sharp.passkeys.validate'); + Route::post('/passkeys/validate', [PasskeyController::class, 'validate']) + ->name('code16.sharp.passkeys.validate'); - Route::post('/passkeys', [PasskeyController::class, 'store']) - ->name('code16.sharp.passkeys.store'); + Route::post('/passkeys', [PasskeyController::class, 'store']) + ->name('code16.sharp.passkeys.store'); - Route::post('/passkeys/skip-prompt', PasskeySkipPromptController::class) - ->name('code16.sharp.passkeys.skip-prompt'); -}); + Route::post('/passkeys/skip-prompt', PasskeySkipPromptController::class) + ->name('code16.sharp.passkeys.skip-prompt'); + }); diff --git a/src/routes/web.php b/src/routes/web.php index d5b778a38..3caf53243 100644 --- a/src/routes/web.php +++ b/src/routes/web.php @@ -13,106 +13,105 @@ use Code16\Sharp\Http\Controllers\UpdateAssetsController; use Illuminate\Support\Facades\Route; -Route::group([ - 'prefix' => '/'.sharp()->config()->get('custom_url_segment'), - 'middleware' => ['sharp_common', 'sharp_web', 'sharp_auth'], -], function () { - // Redirect GET routes without globalFilter - Route::get('/', fn () => redirect( - route('code16.sharp.home', [ - 'globalFilter' => sharp()->context()->globalFilterUrlSegmentValue(), - ]) - )); - Route::get('s-dashboard/{dashboardKey}', fn ($entityKey) => redirect( - route('code16.sharp.dashboard', [ - 'globalFilter' => sharp()->context()->globalFilterUrlSegmentValue(), - 'dashboardKey' => $entityKey, - ]) - )); - Route::get('s-list/{entityKey}', fn ($entityKey) => redirect( - route('code16.sharp.list', [ - 'globalFilter' => sharp()->context()->globalFilterUrlSegmentValue(), - 'entityKey' => $entityKey, - ]) - )); - Route::get('s-show/{entityKey}', fn ($entityKey) => redirect( - route('code16.sharp.single-show', [ - 'globalFilter' => sharp()->context()->globalFilterUrlSegmentValue(), - 'entityKey' => $entityKey, - ]) - )); - - Route::get('{globalFilter}/home', [HomeController::class, 'index']) - ->name('code16.sharp.home'); - - Route::get('{globalFilter}/s-dashboard/{dashboardKey}', [DashboardController::class, 'show']) - ->name('code16.sharp.dashboard'); - - Route::post('{globalFilter}/s-dashboard/{dashboardKey}', [DashboardFiltersController::class, 'store']) - ->name('code16.sharp.dashboard.filters.store'); - - Route::get('{globalFilter}/s-list/{entityKey}', [EntityListController::class, 'show']) - ->name('code16.sharp.list'); - - Route::post('{globalFilter}/s-list/{entityKey}/filters', [EntityListFiltersController::class, 'store']) - ->name('code16.sharp.list.filters.store'); - - Route::get('{globalFilter}/s-show/{entityKey}', [SingleShowController::class, 'show']) - ->name('code16.sharp.single-show'); - - Route::get('{globalFilter}/download/{entityKey}/{instanceId?}', [DownloadController::class, 'show']) - ->name('code16.sharp.download.show'); - - Route::where([ - 'parentUri' => '(s-list|s-show)/.+', - ])->group(function () { +Route::middleware(['sharp_common', 'sharp_web', 'sharp_auth']) + ->prefix('/'.sharp()->config()->get('custom_url_segment')) + ->group(function () { // Redirect GET routes without globalFilter - Route::get('{parentUri}/s-show/{entityKey}/{instanceId}', fn ($parentUri, $entityKey, $instanceId) => redirect( - route('code16.sharp.show.show', [ + Route::get('/', fn () => redirect( + route('code16.sharp.home', [ 'globalFilter' => sharp()->context()->globalFilterUrlSegmentValue(), - 'parentUri' => $parentUri, - 'entityKey' => $entityKey, - 'instanceId' => $instanceId, ]) )); - Route::get('{parentUri}/s-form/{entityKey}', fn ($parentUri, $entityKey) => redirect( - route('code16.sharp.form.create', [ + Route::get('s-dashboard/{dashboardKey}', fn ($entityKey) => redirect( + route('code16.sharp.dashboard', [ + 'globalFilter' => sharp()->context()->globalFilterUrlSegmentValue(), + 'dashboardKey' => $entityKey, + ]) + )); + Route::get('s-list/{entityKey}', fn ($entityKey) => redirect( + route('code16.sharp.list', [ 'globalFilter' => sharp()->context()->globalFilterUrlSegmentValue(), - 'parentUri' => $parentUri, 'entityKey' => $entityKey, ]) )); - Route::get('{parentUri}/s-form/{entityKey}/{instanceId}', fn ($parentUri, $entityKey, $instanceId) => redirect( - route('code16.sharp.form.edit', [ + Route::get('s-show/{entityKey}', fn ($entityKey) => redirect( + route('code16.sharp.single-show', [ 'globalFilter' => sharp()->context()->globalFilterUrlSegmentValue(), - 'parentUri' => $parentUri, 'entityKey' => $entityKey, - 'instanceId' => $instanceId, ]) )); - Route::get('/{globalFilter}/{parentUri}/s-show/{entityKey}/{instanceId}', [ShowController::class, 'show']) - ->name('code16.sharp.show.show'); - - Route::delete('/{globalFilter}/{parentUri}/s-show/{entityKey}/{instanceId}', [ShowController::class, 'delete']) - ->name('code16.sharp.show.delete'); - - Route::get('/{globalFilter}/{parentUri}/s-form/{entityKey}', [FormController::class, 'create']) - ->name('code16.sharp.form.create'); - - Route::post('/{globalFilter}/{parentUri}/s-form/{entityKey}', [FormController::class, 'store']) - ->name('code16.sharp.form.store'); - - Route::get('/{globalFilter}/{parentUri}/s-form/{entityKey}/{instanceId?}', [FormController::class, 'edit']) - ->name('code16.sharp.form.edit'); - - Route::post('/{globalFilter}/{parentUri}/s-form/{entityKey}/{instanceId?}', [FormController::class, 'update']) - ->name('code16.sharp.form.update'); + Route::get('{globalFilter}/home', [HomeController::class, 'index']) + ->name('code16.sharp.home'); + + Route::get('{globalFilter}/s-dashboard/{dashboardKey}', [DashboardController::class, 'show']) + ->name('code16.sharp.dashboard'); + + Route::post('{globalFilter}/s-dashboard/{dashboardKey}', [DashboardFiltersController::class, 'store']) + ->name('code16.sharp.dashboard.filters.store'); + + Route::get('{globalFilter}/s-list/{entityKey}', [EntityListController::class, 'show']) + ->name('code16.sharp.list'); + + Route::post('{globalFilter}/s-list/{entityKey}/filters', [EntityListFiltersController::class, 'store']) + ->name('code16.sharp.list.filters.store'); + + Route::get('{globalFilter}/s-show/{entityKey}', [SingleShowController::class, 'show']) + ->name('code16.sharp.single-show'); + + Route::get('{globalFilter}/download/{entityKey}/{instanceId?}', [DownloadController::class, 'show']) + ->name('code16.sharp.download.show'); + + Route::where([ + 'parentUri' => '(s-list|s-show)/.+', + ])->group(function () { + // Redirect GET routes without globalFilter + Route::get('{parentUri}/s-show/{entityKey}/{instanceId}', fn ($parentUri, $entityKey, $instanceId) => redirect( + route('code16.sharp.show.show', [ + 'globalFilter' => sharp()->context()->globalFilterUrlSegmentValue(), + 'parentUri' => $parentUri, + 'entityKey' => $entityKey, + 'instanceId' => $instanceId, + ]) + )); + Route::get('{parentUri}/s-form/{entityKey}', fn ($parentUri, $entityKey) => redirect( + route('code16.sharp.form.create', [ + 'globalFilter' => sharp()->context()->globalFilterUrlSegmentValue(), + 'parentUri' => $parentUri, + 'entityKey' => $entityKey, + ]) + )); + Route::get('{parentUri}/s-form/{entityKey}/{instanceId}', fn ($parentUri, $entityKey, $instanceId) => redirect( + route('code16.sharp.form.edit', [ + 'globalFilter' => sharp()->context()->globalFilterUrlSegmentValue(), + 'parentUri' => $parentUri, + 'entityKey' => $entityKey, + 'instanceId' => $instanceId, + ]) + )); + + Route::get('/{globalFilter}/{parentUri}/s-show/{entityKey}/{instanceId}', [ShowController::class, 'show']) + ->name('code16.sharp.show.show'); + + Route::delete('/{globalFilter}/{parentUri}/s-show/{entityKey}/{instanceId}', [ShowController::class, 'delete']) + ->name('code16.sharp.show.delete'); + + Route::get('/{globalFilter}/{parentUri}/s-form/{entityKey}', [FormController::class, 'create']) + ->name('code16.sharp.form.create'); + + Route::post('/{globalFilter}/{parentUri}/s-form/{entityKey}', [FormController::class, 'store']) + ->name('code16.sharp.form.store'); + + Route::get('/{globalFilter}/{parentUri}/s-form/{entityKey}/{instanceId?}', [FormController::class, 'edit']) + ->name('code16.sharp.form.edit'); + + Route::post('/{globalFilter}/{parentUri}/s-form/{entityKey}/{instanceId?}', [FormController::class, 'update']) + ->name('code16.sharp.form.update'); + }); + + Route::post('{globalFilter}/filters', [GlobalFilterController::class, 'update']) + ->name('code16.sharp.filters.update'); + + Route::post('/update-assets', UpdateAssetsController::class) + ->name('code16.sharp.update-assets'); }); - - Route::post('{globalFilter}/filters', [GlobalFilterController::class, 'update']) - ->name('code16.sharp.filters.update'); - - Route::post('/update-assets', UpdateAssetsController::class) - ->name('code16.sharp.update-assets'); -}); From a5be9d9e75a28509f83471ea5ae83304488a06ec Mon Sep 17 00:00:00 2001 From: antoine Date: Thu, 7 May 2026 13:07:00 +0200 Subject: [PATCH 4/4] Refactor controllers --- src/Http/Controllers/Api/ApiController.php | 26 ------------------- .../Api/ApiDashboardFiltersController.php | 6 +++-- .../Api/ApiEntityListController.php | 9 ++++--- .../Api/ApiEntityListFiltersController.php | 6 +++-- .../Api/ApiFilterAutocompleteController.php | 3 ++- .../Api/ApiFormAutocompleteController.php | 3 ++- .../Api/ApiFormEditorUploadFormController.php | 3 ++- .../Api/ApiFormRefreshController.php | 3 ++- .../Api/ApiFormUploadController.php | 3 ++- .../Api/ApiFormUploadThumbnailController.php | 3 ++- .../Controllers/Api/ApiSearchController.php | 3 ++- .../ApiDashboardCommandController.php | 8 +++--- .../ApiEntityListEntityCommandController.php | 8 +++--- .../ApiEntityListEntityStateController.php | 6 ++--- ...ApiEntityListInstanceCommandController.php | 8 +++--- ...tityListQuickCreationCommandController.php | 9 ++++--- .../Commands/ApiShowEntityStateController.php | 6 ++--- .../ApiShowInstanceCommandController.php | 6 ++--- .../Controllers/Api/DownloadController.php | 3 ++- .../Api/Embeds/ApiEmbedsFormController.php | 5 +--- ...ProtectedController.php => Controller.php} | 4 +-- src/Http/Controllers/DashboardController.php | 2 +- .../DashboardFiltersController.php | 2 +- src/Http/Controllers/EntityListController.php | 2 +- .../EntityListFiltersController.php | 2 +- src/Http/Controllers/FormController.php | 2 +- .../Controllers/GlobalFilterController.php | 2 +- src/Http/Controllers/HomeController.php | 2 +- src/Http/Controllers/ShowController.php | 2 +- src/Http/Controllers/SingleShowController.php | 2 +- .../Controllers/UpdateAssetsController.php | 2 +- 31 files changed, 68 insertions(+), 83 deletions(-) delete mode 100644 src/Http/Controllers/Api/ApiController.php rename src/Http/Controllers/{SharpProtectedController.php => Controller.php} (82%) diff --git a/src/Http/Controllers/Api/ApiController.php b/src/Http/Controllers/Api/ApiController.php deleted file mode 100644 index cf968e635..000000000 --- a/src/Http/Controllers/Api/ApiController.php +++ /dev/null @@ -1,26 +0,0 @@ -entityManager->entityFor($entityKey)->getListOrFail(); - } - - protected function getShowInstance(string $entityKey): SharpShow - { - return $this->entityManager->entityFor($entityKey)->getShowOrFail(); - } - - protected function getDashboardInstance(string $dashboardKey): ?SharpDashboard - { - return $this->entityManager->entityFor($dashboardKey)->getViewOrFail(); - } -} diff --git a/src/Http/Controllers/Api/ApiDashboardFiltersController.php b/src/Http/Controllers/Api/ApiDashboardFiltersController.php index b20a72708..fde25ae5c 100644 --- a/src/Http/Controllers/Api/ApiDashboardFiltersController.php +++ b/src/Http/Controllers/Api/ApiDashboardFiltersController.php @@ -2,13 +2,15 @@ namespace Code16\Sharp\Http\Controllers\Api; -class ApiDashboardFiltersController extends ApiController +use Code16\Sharp\Http\Controllers\Controller; + +class ApiDashboardFiltersController extends Controller { public function store(string $globalFilter, string $dashboardKey) { $this->authorizationManager->check('entity', $dashboardKey); - $dashboard = $this->getDashboardInstance($dashboardKey); + $dashboard = $this->entityManager->entityFor($dashboardKey)->getViewOrFail(); $dashboard->buildDashboardConfig(); $dashboard->filterContainer() diff --git a/src/Http/Controllers/Api/ApiEntityListController.php b/src/Http/Controllers/Api/ApiEntityListController.php index 5df67a5d6..0c8f0e4dd 100644 --- a/src/Http/Controllers/Api/ApiEntityListController.php +++ b/src/Http/Controllers/Api/ApiEntityListController.php @@ -5,8 +5,9 @@ use Code16\Sharp\EntityList\SharpEntityList; use Code16\Sharp\Exceptions\SharpInvalidEntityKeyException; use Code16\Sharp\Exceptions\SharpMethodNotImplementedException; +use Code16\Sharp\Http\Controllers\Controller; -class ApiEntityListController extends ApiController +class ApiEntityListController extends Controller { /** * Reorder instances. @@ -15,7 +16,7 @@ public function update(string $globalFilter, string $entityKey) { $this->authorizationManager->check('entity', $entityKey); - $list = $this->getListInstance($entityKey); + $list = $this->entityManager->entityFor($entityKey)->getListOrFail(); $list->buildListConfig(); $list->reorderHandler()->reorder(request('instances')); @@ -32,14 +33,14 @@ public function delete(string $globalFilter, string $entityKey, string $instance { $this->authorizationManager->check('delete', $entityKey, $instanceId); - $list = $this->getListInstance($entityKey); + $list = $this->entityManager->entityFor($entityKey)->getListOrFail(); $list->initQueryParams(request()->query()); if (self::isDeleteMethodImplementedInConcreteClass($list)) { $list->delete($instanceId); } else { try { - $show = $this->getShowInstance($entityKey); + $show = $this->entityManager->entityFor($entityKey)->getShowOrFail(); $show->delete($instanceId); } catch (SharpInvalidEntityKeyException $ex) { // No Show Page implementation was defined for this entity diff --git a/src/Http/Controllers/Api/ApiEntityListFiltersController.php b/src/Http/Controllers/Api/ApiEntityListFiltersController.php index 154eeb142..b5e864c82 100644 --- a/src/Http/Controllers/Api/ApiEntityListFiltersController.php +++ b/src/Http/Controllers/Api/ApiEntityListFiltersController.php @@ -2,13 +2,15 @@ namespace Code16\Sharp\Http\Controllers\Api; -class ApiEntityListFiltersController extends ApiController +use Code16\Sharp\Http\Controllers\Controller; + +class ApiEntityListFiltersController extends Controller { public function store(string $globalFilter, string $entityKey) { $this->authorizationManager->check('entity', $entityKey); - $list = $this->getListInstance($entityKey); + $list = $this->entityManager->entityFor($entityKey)->getListOrFail(); $list->buildListConfig(); $list->filterContainer() diff --git a/src/Http/Controllers/Api/ApiFilterAutocompleteController.php b/src/Http/Controllers/Api/ApiFilterAutocompleteController.php index 29fb2b7b8..1322c0326 100644 --- a/src/Http/Controllers/Api/ApiFilterAutocompleteController.php +++ b/src/Http/Controllers/Api/ApiFilterAutocompleteController.php @@ -3,10 +3,11 @@ namespace Code16\Sharp\Http\Controllers\Api; use Code16\Sharp\Filters\AutocompleteRemoteFilter; +use Code16\Sharp\Http\Controllers\Controller; use Code16\Sharp\Utils\Entities\SharpDashboardEntity; use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey; -class ApiFilterAutocompleteController extends ApiController +class ApiFilterAutocompleteController extends Controller { public function index(string $globalFilter, EntityKey $entityKey, string $filterHandlerKey): array { diff --git a/src/Http/Controllers/Api/ApiFormAutocompleteController.php b/src/Http/Controllers/Api/ApiFormAutocompleteController.php index 16faa4856..17ad9b99c 100644 --- a/src/Http/Controllers/Api/ApiFormAutocompleteController.php +++ b/src/Http/Controllers/Api/ApiFormAutocompleteController.php @@ -4,12 +4,13 @@ use Code16\Sharp\Exceptions\SharpInvalidConfigException; use Code16\Sharp\Form\Fields\SharpFormAutocompleteRemoteField; +use Code16\Sharp\Http\Controllers\Controller; use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey; use Illuminate\Http\Request; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Route; -class ApiFormAutocompleteController extends ApiController +class ApiFormAutocompleteController extends Controller { use HandlesFieldContainer; diff --git a/src/Http/Controllers/Api/ApiFormEditorUploadFormController.php b/src/Http/Controllers/Api/ApiFormEditorUploadFormController.php index 5286f6aba..65f1b680f 100644 --- a/src/Http/Controllers/Api/ApiFormEditorUploadFormController.php +++ b/src/Http/Controllers/Api/ApiFormEditorUploadFormController.php @@ -3,8 +3,9 @@ namespace Code16\Sharp\Http\Controllers\Api; use Code16\Sharp\Http\Controllers\Api\Requests\EditorUploadFormRequest; +use Code16\Sharp\Http\Controllers\Controller; -class ApiFormEditorUploadFormController extends ApiController +class ApiFormEditorUploadFormController extends Controller { public function update(string $globalFilter, EditorUploadFormRequest $request, string $entityKey, ?string $instanceId = null) { diff --git a/src/Http/Controllers/Api/ApiFormRefreshController.php b/src/Http/Controllers/Api/ApiFormRefreshController.php index cf907e79b..f06eb0664 100644 --- a/src/Http/Controllers/Api/ApiFormRefreshController.php +++ b/src/Http/Controllers/Api/ApiFormRefreshController.php @@ -2,9 +2,10 @@ namespace Code16\Sharp\Http\Controllers\Api; +use Code16\Sharp\Http\Controllers\Controller; use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey; -class ApiFormRefreshController extends ApiController +class ApiFormRefreshController extends Controller { use HandlesFieldContainer; diff --git a/src/Http/Controllers/Api/ApiFormUploadController.php b/src/Http/Controllers/Api/ApiFormUploadController.php index ef8d677c3..c60c8d4e0 100644 --- a/src/Http/Controllers/Api/ApiFormUploadController.php +++ b/src/Http/Controllers/Api/ApiFormUploadController.php @@ -4,11 +4,12 @@ use Code16\Sharp\Exceptions\SharpInvalidConfigException; use Code16\Sharp\Form\Fields\SharpFormEditorField; +use Code16\Sharp\Http\Controllers\Controller; use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey; use Code16\Sharp\Utils\FileUtil; use Illuminate\Foundation\Validation\ValidatesRequests; -class ApiFormUploadController extends ApiController +class ApiFormUploadController extends Controller { use HandlesFieldContainer; use ValidatesRequests; diff --git a/src/Http/Controllers/Api/ApiFormUploadThumbnailController.php b/src/Http/Controllers/Api/ApiFormUploadThumbnailController.php index 481dace0b..290a641a4 100644 --- a/src/Http/Controllers/Api/ApiFormUploadThumbnailController.php +++ b/src/Http/Controllers/Api/ApiFormUploadThumbnailController.php @@ -3,8 +3,9 @@ namespace Code16\Sharp\Http\Controllers\Api; use Code16\Sharp\Form\Eloquent\Uploads\Traits\UsesSharpUploadModel; +use Code16\Sharp\Http\Controllers\Controller; -class ApiFormUploadThumbnailController extends ApiController +class ApiFormUploadThumbnailController extends Controller { use UsesSharpUploadModel; diff --git a/src/Http/Controllers/Api/ApiSearchController.php b/src/Http/Controllers/Api/ApiSearchController.php index 48ccd49ec..c6b0b317d 100644 --- a/src/Http/Controllers/Api/ApiSearchController.php +++ b/src/Http/Controllers/Api/ApiSearchController.php @@ -3,10 +3,11 @@ namespace Code16\Sharp\Http\Controllers\Api; use Code16\Sharp\Data\SearchResultSetData; +use Code16\Sharp\Http\Controllers\Controller; use Code16\Sharp\Search\SearchResultSet; use Code16\Sharp\Utils\StringUtil; -class ApiSearchController extends ApiController +class ApiSearchController extends Controller { public function index(string $globalFilter) { diff --git a/src/Http/Controllers/Api/Commands/ApiDashboardCommandController.php b/src/Http/Controllers/Api/Commands/ApiDashboardCommandController.php index 79e5ee93d..244a4c4f1 100644 --- a/src/Http/Controllers/Api/Commands/ApiDashboardCommandController.php +++ b/src/Http/Controllers/Api/Commands/ApiDashboardCommandController.php @@ -3,10 +3,10 @@ namespace Code16\Sharp\Http\Controllers\Api\Commands; use Code16\Sharp\Data\Commands\CommandFormData; -use Code16\Sharp\Http\Controllers\Api\ApiController; +use Code16\Sharp\Http\Controllers\Controller; use Code16\Sharp\Utils\Uploads\SharpUploadManager; -class ApiDashboardCommandController extends ApiController +class ApiDashboardCommandController extends Controller { use HandlesCommandForm; use HandlesCommandResult; @@ -20,7 +20,7 @@ public function __construct( public function show(string $globalFilter, string $entityKey, string $commandKey) { - $dashboard = $this->getDashboardInstance($entityKey); + $dashboard = $this->entityManager->entityFor($entityKey)->getViewOrFail(); $dashboard->buildDashboardConfig(); $dashboard->initQueryParams(request()->query()); @@ -35,7 +35,7 @@ public function show(string $globalFilter, string $entityKey, string $commandKey public function update(string $globalFilter, string $entityKey, string $commandKey) { - $dashboard = $this->getDashboardInstance($entityKey); + $dashboard = $this->entityManager->entityFor($entityKey)->getViewOrFail(); $dashboard->buildDashboardConfig(); $dashboard->initQueryParams(request()->input('query')); diff --git a/src/Http/Controllers/Api/Commands/ApiEntityListEntityCommandController.php b/src/Http/Controllers/Api/Commands/ApiEntityListEntityCommandController.php index 1df4bf490..607f96280 100644 --- a/src/Http/Controllers/Api/Commands/ApiEntityListEntityCommandController.php +++ b/src/Http/Controllers/Api/Commands/ApiEntityListEntityCommandController.php @@ -3,10 +3,10 @@ namespace Code16\Sharp\Http\Controllers\Api\Commands; use Code16\Sharp\Data\Commands\CommandFormData; -use Code16\Sharp\Http\Controllers\Api\ApiController; +use Code16\Sharp\Http\Controllers\Controller; use Code16\Sharp\Utils\Uploads\SharpUploadManager; -class ApiEntityListEntityCommandController extends ApiController +class ApiEntityListEntityCommandController extends Controller { use HandlesCommandForm; use HandlesCommandResult; @@ -20,7 +20,7 @@ public function __construct( public function show(string $globalFilter, string $entityKey, string $commandKey) { - $list = $this->getListInstance($entityKey); + $list = $this->entityManager->entityFor($entityKey)->getListOrFail(); $list->buildListConfig(); $list->initQueryParams(request()->query()); @@ -35,7 +35,7 @@ public function show(string $globalFilter, string $entityKey, string $commandKey public function update(string $globalFilter, string $entityKey, string $commandKey) { - $list = $this->getListInstance($entityKey); + $list = $this->entityManager->entityFor($entityKey)->getListOrFail(); $list->buildListConfig(); $list->initQueryParams(request()->input('query')); diff --git a/src/Http/Controllers/Api/Commands/ApiEntityListEntityStateController.php b/src/Http/Controllers/Api/Commands/ApiEntityListEntityStateController.php index 586febf0f..d8650f556 100644 --- a/src/Http/Controllers/Api/Commands/ApiEntityListEntityStateController.php +++ b/src/Http/Controllers/Api/Commands/ApiEntityListEntityStateController.php @@ -3,16 +3,16 @@ namespace Code16\Sharp\Http\Controllers\Api\Commands; use Code16\Sharp\Exceptions\Auth\SharpAuthorizationException; -use Code16\Sharp\Http\Controllers\Api\ApiController; +use Code16\Sharp\Http\Controllers\Controller; -class ApiEntityListEntityStateController extends ApiController +class ApiEntityListEntityStateController extends Controller { use HandlesCommandResult; use HandlesInstanceCommand; public function update(string $globalFilter, string $entityKey, mixed $instanceId) { - $list = $this->getListInstance($entityKey); + $list = $this->entityManager->entityFor($entityKey)->getListOrFail(); $list->buildListConfig(); $list->initQueryParams(request()->input('query')); diff --git a/src/Http/Controllers/Api/Commands/ApiEntityListInstanceCommandController.php b/src/Http/Controllers/Api/Commands/ApiEntityListInstanceCommandController.php index c2a1ee716..3bcd08d8e 100644 --- a/src/Http/Controllers/Api/Commands/ApiEntityListInstanceCommandController.php +++ b/src/Http/Controllers/Api/Commands/ApiEntityListInstanceCommandController.php @@ -3,10 +3,10 @@ namespace Code16\Sharp\Http\Controllers\Api\Commands; use Code16\Sharp\Data\Commands\CommandFormData; -use Code16\Sharp\Http\Controllers\Api\ApiController; +use Code16\Sharp\Http\Controllers\Controller; use Code16\Sharp\Utils\Uploads\SharpUploadManager; -class ApiEntityListInstanceCommandController extends ApiController +class ApiEntityListInstanceCommandController extends Controller { use HandlesCommandForm; use HandlesCommandResult; @@ -20,7 +20,7 @@ public function __construct( public function show(string $globalFilter, string $entityKey, string $commandKey, mixed $instanceId) { - $list = $this->getListInstance($entityKey); + $list = $this->entityManager->entityFor($entityKey)->getListOrFail(); $list->buildListConfig(); $list->initQueryParams(request()->query()); @@ -38,7 +38,7 @@ public function show(string $globalFilter, string $entityKey, string $commandKey */ public function update(string $globalFilter, string $entityKey, string $commandKey, mixed $instanceId) { - $list = $this->getListInstance($entityKey); + $list = $this->entityManager->entityFor($entityKey)->getListOrFail(); $list->buildListConfig(); $list->initQueryParams(request()->input('query')); diff --git a/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php b/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php index 9e22ce736..c821dd5bf 100644 --- a/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php +++ b/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php @@ -3,17 +3,18 @@ namespace Code16\Sharp\Http\Controllers\Api\Commands; use Code16\Sharp\Data\Commands\CommandFormData; -use Code16\Sharp\Http\Controllers\Api\ApiController; +use Code16\Sharp\Http\Controllers\Controller; use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey; use Code16\Sharp\Utils\Uploads\SharpUploadManager; -class ApiEntityListQuickCreationCommandController extends ApiController +class ApiEntityListQuickCreationCommandController extends Controller { use HandlesCommandForm; use HandlesCommandResult; - public function __construct(private readonly SharpUploadManager $uploadManager) - { + public function __construct( + private readonly SharpUploadManager $uploadManager, + ) { parent::__construct(); } diff --git a/src/Http/Controllers/Api/Commands/ApiShowEntityStateController.php b/src/Http/Controllers/Api/Commands/ApiShowEntityStateController.php index 4be029d53..d45c45305 100644 --- a/src/Http/Controllers/Api/Commands/ApiShowEntityStateController.php +++ b/src/Http/Controllers/Api/Commands/ApiShowEntityStateController.php @@ -3,10 +3,10 @@ namespace Code16\Sharp\Http\Controllers\Api\Commands; use Code16\Sharp\Exceptions\Auth\SharpAuthorizationException; -use Code16\Sharp\Http\Controllers\Api\ApiController; +use Code16\Sharp\Http\Controllers\Controller; use Code16\Sharp\Show\SharpSingleShow; -class ApiShowEntityStateController extends ApiController +class ApiShowEntityStateController extends Controller { use HandlesCommandResult; use HandlesInstanceCommand; @@ -33,7 +33,7 @@ public function update(string $globalFilter, string $entityKey, mixed $instanceI private function getShowPage(string $entityKey, mixed $instanceId = null) { - $showPage = $this->getShowInstance($entityKey); + $showPage = $this->entityManager->entityFor($entityKey)->getShowOrFail(); abort_if( (! $instanceId && ! $showPage instanceof SharpSingleShow) diff --git a/src/Http/Controllers/Api/Commands/ApiShowInstanceCommandController.php b/src/Http/Controllers/Api/Commands/ApiShowInstanceCommandController.php index 70daedc5f..3c31e499e 100644 --- a/src/Http/Controllers/Api/Commands/ApiShowInstanceCommandController.php +++ b/src/Http/Controllers/Api/Commands/ApiShowInstanceCommandController.php @@ -3,11 +3,11 @@ namespace Code16\Sharp\Http\Controllers\Api\Commands; use Code16\Sharp\Data\Commands\CommandFormData; -use Code16\Sharp\Http\Controllers\Api\ApiController; +use Code16\Sharp\Http\Controllers\Controller; use Code16\Sharp\Show\SharpSingleShow; use Code16\Sharp\Utils\Uploads\SharpUploadManager; -class ApiShowInstanceCommandController extends ApiController +class ApiShowInstanceCommandController extends Controller { use HandlesCommandForm; use HandlesCommandResult; @@ -45,7 +45,7 @@ public function update(string $globalFilter, string $entityKey, string $commandK private function getShowPage(string $entityKey, mixed $instanceId = null) { - $showPage = $this->getShowInstance($entityKey); + $showPage = $this->entityManager->entityFor($entityKey)->getShowOrFail(); abort_if( (! $instanceId && ! $showPage instanceof SharpSingleShow) diff --git a/src/Http/Controllers/Api/DownloadController.php b/src/Http/Controllers/Api/DownloadController.php index 43ce06eeb..b9ad7ca10 100644 --- a/src/Http/Controllers/Api/DownloadController.php +++ b/src/Http/Controllers/Api/DownloadController.php @@ -2,9 +2,10 @@ namespace Code16\Sharp\Http\Controllers\Api; +use Code16\Sharp\Http\Controllers\Controller; use Illuminate\Support\Facades\Storage; -class DownloadController extends ApiController +class DownloadController extends Controller { public function show(string $globalFilter, string $entityKey, ?string $instanceId = null) { diff --git a/src/Http/Controllers/Api/Embeds/ApiEmbedsFormController.php b/src/Http/Controllers/Api/Embeds/ApiEmbedsFormController.php index 3b09237c5..96fdac71f 100644 --- a/src/Http/Controllers/Api/Embeds/ApiEmbedsFormController.php +++ b/src/Http/Controllers/Api/Embeds/ApiEmbedsFormController.php @@ -2,16 +2,13 @@ namespace Code16\Sharp\Http\Controllers\Api\Embeds; -use Code16\Sharp\Auth\SharpAuthorizationManager; use Code16\Sharp\Data\Embeds\EmbedFormData; -use Illuminate\Routing\Controller; +use Code16\Sharp\Http\Controllers\Controller; class ApiEmbedsFormController extends Controller { use HandlesEmbed; - public function __construct(private readonly SharpAuthorizationManager $authorizationManager) {} - public function show(string $globalFilter, string $embedKey, string $entityKey, ?string $instanceId = null) { if ($instanceId) { diff --git a/src/Http/Controllers/SharpProtectedController.php b/src/Http/Controllers/Controller.php similarity index 82% rename from src/Http/Controllers/SharpProtectedController.php rename to src/Http/Controllers/Controller.php index 84cf2c786..754d45344 100644 --- a/src/Http/Controllers/SharpProtectedController.php +++ b/src/Http/Controllers/Controller.php @@ -4,9 +4,9 @@ use Code16\Sharp\Auth\SharpAuthorizationManager; use Code16\Sharp\Utils\Entities\SharpEntityManager; -use Illuminate\Routing\Controller; +use Illuminate\Routing\Controller as BaseController; -class SharpProtectedController extends Controller +class Controller extends BaseController { protected SharpEntityManager $entityManager; protected SharpAuthorizationManager $authorizationManager; diff --git a/src/Http/Controllers/DashboardController.php b/src/Http/Controllers/DashboardController.php index 699fe1bd1..df837bb16 100644 --- a/src/Http/Controllers/DashboardController.php +++ b/src/Http/Controllers/DashboardController.php @@ -7,7 +7,7 @@ use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey; use Inertia\Inertia; -class DashboardController extends SharpProtectedController +class DashboardController extends Controller { public function show(string $globalFilter, EntityKey $dashboardKey) { diff --git a/src/Http/Controllers/DashboardFiltersController.php b/src/Http/Controllers/DashboardFiltersController.php index b7d557667..f5bfe5c80 100644 --- a/src/Http/Controllers/DashboardFiltersController.php +++ b/src/Http/Controllers/DashboardFiltersController.php @@ -2,7 +2,7 @@ namespace Code16\Sharp\Http\Controllers; -class DashboardFiltersController extends SharpProtectedController +class DashboardFiltersController extends Controller { public function store(string $globalFilter, string $dashboardKey) { diff --git a/src/Http/Controllers/EntityListController.php b/src/Http/Controllers/EntityListController.php index 9ef56e90c..2e36951b6 100644 --- a/src/Http/Controllers/EntityListController.php +++ b/src/Http/Controllers/EntityListController.php @@ -13,7 +13,7 @@ use Code16\Sharp\Utils\Menu\SharpMenuManager; use Inertia\Inertia; -class EntityListController extends SharpProtectedController +class EntityListController extends Controller { use HandlesEntityListItems; use HandlesSharpNotificationsInRequest; diff --git a/src/Http/Controllers/EntityListFiltersController.php b/src/Http/Controllers/EntityListFiltersController.php index a0c320eca..2ee20cb67 100644 --- a/src/Http/Controllers/EntityListFiltersController.php +++ b/src/Http/Controllers/EntityListFiltersController.php @@ -2,7 +2,7 @@ namespace Code16\Sharp\Http\Controllers; -class EntityListFiltersController extends SharpProtectedController +class EntityListFiltersController extends Controller { public function store(string $globalFilter, string $entityKey) { diff --git a/src/Http/Controllers/FormController.php b/src/Http/Controllers/FormController.php index 7bb7ea42f..0d45d1972 100644 --- a/src/Http/Controllers/FormController.php +++ b/src/Http/Controllers/FormController.php @@ -12,7 +12,7 @@ use Illuminate\Support\Uri; use Inertia\Inertia; -class FormController extends SharpProtectedController +class FormController extends Controller { use HandlesSharpNotificationsInRequest; diff --git a/src/Http/Controllers/GlobalFilterController.php b/src/Http/Controllers/GlobalFilterController.php index d2c201e1e..55af453bf 100644 --- a/src/Http/Controllers/GlobalFilterController.php +++ b/src/Http/Controllers/GlobalFilterController.php @@ -5,7 +5,7 @@ use Code16\Sharp\Filters\GlobalFilters\GlobalFilters; use Illuminate\Http\RedirectResponse; -class GlobalFilterController extends SharpProtectedController +class GlobalFilterController extends Controller { public function update(string $globalFilter, GlobalFilters $globalFilters): RedirectResponse { diff --git a/src/Http/Controllers/HomeController.php b/src/Http/Controllers/HomeController.php index c95685d06..9e1efe4a8 100644 --- a/src/Http/Controllers/HomeController.php +++ b/src/Http/Controllers/HomeController.php @@ -6,7 +6,7 @@ use Code16\Sharp\Utils\Menu\SharpMenuManager; use Inertia\Inertia; -class HomeController extends SharpProtectedController +class HomeController extends Controller { public function index(string $globalFilter) { diff --git a/src/Http/Controllers/ShowController.php b/src/Http/Controllers/ShowController.php index 2358b95ca..6ce12757d 100644 --- a/src/Http/Controllers/ShowController.php +++ b/src/Http/Controllers/ShowController.php @@ -9,7 +9,7 @@ use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey; use Inertia\Inertia; -class ShowController extends SharpProtectedController +class ShowController extends Controller { use HandlesSharpNotificationsInRequest; use PreloadsShowFields; diff --git a/src/Http/Controllers/SingleShowController.php b/src/Http/Controllers/SingleShowController.php index 502b6c34a..d88eb3221 100644 --- a/src/Http/Controllers/SingleShowController.php +++ b/src/Http/Controllers/SingleShowController.php @@ -8,7 +8,7 @@ use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey; use Inertia\Inertia; -class SingleShowController extends SharpProtectedController +class SingleShowController extends Controller { use HandlesSharpNotificationsInRequest; use PreloadsShowFields; diff --git a/src/Http/Controllers/UpdateAssetsController.php b/src/Http/Controllers/UpdateAssetsController.php index 1d412beb7..6a5e0caa3 100644 --- a/src/Http/Controllers/UpdateAssetsController.php +++ b/src/Http/Controllers/UpdateAssetsController.php @@ -5,7 +5,7 @@ use Code16\Sharp\Utils\Traits\CanNotify; use Illuminate\Support\Facades\Artisan; -class UpdateAssetsController extends SharpProtectedController +class UpdateAssetsController extends Controller { use CanNotify;