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