@@ -36,7 +36,7 @@ |
||
36 | 36 | * @package OC\AppFramework\Middleware\Security\Exceptions |
37 | 37 | */ |
38 | 38 | class NotAdminException extends SecurityException { |
39 | - public function __construct(string $message) { |
|
40 | - parent::__construct($message, Http::STATUS_FORBIDDEN); |
|
41 | - } |
|
39 | + public function __construct(string $message) { |
|
40 | + parent::__construct($message, Http::STATUS_FORBIDDEN); |
|
41 | + } |
|
42 | 42 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $activity->setApp('systemtags') |
111 | 111 | ->setType('systemtags') |
112 | 112 | ->setAuthor($actor) |
113 | - ->setObject('systemtag', (int)$tag->getId(), $tag->getName()); |
|
113 | + ->setObject('systemtag', (int) $tag->getId(), $tag->getName()); |
|
114 | 114 | if ($event->getEvent() === ManagerEvent::EVENT_CREATE) { |
115 | 115 | $activity->setSubject(Provider::CREATE_TAG, [ |
116 | 116 | $actor, |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | public function mapperEvent(MapperEvent $event) { |
152 | 152 | $tagIds = $event->getTags(); |
153 | - if ($event->getObjectType() !== 'files' ||empty($tagIds) |
|
153 | + if ($event->getObjectType() !== 'files' || empty($tagIds) |
|
154 | 154 | || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) |
155 | 155 | || !$this->appManager->isInstalled('activity')) { |
156 | 156 | // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy) |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | ->setObject($event->getObjectType(), (int) $event->getObjectId()); |
203 | 203 | |
204 | 204 | foreach ($users as $user => $path) { |
205 | - $user = (string)$user; // numerical ids could be ints which are not accepted everywhere |
|
205 | + $user = (string) $user; // numerical ids could be ints which are not accepted everywhere |
|
206 | 206 | $activity->setAffectedUser($user); |
207 | 207 | |
208 | 208 | foreach ($tags as $tag) { |
@@ -43,224 +43,224 @@ |
||
43 | 43 | use OCP\SystemTag\TagNotFoundException; |
44 | 44 | |
45 | 45 | class Listener { |
46 | - /** @var IGroupManager */ |
|
47 | - protected $groupManager; |
|
48 | - /** @var IManager */ |
|
49 | - protected $activityManager; |
|
50 | - /** @var IUserSession */ |
|
51 | - protected $session; |
|
52 | - /** @var IConfig */ |
|
53 | - protected $config; |
|
54 | - /** @var \OCP\SystemTag\ISystemTagManager */ |
|
55 | - protected $tagManager; |
|
56 | - /** @var \OCP\App\IAppManager */ |
|
57 | - protected $appManager; |
|
58 | - /** @var \OCP\Files\Config\IMountProviderCollection */ |
|
59 | - protected $mountCollection; |
|
60 | - /** @var \OCP\Files\IRootFolder */ |
|
61 | - protected $rootFolder; |
|
62 | - /** @var IShareHelper */ |
|
63 | - protected $shareHelper; |
|
46 | + /** @var IGroupManager */ |
|
47 | + protected $groupManager; |
|
48 | + /** @var IManager */ |
|
49 | + protected $activityManager; |
|
50 | + /** @var IUserSession */ |
|
51 | + protected $session; |
|
52 | + /** @var IConfig */ |
|
53 | + protected $config; |
|
54 | + /** @var \OCP\SystemTag\ISystemTagManager */ |
|
55 | + protected $tagManager; |
|
56 | + /** @var \OCP\App\IAppManager */ |
|
57 | + protected $appManager; |
|
58 | + /** @var \OCP\Files\Config\IMountProviderCollection */ |
|
59 | + protected $mountCollection; |
|
60 | + /** @var \OCP\Files\IRootFolder */ |
|
61 | + protected $rootFolder; |
|
62 | + /** @var IShareHelper */ |
|
63 | + protected $shareHelper; |
|
64 | 64 | |
65 | - /** |
|
66 | - * Listener constructor. |
|
67 | - * |
|
68 | - * @param IGroupManager $groupManager |
|
69 | - * @param IManager $activityManager |
|
70 | - * @param IUserSession $session |
|
71 | - * @param IConfig $config |
|
72 | - * @param ISystemTagManager $tagManager |
|
73 | - * @param IAppManager $appManager |
|
74 | - * @param IMountProviderCollection $mountCollection |
|
75 | - * @param IRootFolder $rootFolder |
|
76 | - * @param IShareHelper $shareHelper |
|
77 | - */ |
|
78 | - public function __construct(IGroupManager $groupManager, |
|
79 | - IManager $activityManager, |
|
80 | - IUserSession $session, |
|
81 | - IConfig $config, |
|
82 | - ISystemTagManager $tagManager, |
|
83 | - IAppManager $appManager, |
|
84 | - IMountProviderCollection $mountCollection, |
|
85 | - IRootFolder $rootFolder, |
|
86 | - IShareHelper $shareHelper) { |
|
87 | - $this->groupManager = $groupManager; |
|
88 | - $this->activityManager = $activityManager; |
|
89 | - $this->session = $session; |
|
90 | - $this->config = $config; |
|
91 | - $this->tagManager = $tagManager; |
|
92 | - $this->appManager = $appManager; |
|
93 | - $this->mountCollection = $mountCollection; |
|
94 | - $this->rootFolder = $rootFolder; |
|
95 | - $this->shareHelper = $shareHelper; |
|
96 | - } |
|
65 | + /** |
|
66 | + * Listener constructor. |
|
67 | + * |
|
68 | + * @param IGroupManager $groupManager |
|
69 | + * @param IManager $activityManager |
|
70 | + * @param IUserSession $session |
|
71 | + * @param IConfig $config |
|
72 | + * @param ISystemTagManager $tagManager |
|
73 | + * @param IAppManager $appManager |
|
74 | + * @param IMountProviderCollection $mountCollection |
|
75 | + * @param IRootFolder $rootFolder |
|
76 | + * @param IShareHelper $shareHelper |
|
77 | + */ |
|
78 | + public function __construct(IGroupManager $groupManager, |
|
79 | + IManager $activityManager, |
|
80 | + IUserSession $session, |
|
81 | + IConfig $config, |
|
82 | + ISystemTagManager $tagManager, |
|
83 | + IAppManager $appManager, |
|
84 | + IMountProviderCollection $mountCollection, |
|
85 | + IRootFolder $rootFolder, |
|
86 | + IShareHelper $shareHelper) { |
|
87 | + $this->groupManager = $groupManager; |
|
88 | + $this->activityManager = $activityManager; |
|
89 | + $this->session = $session; |
|
90 | + $this->config = $config; |
|
91 | + $this->tagManager = $tagManager; |
|
92 | + $this->appManager = $appManager; |
|
93 | + $this->mountCollection = $mountCollection; |
|
94 | + $this->rootFolder = $rootFolder; |
|
95 | + $this->shareHelper = $shareHelper; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * @param ManagerEvent $event |
|
100 | - */ |
|
101 | - public function event(ManagerEvent $event) { |
|
102 | - $actor = $this->session->getUser(); |
|
103 | - if ($actor instanceof IUser) { |
|
104 | - $actor = $actor->getUID(); |
|
105 | - } else { |
|
106 | - $actor = ''; |
|
107 | - } |
|
108 | - $tag = $event->getTag(); |
|
98 | + /** |
|
99 | + * @param ManagerEvent $event |
|
100 | + */ |
|
101 | + public function event(ManagerEvent $event) { |
|
102 | + $actor = $this->session->getUser(); |
|
103 | + if ($actor instanceof IUser) { |
|
104 | + $actor = $actor->getUID(); |
|
105 | + } else { |
|
106 | + $actor = ''; |
|
107 | + } |
|
108 | + $tag = $event->getTag(); |
|
109 | 109 | |
110 | - $activity = $this->activityManager->generateEvent(); |
|
111 | - $activity->setApp('systemtags') |
|
112 | - ->setType('systemtags') |
|
113 | - ->setAuthor($actor) |
|
114 | - ->setObject('systemtag', (int)$tag->getId(), $tag->getName()); |
|
115 | - if ($event->getEvent() === ManagerEvent::EVENT_CREATE) { |
|
116 | - $activity->setSubject(Provider::CREATE_TAG, [ |
|
117 | - $actor, |
|
118 | - $this->prepareTagAsParameter($event->getTag()), |
|
119 | - ]); |
|
120 | - } elseif ($event->getEvent() === ManagerEvent::EVENT_UPDATE) { |
|
121 | - $activity->setSubject(Provider::UPDATE_TAG, [ |
|
122 | - $actor, |
|
123 | - $this->prepareTagAsParameter($event->getTag()), |
|
124 | - $this->prepareTagAsParameter($event->getTagBefore()), |
|
125 | - ]); |
|
126 | - } elseif ($event->getEvent() === ManagerEvent::EVENT_DELETE) { |
|
127 | - $activity->setSubject(Provider::DELETE_TAG, [ |
|
128 | - $actor, |
|
129 | - $this->prepareTagAsParameter($event->getTag()), |
|
130 | - ]); |
|
131 | - } else { |
|
132 | - return; |
|
133 | - } |
|
110 | + $activity = $this->activityManager->generateEvent(); |
|
111 | + $activity->setApp('systemtags') |
|
112 | + ->setType('systemtags') |
|
113 | + ->setAuthor($actor) |
|
114 | + ->setObject('systemtag', (int)$tag->getId(), $tag->getName()); |
|
115 | + if ($event->getEvent() === ManagerEvent::EVENT_CREATE) { |
|
116 | + $activity->setSubject(Provider::CREATE_TAG, [ |
|
117 | + $actor, |
|
118 | + $this->prepareTagAsParameter($event->getTag()), |
|
119 | + ]); |
|
120 | + } elseif ($event->getEvent() === ManagerEvent::EVENT_UPDATE) { |
|
121 | + $activity->setSubject(Provider::UPDATE_TAG, [ |
|
122 | + $actor, |
|
123 | + $this->prepareTagAsParameter($event->getTag()), |
|
124 | + $this->prepareTagAsParameter($event->getTagBefore()), |
|
125 | + ]); |
|
126 | + } elseif ($event->getEvent() === ManagerEvent::EVENT_DELETE) { |
|
127 | + $activity->setSubject(Provider::DELETE_TAG, [ |
|
128 | + $actor, |
|
129 | + $this->prepareTagAsParameter($event->getTag()), |
|
130 | + ]); |
|
131 | + } else { |
|
132 | + return; |
|
133 | + } |
|
134 | 134 | |
135 | - $group = $this->groupManager->get('admin'); |
|
136 | - if ($group instanceof IGroup) { |
|
137 | - foreach ($group->getUsers() as $user) { |
|
138 | - $activity->setAffectedUser($user->getUID()); |
|
139 | - $this->activityManager->publish($activity); |
|
140 | - } |
|
141 | - } |
|
135 | + $group = $this->groupManager->get('admin'); |
|
136 | + if ($group instanceof IGroup) { |
|
137 | + foreach ($group->getUsers() as $user) { |
|
138 | + $activity->setAffectedUser($user->getUID()); |
|
139 | + $this->activityManager->publish($activity); |
|
140 | + } |
|
141 | + } |
|
142 | 142 | |
143 | 143 | |
144 | - if ($actor !== '' && ($event->getEvent() === ManagerEvent::EVENT_CREATE || $event->getEvent() === ManagerEvent::EVENT_UPDATE)) { |
|
145 | - $this->updateLastUsedTags($actor, $event->getTag()); |
|
146 | - } |
|
147 | - } |
|
144 | + if ($actor !== '' && ($event->getEvent() === ManagerEvent::EVENT_CREATE || $event->getEvent() === ManagerEvent::EVENT_UPDATE)) { |
|
145 | + $this->updateLastUsedTags($actor, $event->getTag()); |
|
146 | + } |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * @param MapperEvent $event |
|
151 | - */ |
|
152 | - public function mapperEvent(MapperEvent $event) { |
|
153 | - $tagIds = $event->getTags(); |
|
154 | - if ($event->getObjectType() !== 'files' ||empty($tagIds) |
|
155 | - || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) |
|
156 | - || !$this->appManager->isInstalled('activity')) { |
|
157 | - // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy) |
|
158 | - return; |
|
159 | - } |
|
149 | + /** |
|
150 | + * @param MapperEvent $event |
|
151 | + */ |
|
152 | + public function mapperEvent(MapperEvent $event) { |
|
153 | + $tagIds = $event->getTags(); |
|
154 | + if ($event->getObjectType() !== 'files' ||empty($tagIds) |
|
155 | + || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) |
|
156 | + || !$this->appManager->isInstalled('activity')) { |
|
157 | + // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy) |
|
158 | + return; |
|
159 | + } |
|
160 | 160 | |
161 | - try { |
|
162 | - $tags = $this->tagManager->getTagsByIds($tagIds); |
|
163 | - } catch (TagNotFoundException $e) { |
|
164 | - // User assigned/unassigned a non-existing tag, ignore... |
|
165 | - return; |
|
166 | - } |
|
161 | + try { |
|
162 | + $tags = $this->tagManager->getTagsByIds($tagIds); |
|
163 | + } catch (TagNotFoundException $e) { |
|
164 | + // User assigned/unassigned a non-existing tag, ignore... |
|
165 | + return; |
|
166 | + } |
|
167 | 167 | |
168 | - if (empty($tags)) { |
|
169 | - return; |
|
170 | - } |
|
168 | + if (empty($tags)) { |
|
169 | + return; |
|
170 | + } |
|
171 | 171 | |
172 | - // Get all mount point owners |
|
173 | - $cache = $this->mountCollection->getMountCache(); |
|
174 | - $mounts = $cache->getMountsForFileId($event->getObjectId()); |
|
175 | - if (empty($mounts)) { |
|
176 | - return; |
|
177 | - } |
|
172 | + // Get all mount point owners |
|
173 | + $cache = $this->mountCollection->getMountCache(); |
|
174 | + $mounts = $cache->getMountsForFileId($event->getObjectId()); |
|
175 | + if (empty($mounts)) { |
|
176 | + return; |
|
177 | + } |
|
178 | 178 | |
179 | - $users = []; |
|
180 | - foreach ($mounts as $mount) { |
|
181 | - $owner = $mount->getUser()->getUID(); |
|
182 | - $ownerFolder = $this->rootFolder->getUserFolder($owner); |
|
183 | - $nodes = $ownerFolder->getById($event->getObjectId()); |
|
184 | - if (!empty($nodes)) { |
|
185 | - /** @var Node $node */ |
|
186 | - $node = array_shift($nodes); |
|
187 | - $al = $this->shareHelper->getPathsForAccessList($node); |
|
188 | - $users += $al['users']; |
|
189 | - } |
|
190 | - } |
|
179 | + $users = []; |
|
180 | + foreach ($mounts as $mount) { |
|
181 | + $owner = $mount->getUser()->getUID(); |
|
182 | + $ownerFolder = $this->rootFolder->getUserFolder($owner); |
|
183 | + $nodes = $ownerFolder->getById($event->getObjectId()); |
|
184 | + if (!empty($nodes)) { |
|
185 | + /** @var Node $node */ |
|
186 | + $node = array_shift($nodes); |
|
187 | + $al = $this->shareHelper->getPathsForAccessList($node); |
|
188 | + $users += $al['users']; |
|
189 | + } |
|
190 | + } |
|
191 | 191 | |
192 | - $actor = $this->session->getUser(); |
|
193 | - if ($actor instanceof IUser) { |
|
194 | - $actor = $actor->getUID(); |
|
195 | - } else { |
|
196 | - $actor = ''; |
|
197 | - } |
|
192 | + $actor = $this->session->getUser(); |
|
193 | + if ($actor instanceof IUser) { |
|
194 | + $actor = $actor->getUID(); |
|
195 | + } else { |
|
196 | + $actor = ''; |
|
197 | + } |
|
198 | 198 | |
199 | - $activity = $this->activityManager->generateEvent(); |
|
200 | - $activity->setApp('systemtags') |
|
201 | - ->setType('systemtags') |
|
202 | - ->setAuthor($actor) |
|
203 | - ->setObject($event->getObjectType(), (int) $event->getObjectId()); |
|
199 | + $activity = $this->activityManager->generateEvent(); |
|
200 | + $activity->setApp('systemtags') |
|
201 | + ->setType('systemtags') |
|
202 | + ->setAuthor($actor) |
|
203 | + ->setObject($event->getObjectType(), (int) $event->getObjectId()); |
|
204 | 204 | |
205 | - foreach ($users as $user => $path) { |
|
206 | - $user = (string)$user; // numerical ids could be ints which are not accepted everywhere |
|
207 | - $activity->setAffectedUser($user); |
|
205 | + foreach ($users as $user => $path) { |
|
206 | + $user = (string)$user; // numerical ids could be ints which are not accepted everywhere |
|
207 | + $activity->setAffectedUser($user); |
|
208 | 208 | |
209 | - foreach ($tags as $tag) { |
|
210 | - // don't publish activity for non-admins if tag is invisible |
|
211 | - if (!$tag->isUserVisible() && !$this->groupManager->isAdmin($user)) { |
|
212 | - continue; |
|
213 | - } |
|
214 | - if ($event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
215 | - $activity->setSubject(Provider::ASSIGN_TAG, [ |
|
216 | - $actor, |
|
217 | - $path, |
|
218 | - $this->prepareTagAsParameter($tag), |
|
219 | - ]); |
|
220 | - } elseif ($event->getEvent() === MapperEvent::EVENT_UNASSIGN) { |
|
221 | - $activity->setSubject(Provider::UNASSIGN_TAG, [ |
|
222 | - $actor, |
|
223 | - $path, |
|
224 | - $this->prepareTagAsParameter($tag), |
|
225 | - ]); |
|
226 | - } |
|
209 | + foreach ($tags as $tag) { |
|
210 | + // don't publish activity for non-admins if tag is invisible |
|
211 | + if (!$tag->isUserVisible() && !$this->groupManager->isAdmin($user)) { |
|
212 | + continue; |
|
213 | + } |
|
214 | + if ($event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
215 | + $activity->setSubject(Provider::ASSIGN_TAG, [ |
|
216 | + $actor, |
|
217 | + $path, |
|
218 | + $this->prepareTagAsParameter($tag), |
|
219 | + ]); |
|
220 | + } elseif ($event->getEvent() === MapperEvent::EVENT_UNASSIGN) { |
|
221 | + $activity->setSubject(Provider::UNASSIGN_TAG, [ |
|
222 | + $actor, |
|
223 | + $path, |
|
224 | + $this->prepareTagAsParameter($tag), |
|
225 | + ]); |
|
226 | + } |
|
227 | 227 | |
228 | - $this->activityManager->publish($activity); |
|
229 | - } |
|
230 | - } |
|
228 | + $this->activityManager->publish($activity); |
|
229 | + } |
|
230 | + } |
|
231 | 231 | |
232 | - if ($actor !== '' && $event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
233 | - foreach ($tags as $tag) { |
|
234 | - $this->updateLastUsedTags($actor, $tag); |
|
235 | - } |
|
236 | - } |
|
237 | - } |
|
232 | + if ($actor !== '' && $event->getEvent() === MapperEvent::EVENT_ASSIGN) { |
|
233 | + foreach ($tags as $tag) { |
|
234 | + $this->updateLastUsedTags($actor, $tag); |
|
235 | + } |
|
236 | + } |
|
237 | + } |
|
238 | 238 | |
239 | - /** |
|
240 | - * @param string $actor |
|
241 | - * @param ISystemTag $tag |
|
242 | - */ |
|
243 | - protected function updateLastUsedTags($actor, ISystemTag $tag) { |
|
244 | - $lastUsedTags = $this->config->getUserValue($actor, 'systemtags', 'last_used', '[]'); |
|
245 | - $lastUsedTags = json_decode($lastUsedTags, true); |
|
239 | + /** |
|
240 | + * @param string $actor |
|
241 | + * @param ISystemTag $tag |
|
242 | + */ |
|
243 | + protected function updateLastUsedTags($actor, ISystemTag $tag) { |
|
244 | + $lastUsedTags = $this->config->getUserValue($actor, 'systemtags', 'last_used', '[]'); |
|
245 | + $lastUsedTags = json_decode($lastUsedTags, true); |
|
246 | 246 | |
247 | - array_unshift($lastUsedTags, $tag->getId()); |
|
248 | - array_unique($lastUsedTags); |
|
249 | - $lastUsedTags = array_slice($lastUsedTags, 0, 10); |
|
247 | + array_unshift($lastUsedTags, $tag->getId()); |
|
248 | + array_unique($lastUsedTags); |
|
249 | + $lastUsedTags = array_slice($lastUsedTags, 0, 10); |
|
250 | 250 | |
251 | - $this->config->setUserValue($actor, 'systemtags', 'last_used', json_encode($lastUsedTags)); |
|
252 | - } |
|
251 | + $this->config->setUserValue($actor, 'systemtags', 'last_used', json_encode($lastUsedTags)); |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * @param ISystemTag $tag |
|
256 | - * @return string |
|
257 | - */ |
|
258 | - protected function prepareTagAsParameter(ISystemTag $tag) { |
|
259 | - return json_encode([ |
|
260 | - 'id' => $tag->getId(), |
|
261 | - 'name' => $tag->getName(), |
|
262 | - 'assignable' => $tag->isUserAssignable(), |
|
263 | - 'visible' => $tag->isUserVisible(), |
|
264 | - ]); |
|
265 | - } |
|
254 | + /** |
|
255 | + * @param ISystemTag $tag |
|
256 | + * @return string |
|
257 | + */ |
|
258 | + protected function prepareTagAsParameter(ISystemTag $tag) { |
|
259 | + return json_encode([ |
|
260 | + 'id' => $tag->getId(), |
|
261 | + 'name' => $tag->getName(), |
|
262 | + 'assignable' => $tag->isUserAssignable(), |
|
263 | + 'visible' => $tag->isUserVisible(), |
|
264 | + ]); |
|
265 | + } |
|
266 | 266 | } |
@@ -29,53 +29,53 @@ |
||
29 | 29 | |
30 | 30 | abstract class Session implements \ArrayAccess, ISession { |
31 | 31 | |
32 | - /** |
|
33 | - * @var bool |
|
34 | - */ |
|
35 | - protected $sessionClosed = false; |
|
32 | + /** |
|
33 | + * @var bool |
|
34 | + */ |
|
35 | + protected $sessionClosed = false; |
|
36 | 36 | |
37 | - /** |
|
38 | - * $name serves as a namespace for the session keys |
|
39 | - * |
|
40 | - * @param string $name |
|
41 | - */ |
|
42 | - abstract public function __construct(string $name); |
|
37 | + /** |
|
38 | + * $name serves as a namespace for the session keys |
|
39 | + * |
|
40 | + * @param string $name |
|
41 | + */ |
|
42 | + abstract public function __construct(string $name); |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param mixed $offset |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - public function offsetExists($offset): bool { |
|
49 | - return $this->exists($offset); |
|
50 | - } |
|
44 | + /** |
|
45 | + * @param mixed $offset |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + public function offsetExists($offset): bool { |
|
49 | + return $this->exists($offset); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param mixed $offset |
|
54 | - * @return mixed |
|
55 | - */ |
|
56 | - public function offsetGet($offset) { |
|
57 | - return $this->get($offset); |
|
58 | - } |
|
52 | + /** |
|
53 | + * @param mixed $offset |
|
54 | + * @return mixed |
|
55 | + */ |
|
56 | + public function offsetGet($offset) { |
|
57 | + return $this->get($offset); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param mixed $offset |
|
62 | - * @param mixed $value |
|
63 | - */ |
|
64 | - public function offsetSet($offset, $value) { |
|
65 | - $this->set($offset, $value); |
|
66 | - } |
|
60 | + /** |
|
61 | + * @param mixed $offset |
|
62 | + * @param mixed $value |
|
63 | + */ |
|
64 | + public function offsetSet($offset, $value) { |
|
65 | + $this->set($offset, $value); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param mixed $offset |
|
70 | - */ |
|
71 | - public function offsetUnset($offset) { |
|
72 | - $this->remove($offset); |
|
73 | - } |
|
68 | + /** |
|
69 | + * @param mixed $offset |
|
70 | + */ |
|
71 | + public function offsetUnset($offset) { |
|
72 | + $this->remove($offset); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Close the session and release the lock |
|
77 | - */ |
|
78 | - public function close() { |
|
79 | - $this->sessionClosed = true; |
|
80 | - } |
|
75 | + /** |
|
76 | + * Close the session and release the lock |
|
77 | + */ |
|
78 | + public function close() { |
|
79 | + $this->sessionClosed = true; |
|
80 | + } |
|
81 | 81 | } |
@@ -157,11 +157,11 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
160 | - $keys = array_map(function ($header) { |
|
160 | + $keys = array_map(function($header) { |
|
161 | 161 | return strtolower(str_replace(' ', '_', $header)); |
162 | 162 | }, $headers); |
163 | 163 | |
164 | - $pairs = array_map(function (StorageConfig $config) use ($keys, $userId) { |
|
164 | + $pairs = array_map(function(StorageConfig $config) use ($keys, $userId) { |
|
165 | 165 | $values = [ |
166 | 166 | $config->getId(), |
167 | 167 | $config->getMountPoint(), |
@@ -195,23 +195,23 @@ discard block |
||
195 | 195 | 'encoding_compatibility' => false, |
196 | 196 | 'readonly' => false, |
197 | 197 | ]; |
198 | - $rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) { |
|
198 | + $rows = array_map(function(StorageConfig $config) use ($userId, $defaultMountOptions, $full) { |
|
199 | 199 | $storageConfig = $config->getBackendOptions(); |
200 | 200 | $keys = array_keys($storageConfig); |
201 | 201 | $values = array_values($storageConfig); |
202 | 202 | |
203 | 203 | if (!$full) { |
204 | - $values = array_map(function ($value) { |
|
204 | + $values = array_map(function($value) { |
|
205 | 205 | if (is_string($value) && strlen($value) > 32) { |
206 | - return substr($value, 0, 6) . '...' . substr($value, -6, 6); |
|
206 | + return substr($value, 0, 6).'...'.substr($value, -6, 6); |
|
207 | 207 | } else { |
208 | 208 | return $value; |
209 | 209 | } |
210 | 210 | }, $values); |
211 | 211 | } |
212 | 212 | |
213 | - $configStrings = array_map(function ($key, $value) { |
|
214 | - return $key . ': ' . json_encode($value); |
|
213 | + $configStrings = array_map(function($key, $value) { |
|
214 | + return $key.': '.json_encode($value); |
|
215 | 215 | }, $keys, $values); |
216 | 216 | $configString = implode(', ', $configStrings); |
217 | 217 | |
@@ -225,8 +225,8 @@ discard block |
||
225 | 225 | $keys = array_keys($mountOptions); |
226 | 226 | $values = array_values($mountOptions); |
227 | 227 | |
228 | - $optionsStrings = array_map(function ($key, $value) { |
|
229 | - return $key . ': ' . json_encode($value); |
|
228 | + $optionsStrings = array_map(function($key, $value) { |
|
229 | + return $key.': '.json_encode($value); |
|
230 | 230 | }, $keys, $values); |
231 | 231 | $optionsString = implode(', ', $optionsStrings); |
232 | 232 |
@@ -38,240 +38,240 @@ |
||
38 | 38 | use Symfony\Component\Console\Output\OutputInterface; |
39 | 39 | |
40 | 40 | class ListCommand extends Base { |
41 | - /** |
|
42 | - * @var GlobalStoragesService |
|
43 | - */ |
|
44 | - protected $globalService; |
|
41 | + /** |
|
42 | + * @var GlobalStoragesService |
|
43 | + */ |
|
44 | + protected $globalService; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var UserStoragesService |
|
48 | - */ |
|
49 | - protected $userService; |
|
46 | + /** |
|
47 | + * @var UserStoragesService |
|
48 | + */ |
|
49 | + protected $userService; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @var IUserSession |
|
53 | - */ |
|
54 | - protected $userSession; |
|
51 | + /** |
|
52 | + * @var IUserSession |
|
53 | + */ |
|
54 | + protected $userSession; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @var IUserManager |
|
58 | - */ |
|
59 | - protected $userManager; |
|
56 | + /** |
|
57 | + * @var IUserManager |
|
58 | + */ |
|
59 | + protected $userManager; |
|
60 | 60 | |
61 | - public const ALL = -1; |
|
61 | + public const ALL = -1; |
|
62 | 62 | |
63 | - public function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) { |
|
64 | - parent::__construct(); |
|
65 | - $this->globalService = $globalService; |
|
66 | - $this->userService = $userService; |
|
67 | - $this->userSession = $userSession; |
|
68 | - $this->userManager = $userManager; |
|
69 | - } |
|
63 | + public function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) { |
|
64 | + parent::__construct(); |
|
65 | + $this->globalService = $globalService; |
|
66 | + $this->userService = $userService; |
|
67 | + $this->userSession = $userSession; |
|
68 | + $this->userManager = $userManager; |
|
69 | + } |
|
70 | 70 | |
71 | - protected function configure() { |
|
72 | - $this |
|
73 | - ->setName('files_external:list') |
|
74 | - ->setDescription('List configured admin or personal mounts') |
|
75 | - ->addArgument( |
|
76 | - 'user_id', |
|
77 | - InputArgument::OPTIONAL, |
|
78 | - 'user id to list the personal mounts for, if no user is provided admin mounts will be listed' |
|
79 | - )->addOption( |
|
80 | - 'show-password', |
|
81 | - '', |
|
82 | - InputOption::VALUE_NONE, |
|
83 | - 'show passwords and secrets' |
|
84 | - )->addOption( |
|
85 | - 'full', |
|
86 | - null, |
|
87 | - InputOption::VALUE_NONE, |
|
88 | - 'don\'t truncate long values in table output' |
|
89 | - )->addOption( |
|
90 | - 'all', |
|
91 | - 'a', |
|
92 | - InputOption::VALUE_NONE, |
|
93 | - 'show both system wide mounts and all personal mounts' |
|
94 | - ); |
|
95 | - parent::configure(); |
|
96 | - } |
|
71 | + protected function configure() { |
|
72 | + $this |
|
73 | + ->setName('files_external:list') |
|
74 | + ->setDescription('List configured admin or personal mounts') |
|
75 | + ->addArgument( |
|
76 | + 'user_id', |
|
77 | + InputArgument::OPTIONAL, |
|
78 | + 'user id to list the personal mounts for, if no user is provided admin mounts will be listed' |
|
79 | + )->addOption( |
|
80 | + 'show-password', |
|
81 | + '', |
|
82 | + InputOption::VALUE_NONE, |
|
83 | + 'show passwords and secrets' |
|
84 | + )->addOption( |
|
85 | + 'full', |
|
86 | + null, |
|
87 | + InputOption::VALUE_NONE, |
|
88 | + 'don\'t truncate long values in table output' |
|
89 | + )->addOption( |
|
90 | + 'all', |
|
91 | + 'a', |
|
92 | + InputOption::VALUE_NONE, |
|
93 | + 'show both system wide mounts and all personal mounts' |
|
94 | + ); |
|
95 | + parent::configure(); |
|
96 | + } |
|
97 | 97 | |
98 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
99 | - if ($input->getOption('all')) { |
|
100 | - /** @var $mounts StorageConfig[] */ |
|
101 | - $mounts = $this->globalService->getStorageForAllUsers(); |
|
102 | - $userId = self::ALL; |
|
103 | - } else { |
|
104 | - $userId = $input->getArgument('user_id'); |
|
105 | - $storageService = $this->getStorageService($userId); |
|
98 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
99 | + if ($input->getOption('all')) { |
|
100 | + /** @var $mounts StorageConfig[] */ |
|
101 | + $mounts = $this->globalService->getStorageForAllUsers(); |
|
102 | + $userId = self::ALL; |
|
103 | + } else { |
|
104 | + $userId = $input->getArgument('user_id'); |
|
105 | + $storageService = $this->getStorageService($userId); |
|
106 | 106 | |
107 | - /** @var $mounts StorageConfig[] */ |
|
108 | - $mounts = $storageService->getAllStorages(); |
|
109 | - } |
|
107 | + /** @var $mounts StorageConfig[] */ |
|
108 | + $mounts = $storageService->getAllStorages(); |
|
109 | + } |
|
110 | 110 | |
111 | - $this->listMounts($userId, $mounts, $input, $output); |
|
112 | - } |
|
111 | + $this->listMounts($userId, $mounts, $input, $output); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * @param $userId $userId |
|
116 | - * @param StorageConfig[] $mounts |
|
117 | - * @param InputInterface $input |
|
118 | - * @param OutputInterface $output |
|
119 | - */ |
|
120 | - public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output) { |
|
121 | - $outputType = $input->getOption('output'); |
|
122 | - if (count($mounts) === 0) { |
|
123 | - if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
|
124 | - $output->writeln('[]'); |
|
125 | - } else { |
|
126 | - if ($userId === self::ALL) { |
|
127 | - $output->writeln("<info>No mounts configured</info>"); |
|
128 | - } elseif ($userId) { |
|
129 | - $output->writeln("<info>No mounts configured by $userId</info>"); |
|
130 | - } else { |
|
131 | - $output->writeln("<info>No admin mounts configured</info>"); |
|
132 | - } |
|
133 | - } |
|
134 | - return; |
|
135 | - } |
|
114 | + /** |
|
115 | + * @param $userId $userId |
|
116 | + * @param StorageConfig[] $mounts |
|
117 | + * @param InputInterface $input |
|
118 | + * @param OutputInterface $output |
|
119 | + */ |
|
120 | + public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output) { |
|
121 | + $outputType = $input->getOption('output'); |
|
122 | + if (count($mounts) === 0) { |
|
123 | + if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
|
124 | + $output->writeln('[]'); |
|
125 | + } else { |
|
126 | + if ($userId === self::ALL) { |
|
127 | + $output->writeln("<info>No mounts configured</info>"); |
|
128 | + } elseif ($userId) { |
|
129 | + $output->writeln("<info>No mounts configured by $userId</info>"); |
|
130 | + } else { |
|
131 | + $output->writeln("<info>No admin mounts configured</info>"); |
|
132 | + } |
|
133 | + } |
|
134 | + return; |
|
135 | + } |
|
136 | 136 | |
137 | - $headers = ['Mount ID', 'Mount Point', 'Storage', 'Authentication Type', 'Configuration', 'Options']; |
|
137 | + $headers = ['Mount ID', 'Mount Point', 'Storage', 'Authentication Type', 'Configuration', 'Options']; |
|
138 | 138 | |
139 | - if (!$userId || $userId === self::ALL) { |
|
140 | - $headers[] = 'Applicable Users'; |
|
141 | - $headers[] = 'Applicable Groups'; |
|
142 | - } |
|
143 | - if ($userId === self::ALL) { |
|
144 | - $headers[] = 'Type'; |
|
145 | - } |
|
139 | + if (!$userId || $userId === self::ALL) { |
|
140 | + $headers[] = 'Applicable Users'; |
|
141 | + $headers[] = 'Applicable Groups'; |
|
142 | + } |
|
143 | + if ($userId === self::ALL) { |
|
144 | + $headers[] = 'Type'; |
|
145 | + } |
|
146 | 146 | |
147 | - if (!$input->getOption('show-password')) { |
|
148 | - $hideKeys = ['password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key']; |
|
149 | - foreach ($mounts as $mount) { |
|
150 | - $config = $mount->getBackendOptions(); |
|
151 | - foreach ($config as $key => $value) { |
|
152 | - if (in_array($key, $hideKeys)) { |
|
153 | - $mount->setBackendOption($key, '***'); |
|
154 | - } |
|
155 | - } |
|
156 | - } |
|
157 | - } |
|
147 | + if (!$input->getOption('show-password')) { |
|
148 | + $hideKeys = ['password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key']; |
|
149 | + foreach ($mounts as $mount) { |
|
150 | + $config = $mount->getBackendOptions(); |
|
151 | + foreach ($config as $key => $value) { |
|
152 | + if (in_array($key, $hideKeys)) { |
|
153 | + $mount->setBackendOption($key, '***'); |
|
154 | + } |
|
155 | + } |
|
156 | + } |
|
157 | + } |
|
158 | 158 | |
159 | - if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
|
160 | - $keys = array_map(function ($header) { |
|
161 | - return strtolower(str_replace(' ', '_', $header)); |
|
162 | - }, $headers); |
|
159 | + if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
|
160 | + $keys = array_map(function ($header) { |
|
161 | + return strtolower(str_replace(' ', '_', $header)); |
|
162 | + }, $headers); |
|
163 | 163 | |
164 | - $pairs = array_map(function (StorageConfig $config) use ($keys, $userId) { |
|
165 | - $values = [ |
|
166 | - $config->getId(), |
|
167 | - $config->getMountPoint(), |
|
168 | - $config->getBackend()->getStorageClass(), |
|
169 | - $config->getAuthMechanism()->getIdentifier(), |
|
170 | - $config->getBackendOptions(), |
|
171 | - $config->getMountOptions() |
|
172 | - ]; |
|
173 | - if (!$userId || $userId === self::ALL) { |
|
174 | - $values[] = $config->getApplicableUsers(); |
|
175 | - $values[] = $config->getApplicableGroups(); |
|
176 | - } |
|
177 | - if ($userId === self::ALL) { |
|
178 | - $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'admin' : 'personal'; |
|
179 | - } |
|
164 | + $pairs = array_map(function (StorageConfig $config) use ($keys, $userId) { |
|
165 | + $values = [ |
|
166 | + $config->getId(), |
|
167 | + $config->getMountPoint(), |
|
168 | + $config->getBackend()->getStorageClass(), |
|
169 | + $config->getAuthMechanism()->getIdentifier(), |
|
170 | + $config->getBackendOptions(), |
|
171 | + $config->getMountOptions() |
|
172 | + ]; |
|
173 | + if (!$userId || $userId === self::ALL) { |
|
174 | + $values[] = $config->getApplicableUsers(); |
|
175 | + $values[] = $config->getApplicableGroups(); |
|
176 | + } |
|
177 | + if ($userId === self::ALL) { |
|
178 | + $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'admin' : 'personal'; |
|
179 | + } |
|
180 | 180 | |
181 | - return array_combine($keys, $values); |
|
182 | - }, $mounts); |
|
183 | - if ($outputType === self::OUTPUT_FORMAT_JSON) { |
|
184 | - $output->writeln(json_encode(array_values($pairs))); |
|
185 | - } else { |
|
186 | - $output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT)); |
|
187 | - } |
|
188 | - } else { |
|
189 | - $full = $input->getOption('full'); |
|
190 | - $defaultMountOptions = [ |
|
191 | - 'encrypt' => true, |
|
192 | - 'previews' => true, |
|
193 | - 'filesystem_check_changes' => 1, |
|
194 | - 'enable_sharing' => false, |
|
195 | - 'encoding_compatibility' => false, |
|
196 | - 'readonly' => false, |
|
197 | - ]; |
|
198 | - $rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) { |
|
199 | - $storageConfig = $config->getBackendOptions(); |
|
200 | - $keys = array_keys($storageConfig); |
|
201 | - $values = array_values($storageConfig); |
|
181 | + return array_combine($keys, $values); |
|
182 | + }, $mounts); |
|
183 | + if ($outputType === self::OUTPUT_FORMAT_JSON) { |
|
184 | + $output->writeln(json_encode(array_values($pairs))); |
|
185 | + } else { |
|
186 | + $output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT)); |
|
187 | + } |
|
188 | + } else { |
|
189 | + $full = $input->getOption('full'); |
|
190 | + $defaultMountOptions = [ |
|
191 | + 'encrypt' => true, |
|
192 | + 'previews' => true, |
|
193 | + 'filesystem_check_changes' => 1, |
|
194 | + 'enable_sharing' => false, |
|
195 | + 'encoding_compatibility' => false, |
|
196 | + 'readonly' => false, |
|
197 | + ]; |
|
198 | + $rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) { |
|
199 | + $storageConfig = $config->getBackendOptions(); |
|
200 | + $keys = array_keys($storageConfig); |
|
201 | + $values = array_values($storageConfig); |
|
202 | 202 | |
203 | - if (!$full) { |
|
204 | - $values = array_map(function ($value) { |
|
205 | - if (is_string($value) && strlen($value) > 32) { |
|
206 | - return substr($value, 0, 6) . '...' . substr($value, -6, 6); |
|
207 | - } else { |
|
208 | - return $value; |
|
209 | - } |
|
210 | - }, $values); |
|
211 | - } |
|
203 | + if (!$full) { |
|
204 | + $values = array_map(function ($value) { |
|
205 | + if (is_string($value) && strlen($value) > 32) { |
|
206 | + return substr($value, 0, 6) . '...' . substr($value, -6, 6); |
|
207 | + } else { |
|
208 | + return $value; |
|
209 | + } |
|
210 | + }, $values); |
|
211 | + } |
|
212 | 212 | |
213 | - $configStrings = array_map(function ($key, $value) { |
|
214 | - return $key . ': ' . json_encode($value); |
|
215 | - }, $keys, $values); |
|
216 | - $configString = implode(', ', $configStrings); |
|
213 | + $configStrings = array_map(function ($key, $value) { |
|
214 | + return $key . ': ' . json_encode($value); |
|
215 | + }, $keys, $values); |
|
216 | + $configString = implode(', ', $configStrings); |
|
217 | 217 | |
218 | - $mountOptions = $config->getMountOptions(); |
|
219 | - // hide defaults |
|
220 | - foreach ($mountOptions as $key => $value) { |
|
221 | - if ($value === $defaultMountOptions[$key]) { |
|
222 | - unset($mountOptions[$key]); |
|
223 | - } |
|
224 | - } |
|
225 | - $keys = array_keys($mountOptions); |
|
226 | - $values = array_values($mountOptions); |
|
218 | + $mountOptions = $config->getMountOptions(); |
|
219 | + // hide defaults |
|
220 | + foreach ($mountOptions as $key => $value) { |
|
221 | + if ($value === $defaultMountOptions[$key]) { |
|
222 | + unset($mountOptions[$key]); |
|
223 | + } |
|
224 | + } |
|
225 | + $keys = array_keys($mountOptions); |
|
226 | + $values = array_values($mountOptions); |
|
227 | 227 | |
228 | - $optionsStrings = array_map(function ($key, $value) { |
|
229 | - return $key . ': ' . json_encode($value); |
|
230 | - }, $keys, $values); |
|
231 | - $optionsString = implode(', ', $optionsStrings); |
|
228 | + $optionsStrings = array_map(function ($key, $value) { |
|
229 | + return $key . ': ' . json_encode($value); |
|
230 | + }, $keys, $values); |
|
231 | + $optionsString = implode(', ', $optionsStrings); |
|
232 | 232 | |
233 | - $values = [ |
|
234 | - $config->getId(), |
|
235 | - $config->getMountPoint(), |
|
236 | - $config->getBackend()->getText(), |
|
237 | - $config->getAuthMechanism()->getText(), |
|
238 | - $configString, |
|
239 | - $optionsString |
|
240 | - ]; |
|
233 | + $values = [ |
|
234 | + $config->getId(), |
|
235 | + $config->getMountPoint(), |
|
236 | + $config->getBackend()->getText(), |
|
237 | + $config->getAuthMechanism()->getText(), |
|
238 | + $configString, |
|
239 | + $optionsString |
|
240 | + ]; |
|
241 | 241 | |
242 | - if (!$userId || $userId === self::ALL) { |
|
243 | - $applicableUsers = implode(', ', $config->getApplicableUsers()); |
|
244 | - $applicableGroups = implode(', ', $config->getApplicableGroups()); |
|
245 | - if ($applicableUsers === '' && $applicableGroups === '') { |
|
246 | - $applicableUsers = 'All'; |
|
247 | - } |
|
248 | - $values[] = $applicableUsers; |
|
249 | - $values[] = $applicableGroups; |
|
250 | - } |
|
251 | - if ($userId === self::ALL) { |
|
252 | - $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'Admin' : 'Personal'; |
|
253 | - } |
|
242 | + if (!$userId || $userId === self::ALL) { |
|
243 | + $applicableUsers = implode(', ', $config->getApplicableUsers()); |
|
244 | + $applicableGroups = implode(', ', $config->getApplicableGroups()); |
|
245 | + if ($applicableUsers === '' && $applicableGroups === '') { |
|
246 | + $applicableUsers = 'All'; |
|
247 | + } |
|
248 | + $values[] = $applicableUsers; |
|
249 | + $values[] = $applicableGroups; |
|
250 | + } |
|
251 | + if ($userId === self::ALL) { |
|
252 | + $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'Admin' : 'Personal'; |
|
253 | + } |
|
254 | 254 | |
255 | - return $values; |
|
256 | - }, $mounts); |
|
255 | + return $values; |
|
256 | + }, $mounts); |
|
257 | 257 | |
258 | - $table = new Table($output); |
|
259 | - $table->setHeaders($headers); |
|
260 | - $table->setRows($rows); |
|
261 | - $table->render(); |
|
262 | - } |
|
263 | - } |
|
258 | + $table = new Table($output); |
|
259 | + $table->setHeaders($headers); |
|
260 | + $table->setRows($rows); |
|
261 | + $table->render(); |
|
262 | + } |
|
263 | + } |
|
264 | 264 | |
265 | - protected function getStorageService($userId) { |
|
266 | - if (!empty($userId)) { |
|
267 | - $user = $this->userManager->get($userId); |
|
268 | - if (is_null($user)) { |
|
269 | - throw new NoUserException("user $userId not found"); |
|
270 | - } |
|
271 | - $this->userSession->setUser($user); |
|
272 | - return $this->userService; |
|
273 | - } else { |
|
274 | - return $this->globalService; |
|
275 | - } |
|
276 | - } |
|
265 | + protected function getStorageService($userId) { |
|
266 | + if (!empty($userId)) { |
|
267 | + $user = $this->userManager->get($userId); |
|
268 | + if (is_null($user)) { |
|
269 | + throw new NoUserException("user $userId not found"); |
|
270 | + } |
|
271 | + $this->userSession->setUser($user); |
|
272 | + return $this->userService; |
|
273 | + } else { |
|
274 | + return $this->globalService; |
|
275 | + } |
|
276 | + } |
|
277 | 277 | } |
@@ -34,55 +34,55 @@ |
||
34 | 34 | |
35 | 35 | class ProvisioningApiMiddleware extends Middleware { |
36 | 36 | |
37 | - /** @var IControllerMethodReflector */ |
|
38 | - private $reflector; |
|
37 | + /** @var IControllerMethodReflector */ |
|
38 | + private $reflector; |
|
39 | 39 | |
40 | - /** @var bool */ |
|
41 | - private $isAdmin; |
|
40 | + /** @var bool */ |
|
41 | + private $isAdmin; |
|
42 | 42 | |
43 | - /** @var bool */ |
|
44 | - private $isSubAdmin; |
|
43 | + /** @var bool */ |
|
44 | + private $isSubAdmin; |
|
45 | 45 | |
46 | - /** |
|
47 | - * ProvisioningApiMiddleware constructor. |
|
48 | - * |
|
49 | - * @param IControllerMethodReflector $reflector |
|
50 | - * @param bool $isAdmin |
|
51 | - * @param bool $isSubAdmin |
|
52 | - */ |
|
53 | - public function __construct( |
|
54 | - IControllerMethodReflector $reflector, |
|
55 | - bool $isAdmin, |
|
56 | - bool $isSubAdmin) { |
|
57 | - $this->reflector = $reflector; |
|
58 | - $this->isAdmin = $isAdmin; |
|
59 | - $this->isSubAdmin = $isSubAdmin; |
|
60 | - } |
|
46 | + /** |
|
47 | + * ProvisioningApiMiddleware constructor. |
|
48 | + * |
|
49 | + * @param IControllerMethodReflector $reflector |
|
50 | + * @param bool $isAdmin |
|
51 | + * @param bool $isSubAdmin |
|
52 | + */ |
|
53 | + public function __construct( |
|
54 | + IControllerMethodReflector $reflector, |
|
55 | + bool $isAdmin, |
|
56 | + bool $isSubAdmin) { |
|
57 | + $this->reflector = $reflector; |
|
58 | + $this->isAdmin = $isAdmin; |
|
59 | + $this->isSubAdmin = $isSubAdmin; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param Controller $controller |
|
64 | - * @param string $methodName |
|
65 | - * |
|
66 | - * @throws NotSubAdminException |
|
67 | - */ |
|
68 | - public function beforeController($controller, $methodName) { |
|
69 | - if (!$this->isAdmin && !$this->reflector->hasAnnotation('NoSubAdminRequired') && !$this->isSubAdmin) { |
|
70 | - throw new NotSubAdminException(); |
|
71 | - } |
|
72 | - } |
|
62 | + /** |
|
63 | + * @param Controller $controller |
|
64 | + * @param string $methodName |
|
65 | + * |
|
66 | + * @throws NotSubAdminException |
|
67 | + */ |
|
68 | + public function beforeController($controller, $methodName) { |
|
69 | + if (!$this->isAdmin && !$this->reflector->hasAnnotation('NoSubAdminRequired') && !$this->isSubAdmin) { |
|
70 | + throw new NotSubAdminException(); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param Controller $controller |
|
76 | - * @param string $methodName |
|
77 | - * @param \Exception $exception |
|
78 | - * @throws \Exception |
|
79 | - * @return Response |
|
80 | - */ |
|
81 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
82 | - if ($exception instanceof NotSubAdminException) { |
|
83 | - throw new OCSException($exception->getMessage(), \OCP\API::RESPOND_UNAUTHORISED); |
|
84 | - } |
|
74 | + /** |
|
75 | + * @param Controller $controller |
|
76 | + * @param string $methodName |
|
77 | + * @param \Exception $exception |
|
78 | + * @throws \Exception |
|
79 | + * @return Response |
|
80 | + */ |
|
81 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
82 | + if ($exception instanceof NotSubAdminException) { |
|
83 | + throw new OCSException($exception->getMessage(), \OCP\API::RESPOND_UNAUTHORISED); |
|
84 | + } |
|
85 | 85 | |
86 | - throw $exception; |
|
87 | - } |
|
86 | + throw $exception; |
|
87 | + } |
|
88 | 88 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $dir = $pathinfo['dirname']; |
59 | 59 | $i = 2; |
60 | 60 | while ($view->file_exists($path) || in_array($path, $excludeList)) { |
61 | - $path = Filesystem::normalizePath($dir . '/' . $name . ' ('.$i.')' . $ext); |
|
61 | + $path = Filesystem::normalizePath($dir.'/'.$name.' ('.$i.')'.$ext); |
|
62 | 62 | $i++; |
63 | 63 | } |
64 | 64 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $dir = ''; |
83 | 83 | $subdirs = explode('/', $shareFolder); |
84 | 84 | foreach ($subdirs as $subdir) { |
85 | - $dir = $dir . '/' . $subdir; |
|
85 | + $dir = $dir.'/'.$subdir; |
|
86 | 86 | if (!$view->is_dir($dir)) { |
87 | 87 | $view->mkdir($dir); |
88 | 88 | } |
@@ -31,68 +31,68 @@ |
||
31 | 31 | use OC\Files\View; |
32 | 32 | |
33 | 33 | class Helper { |
34 | - public static function registerHooks() { |
|
35 | - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', '\OCA\Files_Sharing\Updater', 'renameHook'); |
|
36 | - \OCP\Util::connectHook('OC_Filesystem', 'post_delete', '\OCA\Files_Sharing\Hooks', 'unshareChildren'); |
|
34 | + public static function registerHooks() { |
|
35 | + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', '\OCA\Files_Sharing\Updater', 'renameHook'); |
|
36 | + \OCP\Util::connectHook('OC_Filesystem', 'post_delete', '\OCA\Files_Sharing\Hooks', 'unshareChildren'); |
|
37 | 37 | |
38 | - \OCP\Util::connectHook('OC_User', 'post_deleteUser', '\OCA\Files_Sharing\Hooks', 'deleteUser'); |
|
39 | - } |
|
38 | + \OCP\Util::connectHook('OC_User', 'post_deleteUser', '\OCA\Files_Sharing\Hooks', 'deleteUser'); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * check if file name already exists and generate unique target |
|
43 | - * |
|
44 | - * @param string $path |
|
45 | - * @param array $excludeList |
|
46 | - * @param View $view |
|
47 | - * @return string $path |
|
48 | - */ |
|
49 | - public static function generateUniqueTarget($path, $excludeList, $view) { |
|
50 | - $pathinfo = pathinfo($path); |
|
51 | - $ext = isset($pathinfo['extension']) ? '.'.$pathinfo['extension'] : ''; |
|
52 | - $name = $pathinfo['filename']; |
|
53 | - $dir = $pathinfo['dirname']; |
|
54 | - $i = 2; |
|
55 | - while ($view->file_exists($path) || in_array($path, $excludeList)) { |
|
56 | - $path = Filesystem::normalizePath($dir . '/' . $name . ' ('.$i.')' . $ext); |
|
57 | - $i++; |
|
58 | - } |
|
41 | + /** |
|
42 | + * check if file name already exists and generate unique target |
|
43 | + * |
|
44 | + * @param string $path |
|
45 | + * @param array $excludeList |
|
46 | + * @param View $view |
|
47 | + * @return string $path |
|
48 | + */ |
|
49 | + public static function generateUniqueTarget($path, $excludeList, $view) { |
|
50 | + $pathinfo = pathinfo($path); |
|
51 | + $ext = isset($pathinfo['extension']) ? '.'.$pathinfo['extension'] : ''; |
|
52 | + $name = $pathinfo['filename']; |
|
53 | + $dir = $pathinfo['dirname']; |
|
54 | + $i = 2; |
|
55 | + while ($view->file_exists($path) || in_array($path, $excludeList)) { |
|
56 | + $path = Filesystem::normalizePath($dir . '/' . $name . ' ('.$i.')' . $ext); |
|
57 | + $i++; |
|
58 | + } |
|
59 | 59 | |
60 | - return $path; |
|
61 | - } |
|
60 | + return $path; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * get default share folder |
|
65 | - * |
|
66 | - * @param \OC\Files\View |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public static function getShareFolder($view = null) { |
|
70 | - if ($view === null) { |
|
71 | - $view = Filesystem::getView(); |
|
72 | - } |
|
73 | - $shareFolder = \OC::$server->getConfig()->getSystemValue('share_folder', '/'); |
|
74 | - $shareFolder = Filesystem::normalizePath($shareFolder); |
|
63 | + /** |
|
64 | + * get default share folder |
|
65 | + * |
|
66 | + * @param \OC\Files\View |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public static function getShareFolder($view = null) { |
|
70 | + if ($view === null) { |
|
71 | + $view = Filesystem::getView(); |
|
72 | + } |
|
73 | + $shareFolder = \OC::$server->getConfig()->getSystemValue('share_folder', '/'); |
|
74 | + $shareFolder = Filesystem::normalizePath($shareFolder); |
|
75 | 75 | |
76 | - if (!$view->file_exists($shareFolder)) { |
|
77 | - $dir = ''; |
|
78 | - $subdirs = explode('/', $shareFolder); |
|
79 | - foreach ($subdirs as $subdir) { |
|
80 | - $dir = $dir . '/' . $subdir; |
|
81 | - if (!$view->is_dir($dir)) { |
|
82 | - $view->mkdir($dir); |
|
83 | - } |
|
84 | - } |
|
85 | - } |
|
76 | + if (!$view->file_exists($shareFolder)) { |
|
77 | + $dir = ''; |
|
78 | + $subdirs = explode('/', $shareFolder); |
|
79 | + foreach ($subdirs as $subdir) { |
|
80 | + $dir = $dir . '/' . $subdir; |
|
81 | + if (!$view->is_dir($dir)) { |
|
82 | + $view->mkdir($dir); |
|
83 | + } |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - return $shareFolder; |
|
88 | - } |
|
87 | + return $shareFolder; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * set default share folder |
|
92 | - * |
|
93 | - * @param string $shareFolder |
|
94 | - */ |
|
95 | - public static function setShareFolder($shareFolder) { |
|
96 | - \OC::$server->getConfig()->setSystemValue('share_folder', $shareFolder); |
|
97 | - } |
|
90 | + /** |
|
91 | + * set default share folder |
|
92 | + * |
|
93 | + * @param string $shareFolder |
|
94 | + */ |
|
95 | + public static function setShareFolder($shareFolder) { |
|
96 | + \OC::$server->getConfig()->setSystemValue('share_folder', $shareFolder); |
|
97 | + } |
|
98 | 98 | } |
@@ -22,11 +22,11 @@ |
||
22 | 22 | */ |
23 | 23 | |
24 | 24 | return [ |
25 | - 'routes' => [ |
|
26 | - ['name' => 'Admin#createCredentials', 'url' => '/credentials', 'verb' => 'GET'], |
|
27 | - ['name' => 'Admin#setChannel', 'url' => '/channel', 'verb' => 'POST'], |
|
28 | - ], |
|
29 | - 'ocs' => [ |
|
30 | - ['name' => 'API#getAppList', 'url' => '/api/{apiVersion}/applist/{newVersion}', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v1']], |
|
31 | - ], |
|
25 | + 'routes' => [ |
|
26 | + ['name' => 'Admin#createCredentials', 'url' => '/credentials', 'verb' => 'GET'], |
|
27 | + ['name' => 'Admin#setChannel', 'url' => '/channel', 'verb' => 'POST'], |
|
28 | + ], |
|
29 | + 'ocs' => [ |
|
30 | + ['name' => 'API#getAppList', 'url' => '/api/{apiVersion}/applist/{newVersion}', 'verb' => 'GET', 'requirements' => ['apiVersion' => 'v1']], |
|
31 | + ], |
|
32 | 32 | ]; |
@@ -34,48 +34,48 @@ |
||
34 | 34 | */ |
35 | 35 | class Attachment implements IAttachment { |
36 | 36 | |
37 | - /** @var \Swift_Mime_Attachment */ |
|
38 | - protected $swiftAttachment; |
|
37 | + /** @var \Swift_Mime_Attachment */ |
|
38 | + protected $swiftAttachment; |
|
39 | 39 | |
40 | - public function __construct(\Swift_Mime_Attachment $attachment) { |
|
41 | - $this->swiftAttachment = $attachment; |
|
42 | - } |
|
40 | + public function __construct(\Swift_Mime_Attachment $attachment) { |
|
41 | + $this->swiftAttachment = $attachment; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param string $filename |
|
46 | - * @return $this |
|
47 | - * @since 13.0.0 |
|
48 | - */ |
|
49 | - public function setFilename(string $filename): IAttachment { |
|
50 | - $this->swiftAttachment->setFilename($filename); |
|
51 | - return $this; |
|
52 | - } |
|
44 | + /** |
|
45 | + * @param string $filename |
|
46 | + * @return $this |
|
47 | + * @since 13.0.0 |
|
48 | + */ |
|
49 | + public function setFilename(string $filename): IAttachment { |
|
50 | + $this->swiftAttachment->setFilename($filename); |
|
51 | + return $this; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param string $contentType |
|
56 | - * @return $this |
|
57 | - * @since 13.0.0 |
|
58 | - */ |
|
59 | - public function setContentType(string $contentType): IAttachment { |
|
60 | - $this->swiftAttachment->setContentType($contentType); |
|
61 | - return $this; |
|
62 | - } |
|
54 | + /** |
|
55 | + * @param string $contentType |
|
56 | + * @return $this |
|
57 | + * @since 13.0.0 |
|
58 | + */ |
|
59 | + public function setContentType(string $contentType): IAttachment { |
|
60 | + $this->swiftAttachment->setContentType($contentType); |
|
61 | + return $this; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param string $body |
|
66 | - * @return $this |
|
67 | - * @since 13.0.0 |
|
68 | - */ |
|
69 | - public function setBody(string $body): IAttachment { |
|
70 | - $this->swiftAttachment->setBody($body); |
|
71 | - return $this; |
|
72 | - } |
|
64 | + /** |
|
65 | + * @param string $body |
|
66 | + * @return $this |
|
67 | + * @since 13.0.0 |
|
68 | + */ |
|
69 | + public function setBody(string $body): IAttachment { |
|
70 | + $this->swiftAttachment->setBody($body); |
|
71 | + return $this; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return \Swift_Mime_Attachment |
|
76 | - */ |
|
77 | - public function getSwiftAttachment(): \Swift_Mime_Attachment { |
|
78 | - return $this->swiftAttachment; |
|
79 | - } |
|
74 | + /** |
|
75 | + * @return \Swift_Mime_Attachment |
|
76 | + */ |
|
77 | + public function getSwiftAttachment(): \Swift_Mime_Attachment { |
|
78 | + return $this->swiftAttachment; |
|
79 | + } |
|
80 | 80 | |
81 | 81 | } |
@@ -46,60 +46,60 @@ |
||
46 | 46 | * @since 8.1.0 |
47 | 47 | */ |
48 | 48 | interface IMailer { |
49 | - /** |
|
50 | - * Creates a new message object that can be passed to send() |
|
51 | - * |
|
52 | - * @return IMessage |
|
53 | - * @since 8.1.0 |
|
54 | - */ |
|
55 | - public function createMessage(): IMessage; |
|
49 | + /** |
|
50 | + * Creates a new message object that can be passed to send() |
|
51 | + * |
|
52 | + * @return IMessage |
|
53 | + * @since 8.1.0 |
|
54 | + */ |
|
55 | + public function createMessage(): IMessage; |
|
56 | 56 | |
57 | - /** |
|
58 | - * @param string|null $data |
|
59 | - * @param string|null $filename |
|
60 | - * @param string|null $contentType |
|
61 | - * @return IAttachment |
|
62 | - * @since 13.0.0 |
|
63 | - */ |
|
64 | - public function createAttachment($data = null, $filename = null, $contentType = null): IAttachment; |
|
57 | + /** |
|
58 | + * @param string|null $data |
|
59 | + * @param string|null $filename |
|
60 | + * @param string|null $contentType |
|
61 | + * @return IAttachment |
|
62 | + * @since 13.0.0 |
|
63 | + */ |
|
64 | + public function createAttachment($data = null, $filename = null, $contentType = null): IAttachment; |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param string $path |
|
68 | - * @param string|null $contentType |
|
69 | - * @return IAttachment |
|
70 | - * @since 13.0.0 |
|
71 | - */ |
|
72 | - public function createAttachmentFromPath(string $path, $contentType = null): IAttachment; |
|
66 | + /** |
|
67 | + * @param string $path |
|
68 | + * @param string|null $contentType |
|
69 | + * @return IAttachment |
|
70 | + * @since 13.0.0 |
|
71 | + */ |
|
72 | + public function createAttachmentFromPath(string $path, $contentType = null): IAttachment; |
|
73 | 73 | |
74 | - /** |
|
75 | - * Creates a new email template object |
|
76 | - * |
|
77 | - * @param string $emailId |
|
78 | - * @param array $data |
|
79 | - * @return IEMailTemplate |
|
80 | - * @since 12.0.0 Parameters added in 12.0.3 |
|
81 | - */ |
|
82 | - public function createEMailTemplate(string $emailId, array $data = []): IEMailTemplate; |
|
74 | + /** |
|
75 | + * Creates a new email template object |
|
76 | + * |
|
77 | + * @param string $emailId |
|
78 | + * @param array $data |
|
79 | + * @return IEMailTemplate |
|
80 | + * @since 12.0.0 Parameters added in 12.0.3 |
|
81 | + */ |
|
82 | + public function createEMailTemplate(string $emailId, array $data = []): IEMailTemplate; |
|
83 | 83 | |
84 | - /** |
|
85 | - * Send the specified message. Also sets the from address to the value defined in config.php |
|
86 | - * if no-one has been passed. |
|
87 | - * |
|
88 | - * @param IMessage $message Message to send |
|
89 | - * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and |
|
90 | - * therefore should be considered |
|
91 | - * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address |
|
92 | - * has been supplied.) |
|
93 | - * @since 8.1.0 |
|
94 | - */ |
|
95 | - public function send(IMessage $message): array; |
|
84 | + /** |
|
85 | + * Send the specified message. Also sets the from address to the value defined in config.php |
|
86 | + * if no-one has been passed. |
|
87 | + * |
|
88 | + * @param IMessage $message Message to send |
|
89 | + * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and |
|
90 | + * therefore should be considered |
|
91 | + * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address |
|
92 | + * has been supplied.) |
|
93 | + * @since 8.1.0 |
|
94 | + */ |
|
95 | + public function send(IMessage $message): array; |
|
96 | 96 | |
97 | - /** |
|
98 | - * Checks if an e-mail address is valid |
|
99 | - * |
|
100 | - * @param string $email Email address to be validated |
|
101 | - * @return bool True if the mail address is valid, false otherwise |
|
102 | - * @since 8.1.0 |
|
103 | - */ |
|
104 | - public function validateMailAddress(string $email): bool; |
|
97 | + /** |
|
98 | + * Checks if an e-mail address is valid |
|
99 | + * |
|
100 | + * @param string $email Email address to be validated |
|
101 | + * @return bool True if the mail address is valid, false otherwise |
|
102 | + * @since 8.1.0 |
|
103 | + */ |
|
104 | + public function validateMailAddress(string $email): bool; |
|
105 | 105 | } |