Skip to content

Commit

Permalink
Environment settings
Browse files Browse the repository at this point in the history
  • Loading branch information
agentphoenix committed Apr 22, 2024
1 parent 273698c commit f3b3914
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public function up()
['name' => 'Posting activity settings', 'uri' => 'settings/posting-activity', 'key' => 'settings.posting-activity.edit', 'resource' => 'Nova\\Settings\\Controllers\\PostingActivitySettingsController@edit', 'layout' => 'admin'],
['name' => 'Update posting activity settings', 'uri' => 'settings/posting-activity', 'key' => 'settings.posting-activity.update', 'verb' => PageVerb::put, 'resource' => 'Nova\\Settings\\Controllers\\PostingActivitySettingsController@update', 'layout' => 'admin'],
['name' => 'Notification settings', 'uri' => 'settings/notifications', 'key' => 'settings.notifications.edit', 'resource' => 'Nova\\Settings\\Controllers\\NotificationSettingsController@edit', 'layout' => 'admin'],
['name' => 'Environment settings', 'uri' => 'settings/environment', 'key' => 'settings.environment.edit', 'resource' => 'Nova\\Settings\\Controllers\\EnvironmentSettingsController@edit', 'layout' => 'admin'],
['name' => 'Update environment settings', 'uri' => 'settings/environment', 'key' => 'settings.environment.update', 'verb' => PageVerb::put, 'resource' => 'Nova\\Settings\\Controllers\\EnvironmentSettingsController@update', 'layout' => 'admin'],

['name' => 'List rank groups', 'uri' => 'ranks/groups', 'key' => 'ranks.groups.index', 'resource' => 'Nova\\Ranks\\Controllers\\RankGroupController@index', 'layout' => 'admin'],
['name' => 'View rank group', 'uri' => 'ranks/groups/{group}/show', 'key' => 'ranks.groups.show', 'resource' => 'Nova\\Ranks\\Controllers\\RankGroupController@show', 'layout' => 'admin'],
Expand Down
77 changes: 77 additions & 0 deletions nova/resources/views/pages/settings/environment.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
@extends($meta->template)

@section('content')
<x-spacing constrained>
<x-page-header>
<x-slot name="heading">Environment settings</x-slot>

<x-slot name="actions">
<div x-data="{}">
<x-button x-on:click="$dispatch('toggle-spotlight')" color="neutral">
<x-icon name="search" size="sm"></x-icon>
Find a setting
</x-button>
</div>
</x-slot>
</x-page-header>

<x-form :action="route('settings.environment.update')" method="PUT">
<x-fieldset>
<x-fieldset.field-group class="w-full max-w-md" x-data="{ environment: '{{ app()->environment() }}' }">
<x-fieldset.field label="Environment" id="environment" name="environment">
<x-select x-model="environment">
<option value="production">Production</option>
<option value="local">Local</option>
</x-select>

<x-slot name="description">
<span x-show="environment === 'local'">
The local environment is intended only for development purposes. Some features may not
work as expected when operating in this mode.
</span>
</x-slot>
</x-fieldset.field>

<x-switch.field>
<x-fieldset.label for="debug_mode">Debug mode</x-fieldset.label>
<x-fieldset.description>
Enabling debug mode will allow informational messages, warnings, and errors to be displayed
on screen.

@if (config('app.debug'))
<x-fieldset.error-message
class="mt-2 font-semibold"
x-show="environment === 'production'"
x-cloak
>
In a production environment, debug mode should always be off. If debug mode is on in
production, you risk exposing sensitive configuration values to your end users.
</x-fieldset.error-message>
@endif
</x-fieldset.description>
<x-switch
id="debug_mode"
name="debug_mode"
:on-value="1"
:off-value="0"
:value="(int) config('app.debug')"
></x-switch>
</x-switch.field>

<x-fieldset.field
label="Site URL"
description="Use caution when changing your site’s URL as it could have unintended side effects."
id="url"
name="url"
>
<x-input.text :value="config('app.url')" placeholder="Update your site URL"></x-input.text>
</x-fieldset.field>
</x-fieldset.field-group>
</x-fieldset>

<x-fieldset.controls>
<x-button type="submit" color="primary">Update</x-button>
</x-fieldset.controls>
</x-form>
</x-spacing>
@endsection
54 changes: 1 addition & 53 deletions nova/resources/views/pages/settings/general.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
id="severity_basic"
name="update_severity[]"
value="critical"
:checked="in_array('critical', old('update_severity[]', $settings->updateSeverity))"
checked
disabled
></x-checkbox>
</x-checkbox.field>
Expand Down Expand Up @@ -157,58 +157,6 @@
</x-fieldset.field-group>
</x-fieldset>

<x-fieldset>
<x-fieldset.heading>
<x-icon name="leaf"></x-icon>
<x-fieldset.legend>Environment settings</x-fieldset.legend>
<x-fieldset.description>
Update how Nova behaves to aid in debugging any issues you may be having.
</x-fieldset.description>
</x-fieldset.heading>

<x-fieldset.field-group class="w-full max-w-md" x-data="{ environment: '{{ app()->environment() }}' }">
<x-fieldset.field label="Environment" id="environment" name="environment">
<x-select x-model="environment">
<option value="production">Production</option>
<option value="local">Local</option>
</x-select>

<x-slot name="description">
<span x-show="environment === 'local'">
The local environment is intended only for development purposes. Some features may not
work as expected when operating in this mode.
</span>
</x-slot>
</x-fieldset.field>

<x-switch.field>
<x-fieldset.label for="debug_mode">Debug mode</x-fieldset.label>
<x-fieldset.description>
Enabling debug mode will allow informational messages, warnings, and errors to be displayed
on screen.

@if (config('app.debug'))
<x-fieldset.error-message
class="mt-2 font-semibold"
x-show="environment === 'production'"
x-cloak
>
In a production environment, debug mode should always be off. If debug mode is on in
production, you risk exposing sensitive configuration values to your end users.
</x-fieldset.error-message>
@endif
</x-fieldset.description>
<x-switch
id="debug_mode"
name="debug_mode"
:on-value="1"
:off-value="0"
:value="(int) config('app.debug')"
></x-switch>
</x-switch.field>
</x-fieldset.field-group>
</x-fieldset>

<x-fieldset.controls>
<x-button type="submit" color="primary">Update</x-button>
</x-fieldset.controls>
Expand Down
6 changes: 6 additions & 0 deletions nova/resources/views/subnavs/settings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
>
Appearance
</x-nav.sub-item>
<x-nav.sub-item
:href="route('settings.environment.edit')"
:active="request()->routeIs('settings.environment.edit')"
>
Environment
</x-nav.sub-item>
<x-nav.sub-item :href="route('settings.email.edit')" :active="request()->routeIs('settings.email.edit')">
Email
</x-nav.sub-item>
Expand Down
39 changes: 39 additions & 0 deletions nova/src/Settings/Actions/UpdateEnvironment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Nova\Settings\Actions;

use Exception;
use Illuminate\Http\Request;
use Lorisleiva\Actions\Concerns\AsAction;
use Nova\Foundation\EnvWriter;
use Nova\Settings\Data\EnvironmentConfiguration;

class UpdateEnvironment
{
use AsAction;

public function handle(Request $request): void
{
$envWriter = app(EnvWriter::class);

if ($envWriter->isEnvWritable()) {
$envConfigData = EnvironmentConfiguration::from($request);

$path = $envWriter->envFilePath();

if (file_exists($path)) {
$write = $envWriter->write([
'APP_ENV' => $envConfigData->environment,
'APP_DEBUG' => $envConfigData->debugMode(),
'APP_URL' => $envConfigData->url,
]);

if (! $write) {
throw new Exception('error');
}
}
}
}
}
47 changes: 0 additions & 47 deletions nova/src/Settings/Actions/UpdateGeneral.php

This file was deleted.

38 changes: 38 additions & 0 deletions nova/src/Settings/Controllers/EnvironmentSettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Nova\Settings\Controllers;

use Illuminate\Http\Request;
use Nova\Foundation\Controllers\Controller;
use Nova\Settings\Actions\UpdateEnvironment;
use Nova\Settings\Responses\EnvironmentSettingsResponse;

class EnvironmentSettingsController extends Controller
{
public function __construct()
{
parent::__construct();

$this->middleware('auth');
}

public function edit()
{
$this->authorize('update', $settings = settings());

return EnvironmentSettingsResponse::send();
}

public function update(Request $request)
{
$this->authorize('update', settings());

UpdateEnvironment::run($request);

return redirect()
->route('settings.environment.edit')
->notify('Environment settings have been updated');
}
}
3 changes: 0 additions & 3 deletions nova/src/Settings/Controllers/GeneralSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Illuminate\Http\Request;
use Nova\Foundation\Controllers\Controller;
use Nova\Settings\Actions\UpdateGeneral;
use Nova\Settings\Actions\UpdateSettings;
use Nova\Settings\Data\General;
use Nova\Settings\Responses\GeneralSettingsResponse;
Expand Down Expand Up @@ -35,8 +34,6 @@ public function update(Request $request)

UpdateSettings::run('general', $data = General::from($request));

UpdateGeneral::run($data, $request);

return redirect()
->route('settings.general.edit')
->notify('General settings have been updated');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
use Spatie\LaravelData\Mappers\SnakeCaseMapper;

#[MapInputName(SnakeCaseMapper::class)]
class GeneralConfiguration extends Data implements Arrayable
class EnvironmentConfiguration extends Data implements Arrayable
{
public function __construct(
public ?string $url,
public ?string $environment,
public ?int $debugMode
) {
Expand Down
14 changes: 14 additions & 0 deletions nova/src/Settings/Responses/EnvironmentSettingsResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Nova\Settings\Responses;

use Nova\Foundation\Responses\Responsable;

class EnvironmentSettingsResponse extends Responsable
{
public ?string $subnav = 'settings';

public string $view = 'settings.environment';
}

0 comments on commit f3b3914

Please sign in to comment.