]> BookStack Code Mirror - bookstack/blob - app/Settings/SettingController.php
Added activity text for each activity type
[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     protected array $settingCategories = ['features', 'customization', 'registration'];
13
14     /**
15      * Handle requests to the settings index path.
16      */
17     public function index()
18     {
19         return redirect('/settings/features');
20     }
21
22     /**
23      * Display the settings for the given category.
24      */
25     public function category(string $category)
26     {
27         $this->ensureCategoryExists($category);
28         $this->checkPermission('settings-manage');
29         $this->setPageTitle(trans('settings.settings'));
30
31         // Get application version
32         $version = trim(file_get_contents(base_path('version')));
33
34         return view('settings.' . $category, [
35             'category'  => $category,
36             'version'   => $version,
37             'guestUser' => User::getDefault(),
38         ]);
39     }
40
41     /**
42      * Update the specified settings in storage.
43      */
44     public function update(Request $request, AppSettingsStore $store, string $category)
45     {
46         $this->ensureCategoryExists($category);
47         $this->preventAccessInDemoMode();
48         $this->checkPermission('settings-manage');
49         $this->validate($request, [
50             'app_logo' => ['nullable', ...$this->getImageValidationRules()],
51             'app_icon' => ['nullable', ...$this->getImageValidationRules()],
52         ]);
53
54         $store->storeFromUpdateRequest($request, $category);
55         $this->logActivity(ActivityType::SETTINGS_UPDATE, $category);
56
57         return redirect("/settings/{$category}");
58     }
59
60     protected function ensureCategoryExists(string $category): void
61     {
62         if (!in_array($category, $this->settingCategories)) {
63             abort(404);
64         }
65     }
66 }