namespace BookStack\Users\Controllers;
use BookStack\Http\Controller;
+use BookStack\Permissions\PermissionApplicator;
+use BookStack\Settings\UserNotificationPreferences;
use BookStack\Settings\UserShortcutMap;
use BookStack\Users\UserRepo;
use Illuminate\Http\Request;
class UserPreferencesController extends Controller
{
- protected UserRepo $userRepo;
+ public function __construct(
+ protected UserRepo $userRepo
+ ) {
+ }
- public function __construct(UserRepo $userRepo)
+ /**
+ * Show the overview for user preferences.
+ */
+ public function index()
{
- $this->userRepo = $userRepo;
+ return view('users.preferences.index');
}
/**
$shortcuts = UserShortcutMap::fromUserPreferences();
$enabled = setting()->getForCurrentUser('ui-shortcuts-enabled', false);
+ $this->setPageTitle(trans('preferences.shortcuts_interface'));
+
return view('users.preferences.shortcuts', [
'shortcuts' => $shortcuts,
'enabled' => $enabled,
return redirect('/preferences/shortcuts');
}
+ /**
+ * Show the notification preferences for the current user.
+ */
+ public function showNotifications(PermissionApplicator $permissions)
+ {
+ $this->checkPermission('receive-notifications');
+ $this->preventGuestAccess();
+
+ $preferences = (new UserNotificationPreferences(user()));
+
+ $query = user()->watches()->getQuery();
+ $query = $permissions->restrictEntityRelationQuery($query, 'watches', 'watchable_id', 'watchable_type');
+ $query = $permissions->filterDeletedFromEntityRelationQuery($query, 'watches', 'watchable_id', 'watchable_type');
+ $watches = $query->with('watchable')->paginate(20);
+
+ $this->setPageTitle(trans('preferences.notifications'));
+ return view('users.preferences.notifications', [
+ 'preferences' => $preferences,
+ 'watches' => $watches,
+ ]);
+ }
+
+ /**
+ * Update the notification preferences for the current user.
+ */
+ public function updateNotifications(Request $request)
+ {
+ $this->checkPermission('receive-notifications');
+ $this->preventGuestAccess();
+ $data = $this->validate($request, [
+ 'preferences' => ['required', 'array'],
+ 'preferences.*' => ['required', 'string'],
+ ]);
+
+ $preferences = (new UserNotificationPreferences(user()));
+ $preferences->updateFromSettingsArray($data['preferences']);
+ $this->showSuccessNotification(trans('preferences.notifications_update_success'));
+
+ return redirect('/preferences/notifications');
+ }
+
/**
* Update the preferred view format for a list view of the given type.
*/
*/
public function toggleDarkMode()
{
- $enabled = setting()->getForCurrentUser('dark-mode-enabled', false);
+ $enabled = setting()->getForCurrentUser('dark-mode-enabled');
setting()->putForCurrentUser('dark-mode-enabled', $enabled ? 'false' : 'true');
return redirect()->back();
{
$validated = $this->validate($request, [
'language' => ['required', 'string', 'max:20'],
- 'active' => ['required', 'bool'],
+ 'active' => ['required', 'bool'],
]);
$currentFavoritesStr = setting()->getForCurrentUser('code-language-favourites', '');