1
0

Application.php 3.8 KB

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