|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016 Joas Schilling <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Joas Schilling <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OCA\Files_Sharing\Activity\Providers; |
|
25
|
|
|
|
|
26
|
|
|
use OCP\Activity\IEvent; |
|
27
|
|
|
use OCP\Activity\IManager; |
|
28
|
|
|
use OCP\IGroup; |
|
29
|
|
|
use OCP\IGroupManager; |
|
30
|
|
|
use OCP\IURLGenerator; |
|
31
|
|
|
use OCP\IUserManager; |
|
32
|
|
|
use OCP\L10N\IFactory; |
|
33
|
|
|
|
|
34
|
|
|
class Groups extends Base { |
|
35
|
|
|
|
|
36
|
|
|
const SUBJECT_SHARED_GROUP_SELF = 'shared_group_self'; |
|
37
|
|
|
const SUBJECT_RESHARED_GROUP_BY = 'reshared_group_by'; |
|
38
|
|
|
const SUBJECT_UNSHARED_GROUP_SELF = 'unshared_group_self'; |
|
39
|
|
|
const SUBJECT_UNSHARED_GROUP_BY = 'unshared_group_by'; |
|
40
|
|
|
|
|
41
|
|
|
/** @var IGroupManager */ |
|
42
|
|
|
protected $groupManager; |
|
43
|
|
|
|
|
44
|
|
|
/** @var string[] */ |
|
45
|
|
|
protected $groupDisplayNames = []; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param IFactory $languageFactory |
|
49
|
|
|
* @param IURLGenerator $url |
|
50
|
|
|
* @param IManager $activityManager |
|
51
|
|
|
* @param IUserManager $userManager |
|
52
|
|
|
* @param IGroupManager $groupManager |
|
53
|
|
|
*/ |
|
54
|
|
|
public function __construct(IFactory $languageFactory, IURLGenerator $url, IManager $activityManager, IUserManager $userManager, IGroupManager $groupManager) { |
|
55
|
|
|
parent::__construct($languageFactory, $url, $activityManager, $userManager); |
|
56
|
|
|
$this->groupManager = $groupManager; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param IEvent $event |
|
61
|
|
|
* @return IEvent |
|
62
|
|
|
* @throws \InvalidArgumentException |
|
63
|
|
|
* @since 11.0.0 |
|
64
|
|
|
*/ |
|
65
|
|
View Code Duplication |
public function parseShortVersion(IEvent $event) { |
|
66
|
|
|
$parsedParameters = $this->getParsedParameters($event); |
|
67
|
|
|
|
|
68
|
|
|
if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) { |
|
69
|
|
|
$subject = $this->l->t('Shared with group {group}'); |
|
70
|
|
|
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) { |
|
71
|
|
|
$subject = $this->l->t('Removed share for group {group}'); |
|
72
|
|
|
} else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) { |
|
73
|
|
|
$subject = $this->l->t('{actor} shared with group {group}'); |
|
74
|
|
|
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { |
|
75
|
|
|
$subject = $this->l->t('{actor} removed share for group {group}'); |
|
76
|
|
|
} else { |
|
77
|
|
|
throw new \InvalidArgumentException(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
if ($this->activityManager->getRequirePNG()) { |
|
81
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
82
|
|
|
} else { |
|
83
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
84
|
|
|
} |
|
85
|
|
|
$this->setSubjects($event, $subject, $parsedParameters); |
|
86
|
|
|
|
|
87
|
|
|
return $event; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param IEvent $event |
|
92
|
|
|
* @return IEvent |
|
93
|
|
|
* @throws \InvalidArgumentException |
|
94
|
|
|
* @since 11.0.0 |
|
95
|
|
|
*/ |
|
96
|
|
View Code Duplication |
public function parseLongVersion(IEvent $event) { |
|
97
|
|
|
$parsedParameters = $this->getParsedParameters($event); |
|
98
|
|
|
|
|
99
|
|
|
if ($event->getSubject() === self::SUBJECT_SHARED_GROUP_SELF) { |
|
100
|
|
|
$subject = $this->l->t('You shared {file} with group {group}'); |
|
101
|
|
|
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_SELF) { |
|
102
|
|
|
$subject = $this->l->t('You removed group {group} from {file}'); |
|
103
|
|
|
} else if ($event->getSubject() === self::SUBJECT_RESHARED_GROUP_BY) { |
|
104
|
|
|
$subject = $this->l->t('{actor} shared {file} with group {group}'); |
|
105
|
|
|
} else if ($event->getSubject() === self::SUBJECT_UNSHARED_GROUP_BY) { |
|
106
|
|
|
$subject = $this->l->t('{actor} removed group {group} from {file}'); |
|
107
|
|
|
} else { |
|
108
|
|
|
throw new \InvalidArgumentException(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
if ($this->activityManager->getRequirePNG()) { |
|
112
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.png'))); |
|
113
|
|
|
} else { |
|
114
|
|
|
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg'))); |
|
115
|
|
|
} |
|
116
|
|
|
$this->setSubjects($event, $subject, $parsedParameters); |
|
117
|
|
|
|
|
118
|
|
|
return $event; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
protected function getParsedParameters(IEvent $event) { |
|
122
|
|
|
$subject = $event->getSubject(); |
|
123
|
|
|
$parameters = $event->getSubjectParameters(); |
|
124
|
|
|
|
|
125
|
|
|
switch ($subject) { |
|
126
|
|
|
case self::SUBJECT_RESHARED_GROUP_BY: |
|
127
|
|
View Code Duplication |
case self::SUBJECT_UNSHARED_GROUP_BY: |
|
128
|
|
|
return [ |
|
129
|
|
|
'file' => $this->getFile($parameters[0], $event), |
|
130
|
|
|
'group' => $this->generateGroupParameter($parameters[2]), |
|
131
|
|
|
'actor' => $this->getUser($parameters[1]), |
|
132
|
|
|
]; |
|
133
|
|
|
case self::SUBJECT_SHARED_GROUP_SELF: |
|
134
|
|
|
case self::SUBJECT_UNSHARED_GROUP_SELF: |
|
135
|
|
|
return [ |
|
136
|
|
|
'file' => $this->getFile($parameters[0], $event), |
|
137
|
|
|
'group' => $this->generateGroupParameter($parameters[1]), |
|
138
|
|
|
]; |
|
139
|
|
|
} |
|
140
|
|
|
return []; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @param string $gid |
|
145
|
|
|
* @return array |
|
146
|
|
|
*/ |
|
147
|
|
View Code Duplication |
protected function generateGroupParameter($gid) { |
|
148
|
|
|
if (!isset($this->groupDisplayNames[$gid])) { |
|
149
|
|
|
$this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
return [ |
|
153
|
|
|
'type' => 'group', |
|
154
|
|
|
'id' => $gid, |
|
155
|
|
|
'name' => $this->groupDisplayNames[$gid], |
|
156
|
|
|
]; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param string $gid |
|
161
|
|
|
* @return string |
|
162
|
|
|
*/ |
|
163
|
|
|
protected function getGroupDisplayName($gid) { |
|
164
|
|
|
$group = $this->groupManager->get($gid); |
|
165
|
|
|
if ($group instanceof IGroup) { |
|
166
|
|
|
return $group->getDisplayName(); |
|
167
|
|
|
} |
|
168
|
|
|
return $gid; |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|