2021-06-26 17:23:15 +02:00
|
|
|
<?php
|
|
|
|
|
2023-05-17 18:56:55 +02:00
|
|
|
namespace BookStack\Settings;
|
2015-08-30 16:31:16 +02:00
|
|
|
|
2023-05-17 18:56:55 +02:00
|
|
|
use BookStack\Activity\ActivityType;
|
|
|
|
use BookStack\Http\Controllers\Controller;
|
|
|
|
use BookStack\Users\Models\User;
|
2015-08-30 16:31:16 +02:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class SettingController extends Controller
|
|
|
|
{
|
2022-03-28 12:16:20 +02:00
|
|
|
protected array $settingCategories = ['features', 'customization', 'registration'];
|
|
|
|
|
2015-08-30 16:31:16 +02:00
|
|
|
/**
|
2022-04-24 19:22:40 +02:00
|
|
|
* Handle requests to the settings index path.
|
2015-08-30 16:31:16 +02:00
|
|
|
*/
|
2022-03-30 20:15:24 +02:00
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
return redirect('/settings/features');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the settings for the given category.
|
|
|
|
*/
|
|
|
|
public function category(string $category)
|
2015-08-30 16:31:16 +02:00
|
|
|
{
|
2022-03-28 12:16:20 +02:00
|
|
|
$this->ensureCategoryExists($category);
|
2016-02-27 20:24:42 +01:00
|
|
|
$this->checkPermission('settings-manage');
|
2018-05-27 20:40:07 +02:00
|
|
|
$this->setPageTitle(trans('settings.settings'));
|
2016-05-03 22:10:05 +02:00
|
|
|
|
|
|
|
// Get application version
|
2016-10-30 18:44:00 +01:00
|
|
|
$version = trim(file_get_contents(base_path('version')));
|
2016-05-03 22:10:05 +02:00
|
|
|
|
2022-03-28 12:09:55 +02:00
|
|
|
return view('settings.' . $category, [
|
|
|
|
'category' => $category,
|
2021-06-26 17:23:15 +02:00
|
|
|
'version' => $version,
|
|
|
|
'guestUser' => User::getDefault(),
|
2019-02-16 15:17:35 +01:00
|
|
|
]);
|
2015-08-30 16:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified settings in storage.
|
|
|
|
*/
|
2023-01-25 12:03:19 +01:00
|
|
|
public function update(Request $request, AppSettingsStore $store, string $category)
|
2015-08-30 16:31:16 +02:00
|
|
|
{
|
2022-03-28 12:16:20 +02:00
|
|
|
$this->ensureCategoryExists($category);
|
2019-09-19 16:12:10 +02:00
|
|
|
$this->preventAccessInDemoMode();
|
2016-02-27 20:24:42 +01:00
|
|
|
$this->checkPermission('settings-manage');
|
2019-05-04 16:48:15 +02:00
|
|
|
$this->validate($request, [
|
2023-01-25 12:03:19 +01:00
|
|
|
'app_logo' => ['nullable', ...$this->getImageValidationRules()],
|
|
|
|
'app_icon' => ['nullable', ...$this->getImageValidationRules()],
|
2019-05-04 16:48:15 +02:00
|
|
|
]);
|
2015-12-31 18:57:34 +01:00
|
|
|
|
2023-01-25 12:03:19 +01:00
|
|
|
$store->storeFromUpdateRequest($request, $category);
|
2015-12-31 18:57:34 +01:00
|
|
|
|
2022-03-28 12:09:55 +02:00
|
|
|
$this->logActivity(ActivityType::SETTINGS_UPDATE, $category);
|
2019-10-05 13:55:01 +02:00
|
|
|
$this->showSuccessNotification(trans('settings.settings_save_success'));
|
2021-06-26 17:23:15 +02:00
|
|
|
|
2022-05-05 10:33:25 +02:00
|
|
|
return redirect("/settings/{$category}");
|
2015-08-30 16:31:16 +02:00
|
|
|
}
|
2022-03-28 12:16:20 +02:00
|
|
|
|
|
|
|
protected function ensureCategoryExists(string $category): void
|
|
|
|
{
|
|
|
|
if (!in_array($category, $this->settingCategories)) {
|
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
}
|
2015-08-30 16:31:16 +02:00
|
|
|
}
|