Application.php 3.3 KB

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