Application.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\OutOfOfficeScheduledEvent;
  24. use OCP\User\Events\UserDeletedEvent;
  25. use OCP\User\Events\UserLiveStatusEvent;
  26. use OCP\UserStatus\IManager;
  27. /**
  28. * Class Application
  29. *
  30. * @package OCA\UserStatus\AppInfo
  31. */
  32. class Application extends App implements IBootstrap {
  33. /** @var string */
  34. public const APP_ID = 'user_status';
  35. /**
  36. * Application constructor.
  37. *
  38. * @param array $urlParams
  39. */
  40. public function __construct(array $urlParams = []) {
  41. parent::__construct(self::APP_ID, $urlParams);
  42. }
  43. /**
  44. * @inheritDoc
  45. */
  46. public function register(IRegistrationContext $context): void {
  47. // Register OCS Capabilities
  48. $context->registerCapability(Capabilities::class);
  49. // Register Event Listeners
  50. $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
  51. $context->registerEventListener(UserLiveStatusEvent::class, UserLiveStatusListener::class);
  52. $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
  53. $context->registerEventListener(OutOfOfficeChangedEvent::class, OutOfOfficeStatusListener::class);
  54. $context->registerEventListener(OutOfOfficeScheduledEvent::class, OutOfOfficeStatusListener::class);
  55. $context->registerEventListener(OutOfOfficeClearedEvent::class, OutOfOfficeStatusListener::class);
  56. $config = $this->getContainer()->query(IConfig::class);
  57. $shareeEnumeration = $config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
  58. $shareeEnumerationInGroupOnly = $shareeEnumeration && $config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
  59. $shareeEnumerationPhone = $shareeEnumeration && $config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
  60. // Register the Dashboard panel if user enumeration is enabled and not limited
  61. if ($shareeEnumeration && !$shareeEnumerationInGroupOnly && !$shareeEnumerationPhone) {
  62. $context->registerDashboardWidget(UserStatusWidget::class);
  63. }
  64. }
  65. public function boot(IBootContext $context): void {
  66. /** @var IManager $userStatusManager */
  67. $userStatusManager = $context->getServerContainer()->get(IManager::class);
  68. $userStatusManager->registerProvider(UserStatusProvider::class);
  69. }
  70. }