Users.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Files_Sharing\Activity\Providers;
  7. use OCP\Activity\IEvent;
  8. class Users extends Base {
  9. public const SUBJECT_SHARED_USER_SELF = 'shared_user_self';
  10. public const SUBJECT_RESHARED_USER_BY = 'reshared_user_by';
  11. public const SUBJECT_UNSHARED_USER_SELF = 'unshared_user_self';
  12. public const SUBJECT_UNSHARED_USER_BY = 'unshared_user_by';
  13. public const SUBJECT_SHARED_WITH_BY = 'shared_with_by';
  14. public const SUBJECT_UNSHARED_BY = 'unshared_by';
  15. public const SUBJECT_SELF_UNSHARED = 'self_unshared';
  16. public const SUBJECT_SELF_UNSHARED_BY = 'self_unshared_by';
  17. public const SUBJECT_EXPIRED_USER = 'expired_user';
  18. public const SUBJECT_EXPIRED = 'expired';
  19. /**
  20. * @param IEvent $event
  21. * @return IEvent
  22. * @throws \InvalidArgumentException
  23. * @since 11.0.0
  24. */
  25. public function parseShortVersion(IEvent $event) {
  26. $parsedParameters = $this->getParsedParameters($event);
  27. if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) {
  28. $subject = $this->l->t('Shared with {user}');
  29. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) {
  30. $subject = $this->l->t('Removed share for {user}');
  31. } elseif ($event->getSubject() === self::SUBJECT_SELF_UNSHARED) {
  32. $subject = $this->l->t('You removed yourself');
  33. } elseif ($event->getSubject() === self::SUBJECT_SELF_UNSHARED_BY) {
  34. $subject = $this->l->t('{actor} removed themselves');
  35. } elseif ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) {
  36. $subject = $this->l->t('{actor} shared with {user}');
  37. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) {
  38. $subject = $this->l->t('{actor} removed share for {user}');
  39. } elseif ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) {
  40. $subject = $this->l->t('Shared by {actor}');
  41. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_BY) {
  42. $subject = $this->l->t('{actor} removed share');
  43. } elseif ($event->getSubject() === self::SUBJECT_EXPIRED_USER) {
  44. $subject = $this->l->t('Share for {user} expired');
  45. } elseif ($event->getSubject() === self::SUBJECT_EXPIRED) {
  46. $subject = $this->l->t('Share expired');
  47. } else {
  48. throw new \InvalidArgumentException();
  49. }
  50. if ($this->activityManager->getRequirePNG()) {
  51. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
  52. } else {
  53. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
  54. }
  55. $this->setSubjects($event, $subject, $parsedParameters);
  56. return $event;
  57. }
  58. /**
  59. * @param IEvent $event
  60. * @param IEvent|null $previousEvent
  61. * @return IEvent
  62. * @throws \InvalidArgumentException
  63. * @since 11.0.0
  64. */
  65. public function parseLongVersion(IEvent $event, ?IEvent $previousEvent = null) {
  66. $parsedParameters = $this->getParsedParameters($event);
  67. if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) {
  68. $subject = $this->l->t('You shared {file} with {user}');
  69. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) {
  70. $subject = $this->l->t('You removed {user} from {file}');
  71. } elseif ($event->getSubject() === self::SUBJECT_SELF_UNSHARED) {
  72. $subject = $this->l->t('You removed yourself from {file}');
  73. } elseif ($event->getSubject() === self::SUBJECT_SELF_UNSHARED_BY) {
  74. $subject = $this->l->t('{actor} removed themselves from {file}');
  75. } elseif ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) {
  76. $subject = $this->l->t('{actor} shared {file} with {user}');
  77. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) {
  78. $subject = $this->l->t('{actor} removed {user} from {file}');
  79. } elseif ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) {
  80. $subject = $this->l->t('{actor} shared {file} with you');
  81. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_BY) {
  82. $subject = $this->l->t('{actor} removed you from the share named {file}');
  83. } elseif ($event->getSubject() === self::SUBJECT_EXPIRED_USER) {
  84. $subject = $this->l->t('Share for file {file} with {user} expired');
  85. } elseif ($event->getSubject() === self::SUBJECT_EXPIRED) {
  86. $subject = $this->l->t('Share for file {file} expired');
  87. } else {
  88. throw new \InvalidArgumentException();
  89. }
  90. if ($this->activityManager->getRequirePNG()) {
  91. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
  92. } else {
  93. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
  94. }
  95. $this->setSubjects($event, $subject, $parsedParameters);
  96. return $event;
  97. }
  98. protected function getParsedParameters(IEvent $event) {
  99. $subject = $event->getSubject();
  100. $parameters = $event->getSubjectParameters();
  101. switch ($subject) {
  102. case self::SUBJECT_SHARED_USER_SELF:
  103. case self::SUBJECT_UNSHARED_USER_SELF:
  104. case self::SUBJECT_EXPIRED_USER:
  105. case self::SUBJECT_EXPIRED:
  106. return [
  107. 'file' => $this->getFile($parameters[0], $event),
  108. 'user' => $this->getUser($parameters[1]),
  109. ];
  110. case self::SUBJECT_SHARED_WITH_BY:
  111. case self::SUBJECT_UNSHARED_BY:
  112. case self::SUBJECT_SELF_UNSHARED:
  113. case self::SUBJECT_SELF_UNSHARED_BY:
  114. return [
  115. 'file' => $this->getFile($parameters[0], $event),
  116. 'actor' => $this->getUser($parameters[1]),
  117. ];
  118. case self::SUBJECT_RESHARED_USER_BY:
  119. case self::SUBJECT_UNSHARED_USER_BY:
  120. return [
  121. 'file' => $this->getFile($parameters[0], $event),
  122. 'user' => $this->getUser($parameters[2]),
  123. 'actor' => $this->getUser($parameters[1]),
  124. ];
  125. }
  126. return [];
  127. }
  128. }