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