Application.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2020, Georg Ehrke
  5. *
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\UserStatus\AppInfo;
  25. use OCA\UserStatus\Capabilities;
  26. use OCA\UserStatus\Connector\UserStatusProvider;
  27. use OCA\UserStatus\Dashboard\UserStatusWidget;
  28. use OCA\UserStatus\Listener\BeforeTemplateRenderedListener;
  29. use OCA\UserStatus\Listener\OutOfOfficeStatusListener;
  30. use OCA\UserStatus\Listener\UserDeletedListener;
  31. use OCA\UserStatus\Listener\UserLiveStatusListener;
  32. use OCP\AppFramework\App;
  33. use OCP\AppFramework\Bootstrap\IBootContext;
  34. use OCP\AppFramework\Bootstrap\IBootstrap;
  35. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  36. use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
  37. use OCP\IConfig;
  38. use OCP\User\Events\OutOfOfficeChangedEvent;
  39. use OCP\User\Events\OutOfOfficeClearedEvent;
  40. use OCP\User\Events\OutOfOfficeEndedEvent;
  41. use OCP\User\Events\OutOfOfficeScheduledEvent;
  42. use OCP\User\Events\OutOfOfficeStartedEvent;
  43. use OCP\User\Events\UserDeletedEvent;
  44. use OCP\User\Events\UserLiveStatusEvent;
  45. use OCP\UserStatus\IManager;
  46. /**
  47. * Class Application
  48. *
  49. * @package OCA\UserStatus\AppInfo
  50. */
  51. class Application extends App implements IBootstrap {
  52. /** @var string */
  53. public const APP_ID = 'user_status';
  54. /**
  55. * Application constructor.
  56. *
  57. * @param array $urlParams
  58. */
  59. public function __construct(array $urlParams = []) {
  60. parent::__construct(self::APP_ID, $urlParams);
  61. }
  62. /**
  63. * @inheritDoc
  64. */
  65. public function register(IRegistrationContext $context): void {
  66. // Register OCS Capabilities
  67. $context->registerCapability(Capabilities::class);
  68. // Register Event Listeners
  69. $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
  70. $context->registerEventListener(UserLiveStatusEvent::class, UserLiveStatusListener::class);
  71. $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
  72. $context->registerEventListener(OutOfOfficeChangedEvent::class, OutOfOfficeStatusListener::class);
  73. $context->registerEventListener(OutOfOfficeScheduledEvent::class, OutOfOfficeStatusListener::class);
  74. $context->registerEventListener(OutOfOfficeClearedEvent::class, OutOfOfficeStatusListener::class);
  75. $context->registerEventListener(OutOfOfficeStartedEvent::class, OutOfOfficeStatusListener::class);
  76. $context->registerEventListener(OutOfOfficeEndedEvent::class, OutOfOfficeStatusListener::class);
  77. $config = $this->getContainer()->query(IConfig::class);
  78. $shareeEnumeration = $config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
  79. $shareeEnumerationInGroupOnly = $shareeEnumeration && $config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
  80. $shareeEnumerationPhone = $shareeEnumeration && $config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
  81. // Register the Dashboard panel if user enumeration is enabled and not limited
  82. if ($shareeEnumeration && !$shareeEnumerationInGroupOnly && !$shareeEnumerationPhone) {
  83. $context->registerDashboardWidget(UserStatusWidget::class);
  84. }
  85. }
  86. public function boot(IBootContext $context): void {
  87. /** @var IManager $userStatusManager */
  88. $userStatusManager = $context->getServerContainer()->get(IManager::class);
  89. $userStatusManager->registerProvider(UserStatusProvider::class);
  90. }
  91. }