Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The addon automatically detects your Statamic version and uses the appropriate U

Navigate to **Utilities > Maintenance** in the control panel to configure and activate maintenance mode.

Control panel users with "access cp" permission can browse the frontend during maintenance.
Control panel users with at least one of the permissions defined in config/maintenance-mode or the default "access cp" permission can browse the frontend during maintenance.

## Configuration

Expand Down
23 changes: 23 additions & 0 deletions config/maintenance-mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,27 @@
|
*/
'show_frontend_notice' => true,

/*
|--------------------------------------------------------------------------
| Only Super Users have Maintenance mode menu
|--------------------------------------------------------------------------
|
| Controls whether to display the maintenance mode in utilities nav for all
| users or superusers only
|
*/
'show_menu_for_supers_only' => false,

/*
|--------------------------------------------------------------------------
| Permissions Allowed to Bypass Maintenance Mode
|--------------------------------------------------------------------------
|
| Super users and users with at least one of the below permissions will be
| allowed to bypass maintenance mode
| By default, users with "access cp" permissions can bypass maintenance mode
|
*/
'allow_bypass_for_perms' => ['access cp'],
];
5 changes: 4 additions & 1 deletion src/Http/Controllers/MaintenanceStatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ protected function isAuthenticatedCpUser(): bool

$user = User::find($authUser->getAuthIdentifier());

return $user && ($user->isSuper() || $user->hasPermission('access cp'));
return $user && ($user->isSuper() || ! empty(array_filter(
config('statamic.maintenance-mode.allow_bypass_for_perms', []),
fn ($perm) => $user->hasPermission($perm)
)));
}

protected function hasValidBypassCookie(Request $request): bool
Expand Down
5 changes: 4 additions & 1 deletion src/Http/Middleware/PreventRequestsDuringMaintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ protected function isAuthenticatedCpUser($request): bool
// Find the user and check permissions
$user = User::find($userId);

return $user && ($user->isSuper() || $user->hasPermission('access cp'));
return $user && ($user->isSuper() || ! empty(array_filter(
config('statamic.maintenance-mode.allow_bypass_for_perms', []),
fn ($perm) => $user->hasPermission($perm)
)));
} catch (Throwable) {
return false;
}
Expand Down
8 changes: 8 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as LaravelMiddleware;
use Illuminate\Support\Facades\Route;
use Statamic\CP\Utilities\Utility;
use Statamic\Facades\User;
use Statamic\Facades\Utility as UtilityFacade;
use Statamic\Providers\AddonServiceProvider;

Expand Down Expand Up @@ -58,7 +59,14 @@ public function register(): void

protected function registerUtility(): void
{

UtilityFacade::extend(function () {
$canDisplayforSupersOnly = config('statamic.maintenance-mode.show_menu_for_supers_only', false);

if ($canDisplayforSupersOnly && ! User::current()?->isSuper()) {
return;
}

$utility = UtilityFacade::register('maintenance-mode')
->title(__('Maintenance Mode'))
->navTitle(__('Maintenance'))
Expand Down