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