From e8c152edc8f22e1d330ccf5e81235c7f7bd5039a Mon Sep 17 00:00:00 2001 From: Grzegorz Date: Mon, 30 Nov 2026 00:49:35 +0100 Subject: [PATCH] refactor(admin): move module switches to their own pages --- .../Controllers/Admin/ConfigController.php | 39 ++++++-- .../Controllers/Admin/ModuleController.php | 14 +-- app/Services/Module/ModuleSwitchboard.php | 56 ++++++----- lang/de/admin.php | 1 - lang/en/admin.php | 1 - lang/es/admin.php | 1 - lang/it/admin.php | 1 - lang/pl/admin.php | 1 - lang/ru/admin.php | 1 - lang/tr/admin.php | 1 - lang/uk/admin.php | 1 - lang/zh/admin.php | 1 - .../admin/config/addon-modules.blade.php | 2 +- .../views/admin/config/modules.blade.php | 92 +++++++++---------- .../views/admin/config/ssl-modules.blade.php | 11 +++ resources/views/admin/layouts/app.blade.php | 2 - routes/admin.php | 4 +- tests/Feature/AdminNavLinksTest.php | 15 +-- tests/Feature/ModulesPageTest.php | 62 +++++++++---- 19 files changed, 177 insertions(+), 129 deletions(-) diff --git a/app/Http/Controllers/Admin/ConfigController.php b/app/Http/Controllers/Admin/ConfigController.php index 7d01b3419..ade6a6d69 100644 --- a/app/Http/Controllers/Admin/ConfigController.php +++ b/app/Http/Controllers/Admin/ConfigController.php @@ -4,6 +4,7 @@ use App\Constants\Permissions; use App\Contracts\TokenizableGatewayInterface; +use App\Enums\AddonOperation; use App\Http\Controllers\Api\ClientApiController; use App\Http\Controllers\Api\DomainApiController; use App\Http\Controllers\Api\InvoiceApiController; @@ -13,7 +14,6 @@ use App\Http\Controllers\Api\TicketApiController; use App\Http\Controllers\Controller; use App\Http\Traits\CsvExportable; -use App\Enums\AddonOperation; use App\Models\ActivityLog; use App\Models\Admin; use App\Models\AdminActivity; @@ -62,9 +62,10 @@ use App\Models\TicketSpamFilter; use App\Models\TicketStatus; use App\Models\TodoItem; -use App\Services\Addons\AddonExecutionService; use App\Models\Transaction; +use App\Rules\EmailList; use App\Services\Module\ModuleRegistry; +use App\Services\Module\ModuleSwitchboard; use App\Services\NotificationService; use App\Services\ServerAccountSync; use App\Support\Addons\AddonPayloadSanitizer; @@ -75,6 +76,7 @@ use App\Support\IpAllowList; use App\Support\ModuleSettings; use App\Support\ServerAddress; +use App\Support\TaxNotice; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Artisan; @@ -662,7 +664,7 @@ public function tax() ]) ->values(); - return view('admin.config.tax', ['groups' => $groups, 'taxEnabled' => $taxEnabled, 'taxInclusive' => $taxInclusive, 'taxNotice' => \App\Support\TaxNotice::text()]); + return view('admin.config.tax', ['groups' => $groups, 'taxEnabled' => $taxEnabled, 'taxInclusive' => $taxInclusive, 'taxNotice' => TaxNotice::text()]); } public function storeTax(Request $request) @@ -1549,7 +1551,7 @@ public function destroyTicketStatus(TicketStatus $status) // Email Templates public function updateEmailTemplate(Request $request, EmailTemplate $template) { - $validated = $request->validate(['type' => 'nullable|string', 'name' => 'nullable|string', 'subject' => 'nullable|string', 'message' => 'nullable|string', 'from_name' => 'nullable|string', 'from_email' => 'nullable|email', 'copy_to' => ['nullable', 'string', 'max:255', new \App\Rules\EmailList], 'disabled' => 'boolean']); + $validated = $request->validate(['type' => 'nullable|string', 'name' => 'nullable|string', 'subject' => 'nullable|string', 'message' => 'nullable|string', 'from_name' => 'nullable|string', 'from_email' => 'nullable|email', 'copy_to' => ['nullable', 'string', 'max:255', new EmailList], 'disabled' => 'boolean']); // Only a changed body makes the template the operator's own, which is // what lets their wording replace the built-in email. The form always @@ -2519,21 +2521,46 @@ public function apiDocs() } // ===== SSL MODULES ===== - public function sslModules() + public function sslModules(ModuleSwitchboard $switchboard) { $registry = app(ModuleRegistry::class); $modules = []; $settings = []; + $active = []; + $usage = []; foreach ($registry->getSslModules() as $name) { $module = $registry->getSslModule($name); if ($module) { $modules[$name] = $module; $settings[$name] = SslModuleSettings::getForModule($name); + $active[$name] = $switchboard->isActive('ssl', $name); + $usage[$name] = $switchboard->usage('ssl', $name); } } - return view('admin.config.ssl-modules', compact('modules', 'settings')); + return view('admin.config.ssl-modules', compact('modules', 'settings', 'active', 'usage')); + } + + public function toggleSslModule(Request $request, string $module, ModuleSwitchboard $switchboard) + { + $request->validate(['active' => ['required', Rule::in(['0', '1'])]]); + + if (! $switchboard->exists('ssl', $module)) { + abort(404); + } + + $on = $request->input('active') === '1'; + $result = $switchboard->setActive('ssl', $module, $on); + + if ($result['success']) { + ActivityLog::log( + 'Module ssl/'.$module.' switched '.($on ? 'on' : 'off'), + auth('admin')->user()?->username + ); + } + + return back()->with($result['success'] ? 'success' : 'error', $result['message']); } /** diff --git a/app/Http/Controllers/Admin/ModuleController.php b/app/Http/Controllers/Admin/ModuleController.php index 7f13b8e99..5b434a890 100644 --- a/app/Http/Controllers/Admin/ModuleController.php +++ b/app/Http/Controllers/Admin/ModuleController.php @@ -9,27 +9,17 @@ use Illuminate\Validation\Rule; /** - * Every installed module on one screen, each with its on/off switch. + * Server modules on one screen, each with its on/off switch. * The rules about what a switch means live in ModuleSwitchboard. */ class ModuleController extends Controller { public function __construct(private ModuleSwitchboard $switchboard) {} - public function index() - { - return view('admin.config.modules', [ - 'groups' => $this->switchboard->rows(), - 'pageIcon' => 'fa-cubes', - ]); - } - public function serverModules() { - $groups = $this->switchboard->rows(); - return view('admin.config.modules', [ - 'groups' => ['server' => $groups['server']], + 'groups' => ['server' => $this->switchboard->rowsFor('server')], 'pageTitle' => __('admin.modules.type_server'), 'pageDescription' => __('admin.modules.server_description'), 'pageIcon' => 'fa-server', diff --git a/app/Services/Module/ModuleSwitchboard.php b/app/Services/Module/ModuleSwitchboard.php index e936158fb..1baa1dc66 100644 --- a/app/Services/Module/ModuleSwitchboard.php +++ b/app/Services/Module/ModuleSwitchboard.php @@ -10,10 +10,10 @@ use Illuminate\Support\Collection; /** - * Every installed module on one screen, each with its on/off switch. + * Installed modules and their on/off switches for the pages that show them. * * NO NEW SWITCH WHERE ONE ALREADY EXISTS. Gateways, registrars and addons - * each had an on/off setting long before this screen, read by the code that + * each had an on/off setting long before this class, read by the code that * matters (checkout, domain search, the addon loader). This class reads and * writes exactly those settings, so flipping a gateway here and on the * gateways page is the same act. Only server and SSL modules had no switch; @@ -43,33 +43,47 @@ public function rows(): Collection { $rows = collect(); - foreach (['server', 'gateway', 'registrar', 'ssl'] as $type) { - $rows[$type] = collect(array_keys($this->registry->classesOf($type))) - ->map(fn (string $key) => (object) [ - 'type' => $type, - 'key' => $key, - 'label' => $this->label($type, $key), - 'third_party' => $this->registry->isDiscovered($type, $key), - 'active' => $this->isActive($type, $key), - 'in_use' => $this->usage($type, $key), + foreach (self::TYPES as $type) { + $rows[$type] = $this->rowsFor($type); + } + + return $rows; + } + + /** + * @return Collection + */ + public function rowsFor(string $type): Collection + { + if (! in_array($type, self::TYPES, true)) { + return collect(); + } + + if ($type === 'addon') { + return $this->addons->all() + ->map(fn ($addon, $key) => (object) [ + 'type' => 'addon', + 'key' => (string) $key, + 'label' => $addon->getDisplayName(), + 'third_party' => false, + 'active' => $this->addons->isActive((string) $key), + 'in_use' => 0, ]) ->sortBy(fn ($row) => mb_strtolower($row->label)) ->values(); } - $rows['addon'] = $this->addons->all() - ->map(fn ($addon, $key) => (object) [ - 'type' => 'addon', - 'key' => (string) $key, - 'label' => $addon->getDisplayName(), - 'third_party' => false, - 'active' => $this->addons->isActive((string) $key), - 'in_use' => 0, + return collect(array_keys($this->registry->classesOf($type))) + ->map(fn (string $key) => (object) [ + 'type' => $type, + 'key' => $key, + 'label' => $this->label($type, $key), + 'third_party' => $this->registry->isDiscovered($type, $key), + 'active' => $this->isActive($type, $key), + 'in_use' => $this->usage($type, $key), ]) ->sortBy(fn ($row) => mb_strtolower($row->label)) ->values(); - - return $rows; } public function exists(string $type, string $key): bool diff --git a/lang/de/admin.php b/lang/de/admin.php index f6456afc4..274948e1d 100644 --- a/lang/de/admin.php +++ b/lang/de/admin.php @@ -3717,7 +3717,6 @@ 'invoices.charge_now_refused' => 'Nicht belastet (:reason).', 'invoices.charge_now_log' => 'Karte jetzt belasten: :outcome', 'dashboard.live_servers' => 'Live-Server', - 'nav.modules' => 'Module', 'live_servers.title' => 'Live-Server', 'live_servers.description' => 'Ihre Panelica-Server. „Anmelden“ öffnet das Control Panel des Servers in einem neuen Tab – angemeldet als Inhaber des API-Schlüssels des Servers.', 'live_servers.none' => 'Noch keine Panelica-Server.', diff --git a/lang/en/admin.php b/lang/en/admin.php index 524b9c619..d8342df4b 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -3723,7 +3723,6 @@ 'invoices.charge_now_refused' => 'Not charged (:reason).', 'invoices.charge_now_log' => 'Charge card now: :outcome', 'dashboard.live_servers' => 'Live Servers', - 'nav.modules' => 'Modules', 'live_servers.title' => 'Live Servers', 'live_servers.description' => 'Your Panelica servers. Log in opens the server\'s control panel in a new tab, signed in as the owner of the server\'s API key.', 'live_servers.none' => 'No Panelica servers yet.', diff --git a/lang/es/admin.php b/lang/es/admin.php index bd23a28f4..d72ded11c 100644 --- a/lang/es/admin.php +++ b/lang/es/admin.php @@ -3463,7 +3463,6 @@ 'invoices.charge_now_refused' => 'No cobrado (:reason).', 'invoices.charge_now_log' => 'Cargar tarjeta ahora: :outcome', 'dashboard.live_servers' => 'Servidores en vivo', - 'nav.modules' => 'Módulos', 'live_servers.title' => 'Servidores en vivo', 'live_servers.description' => 'Sus servidores Panelica. «Iniciar sesión» abre el panel de control del servidor en una pestaña nueva con la sesión iniciada como propietario de la clave API del servidor.', 'live_servers.none' => 'Aún no hay servidores de Panelica.', diff --git a/lang/it/admin.php b/lang/it/admin.php index 64da145ad..29fe3d54e 100644 --- a/lang/it/admin.php +++ b/lang/it/admin.php @@ -3487,7 +3487,6 @@ 'invoices.charge_now_refused' => 'Non addebitata (:reason).', 'invoices.charge_now_log' => 'Addebita la carta ora: :outcome', 'dashboard.live_servers' => 'Server attivi', - 'nav.modules' => 'Moduli', 'live_servers.title' => 'Server attivi', 'live_servers.description' => 'I tuoi server Panelica. Accedi apre il pannello di controllo del server in una nuova scheda, autenticato come il proprietario della chiave API del server.', 'live_servers.none' => 'Nessun server Panelica finora.', diff --git a/lang/pl/admin.php b/lang/pl/admin.php index d72f74da1..52f41b0b4 100644 --- a/lang/pl/admin.php +++ b/lang/pl/admin.php @@ -3721,7 +3721,6 @@ 'invoices.charge_now_refused' => 'Nie obciążono (:reason).', 'invoices.charge_now_log' => 'Obciąż kartę teraz: :outcome', 'dashboard.live_servers' => 'Serwery na żywo', - 'nav.modules' => 'Moduły', 'live_servers.title' => 'Serwery na żywo', 'live_servers.description' => 'Twoje serwery Panelica. Zaloguj otwiera panel serwera w nowej karcie, jako właściciel klucza API serwera.', 'live_servers.none' => 'Brak serwerów Panelica.', diff --git a/lang/ru/admin.php b/lang/ru/admin.php index 6184b770d..e4961ea16 100644 --- a/lang/ru/admin.php +++ b/lang/ru/admin.php @@ -3391,7 +3391,6 @@ 'invoices.charge_now_refused' => 'Не списано (:reason).', 'invoices.charge_now_log' => 'Списать с карты сейчас: :outcome', 'dashboard.live_servers' => 'Рабочие серверы', - 'nav.modules' => 'Модули', 'live_servers.title' => 'Рабочие серверы', 'live_servers.description' => 'Ваши серверы Panelica. «Войти» открывает панель управления сервером в новой вкладке от имени владельца API-ключа сервера.', 'live_servers.none' => 'Серверов Panelica пока нет.', diff --git a/lang/tr/admin.php b/lang/tr/admin.php index cc35dd3dc..4dd3ffdab 100644 --- a/lang/tr/admin.php +++ b/lang/tr/admin.php @@ -3721,7 +3721,6 @@ 'invoices.charge_now_refused' => 'Çekilmedi (:reason).', 'invoices.charge_now_log' => 'Kartı şimdi çek: :outcome', 'dashboard.live_servers' => 'Canlı Sunucular', - 'nav.modules' => 'Modüller', 'live_servers.title' => 'Canlı Sunucular', 'live_servers.description' => 'Panelica sunucularınız. Giriş, sunucunun kontrol panelini yeni sekmede açar; sunucunun API anahtarının sahibi olarak oturum açılır.', 'live_servers.none' => 'Henüz Panelica sunucusu yok.', diff --git a/lang/uk/admin.php b/lang/uk/admin.php index 7e5a794c7..668fc6345 100644 --- a/lang/uk/admin.php +++ b/lang/uk/admin.php @@ -3408,7 +3408,6 @@ 'invoices.charge_now_refused' => 'Не списано (:reason).', 'invoices.charge_now_log' => 'Списати з картки зараз: :outcome', 'dashboard.live_servers' => 'Активні сервери', - 'nav.modules' => 'Модулі', 'live_servers.title' => 'Активні сервери', 'live_servers.description' => 'Ваші сервери Panelica. Кнопка входу відкриває панель керування сервером у новій вкладці від імені власника серверного API-ключа.', 'live_servers.none' => 'Серверів Panelica ще немає.', diff --git a/lang/zh/admin.php b/lang/zh/admin.php index 10de824aa..d07aff0b8 100644 --- a/lang/zh/admin.php +++ b/lang/zh/admin.php @@ -3721,7 +3721,6 @@ 'invoices.charge_now_refused' => '未扣款(:reason)。', 'invoices.charge_now_log' => '立即扣款::outcome', 'dashboard.live_servers' => '在线服务器', - 'nav.modules' => '模块', 'live_servers.title' => '在线服务器', 'live_servers.description' => '您的 Panelica 服务器。点击登录将在新标签页中打开服务器控制面板,并以该服务器 API 密钥所有者的身份登录。', 'live_servers.none' => '尚无 Panelica 服务器。', diff --git a/resources/views/admin/config/addon-modules.blade.php b/resources/views/admin/config/addon-modules.blade.php index 83d83d3f9..75d87c5df 100644 --- a/resources/views/admin/config/addon-modules.blade.php +++ b/resources/views/admin/config/addon-modules.blade.php @@ -24,7 +24,7 @@ v{{ $addon->getVersion() }} - {{ ($statuses[$name] ?? false) ? __('admin.addon_modules.status_active') : __('admin.addon_modules.status_inactive') }} + {{ ($statuses[$name] ?? false) ? __('common.status.active') : __('common.status.inactive') }}
diff --git a/resources/views/admin/config/modules.blade.php b/resources/views/admin/config/modules.blade.php index 0ebd5bc44..fc8784ab0 100644 --- a/resources/views/admin/config/modules.blade.php +++ b/resources/views/admin/config/modules.blade.php @@ -1,65 +1,61 @@ @extends("admin.layouts.app") -@section("title", __("admin.modules.title")) +@section("title", $pageTitle ?? __("admin.modules.type_server")) @section("content") @php - // Where each type is configured. The switch lives here; the settings - // (keys, credentials) stay on the screen that already owns them. - $configure = [ - 'server' => route('admin.config.servers'), - 'gateway' => route('admin.config.gateways'), - 'registrar' => route('admin.config.registrars'), - 'ssl' => route('admin.config.sslModules'), - 'addon' => route('admin.config.addons.modules'), - ]; + $rows = $groups['server'] ?? collect(); @endphp - + + @endforeach
-@endforeach +@endif + @endsection diff --git a/resources/views/admin/config/ssl-modules.blade.php b/resources/views/admin/config/ssl-modules.blade.php index 4a132050a..63f2c75df 100644 --- a/resources/views/admin/config/ssl-modules.blade.php +++ b/resources/views/admin/config/ssl-modules.blade.php @@ -14,8 +14,19 @@ ▸ {{ ucfirst($name) }} + {{ ($active[$name] ?? false) ? __('common.status.active') : __('common.status.inactive') }}
+
+ @csrf + + @if($active[$name] ?? false) + + @else + + @endif +
+
@csrf diff --git a/resources/views/admin/layouts/app.blade.php b/resources/views/admin/layouts/app.blade.php index e24e9b67d..e94d89f3f 100644 --- a/resources/views/admin/layouts/app.blade.php +++ b/resources/views/admin/layouts/app.blade.php @@ -244,7 +244,6 @@
  • {{ __('admin.nav.addon_modules') }}
  • {{ __('admin.modules.type_server') }}
  • -
  • {{ __('admin.nav.modules') }}
  • {{ __('admin.nav.payment_gateways') }}
  • {{ __('admin.nav.domain_registrars') }}
  • {{ __('admin.nav.ssl_modules') }}
  • @@ -510,7 +509,6 @@
  • {{ __('admin.nav.product_addons') }}
  • {{ __('admin.nav.addon_modules') }}
  • {{ __('admin.modules.type_server') }}
  • -
  • {{ __('admin.nav.modules') }}
  • {{ __('admin.nav.product_bundles') }}
  • @if(auth('admin')->user()?->hasPermission('manage_updates'))
  • {{ __('admin.nav.updates') }}
  • diff --git a/routes/admin.php b/routes/admin.php index 7cc44a894..9029317d0 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -441,9 +441,8 @@ Route::post('updates/bar', [UpdateController::class, 'bar'])->name('updates.bar'); }); - // Every installed module and its on/off switch — manage_settings + // Server modules and their on/off switch — manage_settings Route::middleware('admin.permission:manage_settings')->group(function () { - Route::get('modules', [ModuleController::class, 'index'])->name('modules'); Route::get('modules/server', [ModuleController::class, 'serverModules'])->name('server-modules'); Route::post('modules/{type}/{key}/toggle', [ModuleController::class, 'toggle'])->name('modules.toggle'); }); @@ -661,6 +660,7 @@ // SSL Modules — manage_servers Route::middleware('admin.permission:manage_servers')->group(function () { Route::get('ssl-modules', [ConfigController::class, 'sslModules'])->name('sslModules'); + Route::post('ssl-modules/{module}/toggle', [ConfigController::class, 'toggleSslModule'])->name('sslModules.toggle'); Route::post('ssl-modules/{module}', [ConfigController::class, 'updateSslModuleSettings'])->name('updateSslModuleSettings'); Route::post('ssl-modules/{module}/test', [ConfigController::class, 'testSslConnection'])->name('testSslConnection'); }); diff --git a/tests/Feature/AdminNavLinksTest.php b/tests/Feature/AdminNavLinksTest.php index 87a635133..a861041a6 100644 --- a/tests/Feature/AdminNavLinksTest.php +++ b/tests/Feature/AdminNavLinksTest.php @@ -19,23 +19,14 @@ ->and($nav)->toContain('href="'.route('admin.dashboard').'"> '.e(__('admin.sidebar.dashboard'))); }); -test('the config menu leads to add-ons, server modules and all modules', function () { +test('the config menu leads to add-ons and server modules', function () { $admin = Admin::factory()->create(['role_id' => AdminRole::factory()->fullAdmin()->create()->id]); $html = $this->actingAs($admin, 'admin')->get(route('admin.dashboard'))->assertOk()->getContent(); - /* - * The links are asserted as whole anchors, not as URLs appearing anywhere - * in the page: route('admin.config.modules') is /admin/config/modules and - * route('admin.config.server-modules') is /admin/config/modules/server, so - * a bare toContain() on the first is satisfied by the second and passes - * with the entry missing. Measured - that is exactly what it did. - */ - $entry = fn (string $route, string $label): string => - ''.e($label).''; + $entry = fn (string $route, string $label): string => ''.e($label).''; expect($html) ->toContain($entry('admin.config.addons.modules', __('admin.nav.addon_modules'))) - ->toContain($entry('admin.config.server-modules', __('admin.modules.type_server'))) - ->toContain($entry('admin.config.modules', __('admin.nav.modules'))); + ->toContain($entry('admin.config.server-modules', __('admin.modules.type_server'))); }); diff --git a/tests/Feature/ModulesPageTest.php b/tests/Feature/ModulesPageTest.php index a6277f341..3c1b78cd1 100644 --- a/tests/Feature/ModulesPageTest.php +++ b/tests/Feature/ModulesPageTest.php @@ -7,14 +7,15 @@ use App\Models\RegistrarSettings; use App\Models\Server; use App\Services\Module\ModuleRegistry; +use App\Services\Module\ModuleSwitchboard; /* - * The Modules screen: every installed module with its on/off switch. + * Module switches on the server and SSL pages. * - * Gateways, registrars and addons already had switches; the screen must flip - * THOSE, so the checkout and domain search see the same thing it shows. - * Server and SSL modules get their first switch here, and it may not be - * turned off while anything uses the module. + * Gateways, registrars and addons already had switches; those pages must flip + * THOSE, so the checkout and domain search see the same thing they show. + * Server and SSL modules have switches on their own pages, and may not be + * turned off while anything uses them. */ function modulesAdmin(): Admin @@ -32,16 +33,10 @@ function toggleModule($test, Admin $admin, string $type, string $key, bool $on) ); } -test('the page lists every module type with the built-in modules', function () { +test('the all-modules page is gone', function () { $this->actingAs(modulesAdmin(), 'admin') - ->get(route('admin.config.modules')) - ->assertOk() - ->assertSee('data-module="server/panelica"', false) - ->assertSee('data-module="gateway/stripe"', false) - ->assertSee('data-module="gateway/iyzico"', false) - ->assertSee('data-module="registrar/namecheap"', false) - ->assertSee('data-module="ssl/gogetssl"', false) - ->assertSee('data-module="addon/', false); + ->get('/admin/config/modules') + ->assertNotFound(); }); test('switching a gateway writes the same setting the checkout reads', function () { @@ -119,21 +114,56 @@ function toggleModule($test, Admin $admin, string $type, string $key, bool $on) expect(GatewaySettings::where('gateway', 'nosuchgateway')->exists())->toBeFalse(); }); -test('an admin without settings permission cannot reach it', function () { +test('an admin without settings permission cannot reach the server module page or toggles', function () { $admin = Admin::factory()->create([ 'role_id' => AdminRole::factory()->create(['name' => 'Tickets', 'permissions' => ['list_tickets']])->id, ]); - $this->actingAs($admin, 'admin')->get(route('admin.config.modules'))->assertForbidden(); + $this->actingAs($admin, 'admin')->get(route('admin.config.server-modules'))->assertForbidden(); toggleModule($this, $admin, 'gateway', 'banktransfer', true)->assertForbidden(); }); +test('the ssl page switches an unused ssl module off and on', function () { + $admin = modulesAdmin(); + Product::whereRaw('LOWER(ssl_module) = ?', ['gogetssl'])->update(['ssl_module' => null]); + + $this->actingAs($admin, 'admin')->post(route('admin.config.sslModules.toggle', ['module' => 'gogetssl']), ['active' => '0']) + ->assertRedirect()->assertSessionHas('success'); + + expect(app(ModuleRegistry::class)->sslModuleNames())->not->toHaveKey('gogetssl'); + + $this->actingAs($admin, 'admin')->post(route('admin.config.sslModules.toggle', ['module' => 'gogetssl']), ['active' => '1']) + ->assertRedirect()->assertSessionHas('success'); + + expect(app(ModuleRegistry::class)->sslModuleNames())->toHaveKey('gogetssl'); +}); + +test('an ssl module in use cannot be switched off from its page', function () { + Product::factory()->create(['ssl_module' => 'gogetssl']); + + $usage = app(ModuleSwitchboard::class)->usage('ssl', 'gogetssl'); + + $this->actingAs(modulesAdmin(), 'admin') + ->get(route('admin.config.sslModules')) + ->assertOk() + ->assertSee(route('admin.config.sslModules.toggle', ['module' => 'gogetssl']), false) + ->assertSee('disabled title="'.e(__('admin.modules.in_use_cannot_disable', ['count' => $usage])).'"', false); + + $this->actingAs(modulesAdmin(), 'admin') + ->post(route('admin.config.sslModules.toggle', ['module' => 'gogetssl']), ['active' => '0']) + ->assertRedirect()->assertSessionHas('error'); + + expect(app(ModuleRegistry::class)->sslModuleNames())->toHaveKey('gogetssl'); +}); test('the server modules page lists only server modules', function () { $this->actingAs(modulesAdmin(), 'admin') ->get(route('admin.config.server-modules')) ->assertOk() ->assertSee('data-module="server/panelica"', false) ->assertSee('fa-server', false) + ->assertSee('gw-card', false) + ->assertSee('assertSee(e(__('common.status.active')), false) ->assertDontSee('data-module="gateway/stripe"', false) ->assertDontSee('data-module="ssl/gogetssl"', false) ->assertSee(e(__('admin.modules.type_server')));