Application.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\UserStatus\AppInfo;
  8. use OCA\UserStatus\Capabilities;
  9. use OCA\UserStatus\Connector\UserStatusProvider;
  10. use OCA\UserStatus\Dashboard\UserStatusWidget;
  11. use OCA\UserStatus\Listener\BeforeTemplateRenderedListener;
  12. use OCA\UserStatus\Listener\OutOfOfficeStatusListener;
  13. use OCA\UserStatus\Listener\UserDeletedListener;
  14. use OCA\UserStatus\Listener\UserLiveStatusListener;
  15. use OCP\AppFramework\App;
  16. use OCP\AppFramework\Bootstrap\IBootContext;
  17. use OCP\AppFramework\Bootstrap\IBootstrap;
  18. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  19. use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
  20. use OCP\IConfig;
  21. use OCP\User\Events\OutOfOfficeChangedEvent;
  22. use OCP\User\Events\OutOfOfficeClearedEvent;
  23. use OCP\User\Events\OutOfOfficeEndedEvent;
  24. use OCP\User\Events\OutOfOfficeScheduledEvent;
  25. use OCP\User\Events\OutOfOfficeStartedEvent;
  26. use OCP\User\Events\UserDeletedEvent;
  27. use OCP\User\Events\UserLiveStatusEvent;
  28. use OCP\UserStatus\IManager;
  29. /**
  30. * Class Application
  31. *
  32. * @package OCA\UserStatus\AppInfo
  33. */
  34. class Application extends App implements IBootstrap {
  35. /** @var string */
  36. public const APP_ID = 'user_status';
  37. /**
  38. * Application constructor.
  39. *
  40. * @param array $urlParams
  41. */
  42. public function __construct(array $urlParams = []) {
  43. parent::__construct(self::APP_ID, $urlParams);
  44. }
  45. /**
  46. * @inheritDoc
  47. */
  48. public function register(IRegistrationContext $context): void {
  49. // Register OCS Capabilities
  50. $context->registerCapability(Capabilities::class);
  51. // Register Event Listeners
  52. $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
  53. $context->registerEventListener(UserLiveStatusEvent::class, UserLiveStatusListener::class);
  54. $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
  55. $context->registerEventListener(OutOfOfficeChangedEvent::class, OutOfOfficeStatusListener::class);
  56. $context->registerEventListener(OutOfOfficeScheduledEvent::class, OutOfOfficeStatusListener::class);
  57. $context->registerEventListener(OutOfOfficeClearedEvent::class, OutOfOfficeStatusListener::class);
  58. $context->registerEventListener(OutOfOfficeStartedEvent::class, OutOfOfficeStatusListener::class);
  59. $context->registerEventListener(OutOfOfficeEndedEvent::class, OutOfOfficeStatusListener::class);
  60. $config = $this->getContainer()->query(IConfig::class);
  61. $shareeEnumeration = $config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
  62. $shareeEnumerationInGroupOnly = $shareeEnumeration && $config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
  63. $shareeEnumerationPhone = $shareeEnumeration && $config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
  64. // Register the Dashboard panel if user enumeration is enabled and not limited
  65. if ($shareeEnumeration && !$shareeEnumerationInGroupOnly && !$shareeEnumerationPhone) {
  66. $context->registerDashboardWidget(UserStatusWidget::class);
  67. }
  68. }
  69. public function boot(IBootContext $context): void {
  70. /** @var IManager $userStatusManager */
  71. $userStatusManager = $context->getServerContainer()->get(IManager::class);
  72. $userStatusManager->registerProvider(UserStatusProvider::class);
  73. }
  74. }