]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/SettingController.php
Added ability to control app icon (favicon) via settings
[bookstack] / app / Http / Controllers / SettingController.php
1 <?php
2
3 namespace BookStack\Http\Controllers;
4
5 use BookStack\Actions\ActivityType;
6 use BookStack\Auth\User;
7 use BookStack\Settings\AppSettingsStore;
8 use BookStack\Uploads\ImageRepo;
9 use Illuminate\Http\Request;
10
11 class SettingController extends Controller
12 {
13     protected array $settingCategories = ['features', 'customization', 'registration'];
14
15     /**
16      * Handle requests to the settings index path.
17      */
18     public function index()
19     {
20         return redirect('/settings/features');
21     }
22
23     /**
24      * Display the settings for the given category.
25      */
26     public function category(string $category)
27     {
28         $this->ensureCategoryExists($category);
29         $this->checkPermission('settings-manage');
30         $this->setPageTitle(trans('settings.settings'));
31
32         // Get application version
33         $version = trim(file_get_contents(base_path('version')));
34
35         return view('settings.' . $category, [
36             'category'  => $category,
37             'version'   => $version,
38             'guestUser' => User::getDefault(),
39         ]);
40     }
41
42     /**
43      * Update the specified settings in storage.
44      */
45     public function update(Request $request, AppSettingsStore $store, string $category)
46     {
47         $this->ensureCategoryExists($category);
48         $this->preventAccessInDemoMode();
49         $this->checkPermission('settings-manage');
50         $this->validate($request, [
51             'app_logo' => ['nullable', ...$this->getImageValidationRules()],
52             'app_icon' => ['nullable', ...$this->getImageValidationRules()],
53         ]);
54
55         $store->storeFromUpdateRequest($request, $category);
56
57         $this->logActivity(ActivityType::SETTINGS_UPDATE, $category);
58         $this->showSuccessNotification(trans('settings.settings_save_success'));
59
60         return redirect("/settings/{$category}");
61     }
62
63     protected function ensureCategoryExists(string $category): void
64     {
65         if (!in_array($category, $this->settingCategories)) {
66             abort(404);
67         }
68     }
69 }