|
91 | 91 | use OCP\Group\Events\GroupDeletedEvent; |
92 | 92 | use OCP\Group\Events\UserAddedEvent; |
93 | 93 | use OCP\Group\Events\UserRemovedEvent; |
| 94 | +use OCP\Group\ISubAdmin; |
94 | 95 | use OCP\IConfig; |
| 96 | +use OCP\IGroupManager; |
| 97 | +use OCP\INavigationManager; |
95 | 98 | use OCP\IURLGenerator; |
| 99 | +use OCP\IUserSession; |
96 | 100 | use OCP\L10N\IFactory; |
97 | 101 | use OCP\Mail\IMailer; |
98 | 102 | use OCP\Security\ICrypto; |
@@ -227,5 +231,93 @@ public function register(IRegistrationContext $context): void { |
227 | 231 |
|
228 | 232 | #[\Override] |
229 | 233 | public function boot(IBootContext $context): void { |
| 234 | + $context->injectFn($this->registerNavigationEntries(...)); |
| 235 | + } |
| 236 | + |
| 237 | + /** |
| 238 | + * Registers the navigation entries for the user settings. |
| 239 | + * Needed as some entries are dynamic and thus we cannot use the appinfo/info.xml |
| 240 | + * |
| 241 | + * Registers the following entries: |
| 242 | + * - Appearance and accessibility |
| 243 | + * - Personal settings (named "Settings" for non-admins) |
| 244 | + * - Accounts (only for subadmins) |
| 245 | + * - Help & privacy (conditionally enabled based on config) |
| 246 | + */ |
| 247 | + public function registerNavigationEntries( |
| 248 | + INavigationManager $navigationManager, |
| 249 | + IURLGenerator $urlGenerator, |
| 250 | + IUserSession $userSession, |
| 251 | + IConfig $config, |
| 252 | + ): void { |
| 253 | + if ($userSession->getUser() === null) { |
| 254 | + return; |
| 255 | + } |
| 256 | + |
| 257 | + $l = Server::get(IFactory::class) |
| 258 | + ->get('settings'); |
| 259 | + $groupManager = Server::get(IGroupManager::class); |
| 260 | + $subAdmin = Server::get(ISubAdmin::class); |
| 261 | + $isAdmin = $groupManager->isAdmin($userSession->getUser()->getUID()); |
| 262 | + $isSubAdmin = $subAdmin->isSubAdmin($userSession->getUser()); |
| 263 | + |
| 264 | + // Accessibility settings - the URL is dynamic (route parameters) which is currently not supported by appinfo.xml |
| 265 | + $navigationManager->add([ |
| 266 | + 'type' => 'settings', |
| 267 | + 'id' => 'accessibility_settings', |
| 268 | + 'order' => 2, |
| 269 | + 'href' => $urlGenerator->linkToRoute('settings.PersonalSettings.index', ['section' => 'theming']), |
| 270 | + 'name' => $l->t('Appearance and accessibility'), |
| 271 | + 'icon' => $urlGenerator->imagePath('theming', 'accessibility-dark.svg'), |
| 272 | + ]); |
| 273 | + |
| 274 | + // Personal settings - this entry is dynamic so we cannot use appinfo |
| 275 | + $navigationManager->add([ |
| 276 | + 'type' => 'settings', |
| 277 | + 'id' => 'settings_personal', |
| 278 | + 'order' => 3, |
| 279 | + 'href' => $urlGenerator->linkToRoute('settings.PersonalSettings.index'), |
| 280 | + 'name' => $isAdmin |
| 281 | + ? $l->t('Personal settings') |
| 282 | + : $l->t('Settings'), |
| 283 | + 'icon' => $isAdmin |
| 284 | + ? $urlGenerator->imagePath('settings', 'personal.svg') |
| 285 | + : $urlGenerator->imagePath('settings', 'admin.svg'), |
| 286 | + ]); |
| 287 | + |
| 288 | + if ($isAdmin) { |
| 289 | + $navigationManager->add([ |
| 290 | + 'type' => 'settings', |
| 291 | + 'id' => 'settings_administration', |
| 292 | + 'order' => 4, |
| 293 | + 'href' => $urlGenerator->linkToRoute('settings.adminSettings.index'), |
| 294 | + 'name' => $l->t('Administration settings'), |
| 295 | + 'icon' => $urlGenerator->imagePath('settings', 'admin.svg'), |
| 296 | + ]); |
| 297 | + } |
| 298 | + |
| 299 | + // User management is conditionally enabled for subadmins, but appinfo currently only supports full admins |
| 300 | + if ($isSubAdmin) { |
| 301 | + $navigationManager->add([ |
| 302 | + 'type' => 'settings', |
| 303 | + 'id' => 'core_users', |
| 304 | + 'order' => 6, |
| 305 | + 'href' => $urlGenerator->linkToRoute('settings.Users.usersList'), |
| 306 | + 'name' => $l->t('Accounts'), |
| 307 | + 'icon' => $urlGenerator->imagePath('settings', 'users.svg'), |
| 308 | + ]); |
| 309 | + } |
| 310 | + |
| 311 | + // conditionally enabled navigation entry |
| 312 | + if ($config->getSystemValueBool('knowledgebaseenabled', true)) { |
| 313 | + $navigationManager->add([ |
| 314 | + 'type' => 'settings', |
| 315 | + 'id' => 'help', |
| 316 | + 'order' => 99998, |
| 317 | + 'href' => $urlGenerator->linkToRoute('settings.Help.help'), |
| 318 | + 'name' => $l->t('Help & privacy'), |
| 319 | + 'icon' => $urlGenerator->imagePath('settings', 'help.svg'), |
| 320 | + ]); |
| 321 | + } |
230 | 322 | } |
231 | 323 | } |
0 commit comments