Users.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author John Molakvoæ <skjnldsv@protonmail.com>
  8. * @author Kevin Ndung'u <kevgathuku@gmail.com>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\Files_Sharing\Activity\Providers;
  27. use OCP\Activity\IEvent;
  28. class Users extends Base {
  29. public const SUBJECT_SHARED_USER_SELF = 'shared_user_self';
  30. public const SUBJECT_RESHARED_USER_BY = 'reshared_user_by';
  31. public const SUBJECT_UNSHARED_USER_SELF = 'unshared_user_self';
  32. public const SUBJECT_UNSHARED_USER_BY = 'unshared_user_by';
  33. public const SUBJECT_SHARED_WITH_BY = 'shared_with_by';
  34. public const SUBJECT_UNSHARED_BY = 'unshared_by';
  35. public const SUBJECT_SELF_UNSHARED = 'self_unshared';
  36. public const SUBJECT_SELF_UNSHARED_BY = 'self_unshared_by';
  37. public const SUBJECT_EXPIRED_USER = 'expired_user';
  38. public const SUBJECT_EXPIRED = 'expired';
  39. /**
  40. * @param IEvent $event
  41. * @return IEvent
  42. * @throws \InvalidArgumentException
  43. * @since 11.0.0
  44. */
  45. public function parseShortVersion(IEvent $event) {
  46. $parsedParameters = $this->getParsedParameters($event);
  47. if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) {
  48. $subject = $this->l->t('Shared with {user}');
  49. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) {
  50. $subject = $this->l->t('Removed share for {user}');
  51. } elseif ($event->getSubject() === self::SUBJECT_SELF_UNSHARED) {
  52. $subject = $this->l->t('You removed yourself');
  53. } elseif ($event->getSubject() === self::SUBJECT_SELF_UNSHARED_BY) {
  54. $subject = $this->l->t('{actor} removed themselves');
  55. } elseif ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) {
  56. $subject = $this->l->t('{actor} shared with {user}');
  57. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) {
  58. $subject = $this->l->t('{actor} removed share for {user}');
  59. } elseif ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) {
  60. $subject = $this->l->t('Shared by {actor}');
  61. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_BY) {
  62. $subject = $this->l->t('{actor} removed share');
  63. } elseif ($event->getSubject() === self::SUBJECT_EXPIRED_USER) {
  64. $subject = $this->l->t('Share for {user} expired');
  65. } elseif ($event->getSubject() === self::SUBJECT_EXPIRED) {
  66. $subject = $this->l->t('Share expired');
  67. } else {
  68. throw new \InvalidArgumentException();
  69. }
  70. if ($this->activityManager->getRequirePNG()) {
  71. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
  72. } else {
  73. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
  74. }
  75. $this->setSubjects($event, $subject, $parsedParameters);
  76. return $event;
  77. }
  78. /**
  79. * @param IEvent $event
  80. * @param IEvent|null $previousEvent
  81. * @return IEvent
  82. * @throws \InvalidArgumentException
  83. * @since 11.0.0
  84. */
  85. public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) {
  86. $parsedParameters = $this->getParsedParameters($event);
  87. if ($event->getSubject() === self::SUBJECT_SHARED_USER_SELF) {
  88. $subject = $this->l->t('You shared {file} with {user}');
  89. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_USER_SELF) {
  90. $subject = $this->l->t('You removed {user} from {file}');
  91. } elseif ($event->getSubject() === self::SUBJECT_SELF_UNSHARED) {
  92. $subject = $this->l->t('You removed yourself from {file}');
  93. } elseif ($event->getSubject() === self::SUBJECT_SELF_UNSHARED_BY) {
  94. $subject = $this->l->t('{actor} removed themselves from {file}');
  95. } elseif ($event->getSubject() === self::SUBJECT_RESHARED_USER_BY) {
  96. $subject = $this->l->t('{actor} shared {file} with {user}');
  97. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_USER_BY) {
  98. $subject = $this->l->t('{actor} removed {user} from {file}');
  99. } elseif ($event->getSubject() === self::SUBJECT_SHARED_WITH_BY) {
  100. $subject = $this->l->t('{actor} shared {file} with you');
  101. } elseif ($event->getSubject() === self::SUBJECT_UNSHARED_BY) {
  102. $subject = $this->l->t('{actor} removed you from the share named {file}');
  103. } elseif ($event->getSubject() === self::SUBJECT_EXPIRED_USER) {
  104. $subject = $this->l->t('Share for file {file} with {user} expired');
  105. } elseif ($event->getSubject() === self::SUBJECT_EXPIRED) {
  106. $subject = $this->l->t('Share for file {file} expired');
  107. } else {
  108. throw new \InvalidArgumentException();
  109. }
  110. if ($this->activityManager->getRequirePNG()) {
  111. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png')));
  112. } else {
  113. $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
  114. }
  115. $this->setSubjects($event, $subject, $parsedParameters);
  116. return $event;
  117. }
  118. protected function getParsedParameters(IEvent $event) {
  119. $subject = $event->getSubject();
  120. $parameters = $event->getSubjectParameters();
  121. switch ($subject) {
  122. case self::SUBJECT_SHARED_USER_SELF:
  123. case self::SUBJECT_UNSHARED_USER_SELF:
  124. case self::SUBJECT_EXPIRED_USER:
  125. case self::SUBJECT_EXPIRED:
  126. return [
  127. 'file' => $this->getFile($parameters[0], $event),
  128. 'user' => $this->getUser($parameters[1]),
  129. ];
  130. case self::SUBJECT_SHARED_WITH_BY:
  131. case self::SUBJECT_UNSHARED_BY:
  132. case self::SUBJECT_SELF_UNSHARED:
  133. case self::SUBJECT_SELF_UNSHARED_BY:
  134. return [
  135. 'file' => $this->getFile($parameters[0], $event),
  136. 'actor' => $this->getUser($parameters[1]),
  137. ];
  138. case self::SUBJECT_RESHARED_USER_BY:
  139. case self::SUBJECT_UNSHARED_USER_BY:
  140. return [
  141. 'file' => $this->getFile($parameters[0], $event),
  142. 'user' => $this->getUser($parameters[2]),
  143. 'actor' => $this->getUser($parameters[1]),
  144. ];
  145. }
  146. return [];
  147. }
  148. }