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