@@ -29,66 +29,66 @@ |
||
29 | 29 | use Sabre\HTTP\ResponseInterface; |
30 | 30 | |
31 | 31 | class BearerAuth extends AbstractBearer { |
32 | - /** @var IUserSession */ |
|
33 | - private $userSession; |
|
34 | - /** @var ISession */ |
|
35 | - private $session; |
|
36 | - /** @var IRequest */ |
|
37 | - private $request; |
|
38 | - /** @var string */ |
|
39 | - private $principalPrefix; |
|
32 | + /** @var IUserSession */ |
|
33 | + private $userSession; |
|
34 | + /** @var ISession */ |
|
35 | + private $session; |
|
36 | + /** @var IRequest */ |
|
37 | + private $request; |
|
38 | + /** @var string */ |
|
39 | + private $principalPrefix; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param IUserSession $userSession |
|
43 | - * @param ISession $session |
|
44 | - * @param string $principalPrefix |
|
45 | - * @param IRequest $request |
|
46 | - */ |
|
47 | - public function __construct(IUserSession $userSession, |
|
48 | - ISession $session, |
|
49 | - IRequest $request, |
|
50 | - $principalPrefix = 'principals/users/') { |
|
51 | - $this->userSession = $userSession; |
|
52 | - $this->session = $session; |
|
53 | - $this->request = $request; |
|
54 | - $this->principalPrefix = $principalPrefix; |
|
41 | + /** |
|
42 | + * @param IUserSession $userSession |
|
43 | + * @param ISession $session |
|
44 | + * @param string $principalPrefix |
|
45 | + * @param IRequest $request |
|
46 | + */ |
|
47 | + public function __construct(IUserSession $userSession, |
|
48 | + ISession $session, |
|
49 | + IRequest $request, |
|
50 | + $principalPrefix = 'principals/users/') { |
|
51 | + $this->userSession = $userSession; |
|
52 | + $this->session = $session; |
|
53 | + $this->request = $request; |
|
54 | + $this->principalPrefix = $principalPrefix; |
|
55 | 55 | |
56 | - // setup realm |
|
57 | - $defaults = new \OCP\Defaults(); |
|
58 | - $this->realm = $defaults->getName(); |
|
59 | - } |
|
56 | + // setup realm |
|
57 | + $defaults = new \OCP\Defaults(); |
|
58 | + $this->realm = $defaults->getName(); |
|
59 | + } |
|
60 | 60 | |
61 | - private function setupUserFs($userId) { |
|
62 | - \OC_Util::setupFS($userId); |
|
63 | - $this->session->close(); |
|
64 | - return $this->principalPrefix . $userId; |
|
65 | - } |
|
61 | + private function setupUserFs($userId) { |
|
62 | + \OC_Util::setupFS($userId); |
|
63 | + $this->session->close(); |
|
64 | + return $this->principalPrefix . $userId; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * {@inheritdoc} |
|
69 | - */ |
|
70 | - public function validateBearerToken($bearerToken) { |
|
71 | - \OC_Util::setupFS(); |
|
67 | + /** |
|
68 | + * {@inheritdoc} |
|
69 | + */ |
|
70 | + public function validateBearerToken($bearerToken) { |
|
71 | + \OC_Util::setupFS(); |
|
72 | 72 | |
73 | - if(!$this->userSession->isLoggedIn()) { |
|
74 | - $this->userSession->tryTokenLogin($this->request); |
|
75 | - } |
|
76 | - if($this->userSession->isLoggedIn()) { |
|
77 | - return $this->setupUserFs($this->userSession->getUser()->getUID()); |
|
78 | - } |
|
73 | + if(!$this->userSession->isLoggedIn()) { |
|
74 | + $this->userSession->tryTokenLogin($this->request); |
|
75 | + } |
|
76 | + if($this->userSession->isLoggedIn()) { |
|
77 | + return $this->setupUserFs($this->userSession->getUser()->getUID()); |
|
78 | + } |
|
79 | 79 | |
80 | - return false; |
|
81 | - } |
|
80 | + return false; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * \Sabre\DAV\Auth\Backend\AbstractBearer::challenge sets an WWW-Authenticate |
|
85 | - * header which some DAV clients can't handle. Thus we override this function |
|
86 | - * and make it simply return a 401. |
|
87 | - * |
|
88 | - * @param RequestInterface $request |
|
89 | - * @param ResponseInterface $response |
|
90 | - */ |
|
91 | - public function challenge(RequestInterface $request, ResponseInterface $response) { |
|
92 | - $response->setStatus(401); |
|
93 | - } |
|
83 | + /** |
|
84 | + * \Sabre\DAV\Auth\Backend\AbstractBearer::challenge sets an WWW-Authenticate |
|
85 | + * header which some DAV clients can't handle. Thus we override this function |
|
86 | + * and make it simply return a 401. |
|
87 | + * |
|
88 | + * @param RequestInterface $request |
|
89 | + * @param ResponseInterface $response |
|
90 | + */ |
|
91 | + public function challenge(RequestInterface $request, ResponseInterface $response) { |
|
92 | + $response->setStatus(401); |
|
93 | + } |
|
94 | 94 | } |
@@ -30,33 +30,33 @@ |
||
30 | 30 | |
31 | 31 | class ManagerFactory implements ICommentsManagerFactory { |
32 | 32 | |
33 | - /** |
|
34 | - * Server container |
|
35 | - * |
|
36 | - * @var IServerContainer |
|
37 | - */ |
|
38 | - private $serverContainer; |
|
33 | + /** |
|
34 | + * Server container |
|
35 | + * |
|
36 | + * @var IServerContainer |
|
37 | + */ |
|
38 | + private $serverContainer; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Constructor for the comments manager factory |
|
42 | - * |
|
43 | - * @param IServerContainer $serverContainer server container |
|
44 | - */ |
|
45 | - public function __construct(IServerContainer $serverContainer) { |
|
46 | - $this->serverContainer = $serverContainer; |
|
47 | - } |
|
40 | + /** |
|
41 | + * Constructor for the comments manager factory |
|
42 | + * |
|
43 | + * @param IServerContainer $serverContainer server container |
|
44 | + */ |
|
45 | + public function __construct(IServerContainer $serverContainer) { |
|
46 | + $this->serverContainer = $serverContainer; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * creates and returns an instance of the ICommentsManager |
|
51 | - * |
|
52 | - * @return ICommentsManager |
|
53 | - * @since 9.0.0 |
|
54 | - */ |
|
55 | - public function getManager() { |
|
56 | - return new Manager( |
|
57 | - $this->serverContainer->getDatabaseConnection(), |
|
58 | - $this->serverContainer->getLogger(), |
|
59 | - $this->serverContainer->getConfig() |
|
60 | - ); |
|
61 | - } |
|
49 | + /** |
|
50 | + * creates and returns an instance of the ICommentsManager |
|
51 | + * |
|
52 | + * @return ICommentsManager |
|
53 | + * @since 9.0.0 |
|
54 | + */ |
|
55 | + public function getManager() { |
|
56 | + return new Manager( |
|
57 | + $this->serverContainer->getDatabaseConnection(), |
|
58 | + $this->serverContainer->getLogger(), |
|
59 | + $this->serverContainer->getConfig() |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | } |
@@ -24,16 +24,16 @@ |
||
24 | 24 | use Sabre\DAV\Tree; |
25 | 25 | |
26 | 26 | class CachingTree extends Tree { |
27 | - /** |
|
28 | - * Store a node in the cache |
|
29 | - * |
|
30 | - * @param Node $node |
|
31 | - * @param null|string $path |
|
32 | - */ |
|
33 | - public function cacheNode(Node $node, $path = null) { |
|
34 | - if (is_null($path)) { |
|
35 | - $path = $node->getPath(); |
|
36 | - } |
|
37 | - $this->cache[trim($path, '/')] = $node; |
|
38 | - } |
|
27 | + /** |
|
28 | + * Store a node in the cache |
|
29 | + * |
|
30 | + * @param Node $node |
|
31 | + * @param null|string $path |
|
32 | + */ |
|
33 | + public function cacheNode(Node $node, $path = null) { |
|
34 | + if (is_null($path)) { |
|
35 | + $path = $node->getPath(); |
|
36 | + } |
|
37 | + $this->cache[trim($path, '/')] = $node; |
|
38 | + } |
|
39 | 39 | } |
@@ -33,14 +33,14 @@ |
||
33 | 33 | * @see \Sabre\DAV\Server |
34 | 34 | */ |
35 | 35 | class Server extends \Sabre\DAV\Server { |
36 | - /** @var CachingTree $tree */ |
|
36 | + /** @var CachingTree $tree */ |
|
37 | 37 | |
38 | - /** |
|
39 | - * @see \Sabre\DAV\Server |
|
40 | - */ |
|
41 | - public function __construct($treeOrNode = null) { |
|
42 | - parent::__construct($treeOrNode); |
|
43 | - self::$exposeVersion = false; |
|
44 | - $this->enablePropfindDepthInfinity = true; |
|
45 | - } |
|
38 | + /** |
|
39 | + * @see \Sabre\DAV\Server |
|
40 | + */ |
|
41 | + public function __construct($treeOrNode = null) { |
|
42 | + parent::__construct($treeOrNode); |
|
43 | + self::$exposeVersion = false; |
|
44 | + $this->enablePropfindDepthInfinity = true; |
|
45 | + } |
|
46 | 46 | } |
@@ -31,47 +31,47 @@ |
||
31 | 31 | |
32 | 32 | class Provider implements IProvider { |
33 | 33 | |
34 | - /** @var L10nFactory */ |
|
35 | - private $l10n; |
|
34 | + /** @var L10nFactory */ |
|
35 | + private $l10n; |
|
36 | 36 | |
37 | - /** @var IURLGenerator */ |
|
38 | - private $urlGenerator; |
|
37 | + /** @var IURLGenerator */ |
|
38 | + private $urlGenerator; |
|
39 | 39 | |
40 | - /** @var IManager */ |
|
41 | - private $activityManager; |
|
40 | + /** @var IManager */ |
|
41 | + private $activityManager; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param L10nFactory $l10n |
|
45 | - * @param IURLGenerator $urlGenerator |
|
46 | - * @param IManager $activityManager |
|
47 | - */ |
|
48 | - public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator, IManager $activityManager) { |
|
49 | - $this->urlGenerator = $urlGenerator; |
|
50 | - $this->activityManager = $activityManager; |
|
51 | - $this->l10n = $l10n; |
|
52 | - } |
|
43 | + /** |
|
44 | + * @param L10nFactory $l10n |
|
45 | + * @param IURLGenerator $urlGenerator |
|
46 | + * @param IManager $activityManager |
|
47 | + */ |
|
48 | + public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator, IManager $activityManager) { |
|
49 | + $this->urlGenerator = $urlGenerator; |
|
50 | + $this->activityManager = $activityManager; |
|
51 | + $this->l10n = $l10n; |
|
52 | + } |
|
53 | 53 | |
54 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
55 | - if ($event->getApp() !== 'twofactor_backupcodes') { |
|
56 | - throw new InvalidArgumentException(); |
|
57 | - } |
|
54 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
55 | + if ($event->getApp() !== 'twofactor_backupcodes') { |
|
56 | + throw new InvalidArgumentException(); |
|
57 | + } |
|
58 | 58 | |
59 | - $l = $this->l10n->get('twofactor_backupcodes', $language); |
|
59 | + $l = $this->l10n->get('twofactor_backupcodes', $language); |
|
60 | 60 | |
61 | - switch ($event->getSubject()) { |
|
62 | - case 'codes_generated': |
|
63 | - $event->setParsedSubject($l->t('You created two-factor backup codes for your account')); |
|
61 | + switch ($event->getSubject()) { |
|
62 | + case 'codes_generated': |
|
63 | + $event->setParsedSubject($l->t('You created two-factor backup codes for your account')); |
|
64 | 64 | |
65 | - if ($this->activityManager->getRequirePNG()) { |
|
66 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png'))); |
|
67 | - } else { |
|
68 | - $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'))); |
|
69 | - } |
|
70 | - break; |
|
71 | - default: |
|
72 | - throw new InvalidArgumentException(); |
|
73 | - } |
|
74 | - return $event; |
|
75 | - } |
|
65 | + if ($this->activityManager->getRequirePNG()) { |
|
66 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.png'))); |
|
67 | + } else { |
|
68 | + $event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg'))); |
|
69 | + } |
|
70 | + break; |
|
71 | + default: |
|
72 | + throw new InvalidArgumentException(); |
|
73 | + } |
|
74 | + return $event; |
|
75 | + } |
|
76 | 76 | |
77 | 77 | } |
@@ -25,105 +25,105 @@ |
||
25 | 25 | |
26 | 26 | class PublicLinks extends Base { |
27 | 27 | |
28 | - const SUBJECT_SHARED_LINK_SELF = 'shared_link_self'; |
|
29 | - const SUBJECT_RESHARED_LINK_BY = 'reshared_link_by'; |
|
30 | - const SUBJECT_UNSHARED_LINK_SELF = 'unshared_link_self'; |
|
31 | - const SUBJECT_UNSHARED_LINK_BY = 'unshared_link_by'; |
|
32 | - const SUBJECT_LINK_EXPIRED = 'link_expired'; |
|
33 | - const SUBJECT_LINK_BY_EXPIRED = 'link_by_expired'; |
|
34 | - |
|
35 | - /** |
|
36 | - * @param IEvent $event |
|
37 | - * @return IEvent |
|
38 | - * @throws \InvalidArgumentException |
|
39 | - * @since 11.0.0 |
|
40 | - */ |
|
41 | - public function parseShortVersion(IEvent $event) { |
|
42 | - $parsedParameters = $this->getParsedParameters($event); |
|
43 | - |
|
44 | - if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) { |
|
45 | - $subject = $this->l->t('Shared as public link'); |
|
46 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) { |
|
47 | - $subject = $this->l->t('Removed public link'); |
|
48 | - } else if ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) { |
|
49 | - $subject = $this->l->t('Public link expired'); |
|
50 | - } else if ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) { |
|
51 | - $subject = $this->l->t('{actor} shared as public link'); |
|
52 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) { |
|
53 | - $subject = $this->l->t('{actor} removed public link'); |
|
54 | - } else if ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) { |
|
55 | - $subject = $this->l->t('Public link of {actor} expired'); |
|
56 | - |
|
57 | - } else { |
|
58 | - throw new \InvalidArgumentException(); |
|
59 | - } |
|
60 | - |
|
61 | - if ($this->activityManager->getRequirePNG()) { |
|
62 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
63 | - } else { |
|
64 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
65 | - } |
|
66 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
67 | - |
|
68 | - return $event; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @param IEvent $event |
|
73 | - * @return IEvent |
|
74 | - * @throws \InvalidArgumentException |
|
75 | - * @since 11.0.0 |
|
76 | - */ |
|
77 | - public function parseLongVersion(IEvent $event) { |
|
78 | - $parsedParameters = $this->getParsedParameters($event); |
|
79 | - |
|
80 | - if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) { |
|
81 | - $subject = $this->l->t('You shared {file} as public link'); |
|
82 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) { |
|
83 | - $subject = $this->l->t('You removed public link for {file}'); |
|
84 | - } else if ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) { |
|
85 | - $subject = $this->l->t('Public link expired for {file}'); |
|
86 | - } else if ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) { |
|
87 | - $subject = $this->l->t('{actor} shared {file} as public link'); |
|
88 | - } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) { |
|
89 | - $subject = $this->l->t('{actor} removed public link for {file}'); |
|
90 | - } else if ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) { |
|
91 | - $subject = $this->l->t('Public link of {actor} for {file} expired'); |
|
92 | - |
|
93 | - } else { |
|
94 | - throw new \InvalidArgumentException(); |
|
95 | - } |
|
96 | - |
|
97 | - if ($this->activityManager->getRequirePNG()) { |
|
98 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
99 | - } else { |
|
100 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
101 | - } |
|
102 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
103 | - |
|
104 | - return $event; |
|
105 | - } |
|
106 | - |
|
107 | - protected function getParsedParameters(IEvent $event) { |
|
108 | - $subject = $event->getSubject(); |
|
109 | - $parameters = $event->getSubjectParameters(); |
|
110 | - |
|
111 | - switch ($subject) { |
|
112 | - case self::SUBJECT_SHARED_LINK_SELF: |
|
113 | - case self::SUBJECT_UNSHARED_LINK_SELF: |
|
114 | - case self::SUBJECT_LINK_EXPIRED: |
|
115 | - return [ |
|
116 | - 'file' => $this->getFile($parameters[0], $event), |
|
117 | - ]; |
|
118 | - case self::SUBJECT_RESHARED_LINK_BY: |
|
119 | - case self::SUBJECT_UNSHARED_LINK_BY: |
|
120 | - case self::SUBJECT_LINK_BY_EXPIRED: |
|
121 | - return [ |
|
122 | - 'file' => $this->getFile($parameters[0], $event), |
|
123 | - 'actor' => $this->getUser($parameters[1]), |
|
124 | - ]; |
|
125 | - } |
|
126 | - return []; |
|
127 | - } |
|
28 | + const SUBJECT_SHARED_LINK_SELF = 'shared_link_self'; |
|
29 | + const SUBJECT_RESHARED_LINK_BY = 'reshared_link_by'; |
|
30 | + const SUBJECT_UNSHARED_LINK_SELF = 'unshared_link_self'; |
|
31 | + const SUBJECT_UNSHARED_LINK_BY = 'unshared_link_by'; |
|
32 | + const SUBJECT_LINK_EXPIRED = 'link_expired'; |
|
33 | + const SUBJECT_LINK_BY_EXPIRED = 'link_by_expired'; |
|
34 | + |
|
35 | + /** |
|
36 | + * @param IEvent $event |
|
37 | + * @return IEvent |
|
38 | + * @throws \InvalidArgumentException |
|
39 | + * @since 11.0.0 |
|
40 | + */ |
|
41 | + public function parseShortVersion(IEvent $event) { |
|
42 | + $parsedParameters = $this->getParsedParameters($event); |
|
43 | + |
|
44 | + if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) { |
|
45 | + $subject = $this->l->t('Shared as public link'); |
|
46 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) { |
|
47 | + $subject = $this->l->t('Removed public link'); |
|
48 | + } else if ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) { |
|
49 | + $subject = $this->l->t('Public link expired'); |
|
50 | + } else if ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) { |
|
51 | + $subject = $this->l->t('{actor} shared as public link'); |
|
52 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) { |
|
53 | + $subject = $this->l->t('{actor} removed public link'); |
|
54 | + } else if ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) { |
|
55 | + $subject = $this->l->t('Public link of {actor} expired'); |
|
56 | + |
|
57 | + } else { |
|
58 | + throw new \InvalidArgumentException(); |
|
59 | + } |
|
60 | + |
|
61 | + if ($this->activityManager->getRequirePNG()) { |
|
62 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
63 | + } else { |
|
64 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
65 | + } |
|
66 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
67 | + |
|
68 | + return $event; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @param IEvent $event |
|
73 | + * @return IEvent |
|
74 | + * @throws \InvalidArgumentException |
|
75 | + * @since 11.0.0 |
|
76 | + */ |
|
77 | + public function parseLongVersion(IEvent $event) { |
|
78 | + $parsedParameters = $this->getParsedParameters($event); |
|
79 | + |
|
80 | + if ($event->getSubject() === self::SUBJECT_SHARED_LINK_SELF) { |
|
81 | + $subject = $this->l->t('You shared {file} as public link'); |
|
82 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_SELF) { |
|
83 | + $subject = $this->l->t('You removed public link for {file}'); |
|
84 | + } else if ($event->getSubject() === self::SUBJECT_LINK_EXPIRED) { |
|
85 | + $subject = $this->l->t('Public link expired for {file}'); |
|
86 | + } else if ($event->getSubject() === self::SUBJECT_RESHARED_LINK_BY) { |
|
87 | + $subject = $this->l->t('{actor} shared {file} as public link'); |
|
88 | + } else if ($event->getSubject() === self::SUBJECT_UNSHARED_LINK_BY) { |
|
89 | + $subject = $this->l->t('{actor} removed public link for {file}'); |
|
90 | + } else if ($event->getSubject() === self::SUBJECT_LINK_BY_EXPIRED) { |
|
91 | + $subject = $this->l->t('Public link of {actor} for {file} expired'); |
|
92 | + |
|
93 | + } else { |
|
94 | + throw new \InvalidArgumentException(); |
|
95 | + } |
|
96 | + |
|
97 | + if ($this->activityManager->getRequirePNG()) { |
|
98 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
99 | + } else { |
|
100 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
101 | + } |
|
102 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
103 | + |
|
104 | + return $event; |
|
105 | + } |
|
106 | + |
|
107 | + protected function getParsedParameters(IEvent $event) { |
|
108 | + $subject = $event->getSubject(); |
|
109 | + $parameters = $event->getSubjectParameters(); |
|
110 | + |
|
111 | + switch ($subject) { |
|
112 | + case self::SUBJECT_SHARED_LINK_SELF: |
|
113 | + case self::SUBJECT_UNSHARED_LINK_SELF: |
|
114 | + case self::SUBJECT_LINK_EXPIRED: |
|
115 | + return [ |
|
116 | + 'file' => $this->getFile($parameters[0], $event), |
|
117 | + ]; |
|
118 | + case self::SUBJECT_RESHARED_LINK_BY: |
|
119 | + case self::SUBJECT_UNSHARED_LINK_BY: |
|
120 | + case self::SUBJECT_LINK_BY_EXPIRED: |
|
121 | + return [ |
|
122 | + 'file' => $this->getFile($parameters[0], $event), |
|
123 | + 'actor' => $this->getUser($parameters[1]), |
|
124 | + ]; |
|
125 | + } |
|
126 | + return []; |
|
127 | + } |
|
128 | 128 | |
129 | 129 | } |
@@ -26,97 +26,97 @@ |
||
26 | 26 | class Downloads extends Base { |
27 | 27 | |
28 | 28 | |
29 | - const SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED = 'public_shared_file_downloaded'; |
|
30 | - const SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED = 'public_shared_folder_downloaded'; |
|
31 | - |
|
32 | - const SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED = 'file_shared_with_email_downloaded'; |
|
33 | - const SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED = 'folder_shared_with_email_downloaded'; |
|
34 | - |
|
35 | - /** |
|
36 | - * @param IEvent $event |
|
37 | - * @return IEvent |
|
38 | - * @throws \InvalidArgumentException |
|
39 | - * @since 11.0.0 |
|
40 | - */ |
|
41 | - public function parseShortVersion(IEvent $event) { |
|
42 | - $parsedParameters = $this->getParsedParameters($event); |
|
43 | - |
|
44 | - if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED || |
|
45 | - $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { |
|
46 | - $subject = $this->l->t('Downloaded via public link'); |
|
47 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED || |
|
48 | - $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { |
|
49 | - $subject = $this->l->t('Downloaded by {email}'); |
|
50 | - } else { |
|
51 | - throw new \InvalidArgumentException(); |
|
52 | - } |
|
53 | - |
|
54 | - if ($this->activityManager->getRequirePNG()) { |
|
55 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.png'))); |
|
56 | - } else { |
|
57 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg'))); |
|
58 | - } |
|
59 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
60 | - |
|
61 | - return $event; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @param IEvent $event |
|
66 | - * @return IEvent |
|
67 | - * @throws \InvalidArgumentException |
|
68 | - * @since 11.0.0 |
|
69 | - */ |
|
70 | - public function parseLongVersion(IEvent $event) { |
|
71 | - $parsedParameters = $this->getParsedParameters($event); |
|
72 | - |
|
73 | - if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED || |
|
74 | - $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { |
|
75 | - $subject = $this->l->t('{file} downloaded via public link'); |
|
76 | - } else if ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED || |
|
77 | - $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { |
|
78 | - $subject = $this->l->t('{email} downloaded {file}'); |
|
79 | - } else { |
|
80 | - throw new \InvalidArgumentException(); |
|
81 | - } |
|
82 | - |
|
83 | - if ($this->activityManager->getRequirePNG()) { |
|
84 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.png'))); |
|
85 | - } else { |
|
86 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg'))); |
|
87 | - } |
|
88 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
89 | - |
|
90 | - return $event; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param IEvent $event |
|
95 | - * @return array |
|
96 | - * @throws \InvalidArgumentException |
|
97 | - */ |
|
98 | - protected function getParsedParameters(IEvent $event) { |
|
99 | - $subject = $event->getSubject(); |
|
100 | - $parameters = $event->getSubjectParameters(); |
|
101 | - |
|
102 | - switch ($subject) { |
|
103 | - case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED: |
|
104 | - case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED: |
|
105 | - return [ |
|
106 | - 'file' => $this->getFile($parameters[0], $event), |
|
107 | - ]; |
|
108 | - case self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED: |
|
109 | - case self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED: |
|
110 | - return [ |
|
111 | - 'file' => $this->getFile($parameters[0], $event), |
|
112 | - 'email' => [ |
|
113 | - 'type' => 'email', |
|
114 | - 'id' => $parameters[1], |
|
115 | - 'name' => $parameters[1], |
|
116 | - ], |
|
117 | - ]; |
|
118 | - } |
|
119 | - |
|
120 | - throw new \InvalidArgumentException(); |
|
121 | - } |
|
29 | + const SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED = 'public_shared_file_downloaded'; |
|
30 | + const SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED = 'public_shared_folder_downloaded'; |
|
31 | + |
|
32 | + const SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED = 'file_shared_with_email_downloaded'; |
|
33 | + const SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED = 'folder_shared_with_email_downloaded'; |
|
34 | + |
|
35 | + /** |
|
36 | + * @param IEvent $event |
|
37 | + * @return IEvent |
|
38 | + * @throws \InvalidArgumentException |
|
39 | + * @since 11.0.0 |
|
40 | + */ |
|
41 | + public function parseShortVersion(IEvent $event) { |
|
42 | + $parsedParameters = $this->getParsedParameters($event); |
|
43 | + |
|
44 | + if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED || |
|
45 | + $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { |
|
46 | + $subject = $this->l->t('Downloaded via public link'); |
|
47 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED || |
|
48 | + $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { |
|
49 | + $subject = $this->l->t('Downloaded by {email}'); |
|
50 | + } else { |
|
51 | + throw new \InvalidArgumentException(); |
|
52 | + } |
|
53 | + |
|
54 | + if ($this->activityManager->getRequirePNG()) { |
|
55 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.png'))); |
|
56 | + } else { |
|
57 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg'))); |
|
58 | + } |
|
59 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
60 | + |
|
61 | + return $event; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @param IEvent $event |
|
66 | + * @return IEvent |
|
67 | + * @throws \InvalidArgumentException |
|
68 | + * @since 11.0.0 |
|
69 | + */ |
|
70 | + public function parseLongVersion(IEvent $event) { |
|
71 | + $parsedParameters = $this->getParsedParameters($event); |
|
72 | + |
|
73 | + if ($event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED || |
|
74 | + $event->getSubject() === self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED) { |
|
75 | + $subject = $this->l->t('{file} downloaded via public link'); |
|
76 | + } else if ($event->getSubject() === self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED || |
|
77 | + $event->getSubject() === self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED) { |
|
78 | + $subject = $this->l->t('{email} downloaded {file}'); |
|
79 | + } else { |
|
80 | + throw new \InvalidArgumentException(); |
|
81 | + } |
|
82 | + |
|
83 | + if ($this->activityManager->getRequirePNG()) { |
|
84 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.png'))); |
|
85 | + } else { |
|
86 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/download.svg'))); |
|
87 | + } |
|
88 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
89 | + |
|
90 | + return $event; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param IEvent $event |
|
95 | + * @return array |
|
96 | + * @throws \InvalidArgumentException |
|
97 | + */ |
|
98 | + protected function getParsedParameters(IEvent $event) { |
|
99 | + $subject = $event->getSubject(); |
|
100 | + $parameters = $event->getSubjectParameters(); |
|
101 | + |
|
102 | + switch ($subject) { |
|
103 | + case self::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED: |
|
104 | + case self::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED: |
|
105 | + return [ |
|
106 | + 'file' => $this->getFile($parameters[0], $event), |
|
107 | + ]; |
|
108 | + case self::SUBJECT_SHARED_FILE_BY_EMAIL_DOWNLOADED: |
|
109 | + case self::SUBJECT_SHARED_FOLDER_BY_EMAIL_DOWNLOADED: |
|
110 | + return [ |
|
111 | + 'file' => $this->getFile($parameters[0], $event), |
|
112 | + 'email' => [ |
|
113 | + 'type' => 'email', |
|
114 | + 'id' => $parameters[1], |
|
115 | + 'name' => $parameters[1], |
|
116 | + ], |
|
117 | + ]; |
|
118 | + } |
|
119 | + |
|
120 | + throw new \InvalidArgumentException(); |
|
121 | + } |
|
122 | 122 | } |
@@ -31,147 +31,147 @@ |
||
31 | 31 | |
32 | 32 | class FavoriteProvider implements IProvider { |
33 | 33 | |
34 | - const SUBJECT_ADDED = 'added_favorite'; |
|
35 | - const SUBJECT_REMOVED = 'removed_favorite'; |
|
36 | - |
|
37 | - /** @var IFactory */ |
|
38 | - protected $languageFactory; |
|
39 | - |
|
40 | - /** @var IL10N */ |
|
41 | - protected $l; |
|
42 | - |
|
43 | - /** @var IURLGenerator */ |
|
44 | - protected $url; |
|
45 | - |
|
46 | - /** @var IManager */ |
|
47 | - protected $activityManager; |
|
48 | - |
|
49 | - /** @var IEventMerger */ |
|
50 | - protected $eventMerger; |
|
51 | - |
|
52 | - /** |
|
53 | - * @param IFactory $languageFactory |
|
54 | - * @param IURLGenerator $url |
|
55 | - * @param IManager $activityManager |
|
56 | - * @param IEventMerger $eventMerger |
|
57 | - */ |
|
58 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IEventMerger $eventMerger) { |
|
59 | - $this->languageFactory = $languageFactory; |
|
60 | - $this->url = $url; |
|
61 | - $this->activityManager = $activityManager; |
|
62 | - $this->eventMerger = $eventMerger; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $language |
|
67 | - * @param IEvent $event |
|
68 | - * @param IEvent|null $previousEvent |
|
69 | - * @return IEvent |
|
70 | - * @throws \InvalidArgumentException |
|
71 | - * @since 11.0.0 |
|
72 | - */ |
|
73 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
74 | - if ($event->getApp() !== 'files' || $event->getType() !== 'favorite') { |
|
75 | - throw new \InvalidArgumentException(); |
|
76 | - } |
|
77 | - |
|
78 | - $this->l = $this->languageFactory->get('files', $language); |
|
79 | - |
|
80 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
81 | - try { |
|
82 | - return $this->parseShortVersion($event); |
|
83 | - } catch (\InvalidArgumentException $e) { |
|
84 | - // Ignore and simply use the long version... |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - return $this->parseLongVersion($event, $previousEvent); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @param IEvent $event |
|
93 | - * @return IEvent |
|
94 | - * @throws \InvalidArgumentException |
|
95 | - * @since 11.0.0 |
|
96 | - */ |
|
97 | - public function parseShortVersion(IEvent $event) { |
|
98 | - |
|
99 | - if ($event->getSubject() === self::SUBJECT_ADDED) { |
|
100 | - $event->setParsedSubject($this->l->t('Added to favorites')); |
|
101 | - if ($this->activityManager->getRequirePNG()) { |
|
102 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.png'))); |
|
103 | - } else { |
|
104 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))); |
|
105 | - } |
|
106 | - } else if ($event->getSubject() === self::SUBJECT_REMOVED) { |
|
107 | - $event->setParsedSubject($this->l->t('Removed from favorites')); |
|
108 | - if ($this->activityManager->getRequirePNG()) { |
|
109 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.png'))); |
|
110 | - } else { |
|
111 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg'))); |
|
112 | - } |
|
113 | - } else { |
|
114 | - throw new \InvalidArgumentException(); |
|
115 | - } |
|
116 | - |
|
117 | - return $event; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @param IEvent $event |
|
122 | - * @param IEvent|null $previousEvent |
|
123 | - * @return IEvent |
|
124 | - * @throws \InvalidArgumentException |
|
125 | - * @since 11.0.0 |
|
126 | - */ |
|
127 | - public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { |
|
128 | - |
|
129 | - if ($event->getSubject() === self::SUBJECT_ADDED) { |
|
130 | - $subject = $this->l->t('You added {file} to your favorites'); |
|
131 | - if ($this->activityManager->getRequirePNG()) { |
|
132 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.png'))); |
|
133 | - } else { |
|
134 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))); |
|
135 | - } |
|
136 | - } else if ($event->getSubject() === self::SUBJECT_REMOVED) { |
|
137 | - $subject = $this->l->t('You removed {file} from your favorites'); |
|
138 | - if ($this->activityManager->getRequirePNG()) { |
|
139 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.png'))); |
|
140 | - } else { |
|
141 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg'))); |
|
142 | - } |
|
143 | - } else { |
|
144 | - throw new \InvalidArgumentException(); |
|
145 | - } |
|
146 | - |
|
147 | - $this->setSubjects($event, $subject); |
|
148 | - $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); |
|
149 | - return $event; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @param IEvent $event |
|
154 | - * @param string $subject |
|
155 | - */ |
|
156 | - protected function setSubjects(IEvent $event, $subject) { |
|
157 | - $subjectParams = $event->getSubjectParameters(); |
|
158 | - if (empty($subjectParams)) { |
|
159 | - // Try to fall back to the old way, but this does not work for emails. |
|
160 | - // But at least old activities still work. |
|
161 | - $subjectParams = [ |
|
162 | - 'id' => $event->getObjectId(), |
|
163 | - 'path' => $event->getObjectName(), |
|
164 | - ]; |
|
165 | - } |
|
166 | - $parameter = [ |
|
167 | - 'type' => 'file', |
|
168 | - 'id' => $subjectParams['id'], |
|
169 | - 'name' => basename($subjectParams['path']), |
|
170 | - 'path' => trim($subjectParams['path'], '/'), |
|
171 | - 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $subjectParams['id']]), |
|
172 | - ]; |
|
173 | - |
|
174 | - $event->setParsedSubject(str_replace('{file}', $parameter['path'], $subject)) |
|
175 | - ->setRichSubject($subject, ['file' => $parameter]); |
|
176 | - } |
|
34 | + const SUBJECT_ADDED = 'added_favorite'; |
|
35 | + const SUBJECT_REMOVED = 'removed_favorite'; |
|
36 | + |
|
37 | + /** @var IFactory */ |
|
38 | + protected $languageFactory; |
|
39 | + |
|
40 | + /** @var IL10N */ |
|
41 | + protected $l; |
|
42 | + |
|
43 | + /** @var IURLGenerator */ |
|
44 | + protected $url; |
|
45 | + |
|
46 | + /** @var IManager */ |
|
47 | + protected $activityManager; |
|
48 | + |
|
49 | + /** @var IEventMerger */ |
|
50 | + protected $eventMerger; |
|
51 | + |
|
52 | + /** |
|
53 | + * @param IFactory $languageFactory |
|
54 | + * @param IURLGenerator $url |
|
55 | + * @param IManager $activityManager |
|
56 | + * @param IEventMerger $eventMerger |
|
57 | + */ |
|
58 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IEventMerger $eventMerger) { |
|
59 | + $this->languageFactory = $languageFactory; |
|
60 | + $this->url = $url; |
|
61 | + $this->activityManager = $activityManager; |
|
62 | + $this->eventMerger = $eventMerger; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $language |
|
67 | + * @param IEvent $event |
|
68 | + * @param IEvent|null $previousEvent |
|
69 | + * @return IEvent |
|
70 | + * @throws \InvalidArgumentException |
|
71 | + * @since 11.0.0 |
|
72 | + */ |
|
73 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
74 | + if ($event->getApp() !== 'files' || $event->getType() !== 'favorite') { |
|
75 | + throw new \InvalidArgumentException(); |
|
76 | + } |
|
77 | + |
|
78 | + $this->l = $this->languageFactory->get('files', $language); |
|
79 | + |
|
80 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
81 | + try { |
|
82 | + return $this->parseShortVersion($event); |
|
83 | + } catch (\InvalidArgumentException $e) { |
|
84 | + // Ignore and simply use the long version... |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + return $this->parseLongVersion($event, $previousEvent); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @param IEvent $event |
|
93 | + * @return IEvent |
|
94 | + * @throws \InvalidArgumentException |
|
95 | + * @since 11.0.0 |
|
96 | + */ |
|
97 | + public function parseShortVersion(IEvent $event) { |
|
98 | + |
|
99 | + if ($event->getSubject() === self::SUBJECT_ADDED) { |
|
100 | + $event->setParsedSubject($this->l->t('Added to favorites')); |
|
101 | + if ($this->activityManager->getRequirePNG()) { |
|
102 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.png'))); |
|
103 | + } else { |
|
104 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))); |
|
105 | + } |
|
106 | + } else if ($event->getSubject() === self::SUBJECT_REMOVED) { |
|
107 | + $event->setParsedSubject($this->l->t('Removed from favorites')); |
|
108 | + if ($this->activityManager->getRequirePNG()) { |
|
109 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.png'))); |
|
110 | + } else { |
|
111 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg'))); |
|
112 | + } |
|
113 | + } else { |
|
114 | + throw new \InvalidArgumentException(); |
|
115 | + } |
|
116 | + |
|
117 | + return $event; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @param IEvent $event |
|
122 | + * @param IEvent|null $previousEvent |
|
123 | + * @return IEvent |
|
124 | + * @throws \InvalidArgumentException |
|
125 | + * @since 11.0.0 |
|
126 | + */ |
|
127 | + public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) { |
|
128 | + |
|
129 | + if ($event->getSubject() === self::SUBJECT_ADDED) { |
|
130 | + $subject = $this->l->t('You added {file} to your favorites'); |
|
131 | + if ($this->activityManager->getRequirePNG()) { |
|
132 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.png'))); |
|
133 | + } else { |
|
134 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/starred.svg'))); |
|
135 | + } |
|
136 | + } else if ($event->getSubject() === self::SUBJECT_REMOVED) { |
|
137 | + $subject = $this->l->t('You removed {file} from your favorites'); |
|
138 | + if ($this->activityManager->getRequirePNG()) { |
|
139 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.png'))); |
|
140 | + } else { |
|
141 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/star.svg'))); |
|
142 | + } |
|
143 | + } else { |
|
144 | + throw new \InvalidArgumentException(); |
|
145 | + } |
|
146 | + |
|
147 | + $this->setSubjects($event, $subject); |
|
148 | + $event = $this->eventMerger->mergeEvents('file', $event, $previousEvent); |
|
149 | + return $event; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @param IEvent $event |
|
154 | + * @param string $subject |
|
155 | + */ |
|
156 | + protected function setSubjects(IEvent $event, $subject) { |
|
157 | + $subjectParams = $event->getSubjectParameters(); |
|
158 | + if (empty($subjectParams)) { |
|
159 | + // Try to fall back to the old way, but this does not work for emails. |
|
160 | + // But at least old activities still work. |
|
161 | + $subjectParams = [ |
|
162 | + 'id' => $event->getObjectId(), |
|
163 | + 'path' => $event->getObjectName(), |
|
164 | + ]; |
|
165 | + } |
|
166 | + $parameter = [ |
|
167 | + 'type' => 'file', |
|
168 | + 'id' => $subjectParams['id'], |
|
169 | + 'name' => basename($subjectParams['path']), |
|
170 | + 'path' => trim($subjectParams['path'], '/'), |
|
171 | + 'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $subjectParams['id']]), |
|
172 | + ]; |
|
173 | + |
|
174 | + $event->setParsedSubject(str_replace('{file}', $parameter['path'], $subject)) |
|
175 | + ->setRichSubject($subject, ['file' => $parameter]); |
|
176 | + } |
|
177 | 177 | } |
@@ -32,157 +32,157 @@ |
||
32 | 32 | |
33 | 33 | class Provider implements IProvider { |
34 | 34 | |
35 | - const PASSWORD_CHANGED_BY = 'password_changed_by'; |
|
36 | - const PASSWORD_CHANGED_SELF = 'password_changed_self'; |
|
37 | - const PASSWORD_RESET = 'password_changed'; |
|
38 | - const EMAIL_CHANGED_BY = 'email_changed_by'; |
|
39 | - const EMAIL_CHANGED_SELF = 'email_changed_self'; |
|
40 | - const EMAIL_CHANGED = 'email_changed'; |
|
41 | - |
|
42 | - /** @var IFactory */ |
|
43 | - protected $languageFactory; |
|
44 | - |
|
45 | - /** @var IL10N */ |
|
46 | - protected $l; |
|
47 | - |
|
48 | - /** @var IURLGenerator */ |
|
49 | - protected $url; |
|
50 | - |
|
51 | - /** @var IUserManager */ |
|
52 | - protected $userManager; |
|
53 | - |
|
54 | - /** @var IManager */ |
|
55 | - private $activityManager; |
|
56 | - |
|
57 | - /** @var string[] cached displayNames - key is the UID and value the displayname */ |
|
58 | - protected $displayNames = []; |
|
59 | - |
|
60 | - /** |
|
61 | - * @param IFactory $languageFactory |
|
62 | - * @param IURLGenerator $url |
|
63 | - * @param IUserManager $userManager |
|
64 | - * @param IManager $activityManager |
|
65 | - */ |
|
66 | - public function __construct(IFactory $languageFactory, IURLGenerator $url, IUserManager $userManager, IManager $activityManager) { |
|
67 | - $this->languageFactory = $languageFactory; |
|
68 | - $this->url = $url; |
|
69 | - $this->userManager = $userManager; |
|
70 | - $this->activityManager = $activityManager; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param string $language |
|
75 | - * @param IEvent $event |
|
76 | - * @param IEvent|null $previousEvent |
|
77 | - * @return IEvent |
|
78 | - * @throws \InvalidArgumentException |
|
79 | - * @since 11.0.0 |
|
80 | - */ |
|
81 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
82 | - if ($event->getApp() !== 'settings') { |
|
83 | - throw new \InvalidArgumentException(); |
|
84 | - } |
|
85 | - |
|
86 | - $this->l = $this->languageFactory->get('settings', $language); |
|
87 | - |
|
88 | - if ($this->activityManager->getRequirePNG()) { |
|
89 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.png'))); |
|
90 | - } else { |
|
91 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.svg'))); |
|
92 | - } |
|
93 | - |
|
94 | - if ($event->getSubject() === self::PASSWORD_CHANGED_BY) { |
|
95 | - $subject = $this->l->t('{actor} changed your password'); |
|
96 | - } else if ($event->getSubject() === self::PASSWORD_CHANGED_SELF) { |
|
97 | - $subject = $this->l->t('You changed your password'); |
|
98 | - } else if ($event->getSubject() === self::PASSWORD_RESET) { |
|
99 | - $subject = $this->l->t('Your password was reset by an administrator'); |
|
100 | - |
|
101 | - } else if ($event->getSubject() === self::EMAIL_CHANGED_BY) { |
|
102 | - $subject = $this->l->t('{actor} changed your email address'); |
|
103 | - } else if ($event->getSubject() === self::EMAIL_CHANGED_SELF) { |
|
104 | - $subject = $this->l->t('You changed your email address'); |
|
105 | - } else if ($event->getSubject() === self::EMAIL_CHANGED) { |
|
106 | - $subject = $this->l->t('Your email address was changed by an administrator'); |
|
107 | - |
|
108 | - } else { |
|
109 | - throw new \InvalidArgumentException(); |
|
110 | - } |
|
111 | - |
|
112 | - $parsedParameters = $this->getParameters($event); |
|
113 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
114 | - |
|
115 | - return $event; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @param IEvent $event |
|
120 | - * @return array |
|
121 | - * @throws \InvalidArgumentException |
|
122 | - */ |
|
123 | - protected function getParameters(IEvent $event) { |
|
124 | - $subject = $event->getSubject(); |
|
125 | - $parameters = $event->getSubjectParameters(); |
|
126 | - |
|
127 | - switch ($subject) { |
|
128 | - case self::PASSWORD_CHANGED_SELF: |
|
129 | - case self::PASSWORD_RESET: |
|
130 | - case self::EMAIL_CHANGED_SELF: |
|
131 | - case self::EMAIL_CHANGED: |
|
132 | - return []; |
|
133 | - case self::PASSWORD_CHANGED_BY: |
|
134 | - case self::EMAIL_CHANGED_BY: |
|
135 | - return [ |
|
136 | - 'actor' => $this->generateUserParameter($parameters[0]), |
|
137 | - ]; |
|
138 | - } |
|
139 | - |
|
140 | - throw new \InvalidArgumentException(); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param IEvent $event |
|
145 | - * @param string $subject |
|
146 | - * @param array $parameters |
|
147 | - * @throws \InvalidArgumentException |
|
148 | - */ |
|
149 | - protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
150 | - $placeholders = $replacements = []; |
|
151 | - foreach ($parameters as $placeholder => $parameter) { |
|
152 | - $placeholders[] = '{' . $placeholder . '}'; |
|
153 | - $replacements[] = $parameter['name']; |
|
154 | - } |
|
155 | - |
|
156 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
157 | - ->setRichSubject($subject, $parameters); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @param string $uid |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - protected function generateUserParameter($uid) { |
|
165 | - if (!isset($this->displayNames[$uid])) { |
|
166 | - $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
167 | - } |
|
168 | - |
|
169 | - return [ |
|
170 | - 'type' => 'user', |
|
171 | - 'id' => $uid, |
|
172 | - 'name' => $this->displayNames[$uid], |
|
173 | - ]; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @param string $uid |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - protected function getDisplayName($uid) { |
|
181 | - $user = $this->userManager->get($uid); |
|
182 | - if ($user instanceof IUser) { |
|
183 | - return $user->getDisplayName(); |
|
184 | - } |
|
185 | - |
|
186 | - return $uid; |
|
187 | - } |
|
35 | + const PASSWORD_CHANGED_BY = 'password_changed_by'; |
|
36 | + const PASSWORD_CHANGED_SELF = 'password_changed_self'; |
|
37 | + const PASSWORD_RESET = 'password_changed'; |
|
38 | + const EMAIL_CHANGED_BY = 'email_changed_by'; |
|
39 | + const EMAIL_CHANGED_SELF = 'email_changed_self'; |
|
40 | + const EMAIL_CHANGED = 'email_changed'; |
|
41 | + |
|
42 | + /** @var IFactory */ |
|
43 | + protected $languageFactory; |
|
44 | + |
|
45 | + /** @var IL10N */ |
|
46 | + protected $l; |
|
47 | + |
|
48 | + /** @var IURLGenerator */ |
|
49 | + protected $url; |
|
50 | + |
|
51 | + /** @var IUserManager */ |
|
52 | + protected $userManager; |
|
53 | + |
|
54 | + /** @var IManager */ |
|
55 | + private $activityManager; |
|
56 | + |
|
57 | + /** @var string[] cached displayNames - key is the UID and value the displayname */ |
|
58 | + protected $displayNames = []; |
|
59 | + |
|
60 | + /** |
|
61 | + * @param IFactory $languageFactory |
|
62 | + * @param IURLGenerator $url |
|
63 | + * @param IUserManager $userManager |
|
64 | + * @param IManager $activityManager |
|
65 | + */ |
|
66 | + public function __construct(IFactory $languageFactory, IURLGenerator $url, IUserManager $userManager, IManager $activityManager) { |
|
67 | + $this->languageFactory = $languageFactory; |
|
68 | + $this->url = $url; |
|
69 | + $this->userManager = $userManager; |
|
70 | + $this->activityManager = $activityManager; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param string $language |
|
75 | + * @param IEvent $event |
|
76 | + * @param IEvent|null $previousEvent |
|
77 | + * @return IEvent |
|
78 | + * @throws \InvalidArgumentException |
|
79 | + * @since 11.0.0 |
|
80 | + */ |
|
81 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
82 | + if ($event->getApp() !== 'settings') { |
|
83 | + throw new \InvalidArgumentException(); |
|
84 | + } |
|
85 | + |
|
86 | + $this->l = $this->languageFactory->get('settings', $language); |
|
87 | + |
|
88 | + if ($this->activityManager->getRequirePNG()) { |
|
89 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.png'))); |
|
90 | + } else { |
|
91 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.svg'))); |
|
92 | + } |
|
93 | + |
|
94 | + if ($event->getSubject() === self::PASSWORD_CHANGED_BY) { |
|
95 | + $subject = $this->l->t('{actor} changed your password'); |
|
96 | + } else if ($event->getSubject() === self::PASSWORD_CHANGED_SELF) { |
|
97 | + $subject = $this->l->t('You changed your password'); |
|
98 | + } else if ($event->getSubject() === self::PASSWORD_RESET) { |
|
99 | + $subject = $this->l->t('Your password was reset by an administrator'); |
|
100 | + |
|
101 | + } else if ($event->getSubject() === self::EMAIL_CHANGED_BY) { |
|
102 | + $subject = $this->l->t('{actor} changed your email address'); |
|
103 | + } else if ($event->getSubject() === self::EMAIL_CHANGED_SELF) { |
|
104 | + $subject = $this->l->t('You changed your email address'); |
|
105 | + } else if ($event->getSubject() === self::EMAIL_CHANGED) { |
|
106 | + $subject = $this->l->t('Your email address was changed by an administrator'); |
|
107 | + |
|
108 | + } else { |
|
109 | + throw new \InvalidArgumentException(); |
|
110 | + } |
|
111 | + |
|
112 | + $parsedParameters = $this->getParameters($event); |
|
113 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
114 | + |
|
115 | + return $event; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @param IEvent $event |
|
120 | + * @return array |
|
121 | + * @throws \InvalidArgumentException |
|
122 | + */ |
|
123 | + protected function getParameters(IEvent $event) { |
|
124 | + $subject = $event->getSubject(); |
|
125 | + $parameters = $event->getSubjectParameters(); |
|
126 | + |
|
127 | + switch ($subject) { |
|
128 | + case self::PASSWORD_CHANGED_SELF: |
|
129 | + case self::PASSWORD_RESET: |
|
130 | + case self::EMAIL_CHANGED_SELF: |
|
131 | + case self::EMAIL_CHANGED: |
|
132 | + return []; |
|
133 | + case self::PASSWORD_CHANGED_BY: |
|
134 | + case self::EMAIL_CHANGED_BY: |
|
135 | + return [ |
|
136 | + 'actor' => $this->generateUserParameter($parameters[0]), |
|
137 | + ]; |
|
138 | + } |
|
139 | + |
|
140 | + throw new \InvalidArgumentException(); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param IEvent $event |
|
145 | + * @param string $subject |
|
146 | + * @param array $parameters |
|
147 | + * @throws \InvalidArgumentException |
|
148 | + */ |
|
149 | + protected function setSubjects(IEvent $event, $subject, array $parameters) { |
|
150 | + $placeholders = $replacements = []; |
|
151 | + foreach ($parameters as $placeholder => $parameter) { |
|
152 | + $placeholders[] = '{' . $placeholder . '}'; |
|
153 | + $replacements[] = $parameter['name']; |
|
154 | + } |
|
155 | + |
|
156 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
157 | + ->setRichSubject($subject, $parameters); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @param string $uid |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + protected function generateUserParameter($uid) { |
|
165 | + if (!isset($this->displayNames[$uid])) { |
|
166 | + $this->displayNames[$uid] = $this->getDisplayName($uid); |
|
167 | + } |
|
168 | + |
|
169 | + return [ |
|
170 | + 'type' => 'user', |
|
171 | + 'id' => $uid, |
|
172 | + 'name' => $this->displayNames[$uid], |
|
173 | + ]; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @param string $uid |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + protected function getDisplayName($uid) { |
|
181 | + $user = $this->userManager->get($uid); |
|
182 | + if ($user instanceof IUser) { |
|
183 | + return $user->getDisplayName(); |
|
184 | + } |
|
185 | + |
|
186 | + return $uid; |
|
187 | + } |
|
188 | 188 | } |