@@ -72,1572 +72,1572 @@ |
||
72 | 72 | */ |
73 | 73 | class Manager implements IManager { |
74 | 74 | |
75 | - /** @var IProviderFactory */ |
|
76 | - private $factory; |
|
77 | - /** @var ILogger */ |
|
78 | - private $logger; |
|
79 | - /** @var IConfig */ |
|
80 | - private $config; |
|
81 | - /** @var ISecureRandom */ |
|
82 | - private $secureRandom; |
|
83 | - /** @var IHasher */ |
|
84 | - private $hasher; |
|
85 | - /** @var IMountManager */ |
|
86 | - private $mountManager; |
|
87 | - /** @var IGroupManager */ |
|
88 | - private $groupManager; |
|
89 | - /** @var IL10N */ |
|
90 | - private $l; |
|
91 | - /** @var IFactory */ |
|
92 | - private $l10nFactory; |
|
93 | - /** @var IUserManager */ |
|
94 | - private $userManager; |
|
95 | - /** @var IRootFolder */ |
|
96 | - private $rootFolder; |
|
97 | - /** @var CappedMemoryCache */ |
|
98 | - private $sharingDisabledForUsersCache; |
|
99 | - /** @var EventDispatcher */ |
|
100 | - private $eventDispatcher; |
|
101 | - /** @var LegacyHooks */ |
|
102 | - private $legacyHooks; |
|
103 | - /** @var IMailer */ |
|
104 | - private $mailer; |
|
105 | - /** @var IURLGenerator */ |
|
106 | - private $urlGenerator; |
|
107 | - /** @var \OC_Defaults */ |
|
108 | - private $defaults; |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * Manager constructor. |
|
113 | - * |
|
114 | - * @param ILogger $logger |
|
115 | - * @param IConfig $config |
|
116 | - * @param ISecureRandom $secureRandom |
|
117 | - * @param IHasher $hasher |
|
118 | - * @param IMountManager $mountManager |
|
119 | - * @param IGroupManager $groupManager |
|
120 | - * @param IL10N $l |
|
121 | - * @param IFactory $l10nFactory |
|
122 | - * @param IProviderFactory $factory |
|
123 | - * @param IUserManager $userManager |
|
124 | - * @param IRootFolder $rootFolder |
|
125 | - * @param EventDispatcher $eventDispatcher |
|
126 | - * @param IMailer $mailer |
|
127 | - * @param IURLGenerator $urlGenerator |
|
128 | - * @param \OC_Defaults $defaults |
|
129 | - */ |
|
130 | - public function __construct( |
|
131 | - ILogger $logger, |
|
132 | - IConfig $config, |
|
133 | - ISecureRandom $secureRandom, |
|
134 | - IHasher $hasher, |
|
135 | - IMountManager $mountManager, |
|
136 | - IGroupManager $groupManager, |
|
137 | - IL10N $l, |
|
138 | - IFactory $l10nFactory, |
|
139 | - IProviderFactory $factory, |
|
140 | - IUserManager $userManager, |
|
141 | - IRootFolder $rootFolder, |
|
142 | - EventDispatcher $eventDispatcher, |
|
143 | - IMailer $mailer, |
|
144 | - IURLGenerator $urlGenerator, |
|
145 | - \OC_Defaults $defaults |
|
146 | - ) { |
|
147 | - $this->logger = $logger; |
|
148 | - $this->config = $config; |
|
149 | - $this->secureRandom = $secureRandom; |
|
150 | - $this->hasher = $hasher; |
|
151 | - $this->mountManager = $mountManager; |
|
152 | - $this->groupManager = $groupManager; |
|
153 | - $this->l = $l; |
|
154 | - $this->l10nFactory = $l10nFactory; |
|
155 | - $this->factory = $factory; |
|
156 | - $this->userManager = $userManager; |
|
157 | - $this->rootFolder = $rootFolder; |
|
158 | - $this->eventDispatcher = $eventDispatcher; |
|
159 | - $this->sharingDisabledForUsersCache = new CappedMemoryCache(); |
|
160 | - $this->legacyHooks = new LegacyHooks($this->eventDispatcher); |
|
161 | - $this->mailer = $mailer; |
|
162 | - $this->urlGenerator = $urlGenerator; |
|
163 | - $this->defaults = $defaults; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Convert from a full share id to a tuple (providerId, shareId) |
|
168 | - * |
|
169 | - * @param string $id |
|
170 | - * @return string[] |
|
171 | - */ |
|
172 | - private function splitFullId($id) { |
|
173 | - return explode(':', $id, 2); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Verify if a password meets all requirements |
|
178 | - * |
|
179 | - * @param string $password |
|
180 | - * @throws \Exception |
|
181 | - */ |
|
182 | - protected function verifyPassword($password) { |
|
183 | - if ($password === null) { |
|
184 | - // No password is set, check if this is allowed. |
|
185 | - if ($this->shareApiLinkEnforcePassword()) { |
|
186 | - throw new \InvalidArgumentException('Passwords are enforced for link shares'); |
|
187 | - } |
|
188 | - |
|
189 | - return; |
|
190 | - } |
|
191 | - |
|
192 | - // Let others verify the password |
|
193 | - try { |
|
194 | - $event = new GenericEvent($password); |
|
195 | - $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
196 | - } catch (HintException $e) { |
|
197 | - throw new \Exception($e->getHint()); |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Check for generic requirements before creating a share |
|
203 | - * |
|
204 | - * @param \OCP\Share\IShare $share |
|
205 | - * @throws \InvalidArgumentException |
|
206 | - * @throws GenericShareException |
|
207 | - * |
|
208 | - * @suppress PhanUndeclaredClassMethod |
|
209 | - */ |
|
210 | - protected function generalCreateChecks(\OCP\Share\IShare $share) { |
|
211 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
212 | - // We expect a valid user as sharedWith for user shares |
|
213 | - if (!$this->userManager->userExists($share->getSharedWith())) { |
|
214 | - throw new \InvalidArgumentException('SharedWith is not a valid user'); |
|
215 | - } |
|
216 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
217 | - // We expect a valid group as sharedWith for group shares |
|
218 | - if (!$this->groupManager->groupExists($share->getSharedWith())) { |
|
219 | - throw new \InvalidArgumentException('SharedWith is not a valid group'); |
|
220 | - } |
|
221 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
222 | - if ($share->getSharedWith() !== null) { |
|
223 | - throw new \InvalidArgumentException('SharedWith should be empty'); |
|
224 | - } |
|
225 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
226 | - if ($share->getSharedWith() === null) { |
|
227 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
228 | - } |
|
229 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) { |
|
230 | - if ($share->getSharedWith() === null) { |
|
231 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
232 | - } |
|
233 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
234 | - if ($share->getSharedWith() === null) { |
|
235 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
236 | - } |
|
237 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
238 | - $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($share->getSharedWith()); |
|
239 | - if ($circle === null) { |
|
240 | - throw new \InvalidArgumentException('SharedWith is not a valid circle'); |
|
241 | - } |
|
242 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_ROOM) { |
|
243 | - } else { |
|
244 | - // We can't handle other types yet |
|
245 | - throw new \InvalidArgumentException('unknown share type'); |
|
246 | - } |
|
247 | - |
|
248 | - // Verify the initiator of the share is set |
|
249 | - if ($share->getSharedBy() === null) { |
|
250 | - throw new \InvalidArgumentException('SharedBy should be set'); |
|
251 | - } |
|
252 | - |
|
253 | - // Cannot share with yourself |
|
254 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
255 | - $share->getSharedWith() === $share->getSharedBy()) { |
|
256 | - throw new \InvalidArgumentException('Can’t share with yourself'); |
|
257 | - } |
|
258 | - |
|
259 | - // The path should be set |
|
260 | - if ($share->getNode() === null) { |
|
261 | - throw new \InvalidArgumentException('Path should be set'); |
|
262 | - } |
|
263 | - |
|
264 | - // And it should be a file or a folder |
|
265 | - if (!($share->getNode() instanceof \OCP\Files\File) && |
|
266 | - !($share->getNode() instanceof \OCP\Files\Folder)) { |
|
267 | - throw new \InvalidArgumentException('Path should be either a file or a folder'); |
|
268 | - } |
|
269 | - |
|
270 | - // And you can't share your rootfolder |
|
271 | - if ($this->userManager->userExists($share->getSharedBy())) { |
|
272 | - $sharedPath = $this->rootFolder->getUserFolder($share->getSharedBy())->getPath(); |
|
273 | - } else { |
|
274 | - $sharedPath = $this->rootFolder->getUserFolder($share->getShareOwner())->getPath(); |
|
275 | - } |
|
276 | - if ($sharedPath === $share->getNode()->getPath()) { |
|
277 | - throw new \InvalidArgumentException('You can’t share your root folder'); |
|
278 | - } |
|
279 | - |
|
280 | - // Check if we actually have share permissions |
|
281 | - if (!$share->getNode()->isShareable()) { |
|
282 | - $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]); |
|
283 | - throw new GenericShareException($message_t, $message_t, 404); |
|
284 | - } |
|
285 | - |
|
286 | - // Permissions should be set |
|
287 | - if ($share->getPermissions() === null) { |
|
288 | - throw new \InvalidArgumentException('A share requires permissions'); |
|
289 | - } |
|
290 | - |
|
291 | - /* |
|
75 | + /** @var IProviderFactory */ |
|
76 | + private $factory; |
|
77 | + /** @var ILogger */ |
|
78 | + private $logger; |
|
79 | + /** @var IConfig */ |
|
80 | + private $config; |
|
81 | + /** @var ISecureRandom */ |
|
82 | + private $secureRandom; |
|
83 | + /** @var IHasher */ |
|
84 | + private $hasher; |
|
85 | + /** @var IMountManager */ |
|
86 | + private $mountManager; |
|
87 | + /** @var IGroupManager */ |
|
88 | + private $groupManager; |
|
89 | + /** @var IL10N */ |
|
90 | + private $l; |
|
91 | + /** @var IFactory */ |
|
92 | + private $l10nFactory; |
|
93 | + /** @var IUserManager */ |
|
94 | + private $userManager; |
|
95 | + /** @var IRootFolder */ |
|
96 | + private $rootFolder; |
|
97 | + /** @var CappedMemoryCache */ |
|
98 | + private $sharingDisabledForUsersCache; |
|
99 | + /** @var EventDispatcher */ |
|
100 | + private $eventDispatcher; |
|
101 | + /** @var LegacyHooks */ |
|
102 | + private $legacyHooks; |
|
103 | + /** @var IMailer */ |
|
104 | + private $mailer; |
|
105 | + /** @var IURLGenerator */ |
|
106 | + private $urlGenerator; |
|
107 | + /** @var \OC_Defaults */ |
|
108 | + private $defaults; |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * Manager constructor. |
|
113 | + * |
|
114 | + * @param ILogger $logger |
|
115 | + * @param IConfig $config |
|
116 | + * @param ISecureRandom $secureRandom |
|
117 | + * @param IHasher $hasher |
|
118 | + * @param IMountManager $mountManager |
|
119 | + * @param IGroupManager $groupManager |
|
120 | + * @param IL10N $l |
|
121 | + * @param IFactory $l10nFactory |
|
122 | + * @param IProviderFactory $factory |
|
123 | + * @param IUserManager $userManager |
|
124 | + * @param IRootFolder $rootFolder |
|
125 | + * @param EventDispatcher $eventDispatcher |
|
126 | + * @param IMailer $mailer |
|
127 | + * @param IURLGenerator $urlGenerator |
|
128 | + * @param \OC_Defaults $defaults |
|
129 | + */ |
|
130 | + public function __construct( |
|
131 | + ILogger $logger, |
|
132 | + IConfig $config, |
|
133 | + ISecureRandom $secureRandom, |
|
134 | + IHasher $hasher, |
|
135 | + IMountManager $mountManager, |
|
136 | + IGroupManager $groupManager, |
|
137 | + IL10N $l, |
|
138 | + IFactory $l10nFactory, |
|
139 | + IProviderFactory $factory, |
|
140 | + IUserManager $userManager, |
|
141 | + IRootFolder $rootFolder, |
|
142 | + EventDispatcher $eventDispatcher, |
|
143 | + IMailer $mailer, |
|
144 | + IURLGenerator $urlGenerator, |
|
145 | + \OC_Defaults $defaults |
|
146 | + ) { |
|
147 | + $this->logger = $logger; |
|
148 | + $this->config = $config; |
|
149 | + $this->secureRandom = $secureRandom; |
|
150 | + $this->hasher = $hasher; |
|
151 | + $this->mountManager = $mountManager; |
|
152 | + $this->groupManager = $groupManager; |
|
153 | + $this->l = $l; |
|
154 | + $this->l10nFactory = $l10nFactory; |
|
155 | + $this->factory = $factory; |
|
156 | + $this->userManager = $userManager; |
|
157 | + $this->rootFolder = $rootFolder; |
|
158 | + $this->eventDispatcher = $eventDispatcher; |
|
159 | + $this->sharingDisabledForUsersCache = new CappedMemoryCache(); |
|
160 | + $this->legacyHooks = new LegacyHooks($this->eventDispatcher); |
|
161 | + $this->mailer = $mailer; |
|
162 | + $this->urlGenerator = $urlGenerator; |
|
163 | + $this->defaults = $defaults; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Convert from a full share id to a tuple (providerId, shareId) |
|
168 | + * |
|
169 | + * @param string $id |
|
170 | + * @return string[] |
|
171 | + */ |
|
172 | + private function splitFullId($id) { |
|
173 | + return explode(':', $id, 2); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Verify if a password meets all requirements |
|
178 | + * |
|
179 | + * @param string $password |
|
180 | + * @throws \Exception |
|
181 | + */ |
|
182 | + protected function verifyPassword($password) { |
|
183 | + if ($password === null) { |
|
184 | + // No password is set, check if this is allowed. |
|
185 | + if ($this->shareApiLinkEnforcePassword()) { |
|
186 | + throw new \InvalidArgumentException('Passwords are enforced for link shares'); |
|
187 | + } |
|
188 | + |
|
189 | + return; |
|
190 | + } |
|
191 | + |
|
192 | + // Let others verify the password |
|
193 | + try { |
|
194 | + $event = new GenericEvent($password); |
|
195 | + $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
196 | + } catch (HintException $e) { |
|
197 | + throw new \Exception($e->getHint()); |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Check for generic requirements before creating a share |
|
203 | + * |
|
204 | + * @param \OCP\Share\IShare $share |
|
205 | + * @throws \InvalidArgumentException |
|
206 | + * @throws GenericShareException |
|
207 | + * |
|
208 | + * @suppress PhanUndeclaredClassMethod |
|
209 | + */ |
|
210 | + protected function generalCreateChecks(\OCP\Share\IShare $share) { |
|
211 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
212 | + // We expect a valid user as sharedWith for user shares |
|
213 | + if (!$this->userManager->userExists($share->getSharedWith())) { |
|
214 | + throw new \InvalidArgumentException('SharedWith is not a valid user'); |
|
215 | + } |
|
216 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
217 | + // We expect a valid group as sharedWith for group shares |
|
218 | + if (!$this->groupManager->groupExists($share->getSharedWith())) { |
|
219 | + throw new \InvalidArgumentException('SharedWith is not a valid group'); |
|
220 | + } |
|
221 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
222 | + if ($share->getSharedWith() !== null) { |
|
223 | + throw new \InvalidArgumentException('SharedWith should be empty'); |
|
224 | + } |
|
225 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
226 | + if ($share->getSharedWith() === null) { |
|
227 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
228 | + } |
|
229 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE_GROUP) { |
|
230 | + if ($share->getSharedWith() === null) { |
|
231 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
232 | + } |
|
233 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
234 | + if ($share->getSharedWith() === null) { |
|
235 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
236 | + } |
|
237 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
238 | + $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($share->getSharedWith()); |
|
239 | + if ($circle === null) { |
|
240 | + throw new \InvalidArgumentException('SharedWith is not a valid circle'); |
|
241 | + } |
|
242 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_ROOM) { |
|
243 | + } else { |
|
244 | + // We can't handle other types yet |
|
245 | + throw new \InvalidArgumentException('unknown share type'); |
|
246 | + } |
|
247 | + |
|
248 | + // Verify the initiator of the share is set |
|
249 | + if ($share->getSharedBy() === null) { |
|
250 | + throw new \InvalidArgumentException('SharedBy should be set'); |
|
251 | + } |
|
252 | + |
|
253 | + // Cannot share with yourself |
|
254 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
255 | + $share->getSharedWith() === $share->getSharedBy()) { |
|
256 | + throw new \InvalidArgumentException('Can’t share with yourself'); |
|
257 | + } |
|
258 | + |
|
259 | + // The path should be set |
|
260 | + if ($share->getNode() === null) { |
|
261 | + throw new \InvalidArgumentException('Path should be set'); |
|
262 | + } |
|
263 | + |
|
264 | + // And it should be a file or a folder |
|
265 | + if (!($share->getNode() instanceof \OCP\Files\File) && |
|
266 | + !($share->getNode() instanceof \OCP\Files\Folder)) { |
|
267 | + throw new \InvalidArgumentException('Path should be either a file or a folder'); |
|
268 | + } |
|
269 | + |
|
270 | + // And you can't share your rootfolder |
|
271 | + if ($this->userManager->userExists($share->getSharedBy())) { |
|
272 | + $sharedPath = $this->rootFolder->getUserFolder($share->getSharedBy())->getPath(); |
|
273 | + } else { |
|
274 | + $sharedPath = $this->rootFolder->getUserFolder($share->getShareOwner())->getPath(); |
|
275 | + } |
|
276 | + if ($sharedPath === $share->getNode()->getPath()) { |
|
277 | + throw new \InvalidArgumentException('You can’t share your root folder'); |
|
278 | + } |
|
279 | + |
|
280 | + // Check if we actually have share permissions |
|
281 | + if (!$share->getNode()->isShareable()) { |
|
282 | + $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]); |
|
283 | + throw new GenericShareException($message_t, $message_t, 404); |
|
284 | + } |
|
285 | + |
|
286 | + // Permissions should be set |
|
287 | + if ($share->getPermissions() === null) { |
|
288 | + throw new \InvalidArgumentException('A share requires permissions'); |
|
289 | + } |
|
290 | + |
|
291 | + /* |
|
292 | 292 | * Quick fix for #23536 |
293 | 293 | * Non moveable mount points do not have update and delete permissions |
294 | 294 | * while we 'most likely' do have that on the storage. |
295 | 295 | */ |
296 | - $permissions = $share->getNode()->getPermissions(); |
|
297 | - $mount = $share->getNode()->getMountPoint(); |
|
298 | - if (!($mount instanceof MoveableMount)) { |
|
299 | - $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
300 | - } |
|
301 | - |
|
302 | - // Check that we do not share with more permissions than we have |
|
303 | - if ($share->getPermissions() & ~$permissions) { |
|
304 | - $message_t = $this->l->t('Can’t increase permissions of %s', [$share->getNode()->getPath()]); |
|
305 | - throw new GenericShareException($message_t, $message_t, 404); |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - // Check that read permissions are always set |
|
310 | - // Link shares are allowed to have no read permissions to allow upload to hidden folders |
|
311 | - $noReadPermissionRequired = $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK |
|
312 | - || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL; |
|
313 | - if (!$noReadPermissionRequired && |
|
314 | - ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
|
315 | - throw new \InvalidArgumentException('Shares need at least read permissions'); |
|
316 | - } |
|
317 | - |
|
318 | - if ($share->getNode() instanceof \OCP\Files\File) { |
|
319 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
320 | - $message_t = $this->l->t('Files can’t be shared with delete permissions'); |
|
321 | - throw new GenericShareException($message_t); |
|
322 | - } |
|
323 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
324 | - $message_t = $this->l->t('Files can’t be shared with create permissions'); |
|
325 | - throw new GenericShareException($message_t); |
|
326 | - } |
|
327 | - } |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * Validate if the expiration date fits the system settings |
|
332 | - * |
|
333 | - * @param \OCP\Share\IShare $share The share to validate the expiration date of |
|
334 | - * @return \OCP\Share\IShare The modified share object |
|
335 | - * @throws GenericShareException |
|
336 | - * @throws \InvalidArgumentException |
|
337 | - * @throws \Exception |
|
338 | - */ |
|
339 | - protected function validateExpirationDate(\OCP\Share\IShare $share) { |
|
340 | - |
|
341 | - $expirationDate = $share->getExpirationDate(); |
|
342 | - |
|
343 | - if ($expirationDate !== null) { |
|
344 | - //Make sure the expiration date is a date |
|
345 | - $expirationDate->setTime(0, 0, 0); |
|
346 | - |
|
347 | - $date = new \DateTime(); |
|
348 | - $date->setTime(0, 0, 0); |
|
349 | - if ($date >= $expirationDate) { |
|
350 | - $message = $this->l->t('Expiration date is in the past'); |
|
351 | - throw new GenericShareException($message, $message, 404); |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - // If expiredate is empty set a default one if there is a default |
|
356 | - $fullId = null; |
|
357 | - try { |
|
358 | - $fullId = $share->getFullId(); |
|
359 | - } catch (\UnexpectedValueException $e) { |
|
360 | - // This is a new share |
|
361 | - } |
|
362 | - |
|
363 | - if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
|
364 | - $expirationDate = new \DateTime(); |
|
365 | - $expirationDate->setTime(0,0,0); |
|
366 | - $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
367 | - } |
|
368 | - |
|
369 | - // If we enforce the expiration date check that is does not exceed |
|
370 | - if ($this->shareApiLinkDefaultExpireDateEnforced()) { |
|
371 | - if ($expirationDate === null) { |
|
372 | - throw new \InvalidArgumentException('Expiration date is enforced'); |
|
373 | - } |
|
374 | - |
|
375 | - $date = new \DateTime(); |
|
376 | - $date->setTime(0, 0, 0); |
|
377 | - $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
378 | - if ($date < $expirationDate) { |
|
379 | - $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
|
380 | - throw new GenericShareException($message, $message, 404); |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - $accepted = true; |
|
385 | - $message = ''; |
|
386 | - \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
387 | - 'expirationDate' => &$expirationDate, |
|
388 | - 'accepted' => &$accepted, |
|
389 | - 'message' => &$message, |
|
390 | - 'passwordSet' => $share->getPassword() !== null, |
|
391 | - ]); |
|
392 | - |
|
393 | - if (!$accepted) { |
|
394 | - throw new \Exception($message); |
|
395 | - } |
|
396 | - |
|
397 | - $share->setExpirationDate($expirationDate); |
|
398 | - |
|
399 | - return $share; |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * Check for pre share requirements for user shares |
|
404 | - * |
|
405 | - * @param \OCP\Share\IShare $share |
|
406 | - * @throws \Exception |
|
407 | - */ |
|
408 | - protected function userCreateChecks(\OCP\Share\IShare $share) { |
|
409 | - // Check if we can share with group members only |
|
410 | - if ($this->shareWithGroupMembersOnly()) { |
|
411 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
412 | - $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
413 | - // Verify we can share with this user |
|
414 | - $groups = array_intersect( |
|
415 | - $this->groupManager->getUserGroupIds($sharedBy), |
|
416 | - $this->groupManager->getUserGroupIds($sharedWith) |
|
417 | - ); |
|
418 | - if (empty($groups)) { |
|
419 | - throw new \Exception('Sharing is only allowed with group members'); |
|
420 | - } |
|
421 | - } |
|
422 | - |
|
423 | - /* |
|
296 | + $permissions = $share->getNode()->getPermissions(); |
|
297 | + $mount = $share->getNode()->getMountPoint(); |
|
298 | + if (!($mount instanceof MoveableMount)) { |
|
299 | + $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
300 | + } |
|
301 | + |
|
302 | + // Check that we do not share with more permissions than we have |
|
303 | + if ($share->getPermissions() & ~$permissions) { |
|
304 | + $message_t = $this->l->t('Can’t increase permissions of %s', [$share->getNode()->getPath()]); |
|
305 | + throw new GenericShareException($message_t, $message_t, 404); |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + // Check that read permissions are always set |
|
310 | + // Link shares are allowed to have no read permissions to allow upload to hidden folders |
|
311 | + $noReadPermissionRequired = $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK |
|
312 | + || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL; |
|
313 | + if (!$noReadPermissionRequired && |
|
314 | + ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
|
315 | + throw new \InvalidArgumentException('Shares need at least read permissions'); |
|
316 | + } |
|
317 | + |
|
318 | + if ($share->getNode() instanceof \OCP\Files\File) { |
|
319 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
320 | + $message_t = $this->l->t('Files can’t be shared with delete permissions'); |
|
321 | + throw new GenericShareException($message_t); |
|
322 | + } |
|
323 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
324 | + $message_t = $this->l->t('Files can’t be shared with create permissions'); |
|
325 | + throw new GenericShareException($message_t); |
|
326 | + } |
|
327 | + } |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * Validate if the expiration date fits the system settings |
|
332 | + * |
|
333 | + * @param \OCP\Share\IShare $share The share to validate the expiration date of |
|
334 | + * @return \OCP\Share\IShare The modified share object |
|
335 | + * @throws GenericShareException |
|
336 | + * @throws \InvalidArgumentException |
|
337 | + * @throws \Exception |
|
338 | + */ |
|
339 | + protected function validateExpirationDate(\OCP\Share\IShare $share) { |
|
340 | + |
|
341 | + $expirationDate = $share->getExpirationDate(); |
|
342 | + |
|
343 | + if ($expirationDate !== null) { |
|
344 | + //Make sure the expiration date is a date |
|
345 | + $expirationDate->setTime(0, 0, 0); |
|
346 | + |
|
347 | + $date = new \DateTime(); |
|
348 | + $date->setTime(0, 0, 0); |
|
349 | + if ($date >= $expirationDate) { |
|
350 | + $message = $this->l->t('Expiration date is in the past'); |
|
351 | + throw new GenericShareException($message, $message, 404); |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + // If expiredate is empty set a default one if there is a default |
|
356 | + $fullId = null; |
|
357 | + try { |
|
358 | + $fullId = $share->getFullId(); |
|
359 | + } catch (\UnexpectedValueException $e) { |
|
360 | + // This is a new share |
|
361 | + } |
|
362 | + |
|
363 | + if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
|
364 | + $expirationDate = new \DateTime(); |
|
365 | + $expirationDate->setTime(0,0,0); |
|
366 | + $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
367 | + } |
|
368 | + |
|
369 | + // If we enforce the expiration date check that is does not exceed |
|
370 | + if ($this->shareApiLinkDefaultExpireDateEnforced()) { |
|
371 | + if ($expirationDate === null) { |
|
372 | + throw new \InvalidArgumentException('Expiration date is enforced'); |
|
373 | + } |
|
374 | + |
|
375 | + $date = new \DateTime(); |
|
376 | + $date->setTime(0, 0, 0); |
|
377 | + $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
378 | + if ($date < $expirationDate) { |
|
379 | + $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
|
380 | + throw new GenericShareException($message, $message, 404); |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + $accepted = true; |
|
385 | + $message = ''; |
|
386 | + \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
387 | + 'expirationDate' => &$expirationDate, |
|
388 | + 'accepted' => &$accepted, |
|
389 | + 'message' => &$message, |
|
390 | + 'passwordSet' => $share->getPassword() !== null, |
|
391 | + ]); |
|
392 | + |
|
393 | + if (!$accepted) { |
|
394 | + throw new \Exception($message); |
|
395 | + } |
|
396 | + |
|
397 | + $share->setExpirationDate($expirationDate); |
|
398 | + |
|
399 | + return $share; |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * Check for pre share requirements for user shares |
|
404 | + * |
|
405 | + * @param \OCP\Share\IShare $share |
|
406 | + * @throws \Exception |
|
407 | + */ |
|
408 | + protected function userCreateChecks(\OCP\Share\IShare $share) { |
|
409 | + // Check if we can share with group members only |
|
410 | + if ($this->shareWithGroupMembersOnly()) { |
|
411 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
412 | + $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
413 | + // Verify we can share with this user |
|
414 | + $groups = array_intersect( |
|
415 | + $this->groupManager->getUserGroupIds($sharedBy), |
|
416 | + $this->groupManager->getUserGroupIds($sharedWith) |
|
417 | + ); |
|
418 | + if (empty($groups)) { |
|
419 | + throw new \Exception('Sharing is only allowed with group members'); |
|
420 | + } |
|
421 | + } |
|
422 | + |
|
423 | + /* |
|
424 | 424 | * TODO: Could be costly, fix |
425 | 425 | * |
426 | 426 | * Also this is not what we want in the future.. then we want to squash identical shares. |
427 | 427 | */ |
428 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); |
|
429 | - $existingShares = $provider->getSharesByPath($share->getNode()); |
|
430 | - foreach($existingShares as $existingShare) { |
|
431 | - // Ignore if it is the same share |
|
432 | - try { |
|
433 | - if ($existingShare->getFullId() === $share->getFullId()) { |
|
434 | - continue; |
|
435 | - } |
|
436 | - } catch (\UnexpectedValueException $e) { |
|
437 | - //Shares are not identical |
|
438 | - } |
|
439 | - |
|
440 | - // Identical share already existst |
|
441 | - if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
442 | - throw new \Exception('Path is already shared with this user'); |
|
443 | - } |
|
444 | - |
|
445 | - // The share is already shared with this user via a group share |
|
446 | - if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
447 | - $group = $this->groupManager->get($existingShare->getSharedWith()); |
|
448 | - if (!is_null($group)) { |
|
449 | - $user = $this->userManager->get($share->getSharedWith()); |
|
450 | - |
|
451 | - if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
|
452 | - throw new \Exception('Path is already shared with this user'); |
|
453 | - } |
|
454 | - } |
|
455 | - } |
|
456 | - } |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Check for pre share requirements for group shares |
|
461 | - * |
|
462 | - * @param \OCP\Share\IShare $share |
|
463 | - * @throws \Exception |
|
464 | - */ |
|
465 | - protected function groupCreateChecks(\OCP\Share\IShare $share) { |
|
466 | - // Verify group shares are allowed |
|
467 | - if (!$this->allowGroupSharing()) { |
|
468 | - throw new \Exception('Group sharing is now allowed'); |
|
469 | - } |
|
470 | - |
|
471 | - // Verify if the user can share with this group |
|
472 | - if ($this->shareWithGroupMembersOnly()) { |
|
473 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
474 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
475 | - if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) { |
|
476 | - throw new \Exception('Sharing is only allowed within your own groups'); |
|
477 | - } |
|
478 | - } |
|
479 | - |
|
480 | - /* |
|
428 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); |
|
429 | + $existingShares = $provider->getSharesByPath($share->getNode()); |
|
430 | + foreach($existingShares as $existingShare) { |
|
431 | + // Ignore if it is the same share |
|
432 | + try { |
|
433 | + if ($existingShare->getFullId() === $share->getFullId()) { |
|
434 | + continue; |
|
435 | + } |
|
436 | + } catch (\UnexpectedValueException $e) { |
|
437 | + //Shares are not identical |
|
438 | + } |
|
439 | + |
|
440 | + // Identical share already existst |
|
441 | + if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
442 | + throw new \Exception('Path is already shared with this user'); |
|
443 | + } |
|
444 | + |
|
445 | + // The share is already shared with this user via a group share |
|
446 | + if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
447 | + $group = $this->groupManager->get($existingShare->getSharedWith()); |
|
448 | + if (!is_null($group)) { |
|
449 | + $user = $this->userManager->get($share->getSharedWith()); |
|
450 | + |
|
451 | + if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
|
452 | + throw new \Exception('Path is already shared with this user'); |
|
453 | + } |
|
454 | + } |
|
455 | + } |
|
456 | + } |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * Check for pre share requirements for group shares |
|
461 | + * |
|
462 | + * @param \OCP\Share\IShare $share |
|
463 | + * @throws \Exception |
|
464 | + */ |
|
465 | + protected function groupCreateChecks(\OCP\Share\IShare $share) { |
|
466 | + // Verify group shares are allowed |
|
467 | + if (!$this->allowGroupSharing()) { |
|
468 | + throw new \Exception('Group sharing is now allowed'); |
|
469 | + } |
|
470 | + |
|
471 | + // Verify if the user can share with this group |
|
472 | + if ($this->shareWithGroupMembersOnly()) { |
|
473 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
474 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
475 | + if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) { |
|
476 | + throw new \Exception('Sharing is only allowed within your own groups'); |
|
477 | + } |
|
478 | + } |
|
479 | + |
|
480 | + /* |
|
481 | 481 | * TODO: Could be costly, fix |
482 | 482 | * |
483 | 483 | * Also this is not what we want in the future.. then we want to squash identical shares. |
484 | 484 | */ |
485 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
486 | - $existingShares = $provider->getSharesByPath($share->getNode()); |
|
487 | - foreach($existingShares as $existingShare) { |
|
488 | - try { |
|
489 | - if ($existingShare->getFullId() === $share->getFullId()) { |
|
490 | - continue; |
|
491 | - } |
|
492 | - } catch (\UnexpectedValueException $e) { |
|
493 | - //It is a new share so just continue |
|
494 | - } |
|
495 | - |
|
496 | - if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
497 | - throw new \Exception('Path is already shared with this group'); |
|
498 | - } |
|
499 | - } |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * Check for pre share requirements for link shares |
|
504 | - * |
|
505 | - * @param \OCP\Share\IShare $share |
|
506 | - * @throws \Exception |
|
507 | - */ |
|
508 | - protected function linkCreateChecks(\OCP\Share\IShare $share) { |
|
509 | - // Are link shares allowed? |
|
510 | - if (!$this->shareApiAllowLinks()) { |
|
511 | - throw new \Exception('Link sharing is not allowed'); |
|
512 | - } |
|
513 | - |
|
514 | - // Link shares by definition can't have share permissions |
|
515 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_SHARE) { |
|
516 | - throw new \InvalidArgumentException('Link shares can’t have reshare permissions'); |
|
517 | - } |
|
518 | - |
|
519 | - // Check if public upload is allowed |
|
520 | - if (!$this->shareApiLinkAllowPublicUpload() && |
|
521 | - ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
|
522 | - throw new \InvalidArgumentException('Public upload is not allowed'); |
|
523 | - } |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * To make sure we don't get invisible link shares we set the parent |
|
528 | - * of a link if it is a reshare. This is a quick word around |
|
529 | - * until we can properly display multiple link shares in the UI |
|
530 | - * |
|
531 | - * See: https://github.com/owncloud/core/issues/22295 |
|
532 | - * |
|
533 | - * FIXME: Remove once multiple link shares can be properly displayed |
|
534 | - * |
|
535 | - * @param \OCP\Share\IShare $share |
|
536 | - */ |
|
537 | - protected function setLinkParent(\OCP\Share\IShare $share) { |
|
538 | - |
|
539 | - // No sense in checking if the method is not there. |
|
540 | - if (method_exists($share, 'setParent')) { |
|
541 | - $storage = $share->getNode()->getStorage(); |
|
542 | - if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
543 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
544 | - $share->setParent($storage->getShareId()); |
|
545 | - } |
|
546 | - } |
|
547 | - } |
|
548 | - |
|
549 | - /** |
|
550 | - * @param File|Folder $path |
|
551 | - */ |
|
552 | - protected function pathCreateChecks($path) { |
|
553 | - // Make sure that we do not share a path that contains a shared mountpoint |
|
554 | - if ($path instanceof \OCP\Files\Folder) { |
|
555 | - $mounts = $this->mountManager->findIn($path->getPath()); |
|
556 | - foreach($mounts as $mount) { |
|
557 | - if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
558 | - throw new \InvalidArgumentException('Path contains files shared with you'); |
|
559 | - } |
|
560 | - } |
|
561 | - } |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * Check if the user that is sharing can actually share |
|
566 | - * |
|
567 | - * @param \OCP\Share\IShare $share |
|
568 | - * @throws \Exception |
|
569 | - */ |
|
570 | - protected function canShare(\OCP\Share\IShare $share) { |
|
571 | - if (!$this->shareApiEnabled()) { |
|
572 | - throw new \Exception('Sharing is disabled'); |
|
573 | - } |
|
574 | - |
|
575 | - if ($this->sharingDisabledForUser($share->getSharedBy())) { |
|
576 | - throw new \Exception('Sharing is disabled for you'); |
|
577 | - } |
|
578 | - } |
|
579 | - |
|
580 | - /** |
|
581 | - * Share a path |
|
582 | - * |
|
583 | - * @param \OCP\Share\IShare $share |
|
584 | - * @return Share The share object |
|
585 | - * @throws \Exception |
|
586 | - * |
|
587 | - * TODO: handle link share permissions or check them |
|
588 | - */ |
|
589 | - public function createShare(\OCP\Share\IShare $share) { |
|
590 | - $this->canShare($share); |
|
591 | - |
|
592 | - $this->generalCreateChecks($share); |
|
593 | - |
|
594 | - // Verify if there are any issues with the path |
|
595 | - $this->pathCreateChecks($share->getNode()); |
|
596 | - |
|
597 | - /* |
|
485 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
486 | + $existingShares = $provider->getSharesByPath($share->getNode()); |
|
487 | + foreach($existingShares as $existingShare) { |
|
488 | + try { |
|
489 | + if ($existingShare->getFullId() === $share->getFullId()) { |
|
490 | + continue; |
|
491 | + } |
|
492 | + } catch (\UnexpectedValueException $e) { |
|
493 | + //It is a new share so just continue |
|
494 | + } |
|
495 | + |
|
496 | + if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
497 | + throw new \Exception('Path is already shared with this group'); |
|
498 | + } |
|
499 | + } |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * Check for pre share requirements for link shares |
|
504 | + * |
|
505 | + * @param \OCP\Share\IShare $share |
|
506 | + * @throws \Exception |
|
507 | + */ |
|
508 | + protected function linkCreateChecks(\OCP\Share\IShare $share) { |
|
509 | + // Are link shares allowed? |
|
510 | + if (!$this->shareApiAllowLinks()) { |
|
511 | + throw new \Exception('Link sharing is not allowed'); |
|
512 | + } |
|
513 | + |
|
514 | + // Link shares by definition can't have share permissions |
|
515 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_SHARE) { |
|
516 | + throw new \InvalidArgumentException('Link shares can’t have reshare permissions'); |
|
517 | + } |
|
518 | + |
|
519 | + // Check if public upload is allowed |
|
520 | + if (!$this->shareApiLinkAllowPublicUpload() && |
|
521 | + ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
|
522 | + throw new \InvalidArgumentException('Public upload is not allowed'); |
|
523 | + } |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * To make sure we don't get invisible link shares we set the parent |
|
528 | + * of a link if it is a reshare. This is a quick word around |
|
529 | + * until we can properly display multiple link shares in the UI |
|
530 | + * |
|
531 | + * See: https://github.com/owncloud/core/issues/22295 |
|
532 | + * |
|
533 | + * FIXME: Remove once multiple link shares can be properly displayed |
|
534 | + * |
|
535 | + * @param \OCP\Share\IShare $share |
|
536 | + */ |
|
537 | + protected function setLinkParent(\OCP\Share\IShare $share) { |
|
538 | + |
|
539 | + // No sense in checking if the method is not there. |
|
540 | + if (method_exists($share, 'setParent')) { |
|
541 | + $storage = $share->getNode()->getStorage(); |
|
542 | + if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
543 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
544 | + $share->setParent($storage->getShareId()); |
|
545 | + } |
|
546 | + } |
|
547 | + } |
|
548 | + |
|
549 | + /** |
|
550 | + * @param File|Folder $path |
|
551 | + */ |
|
552 | + protected function pathCreateChecks($path) { |
|
553 | + // Make sure that we do not share a path that contains a shared mountpoint |
|
554 | + if ($path instanceof \OCP\Files\Folder) { |
|
555 | + $mounts = $this->mountManager->findIn($path->getPath()); |
|
556 | + foreach($mounts as $mount) { |
|
557 | + if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
558 | + throw new \InvalidArgumentException('Path contains files shared with you'); |
|
559 | + } |
|
560 | + } |
|
561 | + } |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * Check if the user that is sharing can actually share |
|
566 | + * |
|
567 | + * @param \OCP\Share\IShare $share |
|
568 | + * @throws \Exception |
|
569 | + */ |
|
570 | + protected function canShare(\OCP\Share\IShare $share) { |
|
571 | + if (!$this->shareApiEnabled()) { |
|
572 | + throw new \Exception('Sharing is disabled'); |
|
573 | + } |
|
574 | + |
|
575 | + if ($this->sharingDisabledForUser($share->getSharedBy())) { |
|
576 | + throw new \Exception('Sharing is disabled for you'); |
|
577 | + } |
|
578 | + } |
|
579 | + |
|
580 | + /** |
|
581 | + * Share a path |
|
582 | + * |
|
583 | + * @param \OCP\Share\IShare $share |
|
584 | + * @return Share The share object |
|
585 | + * @throws \Exception |
|
586 | + * |
|
587 | + * TODO: handle link share permissions or check them |
|
588 | + */ |
|
589 | + public function createShare(\OCP\Share\IShare $share) { |
|
590 | + $this->canShare($share); |
|
591 | + |
|
592 | + $this->generalCreateChecks($share); |
|
593 | + |
|
594 | + // Verify if there are any issues with the path |
|
595 | + $this->pathCreateChecks($share->getNode()); |
|
596 | + |
|
597 | + /* |
|
598 | 598 | * On creation of a share the owner is always the owner of the path |
599 | 599 | * Except for mounted federated shares. |
600 | 600 | */ |
601 | - $storage = $share->getNode()->getStorage(); |
|
602 | - if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
603 | - $parent = $share->getNode()->getParent(); |
|
604 | - while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
605 | - $parent = $parent->getParent(); |
|
606 | - } |
|
607 | - $share->setShareOwner($parent->getOwner()->getUID()); |
|
608 | - } else { |
|
609 | - $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
|
610 | - } |
|
611 | - |
|
612 | - //Verify share type |
|
613 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
614 | - $this->userCreateChecks($share); |
|
615 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
616 | - $this->groupCreateChecks($share); |
|
617 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
618 | - $this->linkCreateChecks($share); |
|
619 | - $this->setLinkParent($share); |
|
620 | - |
|
621 | - /* |
|
601 | + $storage = $share->getNode()->getStorage(); |
|
602 | + if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
603 | + $parent = $share->getNode()->getParent(); |
|
604 | + while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
605 | + $parent = $parent->getParent(); |
|
606 | + } |
|
607 | + $share->setShareOwner($parent->getOwner()->getUID()); |
|
608 | + } else { |
|
609 | + $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
|
610 | + } |
|
611 | + |
|
612 | + //Verify share type |
|
613 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
614 | + $this->userCreateChecks($share); |
|
615 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
616 | + $this->groupCreateChecks($share); |
|
617 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
618 | + $this->linkCreateChecks($share); |
|
619 | + $this->setLinkParent($share); |
|
620 | + |
|
621 | + /* |
|
622 | 622 | * For now ignore a set token. |
623 | 623 | */ |
624 | - $share->setToken( |
|
625 | - $this->secureRandom->generate( |
|
626 | - \OC\Share\Constants::TOKEN_LENGTH, |
|
627 | - \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE |
|
628 | - ) |
|
629 | - ); |
|
630 | - |
|
631 | - //Verify the expiration date |
|
632 | - $this->validateExpirationDate($share); |
|
633 | - |
|
634 | - //Verify the password |
|
635 | - $this->verifyPassword($share->getPassword()); |
|
636 | - |
|
637 | - // If a password is set. Hash it! |
|
638 | - if ($share->getPassword() !== null) { |
|
639 | - $share->setPassword($this->hasher->hash($share->getPassword())); |
|
640 | - } |
|
641 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
642 | - $share->setToken( |
|
643 | - $this->secureRandom->generate( |
|
644 | - \OC\Share\Constants::TOKEN_LENGTH, |
|
645 | - \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE |
|
646 | - ) |
|
647 | - ); |
|
648 | - } |
|
649 | - |
|
650 | - // Cannot share with the owner |
|
651 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
652 | - $share->getSharedWith() === $share->getShareOwner()) { |
|
653 | - throw new \InvalidArgumentException('Can’t share with the share owner'); |
|
654 | - } |
|
655 | - |
|
656 | - // Generate the target |
|
657 | - $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
|
658 | - $target = \OC\Files\Filesystem::normalizePath($target); |
|
659 | - $share->setTarget($target); |
|
660 | - |
|
661 | - // Pre share event |
|
662 | - $event = new GenericEvent($share); |
|
663 | - $this->eventDispatcher->dispatch('OCP\Share::preShare', $event); |
|
664 | - if ($event->isPropagationStopped() && $event->hasArgument('error')) { |
|
665 | - throw new \Exception($event->getArgument('error')); |
|
666 | - } |
|
667 | - |
|
668 | - $oldShare = $share; |
|
669 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
670 | - $share = $provider->create($share); |
|
671 | - //reuse the node we already have |
|
672 | - $share->setNode($oldShare->getNode()); |
|
673 | - |
|
674 | - // Post share event |
|
675 | - $event = new GenericEvent($share); |
|
676 | - $this->eventDispatcher->dispatch('OCP\Share::postShare', $event); |
|
677 | - |
|
678 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
679 | - $mailSend = $share->getMailSend(); |
|
680 | - if($mailSend === true) { |
|
681 | - $user = $this->userManager->get($share->getSharedWith()); |
|
682 | - if ($user !== null) { |
|
683 | - $emailAddress = $user->getEMailAddress(); |
|
684 | - if ($emailAddress !== null && $emailAddress !== '') { |
|
685 | - $userLang = $this->config->getUserValue($share->getSharedWith(), 'core', 'lang', null); |
|
686 | - $l = $this->l10nFactory->get('lib', $userLang); |
|
687 | - $this->sendMailNotification( |
|
688 | - $l, |
|
689 | - $share->getNode()->getName(), |
|
690 | - $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]), |
|
691 | - $share->getSharedBy(), |
|
692 | - $emailAddress, |
|
693 | - $share->getExpirationDate() |
|
694 | - ); |
|
695 | - $this->logger->debug('Sent share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); |
|
696 | - } else { |
|
697 | - $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); |
|
698 | - } |
|
699 | - } else { |
|
700 | - $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); |
|
701 | - } |
|
702 | - } else { |
|
703 | - $this->logger->debug('Share notification not sent because mailsend is false.', ['app' => 'share']); |
|
704 | - } |
|
705 | - } |
|
706 | - |
|
707 | - return $share; |
|
708 | - } |
|
709 | - |
|
710 | - /** |
|
711 | - * Send mail notifications |
|
712 | - * |
|
713 | - * This method will catch and log mail transmission errors |
|
714 | - * |
|
715 | - * @param IL10N $l Language of the recipient |
|
716 | - * @param string $filename file/folder name |
|
717 | - * @param string $link link to the file/folder |
|
718 | - * @param string $initiator user ID of share sender |
|
719 | - * @param string $shareWith email address of share receiver |
|
720 | - * @param \DateTime|null $expiration |
|
721 | - */ |
|
722 | - protected function sendMailNotification(IL10N $l, |
|
723 | - $filename, |
|
724 | - $link, |
|
725 | - $initiator, |
|
726 | - $shareWith, |
|
727 | - \DateTime $expiration = null) { |
|
728 | - $initiatorUser = $this->userManager->get($initiator); |
|
729 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
730 | - |
|
731 | - $message = $this->mailer->createMessage(); |
|
732 | - |
|
733 | - $emailTemplate = $this->mailer->createEMailTemplate('files_sharing.RecipientNotification', [ |
|
734 | - 'filename' => $filename, |
|
735 | - 'link' => $link, |
|
736 | - 'initiator' => $initiatorDisplayName, |
|
737 | - 'expiration' => $expiration, |
|
738 | - 'shareWith' => $shareWith, |
|
739 | - ]); |
|
740 | - |
|
741 | - $emailTemplate->setSubject($l->t('%1$s shared »%2$s« with you', array($initiatorDisplayName, $filename))); |
|
742 | - $emailTemplate->addHeader(); |
|
743 | - $emailTemplate->addHeading($l->t('%1$s shared »%2$s« with you', [$initiatorDisplayName, $filename]), false); |
|
744 | - $text = $l->t('%1$s shared »%2$s« with you.', [$initiatorDisplayName, $filename]); |
|
745 | - |
|
746 | - $emailTemplate->addBodyText( |
|
747 | - htmlspecialchars($text . ' ' . $l->t('Click the button below to open it.')), |
|
748 | - $text |
|
749 | - ); |
|
750 | - $emailTemplate->addBodyButton( |
|
751 | - $l->t('Open »%s«', [$filename]), |
|
752 | - $link |
|
753 | - ); |
|
754 | - |
|
755 | - $message->setTo([$shareWith]); |
|
756 | - |
|
757 | - // The "From" contains the sharers name |
|
758 | - $instanceName = $this->defaults->getName(); |
|
759 | - $senderName = $l->t( |
|
760 | - '%1$s via %2$s', |
|
761 | - [ |
|
762 | - $initiatorDisplayName, |
|
763 | - $instanceName |
|
764 | - ] |
|
765 | - ); |
|
766 | - $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
767 | - |
|
768 | - // The "Reply-To" is set to the sharer if an mail address is configured |
|
769 | - // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
770 | - $initiatorEmail = $initiatorUser->getEMailAddress(); |
|
771 | - if($initiatorEmail !== null) { |
|
772 | - $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
|
773 | - $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')); |
|
774 | - } else { |
|
775 | - $emailTemplate->addFooter(); |
|
776 | - } |
|
777 | - |
|
778 | - $message->useTemplate($emailTemplate); |
|
779 | - try { |
|
780 | - $failedRecipients = $this->mailer->send($message); |
|
781 | - if(!empty($failedRecipients)) { |
|
782 | - $this->logger->error('Share notification mail could not be sent to: ' . implode(', ', $failedRecipients)); |
|
783 | - return; |
|
784 | - } |
|
785 | - } catch (\Exception $e) { |
|
786 | - $this->logger->logException($e, ['message' => 'Share notification mail could not be sent']); |
|
787 | - } |
|
788 | - } |
|
789 | - |
|
790 | - /** |
|
791 | - * Update a share |
|
792 | - * |
|
793 | - * @param \OCP\Share\IShare $share |
|
794 | - * @return \OCP\Share\IShare The share object |
|
795 | - * @throws \InvalidArgumentException |
|
796 | - */ |
|
797 | - public function updateShare(\OCP\Share\IShare $share) { |
|
798 | - $expirationDateUpdated = false; |
|
799 | - |
|
800 | - $this->canShare($share); |
|
801 | - |
|
802 | - try { |
|
803 | - $originalShare = $this->getShareById($share->getFullId()); |
|
804 | - } catch (\UnexpectedValueException $e) { |
|
805 | - throw new \InvalidArgumentException('Share does not have a full id'); |
|
806 | - } |
|
807 | - |
|
808 | - // We can't change the share type! |
|
809 | - if ($share->getShareType() !== $originalShare->getShareType()) { |
|
810 | - throw new \InvalidArgumentException('Can’t change share type'); |
|
811 | - } |
|
812 | - |
|
813 | - // We can only change the recipient on user shares |
|
814 | - if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
|
815 | - $share->getShareType() !== \OCP\Share::SHARE_TYPE_USER) { |
|
816 | - throw new \InvalidArgumentException('Can only update recipient on user shares'); |
|
817 | - } |
|
818 | - |
|
819 | - // Cannot share with the owner |
|
820 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
821 | - $share->getSharedWith() === $share->getShareOwner()) { |
|
822 | - throw new \InvalidArgumentException('Can’t share with the share owner'); |
|
823 | - } |
|
824 | - |
|
825 | - $this->generalCreateChecks($share); |
|
826 | - |
|
827 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
828 | - $this->userCreateChecks($share); |
|
829 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
830 | - $this->groupCreateChecks($share); |
|
831 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
832 | - $this->linkCreateChecks($share); |
|
833 | - |
|
834 | - $this->updateSharePasswordIfNeeded($share, $originalShare); |
|
835 | - |
|
836 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
837 | - //Verify the expiration date |
|
838 | - $this->validateExpirationDate($share); |
|
839 | - $expirationDateUpdated = true; |
|
840 | - } |
|
841 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
842 | - // The new password is not set again if it is the same as the old |
|
843 | - // one, unless when switching from sending by Talk to sending by |
|
844 | - // mail. |
|
845 | - $plainTextPassword = $share->getPassword(); |
|
846 | - if (!empty($plainTextPassword) && !$this->updateSharePasswordIfNeeded($share, $originalShare) && |
|
847 | - !($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk())) { |
|
848 | - $plainTextPassword = null; |
|
849 | - } |
|
850 | - if (empty($plainTextPassword) && !$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) { |
|
851 | - // If the same password was already sent by mail the recipient |
|
852 | - // would already have access to the share without having to call |
|
853 | - // the sharer to verify her identity |
|
854 | - throw new \InvalidArgumentException('Can’t enable sending the password by Talk without setting a new password'); |
|
855 | - } |
|
856 | - } |
|
857 | - |
|
858 | - $this->pathCreateChecks($share->getNode()); |
|
859 | - |
|
860 | - // Now update the share! |
|
861 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
862 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
863 | - $share = $provider->update($share, $plainTextPassword); |
|
864 | - } else { |
|
865 | - $share = $provider->update($share); |
|
866 | - } |
|
867 | - |
|
868 | - if ($expirationDateUpdated === true) { |
|
869 | - \OC_Hook::emit(Share::class, 'post_set_expiration_date', [ |
|
870 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
871 | - 'itemSource' => $share->getNode()->getId(), |
|
872 | - 'date' => $share->getExpirationDate(), |
|
873 | - 'uidOwner' => $share->getSharedBy(), |
|
874 | - ]); |
|
875 | - } |
|
876 | - |
|
877 | - if ($share->getPassword() !== $originalShare->getPassword()) { |
|
878 | - \OC_Hook::emit(Share::class, 'post_update_password', [ |
|
879 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
880 | - 'itemSource' => $share->getNode()->getId(), |
|
881 | - 'uidOwner' => $share->getSharedBy(), |
|
882 | - 'token' => $share->getToken(), |
|
883 | - 'disabled' => is_null($share->getPassword()), |
|
884 | - ]); |
|
885 | - } |
|
886 | - |
|
887 | - if ($share->getPermissions() !== $originalShare->getPermissions()) { |
|
888 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
889 | - $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
890 | - } else { |
|
891 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
892 | - } |
|
893 | - \OC_Hook::emit(Share::class, 'post_update_permissions', array( |
|
894 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
895 | - 'itemSource' => $share->getNode()->getId(), |
|
896 | - 'shareType' => $share->getShareType(), |
|
897 | - 'shareWith' => $share->getSharedWith(), |
|
898 | - 'uidOwner' => $share->getSharedBy(), |
|
899 | - 'permissions' => $share->getPermissions(), |
|
900 | - 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
|
901 | - )); |
|
902 | - } |
|
903 | - |
|
904 | - return $share; |
|
905 | - } |
|
906 | - |
|
907 | - /** |
|
908 | - * Updates the password of the given share if it is not the same as the |
|
909 | - * password of the original share. |
|
910 | - * |
|
911 | - * @param \OCP\Share\IShare $share the share to update its password. |
|
912 | - * @param \OCP\Share\IShare $originalShare the original share to compare its |
|
913 | - * password with. |
|
914 | - * @return boolean whether the password was updated or not. |
|
915 | - */ |
|
916 | - private function updateSharePasswordIfNeeded(\OCP\Share\IShare $share, \OCP\Share\IShare $originalShare) { |
|
917 | - // Password updated. |
|
918 | - if ($share->getPassword() !== $originalShare->getPassword()) { |
|
919 | - //Verify the password |
|
920 | - $this->verifyPassword($share->getPassword()); |
|
921 | - |
|
922 | - // If a password is set. Hash it! |
|
923 | - if ($share->getPassword() !== null) { |
|
924 | - $share->setPassword($this->hasher->hash($share->getPassword())); |
|
925 | - |
|
926 | - return true; |
|
927 | - } |
|
928 | - } |
|
929 | - |
|
930 | - return false; |
|
931 | - } |
|
932 | - |
|
933 | - /** |
|
934 | - * Delete all the children of this share |
|
935 | - * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
936 | - * |
|
937 | - * @param \OCP\Share\IShare $share |
|
938 | - * @return \OCP\Share\IShare[] List of deleted shares |
|
939 | - */ |
|
940 | - protected function deleteChildren(\OCP\Share\IShare $share) { |
|
941 | - $deletedShares = []; |
|
942 | - |
|
943 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
944 | - |
|
945 | - foreach ($provider->getChildren($share) as $child) { |
|
946 | - $deletedChildren = $this->deleteChildren($child); |
|
947 | - $deletedShares = array_merge($deletedShares, $deletedChildren); |
|
948 | - |
|
949 | - $provider->delete($child); |
|
950 | - $deletedShares[] = $child; |
|
951 | - } |
|
952 | - |
|
953 | - return $deletedShares; |
|
954 | - } |
|
955 | - |
|
956 | - /** |
|
957 | - * Delete a share |
|
958 | - * |
|
959 | - * @param \OCP\Share\IShare $share |
|
960 | - * @throws ShareNotFound |
|
961 | - * @throws \InvalidArgumentException |
|
962 | - */ |
|
963 | - public function deleteShare(\OCP\Share\IShare $share) { |
|
964 | - |
|
965 | - try { |
|
966 | - $share->getFullId(); |
|
967 | - } catch (\UnexpectedValueException $e) { |
|
968 | - throw new \InvalidArgumentException('Share does not have a full id'); |
|
969 | - } |
|
970 | - |
|
971 | - $event = new GenericEvent($share); |
|
972 | - $this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event); |
|
973 | - |
|
974 | - // Get all children and delete them as well |
|
975 | - $deletedShares = $this->deleteChildren($share); |
|
976 | - |
|
977 | - // Do the actual delete |
|
978 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
979 | - $provider->delete($share); |
|
980 | - |
|
981 | - // All the deleted shares caused by this delete |
|
982 | - $deletedShares[] = $share; |
|
983 | - |
|
984 | - // Emit post hook |
|
985 | - $event->setArgument('deletedShares', $deletedShares); |
|
986 | - $this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event); |
|
987 | - } |
|
988 | - |
|
989 | - |
|
990 | - /** |
|
991 | - * Unshare a file as the recipient. |
|
992 | - * This can be different from a regular delete for example when one of |
|
993 | - * the users in a groups deletes that share. But the provider should |
|
994 | - * handle this. |
|
995 | - * |
|
996 | - * @param \OCP\Share\IShare $share |
|
997 | - * @param string $recipientId |
|
998 | - */ |
|
999 | - public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
|
1000 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
1001 | - $provider = $this->factory->getProvider($providerId); |
|
1002 | - |
|
1003 | - $provider->deleteFromSelf($share, $recipientId); |
|
1004 | - $event = new GenericEvent($share); |
|
1005 | - $this->eventDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event); |
|
1006 | - } |
|
1007 | - |
|
1008 | - public function restoreShare(IShare $share, string $recipientId): IShare { |
|
1009 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
1010 | - $provider = $this->factory->getProvider($providerId); |
|
1011 | - |
|
1012 | - return $provider->restore($share, $recipientId); |
|
1013 | - } |
|
1014 | - |
|
1015 | - /** |
|
1016 | - * @inheritdoc |
|
1017 | - */ |
|
1018 | - public function moveShare(\OCP\Share\IShare $share, $recipientId) { |
|
1019 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
1020 | - throw new \InvalidArgumentException('Can’t change target of link share'); |
|
1021 | - } |
|
1022 | - |
|
1023 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) { |
|
1024 | - throw new \InvalidArgumentException('Invalid recipient'); |
|
1025 | - } |
|
1026 | - |
|
1027 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
1028 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
1029 | - if (is_null($sharedWith)) { |
|
1030 | - throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
1031 | - } |
|
1032 | - $recipient = $this->userManager->get($recipientId); |
|
1033 | - if (!$sharedWith->inGroup($recipient)) { |
|
1034 | - throw new \InvalidArgumentException('Invalid recipient'); |
|
1035 | - } |
|
1036 | - } |
|
1037 | - |
|
1038 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
1039 | - $provider = $this->factory->getProvider($providerId); |
|
1040 | - |
|
1041 | - $provider->move($share, $recipientId); |
|
1042 | - } |
|
1043 | - |
|
1044 | - public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
|
1045 | - $providers = $this->factory->getAllProviders(); |
|
1046 | - |
|
1047 | - return array_reduce($providers, function($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
1048 | - $newShares = $provider->getSharesInFolder($userId, $node, $reshares); |
|
1049 | - foreach ($newShares as $fid => $data) { |
|
1050 | - if (!isset($shares[$fid])) { |
|
1051 | - $shares[$fid] = []; |
|
1052 | - } |
|
1053 | - |
|
1054 | - $shares[$fid] = array_merge($shares[$fid], $data); |
|
1055 | - } |
|
1056 | - return $shares; |
|
1057 | - }, []); |
|
1058 | - } |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * @inheritdoc |
|
1062 | - */ |
|
1063 | - public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { |
|
1064 | - if ($path !== null && |
|
1065 | - !($path instanceof \OCP\Files\File) && |
|
1066 | - !($path instanceof \OCP\Files\Folder)) { |
|
1067 | - throw new \InvalidArgumentException('invalid path'); |
|
1068 | - } |
|
1069 | - |
|
1070 | - try { |
|
1071 | - $provider = $this->factory->getProviderForType($shareType); |
|
1072 | - } catch (ProviderException $e) { |
|
1073 | - return []; |
|
1074 | - } |
|
1075 | - |
|
1076 | - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
1077 | - |
|
1078 | - /* |
|
624 | + $share->setToken( |
|
625 | + $this->secureRandom->generate( |
|
626 | + \OC\Share\Constants::TOKEN_LENGTH, |
|
627 | + \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE |
|
628 | + ) |
|
629 | + ); |
|
630 | + |
|
631 | + //Verify the expiration date |
|
632 | + $this->validateExpirationDate($share); |
|
633 | + |
|
634 | + //Verify the password |
|
635 | + $this->verifyPassword($share->getPassword()); |
|
636 | + |
|
637 | + // If a password is set. Hash it! |
|
638 | + if ($share->getPassword() !== null) { |
|
639 | + $share->setPassword($this->hasher->hash($share->getPassword())); |
|
640 | + } |
|
641 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
642 | + $share->setToken( |
|
643 | + $this->secureRandom->generate( |
|
644 | + \OC\Share\Constants::TOKEN_LENGTH, |
|
645 | + \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE |
|
646 | + ) |
|
647 | + ); |
|
648 | + } |
|
649 | + |
|
650 | + // Cannot share with the owner |
|
651 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
652 | + $share->getSharedWith() === $share->getShareOwner()) { |
|
653 | + throw new \InvalidArgumentException('Can’t share with the share owner'); |
|
654 | + } |
|
655 | + |
|
656 | + // Generate the target |
|
657 | + $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
|
658 | + $target = \OC\Files\Filesystem::normalizePath($target); |
|
659 | + $share->setTarget($target); |
|
660 | + |
|
661 | + // Pre share event |
|
662 | + $event = new GenericEvent($share); |
|
663 | + $this->eventDispatcher->dispatch('OCP\Share::preShare', $event); |
|
664 | + if ($event->isPropagationStopped() && $event->hasArgument('error')) { |
|
665 | + throw new \Exception($event->getArgument('error')); |
|
666 | + } |
|
667 | + |
|
668 | + $oldShare = $share; |
|
669 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
670 | + $share = $provider->create($share); |
|
671 | + //reuse the node we already have |
|
672 | + $share->setNode($oldShare->getNode()); |
|
673 | + |
|
674 | + // Post share event |
|
675 | + $event = new GenericEvent($share); |
|
676 | + $this->eventDispatcher->dispatch('OCP\Share::postShare', $event); |
|
677 | + |
|
678 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
679 | + $mailSend = $share->getMailSend(); |
|
680 | + if($mailSend === true) { |
|
681 | + $user = $this->userManager->get($share->getSharedWith()); |
|
682 | + if ($user !== null) { |
|
683 | + $emailAddress = $user->getEMailAddress(); |
|
684 | + if ($emailAddress !== null && $emailAddress !== '') { |
|
685 | + $userLang = $this->config->getUserValue($share->getSharedWith(), 'core', 'lang', null); |
|
686 | + $l = $this->l10nFactory->get('lib', $userLang); |
|
687 | + $this->sendMailNotification( |
|
688 | + $l, |
|
689 | + $share->getNode()->getName(), |
|
690 | + $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]), |
|
691 | + $share->getSharedBy(), |
|
692 | + $emailAddress, |
|
693 | + $share->getExpirationDate() |
|
694 | + ); |
|
695 | + $this->logger->debug('Sent share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); |
|
696 | + } else { |
|
697 | + $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); |
|
698 | + } |
|
699 | + } else { |
|
700 | + $this->logger->debug('Share notification not sent to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); |
|
701 | + } |
|
702 | + } else { |
|
703 | + $this->logger->debug('Share notification not sent because mailsend is false.', ['app' => 'share']); |
|
704 | + } |
|
705 | + } |
|
706 | + |
|
707 | + return $share; |
|
708 | + } |
|
709 | + |
|
710 | + /** |
|
711 | + * Send mail notifications |
|
712 | + * |
|
713 | + * This method will catch and log mail transmission errors |
|
714 | + * |
|
715 | + * @param IL10N $l Language of the recipient |
|
716 | + * @param string $filename file/folder name |
|
717 | + * @param string $link link to the file/folder |
|
718 | + * @param string $initiator user ID of share sender |
|
719 | + * @param string $shareWith email address of share receiver |
|
720 | + * @param \DateTime|null $expiration |
|
721 | + */ |
|
722 | + protected function sendMailNotification(IL10N $l, |
|
723 | + $filename, |
|
724 | + $link, |
|
725 | + $initiator, |
|
726 | + $shareWith, |
|
727 | + \DateTime $expiration = null) { |
|
728 | + $initiatorUser = $this->userManager->get($initiator); |
|
729 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
730 | + |
|
731 | + $message = $this->mailer->createMessage(); |
|
732 | + |
|
733 | + $emailTemplate = $this->mailer->createEMailTemplate('files_sharing.RecipientNotification', [ |
|
734 | + 'filename' => $filename, |
|
735 | + 'link' => $link, |
|
736 | + 'initiator' => $initiatorDisplayName, |
|
737 | + 'expiration' => $expiration, |
|
738 | + 'shareWith' => $shareWith, |
|
739 | + ]); |
|
740 | + |
|
741 | + $emailTemplate->setSubject($l->t('%1$s shared »%2$s« with you', array($initiatorDisplayName, $filename))); |
|
742 | + $emailTemplate->addHeader(); |
|
743 | + $emailTemplate->addHeading($l->t('%1$s shared »%2$s« with you', [$initiatorDisplayName, $filename]), false); |
|
744 | + $text = $l->t('%1$s shared »%2$s« with you.', [$initiatorDisplayName, $filename]); |
|
745 | + |
|
746 | + $emailTemplate->addBodyText( |
|
747 | + htmlspecialchars($text . ' ' . $l->t('Click the button below to open it.')), |
|
748 | + $text |
|
749 | + ); |
|
750 | + $emailTemplate->addBodyButton( |
|
751 | + $l->t('Open »%s«', [$filename]), |
|
752 | + $link |
|
753 | + ); |
|
754 | + |
|
755 | + $message->setTo([$shareWith]); |
|
756 | + |
|
757 | + // The "From" contains the sharers name |
|
758 | + $instanceName = $this->defaults->getName(); |
|
759 | + $senderName = $l->t( |
|
760 | + '%1$s via %2$s', |
|
761 | + [ |
|
762 | + $initiatorDisplayName, |
|
763 | + $instanceName |
|
764 | + ] |
|
765 | + ); |
|
766 | + $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
767 | + |
|
768 | + // The "Reply-To" is set to the sharer if an mail address is configured |
|
769 | + // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
770 | + $initiatorEmail = $initiatorUser->getEMailAddress(); |
|
771 | + if($initiatorEmail !== null) { |
|
772 | + $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
|
773 | + $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')); |
|
774 | + } else { |
|
775 | + $emailTemplate->addFooter(); |
|
776 | + } |
|
777 | + |
|
778 | + $message->useTemplate($emailTemplate); |
|
779 | + try { |
|
780 | + $failedRecipients = $this->mailer->send($message); |
|
781 | + if(!empty($failedRecipients)) { |
|
782 | + $this->logger->error('Share notification mail could not be sent to: ' . implode(', ', $failedRecipients)); |
|
783 | + return; |
|
784 | + } |
|
785 | + } catch (\Exception $e) { |
|
786 | + $this->logger->logException($e, ['message' => 'Share notification mail could not be sent']); |
|
787 | + } |
|
788 | + } |
|
789 | + |
|
790 | + /** |
|
791 | + * Update a share |
|
792 | + * |
|
793 | + * @param \OCP\Share\IShare $share |
|
794 | + * @return \OCP\Share\IShare The share object |
|
795 | + * @throws \InvalidArgumentException |
|
796 | + */ |
|
797 | + public function updateShare(\OCP\Share\IShare $share) { |
|
798 | + $expirationDateUpdated = false; |
|
799 | + |
|
800 | + $this->canShare($share); |
|
801 | + |
|
802 | + try { |
|
803 | + $originalShare = $this->getShareById($share->getFullId()); |
|
804 | + } catch (\UnexpectedValueException $e) { |
|
805 | + throw new \InvalidArgumentException('Share does not have a full id'); |
|
806 | + } |
|
807 | + |
|
808 | + // We can't change the share type! |
|
809 | + if ($share->getShareType() !== $originalShare->getShareType()) { |
|
810 | + throw new \InvalidArgumentException('Can’t change share type'); |
|
811 | + } |
|
812 | + |
|
813 | + // We can only change the recipient on user shares |
|
814 | + if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
|
815 | + $share->getShareType() !== \OCP\Share::SHARE_TYPE_USER) { |
|
816 | + throw new \InvalidArgumentException('Can only update recipient on user shares'); |
|
817 | + } |
|
818 | + |
|
819 | + // Cannot share with the owner |
|
820 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
821 | + $share->getSharedWith() === $share->getShareOwner()) { |
|
822 | + throw new \InvalidArgumentException('Can’t share with the share owner'); |
|
823 | + } |
|
824 | + |
|
825 | + $this->generalCreateChecks($share); |
|
826 | + |
|
827 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
828 | + $this->userCreateChecks($share); |
|
829 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
830 | + $this->groupCreateChecks($share); |
|
831 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
832 | + $this->linkCreateChecks($share); |
|
833 | + |
|
834 | + $this->updateSharePasswordIfNeeded($share, $originalShare); |
|
835 | + |
|
836 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
837 | + //Verify the expiration date |
|
838 | + $this->validateExpirationDate($share); |
|
839 | + $expirationDateUpdated = true; |
|
840 | + } |
|
841 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
842 | + // The new password is not set again if it is the same as the old |
|
843 | + // one, unless when switching from sending by Talk to sending by |
|
844 | + // mail. |
|
845 | + $plainTextPassword = $share->getPassword(); |
|
846 | + if (!empty($plainTextPassword) && !$this->updateSharePasswordIfNeeded($share, $originalShare) && |
|
847 | + !($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk())) { |
|
848 | + $plainTextPassword = null; |
|
849 | + } |
|
850 | + if (empty($plainTextPassword) && !$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) { |
|
851 | + // If the same password was already sent by mail the recipient |
|
852 | + // would already have access to the share without having to call |
|
853 | + // the sharer to verify her identity |
|
854 | + throw new \InvalidArgumentException('Can’t enable sending the password by Talk without setting a new password'); |
|
855 | + } |
|
856 | + } |
|
857 | + |
|
858 | + $this->pathCreateChecks($share->getNode()); |
|
859 | + |
|
860 | + // Now update the share! |
|
861 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
862 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
863 | + $share = $provider->update($share, $plainTextPassword); |
|
864 | + } else { |
|
865 | + $share = $provider->update($share); |
|
866 | + } |
|
867 | + |
|
868 | + if ($expirationDateUpdated === true) { |
|
869 | + \OC_Hook::emit(Share::class, 'post_set_expiration_date', [ |
|
870 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
871 | + 'itemSource' => $share->getNode()->getId(), |
|
872 | + 'date' => $share->getExpirationDate(), |
|
873 | + 'uidOwner' => $share->getSharedBy(), |
|
874 | + ]); |
|
875 | + } |
|
876 | + |
|
877 | + if ($share->getPassword() !== $originalShare->getPassword()) { |
|
878 | + \OC_Hook::emit(Share::class, 'post_update_password', [ |
|
879 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
880 | + 'itemSource' => $share->getNode()->getId(), |
|
881 | + 'uidOwner' => $share->getSharedBy(), |
|
882 | + 'token' => $share->getToken(), |
|
883 | + 'disabled' => is_null($share->getPassword()), |
|
884 | + ]); |
|
885 | + } |
|
886 | + |
|
887 | + if ($share->getPermissions() !== $originalShare->getPermissions()) { |
|
888 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
889 | + $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
890 | + } else { |
|
891 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
892 | + } |
|
893 | + \OC_Hook::emit(Share::class, 'post_update_permissions', array( |
|
894 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
895 | + 'itemSource' => $share->getNode()->getId(), |
|
896 | + 'shareType' => $share->getShareType(), |
|
897 | + 'shareWith' => $share->getSharedWith(), |
|
898 | + 'uidOwner' => $share->getSharedBy(), |
|
899 | + 'permissions' => $share->getPermissions(), |
|
900 | + 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
|
901 | + )); |
|
902 | + } |
|
903 | + |
|
904 | + return $share; |
|
905 | + } |
|
906 | + |
|
907 | + /** |
|
908 | + * Updates the password of the given share if it is not the same as the |
|
909 | + * password of the original share. |
|
910 | + * |
|
911 | + * @param \OCP\Share\IShare $share the share to update its password. |
|
912 | + * @param \OCP\Share\IShare $originalShare the original share to compare its |
|
913 | + * password with. |
|
914 | + * @return boolean whether the password was updated or not. |
|
915 | + */ |
|
916 | + private function updateSharePasswordIfNeeded(\OCP\Share\IShare $share, \OCP\Share\IShare $originalShare) { |
|
917 | + // Password updated. |
|
918 | + if ($share->getPassword() !== $originalShare->getPassword()) { |
|
919 | + //Verify the password |
|
920 | + $this->verifyPassword($share->getPassword()); |
|
921 | + |
|
922 | + // If a password is set. Hash it! |
|
923 | + if ($share->getPassword() !== null) { |
|
924 | + $share->setPassword($this->hasher->hash($share->getPassword())); |
|
925 | + |
|
926 | + return true; |
|
927 | + } |
|
928 | + } |
|
929 | + |
|
930 | + return false; |
|
931 | + } |
|
932 | + |
|
933 | + /** |
|
934 | + * Delete all the children of this share |
|
935 | + * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
936 | + * |
|
937 | + * @param \OCP\Share\IShare $share |
|
938 | + * @return \OCP\Share\IShare[] List of deleted shares |
|
939 | + */ |
|
940 | + protected function deleteChildren(\OCP\Share\IShare $share) { |
|
941 | + $deletedShares = []; |
|
942 | + |
|
943 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
944 | + |
|
945 | + foreach ($provider->getChildren($share) as $child) { |
|
946 | + $deletedChildren = $this->deleteChildren($child); |
|
947 | + $deletedShares = array_merge($deletedShares, $deletedChildren); |
|
948 | + |
|
949 | + $provider->delete($child); |
|
950 | + $deletedShares[] = $child; |
|
951 | + } |
|
952 | + |
|
953 | + return $deletedShares; |
|
954 | + } |
|
955 | + |
|
956 | + /** |
|
957 | + * Delete a share |
|
958 | + * |
|
959 | + * @param \OCP\Share\IShare $share |
|
960 | + * @throws ShareNotFound |
|
961 | + * @throws \InvalidArgumentException |
|
962 | + */ |
|
963 | + public function deleteShare(\OCP\Share\IShare $share) { |
|
964 | + |
|
965 | + try { |
|
966 | + $share->getFullId(); |
|
967 | + } catch (\UnexpectedValueException $e) { |
|
968 | + throw new \InvalidArgumentException('Share does not have a full id'); |
|
969 | + } |
|
970 | + |
|
971 | + $event = new GenericEvent($share); |
|
972 | + $this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event); |
|
973 | + |
|
974 | + // Get all children and delete them as well |
|
975 | + $deletedShares = $this->deleteChildren($share); |
|
976 | + |
|
977 | + // Do the actual delete |
|
978 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
979 | + $provider->delete($share); |
|
980 | + |
|
981 | + // All the deleted shares caused by this delete |
|
982 | + $deletedShares[] = $share; |
|
983 | + |
|
984 | + // Emit post hook |
|
985 | + $event->setArgument('deletedShares', $deletedShares); |
|
986 | + $this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event); |
|
987 | + } |
|
988 | + |
|
989 | + |
|
990 | + /** |
|
991 | + * Unshare a file as the recipient. |
|
992 | + * This can be different from a regular delete for example when one of |
|
993 | + * the users in a groups deletes that share. But the provider should |
|
994 | + * handle this. |
|
995 | + * |
|
996 | + * @param \OCP\Share\IShare $share |
|
997 | + * @param string $recipientId |
|
998 | + */ |
|
999 | + public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
|
1000 | + list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
1001 | + $provider = $this->factory->getProvider($providerId); |
|
1002 | + |
|
1003 | + $provider->deleteFromSelf($share, $recipientId); |
|
1004 | + $event = new GenericEvent($share); |
|
1005 | + $this->eventDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event); |
|
1006 | + } |
|
1007 | + |
|
1008 | + public function restoreShare(IShare $share, string $recipientId): IShare { |
|
1009 | + list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
1010 | + $provider = $this->factory->getProvider($providerId); |
|
1011 | + |
|
1012 | + return $provider->restore($share, $recipientId); |
|
1013 | + } |
|
1014 | + |
|
1015 | + /** |
|
1016 | + * @inheritdoc |
|
1017 | + */ |
|
1018 | + public function moveShare(\OCP\Share\IShare $share, $recipientId) { |
|
1019 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
1020 | + throw new \InvalidArgumentException('Can’t change target of link share'); |
|
1021 | + } |
|
1022 | + |
|
1023 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) { |
|
1024 | + throw new \InvalidArgumentException('Invalid recipient'); |
|
1025 | + } |
|
1026 | + |
|
1027 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
1028 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
1029 | + if (is_null($sharedWith)) { |
|
1030 | + throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
1031 | + } |
|
1032 | + $recipient = $this->userManager->get($recipientId); |
|
1033 | + if (!$sharedWith->inGroup($recipient)) { |
|
1034 | + throw new \InvalidArgumentException('Invalid recipient'); |
|
1035 | + } |
|
1036 | + } |
|
1037 | + |
|
1038 | + list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
1039 | + $provider = $this->factory->getProvider($providerId); |
|
1040 | + |
|
1041 | + $provider->move($share, $recipientId); |
|
1042 | + } |
|
1043 | + |
|
1044 | + public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
|
1045 | + $providers = $this->factory->getAllProviders(); |
|
1046 | + |
|
1047 | + return array_reduce($providers, function($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
1048 | + $newShares = $provider->getSharesInFolder($userId, $node, $reshares); |
|
1049 | + foreach ($newShares as $fid => $data) { |
|
1050 | + if (!isset($shares[$fid])) { |
|
1051 | + $shares[$fid] = []; |
|
1052 | + } |
|
1053 | + |
|
1054 | + $shares[$fid] = array_merge($shares[$fid], $data); |
|
1055 | + } |
|
1056 | + return $shares; |
|
1057 | + }, []); |
|
1058 | + } |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * @inheritdoc |
|
1062 | + */ |
|
1063 | + public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { |
|
1064 | + if ($path !== null && |
|
1065 | + !($path instanceof \OCP\Files\File) && |
|
1066 | + !($path instanceof \OCP\Files\Folder)) { |
|
1067 | + throw new \InvalidArgumentException('invalid path'); |
|
1068 | + } |
|
1069 | + |
|
1070 | + try { |
|
1071 | + $provider = $this->factory->getProviderForType($shareType); |
|
1072 | + } catch (ProviderException $e) { |
|
1073 | + return []; |
|
1074 | + } |
|
1075 | + |
|
1076 | + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
1077 | + |
|
1078 | + /* |
|
1079 | 1079 | * Work around so we don't return expired shares but still follow |
1080 | 1080 | * proper pagination. |
1081 | 1081 | */ |
1082 | 1082 | |
1083 | - $shares2 = []; |
|
1084 | - |
|
1085 | - while(true) { |
|
1086 | - $added = 0; |
|
1087 | - foreach ($shares as $share) { |
|
1088 | - |
|
1089 | - try { |
|
1090 | - $this->checkExpireDate($share); |
|
1091 | - } catch (ShareNotFound $e) { |
|
1092 | - //Ignore since this basically means the share is deleted |
|
1093 | - continue; |
|
1094 | - } |
|
1095 | - |
|
1096 | - $added++; |
|
1097 | - $shares2[] = $share; |
|
1098 | - |
|
1099 | - if (count($shares2) === $limit) { |
|
1100 | - break; |
|
1101 | - } |
|
1102 | - } |
|
1103 | - |
|
1104 | - // If we did not fetch more shares than the limit then there are no more shares |
|
1105 | - if (count($shares) < $limit) { |
|
1106 | - break; |
|
1107 | - } |
|
1108 | - |
|
1109 | - if (count($shares2) === $limit) { |
|
1110 | - break; |
|
1111 | - } |
|
1112 | - |
|
1113 | - // If there was no limit on the select we are done |
|
1114 | - if ($limit === -1) { |
|
1115 | - break; |
|
1116 | - } |
|
1117 | - |
|
1118 | - $offset += $added; |
|
1119 | - |
|
1120 | - // Fetch again $limit shares |
|
1121 | - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
1122 | - |
|
1123 | - // No more shares means we are done |
|
1124 | - if (empty($shares)) { |
|
1125 | - break; |
|
1126 | - } |
|
1127 | - } |
|
1128 | - |
|
1129 | - $shares = $shares2; |
|
1130 | - |
|
1131 | - return $shares; |
|
1132 | - } |
|
1133 | - |
|
1134 | - /** |
|
1135 | - * @inheritdoc |
|
1136 | - */ |
|
1137 | - public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
1138 | - try { |
|
1139 | - $provider = $this->factory->getProviderForType($shareType); |
|
1140 | - } catch (ProviderException $e) { |
|
1141 | - return []; |
|
1142 | - } |
|
1143 | - |
|
1144 | - $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
1145 | - |
|
1146 | - // remove all shares which are already expired |
|
1147 | - foreach ($shares as $key => $share) { |
|
1148 | - try { |
|
1149 | - $this->checkExpireDate($share); |
|
1150 | - } catch (ShareNotFound $e) { |
|
1151 | - unset($shares[$key]); |
|
1152 | - } |
|
1153 | - } |
|
1154 | - |
|
1155 | - return $shares; |
|
1156 | - } |
|
1157 | - |
|
1158 | - /** |
|
1159 | - * @inheritdoc |
|
1160 | - */ |
|
1161 | - public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
1162 | - $shares = $this->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
1163 | - |
|
1164 | - // Only get deleted shares |
|
1165 | - $shares = array_filter($shares, function(IShare $share) { |
|
1166 | - return $share->getPermissions() === 0; |
|
1167 | - }); |
|
1168 | - |
|
1169 | - // Only get shares where the owner still exists |
|
1170 | - $shares = array_filter($shares, function (IShare $share) { |
|
1171 | - return $this->userManager->userExists($share->getShareOwner()); |
|
1172 | - }); |
|
1173 | - |
|
1174 | - return $shares; |
|
1175 | - } |
|
1176 | - |
|
1177 | - /** |
|
1178 | - * @inheritdoc |
|
1179 | - */ |
|
1180 | - public function getShareById($id, $recipient = null) { |
|
1181 | - if ($id === null) { |
|
1182 | - throw new ShareNotFound(); |
|
1183 | - } |
|
1184 | - |
|
1185 | - list($providerId, $id) = $this->splitFullId($id); |
|
1186 | - |
|
1187 | - try { |
|
1188 | - $provider = $this->factory->getProvider($providerId); |
|
1189 | - } catch (ProviderException $e) { |
|
1190 | - throw new ShareNotFound(); |
|
1191 | - } |
|
1192 | - |
|
1193 | - $share = $provider->getShareById($id, $recipient); |
|
1194 | - |
|
1195 | - $this->checkExpireDate($share); |
|
1196 | - |
|
1197 | - return $share; |
|
1198 | - } |
|
1199 | - |
|
1200 | - /** |
|
1201 | - * Get all the shares for a given path |
|
1202 | - * |
|
1203 | - * @param \OCP\Files\Node $path |
|
1204 | - * @param int $page |
|
1205 | - * @param int $perPage |
|
1206 | - * |
|
1207 | - * @return Share[] |
|
1208 | - */ |
|
1209 | - public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
|
1210 | - return []; |
|
1211 | - } |
|
1212 | - |
|
1213 | - /** |
|
1214 | - * Get the share by token possible with password |
|
1215 | - * |
|
1216 | - * @param string $token |
|
1217 | - * @return Share |
|
1218 | - * |
|
1219 | - * @throws ShareNotFound |
|
1220 | - */ |
|
1221 | - public function getShareByToken($token) { |
|
1222 | - // tokens can't be valid local user names |
|
1223 | - if ($this->userManager->userExists($token)) { |
|
1224 | - throw new ShareNotFound(); |
|
1225 | - } |
|
1226 | - $share = null; |
|
1227 | - try { |
|
1228 | - if($this->shareApiAllowLinks()) { |
|
1229 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK); |
|
1230 | - $share = $provider->getShareByToken($token); |
|
1231 | - } |
|
1232 | - } catch (ProviderException $e) { |
|
1233 | - } catch (ShareNotFound $e) { |
|
1234 | - } |
|
1235 | - |
|
1236 | - |
|
1237 | - // If it is not a link share try to fetch a federated share by token |
|
1238 | - if ($share === null) { |
|
1239 | - try { |
|
1240 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE); |
|
1241 | - $share = $provider->getShareByToken($token); |
|
1242 | - } catch (ProviderException $e) { |
|
1243 | - } catch (ShareNotFound $e) { |
|
1244 | - } |
|
1245 | - } |
|
1246 | - |
|
1247 | - // If it is not a link share try to fetch a mail share by token |
|
1248 | - if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
1249 | - try { |
|
1250 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_EMAIL); |
|
1251 | - $share = $provider->getShareByToken($token); |
|
1252 | - } catch (ProviderException $e) { |
|
1253 | - } catch (ShareNotFound $e) { |
|
1254 | - } |
|
1255 | - } |
|
1256 | - |
|
1257 | - if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
1258 | - try { |
|
1259 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_CIRCLE); |
|
1260 | - $share = $provider->getShareByToken($token); |
|
1261 | - } catch (ProviderException $e) { |
|
1262 | - } catch (ShareNotFound $e) { |
|
1263 | - } |
|
1264 | - } |
|
1265 | - |
|
1266 | - if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_ROOM)) { |
|
1267 | - try { |
|
1268 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_ROOM); |
|
1269 | - $share = $provider->getShareByToken($token); |
|
1270 | - } catch (ProviderException $e) { |
|
1271 | - } catch (ShareNotFound $e) { |
|
1272 | - } |
|
1273 | - } |
|
1274 | - |
|
1275 | - if ($share === null) { |
|
1276 | - throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
1277 | - } |
|
1278 | - |
|
1279 | - $this->checkExpireDate($share); |
|
1280 | - |
|
1281 | - /* |
|
1083 | + $shares2 = []; |
|
1084 | + |
|
1085 | + while(true) { |
|
1086 | + $added = 0; |
|
1087 | + foreach ($shares as $share) { |
|
1088 | + |
|
1089 | + try { |
|
1090 | + $this->checkExpireDate($share); |
|
1091 | + } catch (ShareNotFound $e) { |
|
1092 | + //Ignore since this basically means the share is deleted |
|
1093 | + continue; |
|
1094 | + } |
|
1095 | + |
|
1096 | + $added++; |
|
1097 | + $shares2[] = $share; |
|
1098 | + |
|
1099 | + if (count($shares2) === $limit) { |
|
1100 | + break; |
|
1101 | + } |
|
1102 | + } |
|
1103 | + |
|
1104 | + // If we did not fetch more shares than the limit then there are no more shares |
|
1105 | + if (count($shares) < $limit) { |
|
1106 | + break; |
|
1107 | + } |
|
1108 | + |
|
1109 | + if (count($shares2) === $limit) { |
|
1110 | + break; |
|
1111 | + } |
|
1112 | + |
|
1113 | + // If there was no limit on the select we are done |
|
1114 | + if ($limit === -1) { |
|
1115 | + break; |
|
1116 | + } |
|
1117 | + |
|
1118 | + $offset += $added; |
|
1119 | + |
|
1120 | + // Fetch again $limit shares |
|
1121 | + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
1122 | + |
|
1123 | + // No more shares means we are done |
|
1124 | + if (empty($shares)) { |
|
1125 | + break; |
|
1126 | + } |
|
1127 | + } |
|
1128 | + |
|
1129 | + $shares = $shares2; |
|
1130 | + |
|
1131 | + return $shares; |
|
1132 | + } |
|
1133 | + |
|
1134 | + /** |
|
1135 | + * @inheritdoc |
|
1136 | + */ |
|
1137 | + public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
1138 | + try { |
|
1139 | + $provider = $this->factory->getProviderForType($shareType); |
|
1140 | + } catch (ProviderException $e) { |
|
1141 | + return []; |
|
1142 | + } |
|
1143 | + |
|
1144 | + $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
1145 | + |
|
1146 | + // remove all shares which are already expired |
|
1147 | + foreach ($shares as $key => $share) { |
|
1148 | + try { |
|
1149 | + $this->checkExpireDate($share); |
|
1150 | + } catch (ShareNotFound $e) { |
|
1151 | + unset($shares[$key]); |
|
1152 | + } |
|
1153 | + } |
|
1154 | + |
|
1155 | + return $shares; |
|
1156 | + } |
|
1157 | + |
|
1158 | + /** |
|
1159 | + * @inheritdoc |
|
1160 | + */ |
|
1161 | + public function getDeletedSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
1162 | + $shares = $this->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
1163 | + |
|
1164 | + // Only get deleted shares |
|
1165 | + $shares = array_filter($shares, function(IShare $share) { |
|
1166 | + return $share->getPermissions() === 0; |
|
1167 | + }); |
|
1168 | + |
|
1169 | + // Only get shares where the owner still exists |
|
1170 | + $shares = array_filter($shares, function (IShare $share) { |
|
1171 | + return $this->userManager->userExists($share->getShareOwner()); |
|
1172 | + }); |
|
1173 | + |
|
1174 | + return $shares; |
|
1175 | + } |
|
1176 | + |
|
1177 | + /** |
|
1178 | + * @inheritdoc |
|
1179 | + */ |
|
1180 | + public function getShareById($id, $recipient = null) { |
|
1181 | + if ($id === null) { |
|
1182 | + throw new ShareNotFound(); |
|
1183 | + } |
|
1184 | + |
|
1185 | + list($providerId, $id) = $this->splitFullId($id); |
|
1186 | + |
|
1187 | + try { |
|
1188 | + $provider = $this->factory->getProvider($providerId); |
|
1189 | + } catch (ProviderException $e) { |
|
1190 | + throw new ShareNotFound(); |
|
1191 | + } |
|
1192 | + |
|
1193 | + $share = $provider->getShareById($id, $recipient); |
|
1194 | + |
|
1195 | + $this->checkExpireDate($share); |
|
1196 | + |
|
1197 | + return $share; |
|
1198 | + } |
|
1199 | + |
|
1200 | + /** |
|
1201 | + * Get all the shares for a given path |
|
1202 | + * |
|
1203 | + * @param \OCP\Files\Node $path |
|
1204 | + * @param int $page |
|
1205 | + * @param int $perPage |
|
1206 | + * |
|
1207 | + * @return Share[] |
|
1208 | + */ |
|
1209 | + public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
|
1210 | + return []; |
|
1211 | + } |
|
1212 | + |
|
1213 | + /** |
|
1214 | + * Get the share by token possible with password |
|
1215 | + * |
|
1216 | + * @param string $token |
|
1217 | + * @return Share |
|
1218 | + * |
|
1219 | + * @throws ShareNotFound |
|
1220 | + */ |
|
1221 | + public function getShareByToken($token) { |
|
1222 | + // tokens can't be valid local user names |
|
1223 | + if ($this->userManager->userExists($token)) { |
|
1224 | + throw new ShareNotFound(); |
|
1225 | + } |
|
1226 | + $share = null; |
|
1227 | + try { |
|
1228 | + if($this->shareApiAllowLinks()) { |
|
1229 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK); |
|
1230 | + $share = $provider->getShareByToken($token); |
|
1231 | + } |
|
1232 | + } catch (ProviderException $e) { |
|
1233 | + } catch (ShareNotFound $e) { |
|
1234 | + } |
|
1235 | + |
|
1236 | + |
|
1237 | + // If it is not a link share try to fetch a federated share by token |
|
1238 | + if ($share === null) { |
|
1239 | + try { |
|
1240 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE); |
|
1241 | + $share = $provider->getShareByToken($token); |
|
1242 | + } catch (ProviderException $e) { |
|
1243 | + } catch (ShareNotFound $e) { |
|
1244 | + } |
|
1245 | + } |
|
1246 | + |
|
1247 | + // If it is not a link share try to fetch a mail share by token |
|
1248 | + if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
1249 | + try { |
|
1250 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_EMAIL); |
|
1251 | + $share = $provider->getShareByToken($token); |
|
1252 | + } catch (ProviderException $e) { |
|
1253 | + } catch (ShareNotFound $e) { |
|
1254 | + } |
|
1255 | + } |
|
1256 | + |
|
1257 | + if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
1258 | + try { |
|
1259 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_CIRCLE); |
|
1260 | + $share = $provider->getShareByToken($token); |
|
1261 | + } catch (ProviderException $e) { |
|
1262 | + } catch (ShareNotFound $e) { |
|
1263 | + } |
|
1264 | + } |
|
1265 | + |
|
1266 | + if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_ROOM)) { |
|
1267 | + try { |
|
1268 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_ROOM); |
|
1269 | + $share = $provider->getShareByToken($token); |
|
1270 | + } catch (ProviderException $e) { |
|
1271 | + } catch (ShareNotFound $e) { |
|
1272 | + } |
|
1273 | + } |
|
1274 | + |
|
1275 | + if ($share === null) { |
|
1276 | + throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
1277 | + } |
|
1278 | + |
|
1279 | + $this->checkExpireDate($share); |
|
1280 | + |
|
1281 | + /* |
|
1282 | 1282 | * Reduce the permissions for link shares if public upload is not enabled |
1283 | 1283 | */ |
1284 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && |
|
1285 | - !$this->shareApiLinkAllowPublicUpload()) { |
|
1286 | - $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); |
|
1287 | - } |
|
1288 | - |
|
1289 | - return $share; |
|
1290 | - } |
|
1291 | - |
|
1292 | - protected function checkExpireDate($share) { |
|
1293 | - if ($share->getExpirationDate() !== null && |
|
1294 | - $share->getExpirationDate() <= new \DateTime()) { |
|
1295 | - $this->deleteShare($share); |
|
1296 | - throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
1297 | - } |
|
1298 | - |
|
1299 | - } |
|
1300 | - |
|
1301 | - /** |
|
1302 | - * Verify the password of a public share |
|
1303 | - * |
|
1304 | - * @param \OCP\Share\IShare $share |
|
1305 | - * @param string $password |
|
1306 | - * @return bool |
|
1307 | - */ |
|
1308 | - public function checkPassword(\OCP\Share\IShare $share, $password) { |
|
1309 | - $passwordProtected = $share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK |
|
1310 | - || $share->getShareType() !== \OCP\Share::SHARE_TYPE_EMAIL; |
|
1311 | - if (!$passwordProtected) { |
|
1312 | - //TODO maybe exception? |
|
1313 | - return false; |
|
1314 | - } |
|
1315 | - |
|
1316 | - if ($password === null || $share->getPassword() === null) { |
|
1317 | - return false; |
|
1318 | - } |
|
1319 | - |
|
1320 | - $newHash = ''; |
|
1321 | - if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) { |
|
1322 | - return false; |
|
1323 | - } |
|
1324 | - |
|
1325 | - if (!empty($newHash)) { |
|
1326 | - $share->setPassword($newHash); |
|
1327 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
1328 | - $provider->update($share); |
|
1329 | - } |
|
1330 | - |
|
1331 | - return true; |
|
1332 | - } |
|
1333 | - |
|
1334 | - /** |
|
1335 | - * @inheritdoc |
|
1336 | - */ |
|
1337 | - public function userDeleted($uid) { |
|
1338 | - $types = [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE, \OCP\Share::SHARE_TYPE_EMAIL]; |
|
1339 | - |
|
1340 | - foreach ($types as $type) { |
|
1341 | - try { |
|
1342 | - $provider = $this->factory->getProviderForType($type); |
|
1343 | - } catch (ProviderException $e) { |
|
1344 | - continue; |
|
1345 | - } |
|
1346 | - $provider->userDeleted($uid, $type); |
|
1347 | - } |
|
1348 | - } |
|
1349 | - |
|
1350 | - /** |
|
1351 | - * @inheritdoc |
|
1352 | - */ |
|
1353 | - public function groupDeleted($gid) { |
|
1354 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
1355 | - $provider->groupDeleted($gid); |
|
1356 | - } |
|
1357 | - |
|
1358 | - /** |
|
1359 | - * @inheritdoc |
|
1360 | - */ |
|
1361 | - public function userDeletedFromGroup($uid, $gid) { |
|
1362 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
1363 | - $provider->userDeletedFromGroup($uid, $gid); |
|
1364 | - } |
|
1365 | - |
|
1366 | - /** |
|
1367 | - * Get access list to a path. This means |
|
1368 | - * all the users that can access a given path. |
|
1369 | - * |
|
1370 | - * Consider: |
|
1371 | - * -root |
|
1372 | - * |-folder1 (23) |
|
1373 | - * |-folder2 (32) |
|
1374 | - * |-fileA (42) |
|
1375 | - * |
|
1376 | - * fileA is shared with user1 and user1@server1 |
|
1377 | - * folder2 is shared with group2 (user4 is a member of group2) |
|
1378 | - * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
1379 | - * |
|
1380 | - * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
1381 | - * [ |
|
1382 | - * users => [ |
|
1383 | - * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
1384 | - * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
1385 | - * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
1386 | - * ], |
|
1387 | - * remote => [ |
|
1388 | - * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
1389 | - * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
1390 | - * ], |
|
1391 | - * public => bool |
|
1392 | - * mail => bool |
|
1393 | - * ] |
|
1394 | - * |
|
1395 | - * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
1396 | - * [ |
|
1397 | - * users => ['user1', 'user2', 'user4'], |
|
1398 | - * remote => bool, |
|
1399 | - * public => bool |
|
1400 | - * mail => bool |
|
1401 | - * ] |
|
1402 | - * |
|
1403 | - * This is required for encryption/activity |
|
1404 | - * |
|
1405 | - * @param \OCP\Files\Node $path |
|
1406 | - * @param bool $recursive Should we check all parent folders as well |
|
1407 | - * @param bool $currentAccess Ensure the recipient has access to the file (e.g. did not unshare it) |
|
1408 | - * @return array |
|
1409 | - */ |
|
1410 | - public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { |
|
1411 | - $owner = $path->getOwner()->getUID(); |
|
1412 | - |
|
1413 | - if ($currentAccess) { |
|
1414 | - $al = ['users' => [], 'remote' => [], 'public' => false]; |
|
1415 | - } else { |
|
1416 | - $al = ['users' => [], 'remote' => false, 'public' => false]; |
|
1417 | - } |
|
1418 | - if (!$this->userManager->userExists($owner)) { |
|
1419 | - return $al; |
|
1420 | - } |
|
1421 | - |
|
1422 | - //Get node for the owner and correct the owner in case of external storages |
|
1423 | - $userFolder = $this->rootFolder->getUserFolder($owner); |
|
1424 | - if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) { |
|
1425 | - $nodes = $userFolder->getById($path->getId()); |
|
1426 | - $path = array_shift($nodes); |
|
1427 | - $owner = $path->getOwner()->getUID(); |
|
1428 | - } |
|
1429 | - |
|
1430 | - $providers = $this->factory->getAllProviders(); |
|
1431 | - |
|
1432 | - /** @var Node[] $nodes */ |
|
1433 | - $nodes = []; |
|
1434 | - |
|
1435 | - |
|
1436 | - if ($currentAccess) { |
|
1437 | - $ownerPath = $path->getPath(); |
|
1438 | - $ownerPath = explode('/', $ownerPath, 4); |
|
1439 | - if (count($ownerPath) < 4) { |
|
1440 | - $ownerPath = ''; |
|
1441 | - } else { |
|
1442 | - $ownerPath = $ownerPath[3]; |
|
1443 | - } |
|
1444 | - $al['users'][$owner] = [ |
|
1445 | - 'node_id' => $path->getId(), |
|
1446 | - 'node_path' => '/' . $ownerPath, |
|
1447 | - ]; |
|
1448 | - } else { |
|
1449 | - $al['users'][] = $owner; |
|
1450 | - } |
|
1451 | - |
|
1452 | - // Collect all the shares |
|
1453 | - while ($path->getPath() !== $userFolder->getPath()) { |
|
1454 | - $nodes[] = $path; |
|
1455 | - if (!$recursive) { |
|
1456 | - break; |
|
1457 | - } |
|
1458 | - $path = $path->getParent(); |
|
1459 | - } |
|
1460 | - |
|
1461 | - foreach ($providers as $provider) { |
|
1462 | - $tmp = $provider->getAccessList($nodes, $currentAccess); |
|
1463 | - |
|
1464 | - foreach ($tmp as $k => $v) { |
|
1465 | - if (isset($al[$k])) { |
|
1466 | - if (is_array($al[$k])) { |
|
1467 | - if ($currentAccess) { |
|
1468 | - $al[$k] += $v; |
|
1469 | - } else { |
|
1470 | - $al[$k] = array_merge($al[$k], $v); |
|
1471 | - $al[$k] = array_unique($al[$k]); |
|
1472 | - $al[$k] = array_values($al[$k]); |
|
1473 | - } |
|
1474 | - } else { |
|
1475 | - $al[$k] = $al[$k] || $v; |
|
1476 | - } |
|
1477 | - } else { |
|
1478 | - $al[$k] = $v; |
|
1479 | - } |
|
1480 | - } |
|
1481 | - } |
|
1482 | - |
|
1483 | - return $al; |
|
1484 | - } |
|
1485 | - |
|
1486 | - /** |
|
1487 | - * Create a new share |
|
1488 | - * @return \OCP\Share\IShare |
|
1489 | - */ |
|
1490 | - public function newShare() { |
|
1491 | - return new \OC\Share20\Share($this->rootFolder, $this->userManager); |
|
1492 | - } |
|
1493 | - |
|
1494 | - /** |
|
1495 | - * Is the share API enabled |
|
1496 | - * |
|
1497 | - * @return bool |
|
1498 | - */ |
|
1499 | - public function shareApiEnabled() { |
|
1500 | - return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; |
|
1501 | - } |
|
1502 | - |
|
1503 | - /** |
|
1504 | - * Is public link sharing enabled |
|
1505 | - * |
|
1506 | - * @return bool |
|
1507 | - */ |
|
1508 | - public function shareApiAllowLinks() { |
|
1509 | - return $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
1510 | - } |
|
1511 | - |
|
1512 | - /** |
|
1513 | - * Is password on public link requires |
|
1514 | - * |
|
1515 | - * @return bool |
|
1516 | - */ |
|
1517 | - public function shareApiLinkEnforcePassword() { |
|
1518 | - return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; |
|
1519 | - } |
|
1520 | - |
|
1521 | - /** |
|
1522 | - * Is default expire date enabled |
|
1523 | - * |
|
1524 | - * @return bool |
|
1525 | - */ |
|
1526 | - public function shareApiLinkDefaultExpireDate() { |
|
1527 | - return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
1528 | - } |
|
1529 | - |
|
1530 | - /** |
|
1531 | - * Is default expire date enforced |
|
1532 | - *` |
|
1533 | - * @return bool |
|
1534 | - */ |
|
1535 | - public function shareApiLinkDefaultExpireDateEnforced() { |
|
1536 | - return $this->shareApiLinkDefaultExpireDate() && |
|
1537 | - $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
1538 | - } |
|
1539 | - |
|
1540 | - /** |
|
1541 | - * Number of default expire days |
|
1542 | - *shareApiLinkAllowPublicUpload |
|
1543 | - * @return int |
|
1544 | - */ |
|
1545 | - public function shareApiLinkDefaultExpireDays() { |
|
1546 | - return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
1547 | - } |
|
1548 | - |
|
1549 | - /** |
|
1550 | - * Allow public upload on link shares |
|
1551 | - * |
|
1552 | - * @return bool |
|
1553 | - */ |
|
1554 | - public function shareApiLinkAllowPublicUpload() { |
|
1555 | - return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
1556 | - } |
|
1557 | - |
|
1558 | - /** |
|
1559 | - * check if user can only share with group members |
|
1560 | - * @return bool |
|
1561 | - */ |
|
1562 | - public function shareWithGroupMembersOnly() { |
|
1563 | - return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
1564 | - } |
|
1565 | - |
|
1566 | - /** |
|
1567 | - * Check if users can share with groups |
|
1568 | - * @return bool |
|
1569 | - */ |
|
1570 | - public function allowGroupSharing() { |
|
1571 | - return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
1572 | - } |
|
1573 | - |
|
1574 | - /** |
|
1575 | - * Copied from \OC_Util::isSharingDisabledForUser |
|
1576 | - * |
|
1577 | - * TODO: Deprecate fuction from OC_Util |
|
1578 | - * |
|
1579 | - * @param string $userId |
|
1580 | - * @return bool |
|
1581 | - */ |
|
1582 | - public function sharingDisabledForUser($userId) { |
|
1583 | - if ($userId === null) { |
|
1584 | - return false; |
|
1585 | - } |
|
1586 | - |
|
1587 | - if (isset($this->sharingDisabledForUsersCache[$userId])) { |
|
1588 | - return $this->sharingDisabledForUsersCache[$userId]; |
|
1589 | - } |
|
1590 | - |
|
1591 | - if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
1592 | - $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
1593 | - $excludedGroups = json_decode($groupsList); |
|
1594 | - if (is_null($excludedGroups)) { |
|
1595 | - $excludedGroups = explode(',', $groupsList); |
|
1596 | - $newValue = json_encode($excludedGroups); |
|
1597 | - $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
1598 | - } |
|
1599 | - $user = $this->userManager->get($userId); |
|
1600 | - $usersGroups = $this->groupManager->getUserGroupIds($user); |
|
1601 | - if (!empty($usersGroups)) { |
|
1602 | - $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
1603 | - // if the user is only in groups which are disabled for sharing then |
|
1604 | - // sharing is also disabled for the user |
|
1605 | - if (empty($remainingGroups)) { |
|
1606 | - $this->sharingDisabledForUsersCache[$userId] = true; |
|
1607 | - return true; |
|
1608 | - } |
|
1609 | - } |
|
1610 | - } |
|
1611 | - |
|
1612 | - $this->sharingDisabledForUsersCache[$userId] = false; |
|
1613 | - return false; |
|
1614 | - } |
|
1615 | - |
|
1616 | - /** |
|
1617 | - * @inheritdoc |
|
1618 | - */ |
|
1619 | - public function outgoingServer2ServerSharesAllowed() { |
|
1620 | - return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
1621 | - } |
|
1622 | - |
|
1623 | - /** |
|
1624 | - * @inheritdoc |
|
1625 | - */ |
|
1626 | - public function outgoingServer2ServerGroupSharesAllowed() { |
|
1627 | - return $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no') === 'yes'; |
|
1628 | - } |
|
1629 | - |
|
1630 | - /** |
|
1631 | - * @inheritdoc |
|
1632 | - */ |
|
1633 | - public function shareProviderExists($shareType) { |
|
1634 | - try { |
|
1635 | - $this->factory->getProviderForType($shareType); |
|
1636 | - } catch (ProviderException $e) { |
|
1637 | - return false; |
|
1638 | - } |
|
1639 | - |
|
1640 | - return true; |
|
1641 | - } |
|
1284 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && |
|
1285 | + !$this->shareApiLinkAllowPublicUpload()) { |
|
1286 | + $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); |
|
1287 | + } |
|
1288 | + |
|
1289 | + return $share; |
|
1290 | + } |
|
1291 | + |
|
1292 | + protected function checkExpireDate($share) { |
|
1293 | + if ($share->getExpirationDate() !== null && |
|
1294 | + $share->getExpirationDate() <= new \DateTime()) { |
|
1295 | + $this->deleteShare($share); |
|
1296 | + throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
1297 | + } |
|
1298 | + |
|
1299 | + } |
|
1300 | + |
|
1301 | + /** |
|
1302 | + * Verify the password of a public share |
|
1303 | + * |
|
1304 | + * @param \OCP\Share\IShare $share |
|
1305 | + * @param string $password |
|
1306 | + * @return bool |
|
1307 | + */ |
|
1308 | + public function checkPassword(\OCP\Share\IShare $share, $password) { |
|
1309 | + $passwordProtected = $share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK |
|
1310 | + || $share->getShareType() !== \OCP\Share::SHARE_TYPE_EMAIL; |
|
1311 | + if (!$passwordProtected) { |
|
1312 | + //TODO maybe exception? |
|
1313 | + return false; |
|
1314 | + } |
|
1315 | + |
|
1316 | + if ($password === null || $share->getPassword() === null) { |
|
1317 | + return false; |
|
1318 | + } |
|
1319 | + |
|
1320 | + $newHash = ''; |
|
1321 | + if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) { |
|
1322 | + return false; |
|
1323 | + } |
|
1324 | + |
|
1325 | + if (!empty($newHash)) { |
|
1326 | + $share->setPassword($newHash); |
|
1327 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
1328 | + $provider->update($share); |
|
1329 | + } |
|
1330 | + |
|
1331 | + return true; |
|
1332 | + } |
|
1333 | + |
|
1334 | + /** |
|
1335 | + * @inheritdoc |
|
1336 | + */ |
|
1337 | + public function userDeleted($uid) { |
|
1338 | + $types = [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE, \OCP\Share::SHARE_TYPE_EMAIL]; |
|
1339 | + |
|
1340 | + foreach ($types as $type) { |
|
1341 | + try { |
|
1342 | + $provider = $this->factory->getProviderForType($type); |
|
1343 | + } catch (ProviderException $e) { |
|
1344 | + continue; |
|
1345 | + } |
|
1346 | + $provider->userDeleted($uid, $type); |
|
1347 | + } |
|
1348 | + } |
|
1349 | + |
|
1350 | + /** |
|
1351 | + * @inheritdoc |
|
1352 | + */ |
|
1353 | + public function groupDeleted($gid) { |
|
1354 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
1355 | + $provider->groupDeleted($gid); |
|
1356 | + } |
|
1357 | + |
|
1358 | + /** |
|
1359 | + * @inheritdoc |
|
1360 | + */ |
|
1361 | + public function userDeletedFromGroup($uid, $gid) { |
|
1362 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
1363 | + $provider->userDeletedFromGroup($uid, $gid); |
|
1364 | + } |
|
1365 | + |
|
1366 | + /** |
|
1367 | + * Get access list to a path. This means |
|
1368 | + * all the users that can access a given path. |
|
1369 | + * |
|
1370 | + * Consider: |
|
1371 | + * -root |
|
1372 | + * |-folder1 (23) |
|
1373 | + * |-folder2 (32) |
|
1374 | + * |-fileA (42) |
|
1375 | + * |
|
1376 | + * fileA is shared with user1 and user1@server1 |
|
1377 | + * folder2 is shared with group2 (user4 is a member of group2) |
|
1378 | + * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
1379 | + * |
|
1380 | + * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
1381 | + * [ |
|
1382 | + * users => [ |
|
1383 | + * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
1384 | + * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
1385 | + * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
1386 | + * ], |
|
1387 | + * remote => [ |
|
1388 | + * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
1389 | + * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
1390 | + * ], |
|
1391 | + * public => bool |
|
1392 | + * mail => bool |
|
1393 | + * ] |
|
1394 | + * |
|
1395 | + * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
1396 | + * [ |
|
1397 | + * users => ['user1', 'user2', 'user4'], |
|
1398 | + * remote => bool, |
|
1399 | + * public => bool |
|
1400 | + * mail => bool |
|
1401 | + * ] |
|
1402 | + * |
|
1403 | + * This is required for encryption/activity |
|
1404 | + * |
|
1405 | + * @param \OCP\Files\Node $path |
|
1406 | + * @param bool $recursive Should we check all parent folders as well |
|
1407 | + * @param bool $currentAccess Ensure the recipient has access to the file (e.g. did not unshare it) |
|
1408 | + * @return array |
|
1409 | + */ |
|
1410 | + public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { |
|
1411 | + $owner = $path->getOwner()->getUID(); |
|
1412 | + |
|
1413 | + if ($currentAccess) { |
|
1414 | + $al = ['users' => [], 'remote' => [], 'public' => false]; |
|
1415 | + } else { |
|
1416 | + $al = ['users' => [], 'remote' => false, 'public' => false]; |
|
1417 | + } |
|
1418 | + if (!$this->userManager->userExists($owner)) { |
|
1419 | + return $al; |
|
1420 | + } |
|
1421 | + |
|
1422 | + //Get node for the owner and correct the owner in case of external storages |
|
1423 | + $userFolder = $this->rootFolder->getUserFolder($owner); |
|
1424 | + if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) { |
|
1425 | + $nodes = $userFolder->getById($path->getId()); |
|
1426 | + $path = array_shift($nodes); |
|
1427 | + $owner = $path->getOwner()->getUID(); |
|
1428 | + } |
|
1429 | + |
|
1430 | + $providers = $this->factory->getAllProviders(); |
|
1431 | + |
|
1432 | + /** @var Node[] $nodes */ |
|
1433 | + $nodes = []; |
|
1434 | + |
|
1435 | + |
|
1436 | + if ($currentAccess) { |
|
1437 | + $ownerPath = $path->getPath(); |
|
1438 | + $ownerPath = explode('/', $ownerPath, 4); |
|
1439 | + if (count($ownerPath) < 4) { |
|
1440 | + $ownerPath = ''; |
|
1441 | + } else { |
|
1442 | + $ownerPath = $ownerPath[3]; |
|
1443 | + } |
|
1444 | + $al['users'][$owner] = [ |
|
1445 | + 'node_id' => $path->getId(), |
|
1446 | + 'node_path' => '/' . $ownerPath, |
|
1447 | + ]; |
|
1448 | + } else { |
|
1449 | + $al['users'][] = $owner; |
|
1450 | + } |
|
1451 | + |
|
1452 | + // Collect all the shares |
|
1453 | + while ($path->getPath() !== $userFolder->getPath()) { |
|
1454 | + $nodes[] = $path; |
|
1455 | + if (!$recursive) { |
|
1456 | + break; |
|
1457 | + } |
|
1458 | + $path = $path->getParent(); |
|
1459 | + } |
|
1460 | + |
|
1461 | + foreach ($providers as $provider) { |
|
1462 | + $tmp = $provider->getAccessList($nodes, $currentAccess); |
|
1463 | + |
|
1464 | + foreach ($tmp as $k => $v) { |
|
1465 | + if (isset($al[$k])) { |
|
1466 | + if (is_array($al[$k])) { |
|
1467 | + if ($currentAccess) { |
|
1468 | + $al[$k] += $v; |
|
1469 | + } else { |
|
1470 | + $al[$k] = array_merge($al[$k], $v); |
|
1471 | + $al[$k] = array_unique($al[$k]); |
|
1472 | + $al[$k] = array_values($al[$k]); |
|
1473 | + } |
|
1474 | + } else { |
|
1475 | + $al[$k] = $al[$k] || $v; |
|
1476 | + } |
|
1477 | + } else { |
|
1478 | + $al[$k] = $v; |
|
1479 | + } |
|
1480 | + } |
|
1481 | + } |
|
1482 | + |
|
1483 | + return $al; |
|
1484 | + } |
|
1485 | + |
|
1486 | + /** |
|
1487 | + * Create a new share |
|
1488 | + * @return \OCP\Share\IShare |
|
1489 | + */ |
|
1490 | + public function newShare() { |
|
1491 | + return new \OC\Share20\Share($this->rootFolder, $this->userManager); |
|
1492 | + } |
|
1493 | + |
|
1494 | + /** |
|
1495 | + * Is the share API enabled |
|
1496 | + * |
|
1497 | + * @return bool |
|
1498 | + */ |
|
1499 | + public function shareApiEnabled() { |
|
1500 | + return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; |
|
1501 | + } |
|
1502 | + |
|
1503 | + /** |
|
1504 | + * Is public link sharing enabled |
|
1505 | + * |
|
1506 | + * @return bool |
|
1507 | + */ |
|
1508 | + public function shareApiAllowLinks() { |
|
1509 | + return $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
1510 | + } |
|
1511 | + |
|
1512 | + /** |
|
1513 | + * Is password on public link requires |
|
1514 | + * |
|
1515 | + * @return bool |
|
1516 | + */ |
|
1517 | + public function shareApiLinkEnforcePassword() { |
|
1518 | + return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; |
|
1519 | + } |
|
1520 | + |
|
1521 | + /** |
|
1522 | + * Is default expire date enabled |
|
1523 | + * |
|
1524 | + * @return bool |
|
1525 | + */ |
|
1526 | + public function shareApiLinkDefaultExpireDate() { |
|
1527 | + return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
1528 | + } |
|
1529 | + |
|
1530 | + /** |
|
1531 | + * Is default expire date enforced |
|
1532 | + *` |
|
1533 | + * @return bool |
|
1534 | + */ |
|
1535 | + public function shareApiLinkDefaultExpireDateEnforced() { |
|
1536 | + return $this->shareApiLinkDefaultExpireDate() && |
|
1537 | + $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
1538 | + } |
|
1539 | + |
|
1540 | + /** |
|
1541 | + * Number of default expire days |
|
1542 | + *shareApiLinkAllowPublicUpload |
|
1543 | + * @return int |
|
1544 | + */ |
|
1545 | + public function shareApiLinkDefaultExpireDays() { |
|
1546 | + return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
1547 | + } |
|
1548 | + |
|
1549 | + /** |
|
1550 | + * Allow public upload on link shares |
|
1551 | + * |
|
1552 | + * @return bool |
|
1553 | + */ |
|
1554 | + public function shareApiLinkAllowPublicUpload() { |
|
1555 | + return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
1556 | + } |
|
1557 | + |
|
1558 | + /** |
|
1559 | + * check if user can only share with group members |
|
1560 | + * @return bool |
|
1561 | + */ |
|
1562 | + public function shareWithGroupMembersOnly() { |
|
1563 | + return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
1564 | + } |
|
1565 | + |
|
1566 | + /** |
|
1567 | + * Check if users can share with groups |
|
1568 | + * @return bool |
|
1569 | + */ |
|
1570 | + public function allowGroupSharing() { |
|
1571 | + return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
1572 | + } |
|
1573 | + |
|
1574 | + /** |
|
1575 | + * Copied from \OC_Util::isSharingDisabledForUser |
|
1576 | + * |
|
1577 | + * TODO: Deprecate fuction from OC_Util |
|
1578 | + * |
|
1579 | + * @param string $userId |
|
1580 | + * @return bool |
|
1581 | + */ |
|
1582 | + public function sharingDisabledForUser($userId) { |
|
1583 | + if ($userId === null) { |
|
1584 | + return false; |
|
1585 | + } |
|
1586 | + |
|
1587 | + if (isset($this->sharingDisabledForUsersCache[$userId])) { |
|
1588 | + return $this->sharingDisabledForUsersCache[$userId]; |
|
1589 | + } |
|
1590 | + |
|
1591 | + if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
1592 | + $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
1593 | + $excludedGroups = json_decode($groupsList); |
|
1594 | + if (is_null($excludedGroups)) { |
|
1595 | + $excludedGroups = explode(',', $groupsList); |
|
1596 | + $newValue = json_encode($excludedGroups); |
|
1597 | + $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
1598 | + } |
|
1599 | + $user = $this->userManager->get($userId); |
|
1600 | + $usersGroups = $this->groupManager->getUserGroupIds($user); |
|
1601 | + if (!empty($usersGroups)) { |
|
1602 | + $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
1603 | + // if the user is only in groups which are disabled for sharing then |
|
1604 | + // sharing is also disabled for the user |
|
1605 | + if (empty($remainingGroups)) { |
|
1606 | + $this->sharingDisabledForUsersCache[$userId] = true; |
|
1607 | + return true; |
|
1608 | + } |
|
1609 | + } |
|
1610 | + } |
|
1611 | + |
|
1612 | + $this->sharingDisabledForUsersCache[$userId] = false; |
|
1613 | + return false; |
|
1614 | + } |
|
1615 | + |
|
1616 | + /** |
|
1617 | + * @inheritdoc |
|
1618 | + */ |
|
1619 | + public function outgoingServer2ServerSharesAllowed() { |
|
1620 | + return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
1621 | + } |
|
1622 | + |
|
1623 | + /** |
|
1624 | + * @inheritdoc |
|
1625 | + */ |
|
1626 | + public function outgoingServer2ServerGroupSharesAllowed() { |
|
1627 | + return $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no') === 'yes'; |
|
1628 | + } |
|
1629 | + |
|
1630 | + /** |
|
1631 | + * @inheritdoc |
|
1632 | + */ |
|
1633 | + public function shareProviderExists($shareType) { |
|
1634 | + try { |
|
1635 | + $this->factory->getProviderForType($shareType); |
|
1636 | + } catch (ProviderException $e) { |
|
1637 | + return false; |
|
1638 | + } |
|
1639 | + |
|
1640 | + return true; |
|
1641 | + } |
|
1642 | 1642 | |
1643 | 1643 | } |
@@ -170,1893 +170,1893 @@ |
||
170 | 170 | * TODO: hookup all manager classes |
171 | 171 | */ |
172 | 172 | class Server extends ServerContainer implements IServerContainer { |
173 | - /** @var string */ |
|
174 | - private $webRoot; |
|
175 | - |
|
176 | - /** |
|
177 | - * @param string $webRoot |
|
178 | - * @param \OC\Config $config |
|
179 | - */ |
|
180 | - public function __construct($webRoot, \OC\Config $config) { |
|
181 | - parent::__construct(); |
|
182 | - $this->webRoot = $webRoot; |
|
183 | - |
|
184 | - // To find out if we are running from CLI or not |
|
185 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
186 | - |
|
187 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
188 | - return $c; |
|
189 | - }); |
|
190 | - |
|
191 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
192 | - $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
193 | - |
|
194 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
195 | - $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
196 | - |
|
197 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
198 | - $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
199 | - |
|
200 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
201 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
202 | - |
|
203 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
204 | - |
|
205 | - |
|
206 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
207 | - return new PreviewManager( |
|
208 | - $c->getConfig(), |
|
209 | - $c->getRootFolder(), |
|
210 | - $c->getAppDataDir('preview'), |
|
211 | - $c->getEventDispatcher(), |
|
212 | - $c->getSession()->get('user_id') |
|
213 | - ); |
|
214 | - }); |
|
215 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
216 | - |
|
217 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
218 | - return new \OC\Preview\Watcher( |
|
219 | - $c->getAppDataDir('preview') |
|
220 | - ); |
|
221 | - }); |
|
222 | - |
|
223 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
224 | - $view = new View(); |
|
225 | - $util = new Encryption\Util( |
|
226 | - $view, |
|
227 | - $c->getUserManager(), |
|
228 | - $c->getGroupManager(), |
|
229 | - $c->getConfig() |
|
230 | - ); |
|
231 | - return new Encryption\Manager( |
|
232 | - $c->getConfig(), |
|
233 | - $c->getLogger(), |
|
234 | - $c->getL10N('core'), |
|
235 | - new View(), |
|
236 | - $util, |
|
237 | - new ArrayCache() |
|
238 | - ); |
|
239 | - }); |
|
240 | - $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
241 | - |
|
242 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
243 | - $util = new Encryption\Util( |
|
244 | - new View(), |
|
245 | - $c->getUserManager(), |
|
246 | - $c->getGroupManager(), |
|
247 | - $c->getConfig() |
|
248 | - ); |
|
249 | - return new Encryption\File( |
|
250 | - $util, |
|
251 | - $c->getRootFolder(), |
|
252 | - $c->getShareManager() |
|
253 | - ); |
|
254 | - }); |
|
255 | - |
|
256 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
257 | - $view = new View(); |
|
258 | - $util = new Encryption\Util( |
|
259 | - $view, |
|
260 | - $c->getUserManager(), |
|
261 | - $c->getGroupManager(), |
|
262 | - $c->getConfig() |
|
263 | - ); |
|
264 | - |
|
265 | - return new Encryption\Keys\Storage($view, $util); |
|
266 | - }); |
|
267 | - $this->registerService('TagMapper', function (Server $c) { |
|
268 | - return new TagMapper($c->getDatabaseConnection()); |
|
269 | - }); |
|
270 | - |
|
271 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
272 | - $tagMapper = $c->query('TagMapper'); |
|
273 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
274 | - }); |
|
275 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
276 | - |
|
277 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
278 | - $config = $c->getConfig(); |
|
279 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
280 | - return new $factoryClass($this); |
|
281 | - }); |
|
282 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
283 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
284 | - }); |
|
285 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
286 | - |
|
287 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
288 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
289 | - }); |
|
290 | - $this->registerService('RootFolder', function (Server $c) { |
|
291 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
292 | - $view = new View(); |
|
293 | - $root = new Root( |
|
294 | - $manager, |
|
295 | - $view, |
|
296 | - null, |
|
297 | - $c->getUserMountCache(), |
|
298 | - $this->getLogger(), |
|
299 | - $this->getUserManager() |
|
300 | - ); |
|
301 | - $connector = new HookConnector($root, $view); |
|
302 | - $connector->viewToNode(); |
|
303 | - |
|
304 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
305 | - $previewConnector->connectWatcher(); |
|
306 | - |
|
307 | - return $root; |
|
308 | - }); |
|
309 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
310 | - |
|
311 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
312 | - return new LazyRoot(function () use ($c) { |
|
313 | - return $c->query('RootFolder'); |
|
314 | - }); |
|
315 | - }); |
|
316 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
317 | - |
|
318 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
319 | - return new \OC\User\Manager($c->getConfig(), $c->getEventDispatcher()); |
|
320 | - }); |
|
321 | - $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
322 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
323 | - |
|
324 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
325 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
|
326 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
327 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
328 | - }); |
|
329 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
330 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
331 | - }); |
|
332 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
333 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
334 | - }); |
|
335 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
336 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
337 | - }); |
|
338 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
339 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
340 | - }); |
|
341 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
342 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
343 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
344 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
345 | - }); |
|
346 | - return $groupManager; |
|
347 | - }); |
|
348 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
349 | - |
|
350 | - $this->registerService(Store::class, function (Server $c) { |
|
351 | - $session = $c->getSession(); |
|
352 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
353 | - $tokenProvider = $c->query(IProvider::class); |
|
354 | - } else { |
|
355 | - $tokenProvider = null; |
|
356 | - } |
|
357 | - $logger = $c->getLogger(); |
|
358 | - return new Store($session, $logger, $tokenProvider); |
|
359 | - }); |
|
360 | - $this->registerAlias(IStore::class, Store::class); |
|
361 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
362 | - $dbConnection = $c->getDatabaseConnection(); |
|
363 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
364 | - }); |
|
365 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
366 | - |
|
367 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
368 | - $manager = $c->getUserManager(); |
|
369 | - $session = new \OC\Session\Memory(''); |
|
370 | - $timeFactory = new TimeFactory(); |
|
371 | - // Token providers might require a working database. This code |
|
372 | - // might however be called when ownCloud is not yet setup. |
|
373 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
374 | - $defaultTokenProvider = $c->query(IProvider::class); |
|
375 | - } else { |
|
376 | - $defaultTokenProvider = null; |
|
377 | - } |
|
378 | - |
|
379 | - $dispatcher = $c->getEventDispatcher(); |
|
380 | - |
|
381 | - $userSession = new \OC\User\Session( |
|
382 | - $manager, |
|
383 | - $session, |
|
384 | - $timeFactory, |
|
385 | - $defaultTokenProvider, |
|
386 | - $c->getConfig(), |
|
387 | - $c->getSecureRandom(), |
|
388 | - $c->getLockdownManager(), |
|
389 | - $c->getLogger() |
|
390 | - ); |
|
391 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
392 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
393 | - }); |
|
394 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
395 | - /** @var $user \OC\User\User */ |
|
396 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
397 | - }); |
|
398 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
399 | - /** @var $user \OC\User\User */ |
|
400 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
401 | - $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
402 | - }); |
|
403 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
404 | - /** @var $user \OC\User\User */ |
|
405 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
406 | - }); |
|
407 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
408 | - /** @var $user \OC\User\User */ |
|
409 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
410 | - }); |
|
411 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
412 | - /** @var $user \OC\User\User */ |
|
413 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
414 | - }); |
|
415 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
416 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
417 | - }); |
|
418 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
419 | - /** @var $user \OC\User\User */ |
|
420 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin)); |
|
421 | - }); |
|
422 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
423 | - /** @var $user \OC\User\User */ |
|
424 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
425 | - }); |
|
426 | - $userSession->listen('\OC\User', 'logout', function () { |
|
427 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
428 | - }); |
|
429 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
430 | - /** @var $user \OC\User\User */ |
|
431 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
432 | - $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
433 | - }); |
|
434 | - return $userSession; |
|
435 | - }); |
|
436 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
437 | - $this->registerAlias('UserSession', \OC\User\Session::class); |
|
438 | - |
|
439 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
440 | - |
|
441 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
442 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
443 | - |
|
444 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
445 | - return new \OC\AllConfig( |
|
446 | - $c->getSystemConfig() |
|
447 | - ); |
|
448 | - }); |
|
449 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
450 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
451 | - |
|
452 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
453 | - return new \OC\SystemConfig($config); |
|
454 | - }); |
|
455 | - |
|
456 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
457 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
458 | - }); |
|
459 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
460 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
461 | - |
|
462 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
463 | - return new \OC\L10N\Factory( |
|
464 | - $c->getConfig(), |
|
465 | - $c->getRequest(), |
|
466 | - $c->getUserSession(), |
|
467 | - \OC::$SERVERROOT |
|
468 | - ); |
|
469 | - }); |
|
470 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
471 | - |
|
472 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
473 | - $config = $c->getConfig(); |
|
474 | - $cacheFactory = $c->getMemCacheFactory(); |
|
475 | - $request = $c->getRequest(); |
|
476 | - return new \OC\URLGenerator( |
|
477 | - $config, |
|
478 | - $cacheFactory, |
|
479 | - $request |
|
480 | - ); |
|
481 | - }); |
|
482 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
483 | - |
|
484 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
485 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
486 | - |
|
487 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
488 | - return new Cache\File(); |
|
489 | - }); |
|
490 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
491 | - |
|
492 | - $this->registerService(Factory::class, function (Server $c) { |
|
493 | - |
|
494 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
495 | - ArrayCache::class, |
|
496 | - ArrayCache::class, |
|
497 | - ArrayCache::class |
|
498 | - ); |
|
499 | - $config = $c->getConfig(); |
|
500 | - |
|
501 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
502 | - $v = \OC_App::getAppVersions(); |
|
503 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
504 | - $version = implode(',', $v); |
|
505 | - $instanceId = \OC_Util::getInstanceId(); |
|
506 | - $path = \OC::$SERVERROOT; |
|
507 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
508 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
509 | - $config->getSystemValue('memcache.local', null), |
|
510 | - $config->getSystemValue('memcache.distributed', null), |
|
511 | - $config->getSystemValue('memcache.locking', null) |
|
512 | - ); |
|
513 | - } |
|
514 | - return $arrayCacheFactory; |
|
515 | - |
|
516 | - }); |
|
517 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
518 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
519 | - |
|
520 | - $this->registerService('RedisFactory', function (Server $c) { |
|
521 | - $systemConfig = $c->getSystemConfig(); |
|
522 | - return new RedisFactory($systemConfig); |
|
523 | - }); |
|
524 | - |
|
525 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
526 | - return new \OC\Activity\Manager( |
|
527 | - $c->getRequest(), |
|
528 | - $c->getUserSession(), |
|
529 | - $c->getConfig(), |
|
530 | - $c->query(IValidator::class) |
|
531 | - ); |
|
532 | - }); |
|
533 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
534 | - |
|
535 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
536 | - return new \OC\Activity\EventMerger( |
|
537 | - $c->getL10N('lib') |
|
538 | - ); |
|
539 | - }); |
|
540 | - $this->registerAlias(IValidator::class, Validator::class); |
|
541 | - |
|
542 | - $this->registerService(AvatarManager::class, function(Server $c) { |
|
543 | - return new AvatarManager( |
|
544 | - $c->query(\OC\User\Manager::class), |
|
545 | - $c->getAppDataDir('avatar'), |
|
546 | - $c->getL10N('lib'), |
|
547 | - $c->getLogger(), |
|
548 | - $c->getConfig() |
|
549 | - ); |
|
550 | - }); |
|
551 | - $this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class); |
|
552 | - $this->registerAlias('AvatarManager', AvatarManager::class); |
|
553 | - |
|
554 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
555 | - |
|
556 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
557 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
558 | - $factory = new LogFactory($c, $this->getSystemConfig()); |
|
559 | - $logger = $factory->get($logType); |
|
560 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
561 | - |
|
562 | - return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
563 | - }); |
|
564 | - $this->registerAlias(\OCP\ILogger::class, \OC\Log::class); |
|
565 | - $this->registerAlias('Logger', \OC\Log::class); |
|
566 | - |
|
567 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
568 | - return new LogFactory($c, $this->getSystemConfig()); |
|
569 | - }); |
|
570 | - |
|
571 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
572 | - $config = $c->getConfig(); |
|
573 | - return new \OC\BackgroundJob\JobList( |
|
574 | - $c->getDatabaseConnection(), |
|
575 | - $config, |
|
576 | - new TimeFactory() |
|
577 | - ); |
|
578 | - }); |
|
579 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
580 | - |
|
581 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
582 | - $cacheFactory = $c->getMemCacheFactory(); |
|
583 | - $logger = $c->getLogger(); |
|
584 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
585 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
586 | - } else { |
|
587 | - $router = new \OC\Route\Router($logger); |
|
588 | - } |
|
589 | - return $router; |
|
590 | - }); |
|
591 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
592 | - |
|
593 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
594 | - return new Search(); |
|
595 | - }); |
|
596 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
597 | - |
|
598 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
599 | - return new \OC\Security\RateLimiting\Limiter( |
|
600 | - $this->getUserSession(), |
|
601 | - $this->getRequest(), |
|
602 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
603 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
604 | - ); |
|
605 | - }); |
|
606 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
607 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
608 | - $this->getMemCacheFactory(), |
|
609 | - new \OC\AppFramework\Utility\TimeFactory() |
|
610 | - ); |
|
611 | - }); |
|
612 | - |
|
613 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
614 | - return new SecureRandom(); |
|
615 | - }); |
|
616 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
617 | - |
|
618 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
619 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
620 | - }); |
|
621 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
622 | - |
|
623 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
624 | - return new Hasher($c->getConfig()); |
|
625 | - }); |
|
626 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
627 | - |
|
628 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
629 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
630 | - }); |
|
631 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
632 | - |
|
633 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
634 | - $systemConfig = $c->getSystemConfig(); |
|
635 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
636 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
637 | - if (!$factory->isValidType($type)) { |
|
638 | - throw new \OC\DatabaseException('Invalid database type'); |
|
639 | - } |
|
640 | - $connectionParams = $factory->createConnectionParams(); |
|
641 | - $connection = $factory->getConnection($type, $connectionParams); |
|
642 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
643 | - return $connection; |
|
644 | - }); |
|
645 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
646 | - |
|
647 | - |
|
648 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
649 | - $user = \OC_User::getUser(); |
|
650 | - $uid = $user ? $user : null; |
|
651 | - return new ClientService( |
|
652 | - $c->getConfig(), |
|
653 | - new \OC\Security\CertificateManager( |
|
654 | - $uid, |
|
655 | - new View(), |
|
656 | - $c->getConfig(), |
|
657 | - $c->getLogger(), |
|
658 | - $c->getSecureRandom() |
|
659 | - ) |
|
660 | - ); |
|
661 | - }); |
|
662 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
663 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
664 | - $eventLogger = new EventLogger(); |
|
665 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
666 | - // In debug mode, module is being activated by default |
|
667 | - $eventLogger->activate(); |
|
668 | - } |
|
669 | - return $eventLogger; |
|
670 | - }); |
|
671 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
672 | - |
|
673 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
674 | - $queryLogger = new QueryLogger(); |
|
675 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
676 | - // In debug mode, module is being activated by default |
|
677 | - $queryLogger->activate(); |
|
678 | - } |
|
679 | - return $queryLogger; |
|
680 | - }); |
|
681 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
682 | - |
|
683 | - $this->registerService(TempManager::class, function (Server $c) { |
|
684 | - return new TempManager( |
|
685 | - $c->getLogger(), |
|
686 | - $c->getConfig() |
|
687 | - ); |
|
688 | - }); |
|
689 | - $this->registerAlias('TempManager', TempManager::class); |
|
690 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
691 | - |
|
692 | - $this->registerService(AppManager::class, function (Server $c) { |
|
693 | - return new \OC\App\AppManager( |
|
694 | - $c->getUserSession(), |
|
695 | - $c->query(\OC\AppConfig::class), |
|
696 | - $c->getGroupManager(), |
|
697 | - $c->getMemCacheFactory(), |
|
698 | - $c->getEventDispatcher() |
|
699 | - ); |
|
700 | - }); |
|
701 | - $this->registerAlias('AppManager', AppManager::class); |
|
702 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
703 | - |
|
704 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
705 | - return new DateTimeZone( |
|
706 | - $c->getConfig(), |
|
707 | - $c->getSession() |
|
708 | - ); |
|
709 | - }); |
|
710 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
711 | - |
|
712 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
713 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
714 | - |
|
715 | - return new DateTimeFormatter( |
|
716 | - $c->getDateTimeZone()->getTimeZone(), |
|
717 | - $c->getL10N('lib', $language) |
|
718 | - ); |
|
719 | - }); |
|
720 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
721 | - |
|
722 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
723 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
724 | - $listener = new UserMountCacheListener($mountCache); |
|
725 | - $listener->listen($c->getUserManager()); |
|
726 | - return $mountCache; |
|
727 | - }); |
|
728 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
729 | - |
|
730 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
731 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
732 | - $mountCache = $c->query('UserMountCache'); |
|
733 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
734 | - |
|
735 | - // builtin providers |
|
736 | - |
|
737 | - $config = $c->getConfig(); |
|
738 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
739 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
740 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
741 | - |
|
742 | - return $manager; |
|
743 | - }); |
|
744 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
745 | - |
|
746 | - $this->registerService('IniWrapper', function ($c) { |
|
747 | - return new IniGetWrapper(); |
|
748 | - }); |
|
749 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
750 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
751 | - if ($busClass) { |
|
752 | - list($app, $class) = explode('::', $busClass, 2); |
|
753 | - if ($c->getAppManager()->isInstalled($app)) { |
|
754 | - \OC_App::loadApp($app); |
|
755 | - return $c->query($class); |
|
756 | - } else { |
|
757 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
758 | - } |
|
759 | - } else { |
|
760 | - $jobList = $c->getJobList(); |
|
761 | - return new CronBus($jobList); |
|
762 | - } |
|
763 | - }); |
|
764 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
765 | - return new TrustedDomainHelper($this->getConfig()); |
|
766 | - }); |
|
767 | - $this->registerService(Throttler::class, function (Server $c) { |
|
768 | - return new Throttler( |
|
769 | - $c->getDatabaseConnection(), |
|
770 | - new TimeFactory(), |
|
771 | - $c->getLogger(), |
|
772 | - $c->getConfig() |
|
773 | - ); |
|
774 | - }); |
|
775 | - $this->registerAlias('Throttler', Throttler::class); |
|
776 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
777 | - // IConfig and IAppManager requires a working database. This code |
|
778 | - // might however be called when ownCloud is not yet setup. |
|
779 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
780 | - $config = $c->getConfig(); |
|
781 | - $appManager = $c->getAppManager(); |
|
782 | - } else { |
|
783 | - $config = null; |
|
784 | - $appManager = null; |
|
785 | - } |
|
786 | - |
|
787 | - return new Checker( |
|
788 | - new EnvironmentHelper(), |
|
789 | - new FileAccessHelper(), |
|
790 | - new AppLocator(), |
|
791 | - $config, |
|
792 | - $c->getMemCacheFactory(), |
|
793 | - $appManager, |
|
794 | - $c->getTempManager() |
|
795 | - ); |
|
796 | - }); |
|
797 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
798 | - if (isset($this['urlParams'])) { |
|
799 | - $urlParams = $this['urlParams']; |
|
800 | - } else { |
|
801 | - $urlParams = []; |
|
802 | - } |
|
803 | - |
|
804 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
805 | - && in_array('fakeinput', stream_get_wrappers()) |
|
806 | - ) { |
|
807 | - $stream = 'fakeinput://data'; |
|
808 | - } else { |
|
809 | - $stream = 'php://input'; |
|
810 | - } |
|
811 | - |
|
812 | - return new Request( |
|
813 | - [ |
|
814 | - 'get' => $_GET, |
|
815 | - 'post' => $_POST, |
|
816 | - 'files' => $_FILES, |
|
817 | - 'server' => $_SERVER, |
|
818 | - 'env' => $_ENV, |
|
819 | - 'cookies' => $_COOKIE, |
|
820 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
821 | - ? $_SERVER['REQUEST_METHOD'] |
|
822 | - : '', |
|
823 | - 'urlParams' => $urlParams, |
|
824 | - ], |
|
825 | - $this->getSecureRandom(), |
|
826 | - $this->getConfig(), |
|
827 | - $this->getCsrfTokenManager(), |
|
828 | - $stream |
|
829 | - ); |
|
830 | - }); |
|
831 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
832 | - |
|
833 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
834 | - return new Mailer( |
|
835 | - $c->getConfig(), |
|
836 | - $c->getLogger(), |
|
837 | - $c->query(Defaults::class), |
|
838 | - $c->getURLGenerator(), |
|
839 | - $c->getL10N('lib') |
|
840 | - ); |
|
841 | - }); |
|
842 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
843 | - |
|
844 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
845 | - $config = $c->getConfig(); |
|
846 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
847 | - if (is_null($factoryClass)) { |
|
848 | - throw new \Exception('ldapProviderFactory not set'); |
|
849 | - } |
|
850 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
851 | - $factory = new $factoryClass($this); |
|
852 | - return $factory->getLDAPProvider(); |
|
853 | - }); |
|
854 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
855 | - $ini = $c->getIniWrapper(); |
|
856 | - $config = $c->getConfig(); |
|
857 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
858 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
859 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
860 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
861 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
862 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
863 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
864 | - } |
|
865 | - return new DBLockingProvider( |
|
866 | - $c->getDatabaseConnection(), |
|
867 | - $c->getLogger(), |
|
868 | - new TimeFactory(), |
|
869 | - $ttl, |
|
870 | - !\OC::$CLI |
|
871 | - ); |
|
872 | - } |
|
873 | - return new NoopLockingProvider(); |
|
874 | - }); |
|
875 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
876 | - |
|
877 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
878 | - return new \OC\Files\Mount\Manager(); |
|
879 | - }); |
|
880 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
881 | - |
|
882 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
883 | - return new \OC\Files\Type\Detection( |
|
884 | - $c->getURLGenerator(), |
|
885 | - \OC::$configDir, |
|
886 | - \OC::$SERVERROOT . '/resources/config/' |
|
887 | - ); |
|
888 | - }); |
|
889 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
890 | - |
|
891 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
892 | - return new \OC\Files\Type\Loader( |
|
893 | - $c->getDatabaseConnection() |
|
894 | - ); |
|
895 | - }); |
|
896 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
897 | - $this->registerService(BundleFetcher::class, function () { |
|
898 | - return new BundleFetcher($this->getL10N('lib')); |
|
899 | - }); |
|
900 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
901 | - return new Manager( |
|
902 | - $c->query(IValidator::class) |
|
903 | - ); |
|
904 | - }); |
|
905 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
906 | - |
|
907 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
908 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
909 | - $manager->registerCapability(function () use ($c) { |
|
910 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
911 | - }); |
|
912 | - $manager->registerCapability(function () use ($c) { |
|
913 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
914 | - }); |
|
915 | - return $manager; |
|
916 | - }); |
|
917 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
918 | - |
|
919 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
920 | - $config = $c->getConfig(); |
|
921 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
922 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
923 | - $factory = new $factoryClass($this); |
|
924 | - $manager = $factory->getManager(); |
|
925 | - |
|
926 | - $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
927 | - $manager = $c->getUserManager(); |
|
928 | - $user = $manager->get($id); |
|
929 | - if(is_null($user)) { |
|
930 | - $l = $c->getL10N('core'); |
|
931 | - $displayName = $l->t('Unknown user'); |
|
932 | - } else { |
|
933 | - $displayName = $user->getDisplayName(); |
|
934 | - } |
|
935 | - return $displayName; |
|
936 | - }); |
|
937 | - |
|
938 | - return $manager; |
|
939 | - }); |
|
940 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
941 | - |
|
942 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
943 | - /* |
|
173 | + /** @var string */ |
|
174 | + private $webRoot; |
|
175 | + |
|
176 | + /** |
|
177 | + * @param string $webRoot |
|
178 | + * @param \OC\Config $config |
|
179 | + */ |
|
180 | + public function __construct($webRoot, \OC\Config $config) { |
|
181 | + parent::__construct(); |
|
182 | + $this->webRoot = $webRoot; |
|
183 | + |
|
184 | + // To find out if we are running from CLI or not |
|
185 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
186 | + |
|
187 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
188 | + return $c; |
|
189 | + }); |
|
190 | + |
|
191 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
192 | + $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
193 | + |
|
194 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
195 | + $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
196 | + |
|
197 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
198 | + $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
199 | + |
|
200 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
201 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
202 | + |
|
203 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
204 | + |
|
205 | + |
|
206 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
207 | + return new PreviewManager( |
|
208 | + $c->getConfig(), |
|
209 | + $c->getRootFolder(), |
|
210 | + $c->getAppDataDir('preview'), |
|
211 | + $c->getEventDispatcher(), |
|
212 | + $c->getSession()->get('user_id') |
|
213 | + ); |
|
214 | + }); |
|
215 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
216 | + |
|
217 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
218 | + return new \OC\Preview\Watcher( |
|
219 | + $c->getAppDataDir('preview') |
|
220 | + ); |
|
221 | + }); |
|
222 | + |
|
223 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
224 | + $view = new View(); |
|
225 | + $util = new Encryption\Util( |
|
226 | + $view, |
|
227 | + $c->getUserManager(), |
|
228 | + $c->getGroupManager(), |
|
229 | + $c->getConfig() |
|
230 | + ); |
|
231 | + return new Encryption\Manager( |
|
232 | + $c->getConfig(), |
|
233 | + $c->getLogger(), |
|
234 | + $c->getL10N('core'), |
|
235 | + new View(), |
|
236 | + $util, |
|
237 | + new ArrayCache() |
|
238 | + ); |
|
239 | + }); |
|
240 | + $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
241 | + |
|
242 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
243 | + $util = new Encryption\Util( |
|
244 | + new View(), |
|
245 | + $c->getUserManager(), |
|
246 | + $c->getGroupManager(), |
|
247 | + $c->getConfig() |
|
248 | + ); |
|
249 | + return new Encryption\File( |
|
250 | + $util, |
|
251 | + $c->getRootFolder(), |
|
252 | + $c->getShareManager() |
|
253 | + ); |
|
254 | + }); |
|
255 | + |
|
256 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
257 | + $view = new View(); |
|
258 | + $util = new Encryption\Util( |
|
259 | + $view, |
|
260 | + $c->getUserManager(), |
|
261 | + $c->getGroupManager(), |
|
262 | + $c->getConfig() |
|
263 | + ); |
|
264 | + |
|
265 | + return new Encryption\Keys\Storage($view, $util); |
|
266 | + }); |
|
267 | + $this->registerService('TagMapper', function (Server $c) { |
|
268 | + return new TagMapper($c->getDatabaseConnection()); |
|
269 | + }); |
|
270 | + |
|
271 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
272 | + $tagMapper = $c->query('TagMapper'); |
|
273 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
274 | + }); |
|
275 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
276 | + |
|
277 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
278 | + $config = $c->getConfig(); |
|
279 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
280 | + return new $factoryClass($this); |
|
281 | + }); |
|
282 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
283 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
284 | + }); |
|
285 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
286 | + |
|
287 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
288 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
289 | + }); |
|
290 | + $this->registerService('RootFolder', function (Server $c) { |
|
291 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
292 | + $view = new View(); |
|
293 | + $root = new Root( |
|
294 | + $manager, |
|
295 | + $view, |
|
296 | + null, |
|
297 | + $c->getUserMountCache(), |
|
298 | + $this->getLogger(), |
|
299 | + $this->getUserManager() |
|
300 | + ); |
|
301 | + $connector = new HookConnector($root, $view); |
|
302 | + $connector->viewToNode(); |
|
303 | + |
|
304 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
305 | + $previewConnector->connectWatcher(); |
|
306 | + |
|
307 | + return $root; |
|
308 | + }); |
|
309 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
310 | + |
|
311 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
312 | + return new LazyRoot(function () use ($c) { |
|
313 | + return $c->query('RootFolder'); |
|
314 | + }); |
|
315 | + }); |
|
316 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
317 | + |
|
318 | + $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
319 | + return new \OC\User\Manager($c->getConfig(), $c->getEventDispatcher()); |
|
320 | + }); |
|
321 | + $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
322 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
323 | + |
|
324 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
325 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
|
326 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
327 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
328 | + }); |
|
329 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
330 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
331 | + }); |
|
332 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
333 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
334 | + }); |
|
335 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
336 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
337 | + }); |
|
338 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
339 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
340 | + }); |
|
341 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
342 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
343 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
344 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
345 | + }); |
|
346 | + return $groupManager; |
|
347 | + }); |
|
348 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
349 | + |
|
350 | + $this->registerService(Store::class, function (Server $c) { |
|
351 | + $session = $c->getSession(); |
|
352 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
353 | + $tokenProvider = $c->query(IProvider::class); |
|
354 | + } else { |
|
355 | + $tokenProvider = null; |
|
356 | + } |
|
357 | + $logger = $c->getLogger(); |
|
358 | + return new Store($session, $logger, $tokenProvider); |
|
359 | + }); |
|
360 | + $this->registerAlias(IStore::class, Store::class); |
|
361 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
362 | + $dbConnection = $c->getDatabaseConnection(); |
|
363 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
364 | + }); |
|
365 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
366 | + |
|
367 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
368 | + $manager = $c->getUserManager(); |
|
369 | + $session = new \OC\Session\Memory(''); |
|
370 | + $timeFactory = new TimeFactory(); |
|
371 | + // Token providers might require a working database. This code |
|
372 | + // might however be called when ownCloud is not yet setup. |
|
373 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
374 | + $defaultTokenProvider = $c->query(IProvider::class); |
|
375 | + } else { |
|
376 | + $defaultTokenProvider = null; |
|
377 | + } |
|
378 | + |
|
379 | + $dispatcher = $c->getEventDispatcher(); |
|
380 | + |
|
381 | + $userSession = new \OC\User\Session( |
|
382 | + $manager, |
|
383 | + $session, |
|
384 | + $timeFactory, |
|
385 | + $defaultTokenProvider, |
|
386 | + $c->getConfig(), |
|
387 | + $c->getSecureRandom(), |
|
388 | + $c->getLockdownManager(), |
|
389 | + $c->getLogger() |
|
390 | + ); |
|
391 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
392 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
393 | + }); |
|
394 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
395 | + /** @var $user \OC\User\User */ |
|
396 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
397 | + }); |
|
398 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
399 | + /** @var $user \OC\User\User */ |
|
400 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
401 | + $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
402 | + }); |
|
403 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
404 | + /** @var $user \OC\User\User */ |
|
405 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
406 | + }); |
|
407 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
408 | + /** @var $user \OC\User\User */ |
|
409 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
410 | + }); |
|
411 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
412 | + /** @var $user \OC\User\User */ |
|
413 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
414 | + }); |
|
415 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
416 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
417 | + }); |
|
418 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
419 | + /** @var $user \OC\User\User */ |
|
420 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin)); |
|
421 | + }); |
|
422 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
423 | + /** @var $user \OC\User\User */ |
|
424 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
425 | + }); |
|
426 | + $userSession->listen('\OC\User', 'logout', function () { |
|
427 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
428 | + }); |
|
429 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
430 | + /** @var $user \OC\User\User */ |
|
431 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
432 | + $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
433 | + }); |
|
434 | + return $userSession; |
|
435 | + }); |
|
436 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
437 | + $this->registerAlias('UserSession', \OC\User\Session::class); |
|
438 | + |
|
439 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
440 | + |
|
441 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
442 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
443 | + |
|
444 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
445 | + return new \OC\AllConfig( |
|
446 | + $c->getSystemConfig() |
|
447 | + ); |
|
448 | + }); |
|
449 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
450 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
451 | + |
|
452 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
453 | + return new \OC\SystemConfig($config); |
|
454 | + }); |
|
455 | + |
|
456 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
457 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
458 | + }); |
|
459 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
460 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
461 | + |
|
462 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
463 | + return new \OC\L10N\Factory( |
|
464 | + $c->getConfig(), |
|
465 | + $c->getRequest(), |
|
466 | + $c->getUserSession(), |
|
467 | + \OC::$SERVERROOT |
|
468 | + ); |
|
469 | + }); |
|
470 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
471 | + |
|
472 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
473 | + $config = $c->getConfig(); |
|
474 | + $cacheFactory = $c->getMemCacheFactory(); |
|
475 | + $request = $c->getRequest(); |
|
476 | + return new \OC\URLGenerator( |
|
477 | + $config, |
|
478 | + $cacheFactory, |
|
479 | + $request |
|
480 | + ); |
|
481 | + }); |
|
482 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
483 | + |
|
484 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
485 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
486 | + |
|
487 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
488 | + return new Cache\File(); |
|
489 | + }); |
|
490 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
491 | + |
|
492 | + $this->registerService(Factory::class, function (Server $c) { |
|
493 | + |
|
494 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
495 | + ArrayCache::class, |
|
496 | + ArrayCache::class, |
|
497 | + ArrayCache::class |
|
498 | + ); |
|
499 | + $config = $c->getConfig(); |
|
500 | + |
|
501 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
502 | + $v = \OC_App::getAppVersions(); |
|
503 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
504 | + $version = implode(',', $v); |
|
505 | + $instanceId = \OC_Util::getInstanceId(); |
|
506 | + $path = \OC::$SERVERROOT; |
|
507 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
508 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
509 | + $config->getSystemValue('memcache.local', null), |
|
510 | + $config->getSystemValue('memcache.distributed', null), |
|
511 | + $config->getSystemValue('memcache.locking', null) |
|
512 | + ); |
|
513 | + } |
|
514 | + return $arrayCacheFactory; |
|
515 | + |
|
516 | + }); |
|
517 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
518 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
519 | + |
|
520 | + $this->registerService('RedisFactory', function (Server $c) { |
|
521 | + $systemConfig = $c->getSystemConfig(); |
|
522 | + return new RedisFactory($systemConfig); |
|
523 | + }); |
|
524 | + |
|
525 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
526 | + return new \OC\Activity\Manager( |
|
527 | + $c->getRequest(), |
|
528 | + $c->getUserSession(), |
|
529 | + $c->getConfig(), |
|
530 | + $c->query(IValidator::class) |
|
531 | + ); |
|
532 | + }); |
|
533 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
534 | + |
|
535 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
536 | + return new \OC\Activity\EventMerger( |
|
537 | + $c->getL10N('lib') |
|
538 | + ); |
|
539 | + }); |
|
540 | + $this->registerAlias(IValidator::class, Validator::class); |
|
541 | + |
|
542 | + $this->registerService(AvatarManager::class, function(Server $c) { |
|
543 | + return new AvatarManager( |
|
544 | + $c->query(\OC\User\Manager::class), |
|
545 | + $c->getAppDataDir('avatar'), |
|
546 | + $c->getL10N('lib'), |
|
547 | + $c->getLogger(), |
|
548 | + $c->getConfig() |
|
549 | + ); |
|
550 | + }); |
|
551 | + $this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class); |
|
552 | + $this->registerAlias('AvatarManager', AvatarManager::class); |
|
553 | + |
|
554 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
555 | + |
|
556 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
557 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
558 | + $factory = new LogFactory($c, $this->getSystemConfig()); |
|
559 | + $logger = $factory->get($logType); |
|
560 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
561 | + |
|
562 | + return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
563 | + }); |
|
564 | + $this->registerAlias(\OCP\ILogger::class, \OC\Log::class); |
|
565 | + $this->registerAlias('Logger', \OC\Log::class); |
|
566 | + |
|
567 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
568 | + return new LogFactory($c, $this->getSystemConfig()); |
|
569 | + }); |
|
570 | + |
|
571 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
572 | + $config = $c->getConfig(); |
|
573 | + return new \OC\BackgroundJob\JobList( |
|
574 | + $c->getDatabaseConnection(), |
|
575 | + $config, |
|
576 | + new TimeFactory() |
|
577 | + ); |
|
578 | + }); |
|
579 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
580 | + |
|
581 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
582 | + $cacheFactory = $c->getMemCacheFactory(); |
|
583 | + $logger = $c->getLogger(); |
|
584 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
585 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
586 | + } else { |
|
587 | + $router = new \OC\Route\Router($logger); |
|
588 | + } |
|
589 | + return $router; |
|
590 | + }); |
|
591 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
592 | + |
|
593 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
594 | + return new Search(); |
|
595 | + }); |
|
596 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
597 | + |
|
598 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
599 | + return new \OC\Security\RateLimiting\Limiter( |
|
600 | + $this->getUserSession(), |
|
601 | + $this->getRequest(), |
|
602 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
603 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
604 | + ); |
|
605 | + }); |
|
606 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
607 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
608 | + $this->getMemCacheFactory(), |
|
609 | + new \OC\AppFramework\Utility\TimeFactory() |
|
610 | + ); |
|
611 | + }); |
|
612 | + |
|
613 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
614 | + return new SecureRandom(); |
|
615 | + }); |
|
616 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
617 | + |
|
618 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
619 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
620 | + }); |
|
621 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
622 | + |
|
623 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
624 | + return new Hasher($c->getConfig()); |
|
625 | + }); |
|
626 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
627 | + |
|
628 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
629 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
630 | + }); |
|
631 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
632 | + |
|
633 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
634 | + $systemConfig = $c->getSystemConfig(); |
|
635 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
636 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
637 | + if (!$factory->isValidType($type)) { |
|
638 | + throw new \OC\DatabaseException('Invalid database type'); |
|
639 | + } |
|
640 | + $connectionParams = $factory->createConnectionParams(); |
|
641 | + $connection = $factory->getConnection($type, $connectionParams); |
|
642 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
643 | + return $connection; |
|
644 | + }); |
|
645 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
646 | + |
|
647 | + |
|
648 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
649 | + $user = \OC_User::getUser(); |
|
650 | + $uid = $user ? $user : null; |
|
651 | + return new ClientService( |
|
652 | + $c->getConfig(), |
|
653 | + new \OC\Security\CertificateManager( |
|
654 | + $uid, |
|
655 | + new View(), |
|
656 | + $c->getConfig(), |
|
657 | + $c->getLogger(), |
|
658 | + $c->getSecureRandom() |
|
659 | + ) |
|
660 | + ); |
|
661 | + }); |
|
662 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
663 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
664 | + $eventLogger = new EventLogger(); |
|
665 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
666 | + // In debug mode, module is being activated by default |
|
667 | + $eventLogger->activate(); |
|
668 | + } |
|
669 | + return $eventLogger; |
|
670 | + }); |
|
671 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
672 | + |
|
673 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
674 | + $queryLogger = new QueryLogger(); |
|
675 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
676 | + // In debug mode, module is being activated by default |
|
677 | + $queryLogger->activate(); |
|
678 | + } |
|
679 | + return $queryLogger; |
|
680 | + }); |
|
681 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
682 | + |
|
683 | + $this->registerService(TempManager::class, function (Server $c) { |
|
684 | + return new TempManager( |
|
685 | + $c->getLogger(), |
|
686 | + $c->getConfig() |
|
687 | + ); |
|
688 | + }); |
|
689 | + $this->registerAlias('TempManager', TempManager::class); |
|
690 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
691 | + |
|
692 | + $this->registerService(AppManager::class, function (Server $c) { |
|
693 | + return new \OC\App\AppManager( |
|
694 | + $c->getUserSession(), |
|
695 | + $c->query(\OC\AppConfig::class), |
|
696 | + $c->getGroupManager(), |
|
697 | + $c->getMemCacheFactory(), |
|
698 | + $c->getEventDispatcher() |
|
699 | + ); |
|
700 | + }); |
|
701 | + $this->registerAlias('AppManager', AppManager::class); |
|
702 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
703 | + |
|
704 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
705 | + return new DateTimeZone( |
|
706 | + $c->getConfig(), |
|
707 | + $c->getSession() |
|
708 | + ); |
|
709 | + }); |
|
710 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
711 | + |
|
712 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
713 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
714 | + |
|
715 | + return new DateTimeFormatter( |
|
716 | + $c->getDateTimeZone()->getTimeZone(), |
|
717 | + $c->getL10N('lib', $language) |
|
718 | + ); |
|
719 | + }); |
|
720 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
721 | + |
|
722 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
723 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
724 | + $listener = new UserMountCacheListener($mountCache); |
|
725 | + $listener->listen($c->getUserManager()); |
|
726 | + return $mountCache; |
|
727 | + }); |
|
728 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
729 | + |
|
730 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
731 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
732 | + $mountCache = $c->query('UserMountCache'); |
|
733 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
734 | + |
|
735 | + // builtin providers |
|
736 | + |
|
737 | + $config = $c->getConfig(); |
|
738 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
739 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
740 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
741 | + |
|
742 | + return $manager; |
|
743 | + }); |
|
744 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
745 | + |
|
746 | + $this->registerService('IniWrapper', function ($c) { |
|
747 | + return new IniGetWrapper(); |
|
748 | + }); |
|
749 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
750 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
751 | + if ($busClass) { |
|
752 | + list($app, $class) = explode('::', $busClass, 2); |
|
753 | + if ($c->getAppManager()->isInstalled($app)) { |
|
754 | + \OC_App::loadApp($app); |
|
755 | + return $c->query($class); |
|
756 | + } else { |
|
757 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
758 | + } |
|
759 | + } else { |
|
760 | + $jobList = $c->getJobList(); |
|
761 | + return new CronBus($jobList); |
|
762 | + } |
|
763 | + }); |
|
764 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
765 | + return new TrustedDomainHelper($this->getConfig()); |
|
766 | + }); |
|
767 | + $this->registerService(Throttler::class, function (Server $c) { |
|
768 | + return new Throttler( |
|
769 | + $c->getDatabaseConnection(), |
|
770 | + new TimeFactory(), |
|
771 | + $c->getLogger(), |
|
772 | + $c->getConfig() |
|
773 | + ); |
|
774 | + }); |
|
775 | + $this->registerAlias('Throttler', Throttler::class); |
|
776 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
777 | + // IConfig and IAppManager requires a working database. This code |
|
778 | + // might however be called when ownCloud is not yet setup. |
|
779 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
780 | + $config = $c->getConfig(); |
|
781 | + $appManager = $c->getAppManager(); |
|
782 | + } else { |
|
783 | + $config = null; |
|
784 | + $appManager = null; |
|
785 | + } |
|
786 | + |
|
787 | + return new Checker( |
|
788 | + new EnvironmentHelper(), |
|
789 | + new FileAccessHelper(), |
|
790 | + new AppLocator(), |
|
791 | + $config, |
|
792 | + $c->getMemCacheFactory(), |
|
793 | + $appManager, |
|
794 | + $c->getTempManager() |
|
795 | + ); |
|
796 | + }); |
|
797 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
798 | + if (isset($this['urlParams'])) { |
|
799 | + $urlParams = $this['urlParams']; |
|
800 | + } else { |
|
801 | + $urlParams = []; |
|
802 | + } |
|
803 | + |
|
804 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
805 | + && in_array('fakeinput', stream_get_wrappers()) |
|
806 | + ) { |
|
807 | + $stream = 'fakeinput://data'; |
|
808 | + } else { |
|
809 | + $stream = 'php://input'; |
|
810 | + } |
|
811 | + |
|
812 | + return new Request( |
|
813 | + [ |
|
814 | + 'get' => $_GET, |
|
815 | + 'post' => $_POST, |
|
816 | + 'files' => $_FILES, |
|
817 | + 'server' => $_SERVER, |
|
818 | + 'env' => $_ENV, |
|
819 | + 'cookies' => $_COOKIE, |
|
820 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
821 | + ? $_SERVER['REQUEST_METHOD'] |
|
822 | + : '', |
|
823 | + 'urlParams' => $urlParams, |
|
824 | + ], |
|
825 | + $this->getSecureRandom(), |
|
826 | + $this->getConfig(), |
|
827 | + $this->getCsrfTokenManager(), |
|
828 | + $stream |
|
829 | + ); |
|
830 | + }); |
|
831 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
832 | + |
|
833 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
834 | + return new Mailer( |
|
835 | + $c->getConfig(), |
|
836 | + $c->getLogger(), |
|
837 | + $c->query(Defaults::class), |
|
838 | + $c->getURLGenerator(), |
|
839 | + $c->getL10N('lib') |
|
840 | + ); |
|
841 | + }); |
|
842 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
843 | + |
|
844 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
845 | + $config = $c->getConfig(); |
|
846 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
847 | + if (is_null($factoryClass)) { |
|
848 | + throw new \Exception('ldapProviderFactory not set'); |
|
849 | + } |
|
850 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
851 | + $factory = new $factoryClass($this); |
|
852 | + return $factory->getLDAPProvider(); |
|
853 | + }); |
|
854 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
855 | + $ini = $c->getIniWrapper(); |
|
856 | + $config = $c->getConfig(); |
|
857 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
858 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
859 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
860 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
861 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
862 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
863 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
864 | + } |
|
865 | + return new DBLockingProvider( |
|
866 | + $c->getDatabaseConnection(), |
|
867 | + $c->getLogger(), |
|
868 | + new TimeFactory(), |
|
869 | + $ttl, |
|
870 | + !\OC::$CLI |
|
871 | + ); |
|
872 | + } |
|
873 | + return new NoopLockingProvider(); |
|
874 | + }); |
|
875 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
876 | + |
|
877 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
878 | + return new \OC\Files\Mount\Manager(); |
|
879 | + }); |
|
880 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
881 | + |
|
882 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
883 | + return new \OC\Files\Type\Detection( |
|
884 | + $c->getURLGenerator(), |
|
885 | + \OC::$configDir, |
|
886 | + \OC::$SERVERROOT . '/resources/config/' |
|
887 | + ); |
|
888 | + }); |
|
889 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
890 | + |
|
891 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
892 | + return new \OC\Files\Type\Loader( |
|
893 | + $c->getDatabaseConnection() |
|
894 | + ); |
|
895 | + }); |
|
896 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
897 | + $this->registerService(BundleFetcher::class, function () { |
|
898 | + return new BundleFetcher($this->getL10N('lib')); |
|
899 | + }); |
|
900 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
901 | + return new Manager( |
|
902 | + $c->query(IValidator::class) |
|
903 | + ); |
|
904 | + }); |
|
905 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
906 | + |
|
907 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
908 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
909 | + $manager->registerCapability(function () use ($c) { |
|
910 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
911 | + }); |
|
912 | + $manager->registerCapability(function () use ($c) { |
|
913 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
914 | + }); |
|
915 | + return $manager; |
|
916 | + }); |
|
917 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
918 | + |
|
919 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
920 | + $config = $c->getConfig(); |
|
921 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
922 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
923 | + $factory = new $factoryClass($this); |
|
924 | + $manager = $factory->getManager(); |
|
925 | + |
|
926 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
927 | + $manager = $c->getUserManager(); |
|
928 | + $user = $manager->get($id); |
|
929 | + if(is_null($user)) { |
|
930 | + $l = $c->getL10N('core'); |
|
931 | + $displayName = $l->t('Unknown user'); |
|
932 | + } else { |
|
933 | + $displayName = $user->getDisplayName(); |
|
934 | + } |
|
935 | + return $displayName; |
|
936 | + }); |
|
937 | + |
|
938 | + return $manager; |
|
939 | + }); |
|
940 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
941 | + |
|
942 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
943 | + /* |
|
944 | 944 | * Dark magic for autoloader. |
945 | 945 | * If we do a class_exists it will try to load the class which will |
946 | 946 | * make composer cache the result. Resulting in errors when enabling |
947 | 947 | * the theming app. |
948 | 948 | */ |
949 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
950 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
951 | - $classExists = true; |
|
952 | - } else { |
|
953 | - $classExists = false; |
|
954 | - } |
|
955 | - |
|
956 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
957 | - return new ThemingDefaults( |
|
958 | - $c->getConfig(), |
|
959 | - $c->getL10N('theming'), |
|
960 | - $c->getURLGenerator(), |
|
961 | - $c->getMemCacheFactory(), |
|
962 | - new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
963 | - new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
964 | - $c->getAppManager(), |
|
965 | - $c->getNavigationManager() |
|
966 | - ); |
|
967 | - } |
|
968 | - return new \OC_Defaults(); |
|
969 | - }); |
|
970 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
971 | - return new SCSSCacher( |
|
972 | - $c->getLogger(), |
|
973 | - $c->query(\OC\Files\AppData\Factory::class), |
|
974 | - $c->getURLGenerator(), |
|
975 | - $c->getConfig(), |
|
976 | - $c->getThemingDefaults(), |
|
977 | - \OC::$SERVERROOT, |
|
978 | - $this->getMemCacheFactory(), |
|
979 | - $c->query(IconsCacher::class), |
|
980 | - new TimeFactory() |
|
981 | - ); |
|
982 | - }); |
|
983 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
984 | - return new JSCombiner( |
|
985 | - $c->getAppDataDir('js'), |
|
986 | - $c->getURLGenerator(), |
|
987 | - $this->getMemCacheFactory(), |
|
988 | - $c->getSystemConfig(), |
|
989 | - $c->getLogger() |
|
990 | - ); |
|
991 | - }); |
|
992 | - $this->registerService(EventDispatcher::class, function () { |
|
993 | - return new EventDispatcher(); |
|
994 | - }); |
|
995 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
996 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
997 | - |
|
998 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
999 | - // FIXME: Instantiiated here due to cyclic dependency |
|
1000 | - $request = new Request( |
|
1001 | - [ |
|
1002 | - 'get' => $_GET, |
|
1003 | - 'post' => $_POST, |
|
1004 | - 'files' => $_FILES, |
|
1005 | - 'server' => $_SERVER, |
|
1006 | - 'env' => $_ENV, |
|
1007 | - 'cookies' => $_COOKIE, |
|
1008 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1009 | - ? $_SERVER['REQUEST_METHOD'] |
|
1010 | - : null, |
|
1011 | - ], |
|
1012 | - $c->getSecureRandom(), |
|
1013 | - $c->getConfig() |
|
1014 | - ); |
|
1015 | - |
|
1016 | - return new CryptoWrapper( |
|
1017 | - $c->getConfig(), |
|
1018 | - $c->getCrypto(), |
|
1019 | - $c->getSecureRandom(), |
|
1020 | - $request |
|
1021 | - ); |
|
1022 | - }); |
|
1023 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1024 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1025 | - |
|
1026 | - return new CsrfTokenManager( |
|
1027 | - $tokenGenerator, |
|
1028 | - $c->query(SessionStorage::class) |
|
1029 | - ); |
|
1030 | - }); |
|
1031 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1032 | - return new SessionStorage($c->getSession()); |
|
1033 | - }); |
|
1034 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1035 | - return new ContentSecurityPolicyManager(); |
|
1036 | - }); |
|
1037 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1038 | - |
|
1039 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1040 | - return new ContentSecurityPolicyNonceManager( |
|
1041 | - $c->getCsrfTokenManager(), |
|
1042 | - $c->getRequest() |
|
1043 | - ); |
|
1044 | - }); |
|
1045 | - |
|
1046 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1047 | - $config = $c->getConfig(); |
|
1048 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1049 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1050 | - $factory = new $factoryClass($this); |
|
1051 | - |
|
1052 | - $manager = new \OC\Share20\Manager( |
|
1053 | - $c->getLogger(), |
|
1054 | - $c->getConfig(), |
|
1055 | - $c->getSecureRandom(), |
|
1056 | - $c->getHasher(), |
|
1057 | - $c->getMountManager(), |
|
1058 | - $c->getGroupManager(), |
|
1059 | - $c->getL10N('lib'), |
|
1060 | - $c->getL10NFactory(), |
|
1061 | - $factory, |
|
1062 | - $c->getUserManager(), |
|
1063 | - $c->getLazyRootFolder(), |
|
1064 | - $c->getEventDispatcher(), |
|
1065 | - $c->getMailer(), |
|
1066 | - $c->getURLGenerator(), |
|
1067 | - $c->getThemingDefaults() |
|
1068 | - ); |
|
1069 | - |
|
1070 | - return $manager; |
|
1071 | - }); |
|
1072 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1073 | - |
|
1074 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1075 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1076 | - |
|
1077 | - // register default plugins |
|
1078 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1079 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1080 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1081 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1082 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1083 | - |
|
1084 | - return $instance; |
|
1085 | - }); |
|
1086 | - $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1087 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1088 | - |
|
1089 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1090 | - |
|
1091 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1092 | - |
|
1093 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1094 | - $manager = new \OC\Settings\Manager( |
|
1095 | - $c->getLogger(), |
|
1096 | - $c->getL10N('lib'), |
|
1097 | - $c->getURLGenerator(), |
|
1098 | - $c |
|
1099 | - ); |
|
1100 | - return $manager; |
|
1101 | - }); |
|
1102 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1103 | - return new \OC\Files\AppData\Factory( |
|
1104 | - $c->getRootFolder(), |
|
1105 | - $c->getSystemConfig() |
|
1106 | - ); |
|
1107 | - }); |
|
1108 | - |
|
1109 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1110 | - return new LockdownManager(function () use ($c) { |
|
1111 | - return $c->getSession(); |
|
1112 | - }); |
|
1113 | - }); |
|
1114 | - |
|
1115 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1116 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1117 | - }); |
|
1118 | - |
|
1119 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1120 | - return new CloudIdManager(); |
|
1121 | - }); |
|
1122 | - |
|
1123 | - $this->registerService(IConfig::class, function (Server $c) { |
|
1124 | - return new GlobalScale\Config($c->getConfig()); |
|
1125 | - }); |
|
1126 | - |
|
1127 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1128 | - return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
1129 | - }); |
|
1130 | - |
|
1131 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1132 | - return new CloudFederationFactory(); |
|
1133 | - }); |
|
1134 | - |
|
1135 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1136 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1137 | - |
|
1138 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1139 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1140 | - |
|
1141 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1142 | - return new Defaults( |
|
1143 | - $c->getThemingDefaults() |
|
1144 | - ); |
|
1145 | - }); |
|
1146 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1147 | - |
|
1148 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1149 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1150 | - }); |
|
1151 | - |
|
1152 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1153 | - return new ShareHelper( |
|
1154 | - $c->query(\OCP\Share\IManager::class) |
|
1155 | - ); |
|
1156 | - }); |
|
1157 | - |
|
1158 | - $this->registerService(Installer::class, function(Server $c) { |
|
1159 | - return new Installer( |
|
1160 | - $c->getAppFetcher(), |
|
1161 | - $c->getHTTPClientService(), |
|
1162 | - $c->getTempManager(), |
|
1163 | - $c->getLogger(), |
|
1164 | - $c->getConfig() |
|
1165 | - ); |
|
1166 | - }); |
|
1167 | - |
|
1168 | - $this->registerService(IApiFactory::class, function(Server $c) { |
|
1169 | - return new ApiFactory($c->getHTTPClientService()); |
|
1170 | - }); |
|
1171 | - |
|
1172 | - $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1173 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
1174 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1175 | - }); |
|
1176 | - |
|
1177 | - $this->registerService(IContactsStore::class, function(Server $c) { |
|
1178 | - return new ContactsStore( |
|
1179 | - $c->getContactsManager(), |
|
1180 | - $c->getConfig(), |
|
1181 | - $c->getUserManager(), |
|
1182 | - $c->getGroupManager() |
|
1183 | - ); |
|
1184 | - }); |
|
1185 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1186 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1187 | - |
|
1188 | - $this->registerService(IStorageFactory::class, function() { |
|
1189 | - return new StorageFactory(); |
|
1190 | - }); |
|
1191 | - |
|
1192 | - $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
1193 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1194 | - |
|
1195 | - $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) { |
|
1196 | - return new \OC\Security\IdentityProof\Manager( |
|
1197 | - $c->query(\OC\Files\AppData\Factory::class), |
|
1198 | - $c->getCrypto(), |
|
1199 | - $c->getConfig() |
|
1200 | - ); |
|
1201 | - }); |
|
1202 | - |
|
1203 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1204 | - |
|
1205 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1206 | - |
|
1207 | - $this->connectDispatcher(); |
|
1208 | - } |
|
1209 | - |
|
1210 | - /** |
|
1211 | - * @return \OCP\Calendar\IManager |
|
1212 | - */ |
|
1213 | - public function getCalendarManager() { |
|
1214 | - return $this->query('CalendarManager'); |
|
1215 | - } |
|
1216 | - |
|
1217 | - /** |
|
1218 | - * @return \OCP\Calendar\Resource\IManager |
|
1219 | - */ |
|
1220 | - public function getCalendarResourceBackendManager() { |
|
1221 | - return $this->query('CalendarResourceBackendManager'); |
|
1222 | - } |
|
1223 | - |
|
1224 | - /** |
|
1225 | - * @return \OCP\Calendar\Room\IManager |
|
1226 | - */ |
|
1227 | - public function getCalendarRoomBackendManager() { |
|
1228 | - return $this->query('CalendarRoomBackendManager'); |
|
1229 | - } |
|
1230 | - |
|
1231 | - private function connectDispatcher() { |
|
1232 | - $dispatcher = $this->getEventDispatcher(); |
|
1233 | - |
|
1234 | - // Delete avatar on user deletion |
|
1235 | - $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1236 | - $logger = $this->getLogger(); |
|
1237 | - $manager = $this->getAvatarManager(); |
|
1238 | - /** @var IUser $user */ |
|
1239 | - $user = $e->getSubject(); |
|
1240 | - |
|
1241 | - try { |
|
1242 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1243 | - $avatar->remove(); |
|
1244 | - } catch (NotFoundException $e) { |
|
1245 | - // no avatar to remove |
|
1246 | - } catch (\Exception $e) { |
|
1247 | - // Ignore exceptions |
|
1248 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1249 | - } |
|
1250 | - }); |
|
1251 | - |
|
1252 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1253 | - $manager = $this->getAvatarManager(); |
|
1254 | - /** @var IUser $user */ |
|
1255 | - $user = $e->getSubject(); |
|
1256 | - $feature = $e->getArgument('feature'); |
|
1257 | - $oldValue = $e->getArgument('oldValue'); |
|
1258 | - $value = $e->getArgument('value'); |
|
1259 | - |
|
1260 | - try { |
|
1261 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1262 | - $avatar->userChanged($feature, $oldValue, $value); |
|
1263 | - } catch (NotFoundException $e) { |
|
1264 | - // no avatar to remove |
|
1265 | - } |
|
1266 | - }); |
|
1267 | - } |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * @return \OCP\Contacts\IManager |
|
1271 | - */ |
|
1272 | - public function getContactsManager() { |
|
1273 | - return $this->query('ContactsManager'); |
|
1274 | - } |
|
1275 | - |
|
1276 | - /** |
|
1277 | - * @return \OC\Encryption\Manager |
|
1278 | - */ |
|
1279 | - public function getEncryptionManager() { |
|
1280 | - return $this->query('EncryptionManager'); |
|
1281 | - } |
|
1282 | - |
|
1283 | - /** |
|
1284 | - * @return \OC\Encryption\File |
|
1285 | - */ |
|
1286 | - public function getEncryptionFilesHelper() { |
|
1287 | - return $this->query('EncryptionFileHelper'); |
|
1288 | - } |
|
1289 | - |
|
1290 | - /** |
|
1291 | - * @return \OCP\Encryption\Keys\IStorage |
|
1292 | - */ |
|
1293 | - public function getEncryptionKeyStorage() { |
|
1294 | - return $this->query('EncryptionKeyStorage'); |
|
1295 | - } |
|
1296 | - |
|
1297 | - /** |
|
1298 | - * The current request object holding all information about the request |
|
1299 | - * currently being processed is returned from this method. |
|
1300 | - * In case the current execution was not initiated by a web request null is returned |
|
1301 | - * |
|
1302 | - * @return \OCP\IRequest |
|
1303 | - */ |
|
1304 | - public function getRequest() { |
|
1305 | - return $this->query('Request'); |
|
1306 | - } |
|
1307 | - |
|
1308 | - /** |
|
1309 | - * Returns the preview manager which can create preview images for a given file |
|
1310 | - * |
|
1311 | - * @return \OCP\IPreview |
|
1312 | - */ |
|
1313 | - public function getPreviewManager() { |
|
1314 | - return $this->query('PreviewManager'); |
|
1315 | - } |
|
1316 | - |
|
1317 | - /** |
|
1318 | - * Returns the tag manager which can get and set tags for different object types |
|
1319 | - * |
|
1320 | - * @see \OCP\ITagManager::load() |
|
1321 | - * @return \OCP\ITagManager |
|
1322 | - */ |
|
1323 | - public function getTagManager() { |
|
1324 | - return $this->query('TagManager'); |
|
1325 | - } |
|
1326 | - |
|
1327 | - /** |
|
1328 | - * Returns the system-tag manager |
|
1329 | - * |
|
1330 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1331 | - * |
|
1332 | - * @since 9.0.0 |
|
1333 | - */ |
|
1334 | - public function getSystemTagManager() { |
|
1335 | - return $this->query('SystemTagManager'); |
|
1336 | - } |
|
1337 | - |
|
1338 | - /** |
|
1339 | - * Returns the system-tag object mapper |
|
1340 | - * |
|
1341 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1342 | - * |
|
1343 | - * @since 9.0.0 |
|
1344 | - */ |
|
1345 | - public function getSystemTagObjectMapper() { |
|
1346 | - return $this->query('SystemTagObjectMapper'); |
|
1347 | - } |
|
1348 | - |
|
1349 | - /** |
|
1350 | - * Returns the avatar manager, used for avatar functionality |
|
1351 | - * |
|
1352 | - * @return \OCP\IAvatarManager |
|
1353 | - */ |
|
1354 | - public function getAvatarManager() { |
|
1355 | - return $this->query('AvatarManager'); |
|
1356 | - } |
|
1357 | - |
|
1358 | - /** |
|
1359 | - * Returns the root folder of ownCloud's data directory |
|
1360 | - * |
|
1361 | - * @return \OCP\Files\IRootFolder |
|
1362 | - */ |
|
1363 | - public function getRootFolder() { |
|
1364 | - return $this->query('LazyRootFolder'); |
|
1365 | - } |
|
1366 | - |
|
1367 | - /** |
|
1368 | - * Returns the root folder of ownCloud's data directory |
|
1369 | - * This is the lazy variant so this gets only initialized once it |
|
1370 | - * is actually used. |
|
1371 | - * |
|
1372 | - * @return \OCP\Files\IRootFolder |
|
1373 | - */ |
|
1374 | - public function getLazyRootFolder() { |
|
1375 | - return $this->query('LazyRootFolder'); |
|
1376 | - } |
|
1377 | - |
|
1378 | - /** |
|
1379 | - * Returns a view to ownCloud's files folder |
|
1380 | - * |
|
1381 | - * @param string $userId user ID |
|
1382 | - * @return \OCP\Files\Folder|null |
|
1383 | - */ |
|
1384 | - public function getUserFolder($userId = null) { |
|
1385 | - if ($userId === null) { |
|
1386 | - $user = $this->getUserSession()->getUser(); |
|
1387 | - if (!$user) { |
|
1388 | - return null; |
|
1389 | - } |
|
1390 | - $userId = $user->getUID(); |
|
1391 | - } |
|
1392 | - $root = $this->getRootFolder(); |
|
1393 | - return $root->getUserFolder($userId); |
|
1394 | - } |
|
1395 | - |
|
1396 | - /** |
|
1397 | - * Returns an app-specific view in ownClouds data directory |
|
1398 | - * |
|
1399 | - * @return \OCP\Files\Folder |
|
1400 | - * @deprecated since 9.2.0 use IAppData |
|
1401 | - */ |
|
1402 | - public function getAppFolder() { |
|
1403 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1404 | - $root = $this->getRootFolder(); |
|
1405 | - if (!$root->nodeExists($dir)) { |
|
1406 | - $folder = $root->newFolder($dir); |
|
1407 | - } else { |
|
1408 | - $folder = $root->get($dir); |
|
1409 | - } |
|
1410 | - return $folder; |
|
1411 | - } |
|
1412 | - |
|
1413 | - /** |
|
1414 | - * @return \OC\User\Manager |
|
1415 | - */ |
|
1416 | - public function getUserManager() { |
|
1417 | - return $this->query('UserManager'); |
|
1418 | - } |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * @return \OC\Group\Manager |
|
1422 | - */ |
|
1423 | - public function getGroupManager() { |
|
1424 | - return $this->query('GroupManager'); |
|
1425 | - } |
|
1426 | - |
|
1427 | - /** |
|
1428 | - * @return \OC\User\Session |
|
1429 | - */ |
|
1430 | - public function getUserSession() { |
|
1431 | - return $this->query('UserSession'); |
|
1432 | - } |
|
1433 | - |
|
1434 | - /** |
|
1435 | - * @return \OCP\ISession |
|
1436 | - */ |
|
1437 | - public function getSession() { |
|
1438 | - return $this->query('UserSession')->getSession(); |
|
1439 | - } |
|
1440 | - |
|
1441 | - /** |
|
1442 | - * @param \OCP\ISession $session |
|
1443 | - */ |
|
1444 | - public function setSession(\OCP\ISession $session) { |
|
1445 | - $this->query(SessionStorage::class)->setSession($session); |
|
1446 | - $this->query('UserSession')->setSession($session); |
|
1447 | - $this->query(Store::class)->setSession($session); |
|
1448 | - } |
|
1449 | - |
|
1450 | - /** |
|
1451 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1452 | - */ |
|
1453 | - public function getTwoFactorAuthManager() { |
|
1454 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1455 | - } |
|
1456 | - |
|
1457 | - /** |
|
1458 | - * @return \OC\NavigationManager |
|
1459 | - */ |
|
1460 | - public function getNavigationManager() { |
|
1461 | - return $this->query('NavigationManager'); |
|
1462 | - } |
|
1463 | - |
|
1464 | - /** |
|
1465 | - * @return \OCP\IConfig |
|
1466 | - */ |
|
1467 | - public function getConfig() { |
|
1468 | - return $this->query('AllConfig'); |
|
1469 | - } |
|
1470 | - |
|
1471 | - /** |
|
1472 | - * @return \OC\SystemConfig |
|
1473 | - */ |
|
1474 | - public function getSystemConfig() { |
|
1475 | - return $this->query('SystemConfig'); |
|
1476 | - } |
|
1477 | - |
|
1478 | - /** |
|
1479 | - * Returns the app config manager |
|
1480 | - * |
|
1481 | - * @return \OCP\IAppConfig |
|
1482 | - */ |
|
1483 | - public function getAppConfig() { |
|
1484 | - return $this->query('AppConfig'); |
|
1485 | - } |
|
1486 | - |
|
1487 | - /** |
|
1488 | - * @return \OCP\L10N\IFactory |
|
1489 | - */ |
|
1490 | - public function getL10NFactory() { |
|
1491 | - return $this->query('L10NFactory'); |
|
1492 | - } |
|
1493 | - |
|
1494 | - /** |
|
1495 | - * get an L10N instance |
|
1496 | - * |
|
1497 | - * @param string $app appid |
|
1498 | - * @param string $lang |
|
1499 | - * @return IL10N |
|
1500 | - */ |
|
1501 | - public function getL10N($app, $lang = null) { |
|
1502 | - return $this->getL10NFactory()->get($app, $lang); |
|
1503 | - } |
|
1504 | - |
|
1505 | - /** |
|
1506 | - * @return \OCP\IURLGenerator |
|
1507 | - */ |
|
1508 | - public function getURLGenerator() { |
|
1509 | - return $this->query('URLGenerator'); |
|
1510 | - } |
|
1511 | - |
|
1512 | - /** |
|
1513 | - * @return AppFetcher |
|
1514 | - */ |
|
1515 | - public function getAppFetcher() { |
|
1516 | - return $this->query(AppFetcher::class); |
|
1517 | - } |
|
1518 | - |
|
1519 | - /** |
|
1520 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1521 | - * getMemCacheFactory() instead. |
|
1522 | - * |
|
1523 | - * @return \OCP\ICache |
|
1524 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1525 | - */ |
|
1526 | - public function getCache() { |
|
1527 | - return $this->query('UserCache'); |
|
1528 | - } |
|
1529 | - |
|
1530 | - /** |
|
1531 | - * Returns an \OCP\CacheFactory instance |
|
1532 | - * |
|
1533 | - * @return \OCP\ICacheFactory |
|
1534 | - */ |
|
1535 | - public function getMemCacheFactory() { |
|
1536 | - return $this->query('MemCacheFactory'); |
|
1537 | - } |
|
1538 | - |
|
1539 | - /** |
|
1540 | - * Returns an \OC\RedisFactory instance |
|
1541 | - * |
|
1542 | - * @return \OC\RedisFactory |
|
1543 | - */ |
|
1544 | - public function getGetRedisFactory() { |
|
1545 | - return $this->query('RedisFactory'); |
|
1546 | - } |
|
1547 | - |
|
1548 | - |
|
1549 | - /** |
|
1550 | - * Returns the current session |
|
1551 | - * |
|
1552 | - * @return \OCP\IDBConnection |
|
1553 | - */ |
|
1554 | - public function getDatabaseConnection() { |
|
1555 | - return $this->query('DatabaseConnection'); |
|
1556 | - } |
|
1557 | - |
|
1558 | - /** |
|
1559 | - * Returns the activity manager |
|
1560 | - * |
|
1561 | - * @return \OCP\Activity\IManager |
|
1562 | - */ |
|
1563 | - public function getActivityManager() { |
|
1564 | - return $this->query('ActivityManager'); |
|
1565 | - } |
|
1566 | - |
|
1567 | - /** |
|
1568 | - * Returns an job list for controlling background jobs |
|
1569 | - * |
|
1570 | - * @return \OCP\BackgroundJob\IJobList |
|
1571 | - */ |
|
1572 | - public function getJobList() { |
|
1573 | - return $this->query('JobList'); |
|
1574 | - } |
|
1575 | - |
|
1576 | - /** |
|
1577 | - * Returns a logger instance |
|
1578 | - * |
|
1579 | - * @return \OCP\ILogger |
|
1580 | - */ |
|
1581 | - public function getLogger() { |
|
1582 | - return $this->query('Logger'); |
|
1583 | - } |
|
1584 | - |
|
1585 | - /** |
|
1586 | - * @return ILogFactory |
|
1587 | - * @throws \OCP\AppFramework\QueryException |
|
1588 | - */ |
|
1589 | - public function getLogFactory() { |
|
1590 | - return $this->query(ILogFactory::class); |
|
1591 | - } |
|
1592 | - |
|
1593 | - /** |
|
1594 | - * Returns a router for generating and matching urls |
|
1595 | - * |
|
1596 | - * @return \OCP\Route\IRouter |
|
1597 | - */ |
|
1598 | - public function getRouter() { |
|
1599 | - return $this->query('Router'); |
|
1600 | - } |
|
1601 | - |
|
1602 | - /** |
|
1603 | - * Returns a search instance |
|
1604 | - * |
|
1605 | - * @return \OCP\ISearch |
|
1606 | - */ |
|
1607 | - public function getSearch() { |
|
1608 | - return $this->query('Search'); |
|
1609 | - } |
|
1610 | - |
|
1611 | - /** |
|
1612 | - * Returns a SecureRandom instance |
|
1613 | - * |
|
1614 | - * @return \OCP\Security\ISecureRandom |
|
1615 | - */ |
|
1616 | - public function getSecureRandom() { |
|
1617 | - return $this->query('SecureRandom'); |
|
1618 | - } |
|
1619 | - |
|
1620 | - /** |
|
1621 | - * Returns a Crypto instance |
|
1622 | - * |
|
1623 | - * @return \OCP\Security\ICrypto |
|
1624 | - */ |
|
1625 | - public function getCrypto() { |
|
1626 | - return $this->query('Crypto'); |
|
1627 | - } |
|
1628 | - |
|
1629 | - /** |
|
1630 | - * Returns a Hasher instance |
|
1631 | - * |
|
1632 | - * @return \OCP\Security\IHasher |
|
1633 | - */ |
|
1634 | - public function getHasher() { |
|
1635 | - return $this->query('Hasher'); |
|
1636 | - } |
|
1637 | - |
|
1638 | - /** |
|
1639 | - * Returns a CredentialsManager instance |
|
1640 | - * |
|
1641 | - * @return \OCP\Security\ICredentialsManager |
|
1642 | - */ |
|
1643 | - public function getCredentialsManager() { |
|
1644 | - return $this->query('CredentialsManager'); |
|
1645 | - } |
|
1646 | - |
|
1647 | - /** |
|
1648 | - * Get the certificate manager for the user |
|
1649 | - * |
|
1650 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1651 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1652 | - */ |
|
1653 | - public function getCertificateManager($userId = '') { |
|
1654 | - if ($userId === '') { |
|
1655 | - $userSession = $this->getUserSession(); |
|
1656 | - $user = $userSession->getUser(); |
|
1657 | - if (is_null($user)) { |
|
1658 | - return null; |
|
1659 | - } |
|
1660 | - $userId = $user->getUID(); |
|
1661 | - } |
|
1662 | - return new CertificateManager( |
|
1663 | - $userId, |
|
1664 | - new View(), |
|
1665 | - $this->getConfig(), |
|
1666 | - $this->getLogger(), |
|
1667 | - $this->getSecureRandom() |
|
1668 | - ); |
|
1669 | - } |
|
1670 | - |
|
1671 | - /** |
|
1672 | - * Returns an instance of the HTTP client service |
|
1673 | - * |
|
1674 | - * @return \OCP\Http\Client\IClientService |
|
1675 | - */ |
|
1676 | - public function getHTTPClientService() { |
|
1677 | - return $this->query('HttpClientService'); |
|
1678 | - } |
|
1679 | - |
|
1680 | - /** |
|
1681 | - * Create a new event source |
|
1682 | - * |
|
1683 | - * @return \OCP\IEventSource |
|
1684 | - */ |
|
1685 | - public function createEventSource() { |
|
1686 | - return new \OC_EventSource(); |
|
1687 | - } |
|
1688 | - |
|
1689 | - /** |
|
1690 | - * Get the active event logger |
|
1691 | - * |
|
1692 | - * The returned logger only logs data when debug mode is enabled |
|
1693 | - * |
|
1694 | - * @return \OCP\Diagnostics\IEventLogger |
|
1695 | - */ |
|
1696 | - public function getEventLogger() { |
|
1697 | - return $this->query('EventLogger'); |
|
1698 | - } |
|
1699 | - |
|
1700 | - /** |
|
1701 | - * Get the active query logger |
|
1702 | - * |
|
1703 | - * The returned logger only logs data when debug mode is enabled |
|
1704 | - * |
|
1705 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1706 | - */ |
|
1707 | - public function getQueryLogger() { |
|
1708 | - return $this->query('QueryLogger'); |
|
1709 | - } |
|
1710 | - |
|
1711 | - /** |
|
1712 | - * Get the manager for temporary files and folders |
|
1713 | - * |
|
1714 | - * @return \OCP\ITempManager |
|
1715 | - */ |
|
1716 | - public function getTempManager() { |
|
1717 | - return $this->query('TempManager'); |
|
1718 | - } |
|
1719 | - |
|
1720 | - /** |
|
1721 | - * Get the app manager |
|
1722 | - * |
|
1723 | - * @return \OCP\App\IAppManager |
|
1724 | - */ |
|
1725 | - public function getAppManager() { |
|
1726 | - return $this->query('AppManager'); |
|
1727 | - } |
|
1728 | - |
|
1729 | - /** |
|
1730 | - * Creates a new mailer |
|
1731 | - * |
|
1732 | - * @return \OCP\Mail\IMailer |
|
1733 | - */ |
|
1734 | - public function getMailer() { |
|
1735 | - return $this->query('Mailer'); |
|
1736 | - } |
|
1737 | - |
|
1738 | - /** |
|
1739 | - * Get the webroot |
|
1740 | - * |
|
1741 | - * @return string |
|
1742 | - */ |
|
1743 | - public function getWebRoot() { |
|
1744 | - return $this->webRoot; |
|
1745 | - } |
|
1746 | - |
|
1747 | - /** |
|
1748 | - * @return \OC\OCSClient |
|
1749 | - */ |
|
1750 | - public function getOcsClient() { |
|
1751 | - return $this->query('OcsClient'); |
|
1752 | - } |
|
1753 | - |
|
1754 | - /** |
|
1755 | - * @return \OCP\IDateTimeZone |
|
1756 | - */ |
|
1757 | - public function getDateTimeZone() { |
|
1758 | - return $this->query('DateTimeZone'); |
|
1759 | - } |
|
1760 | - |
|
1761 | - /** |
|
1762 | - * @return \OCP\IDateTimeFormatter |
|
1763 | - */ |
|
1764 | - public function getDateTimeFormatter() { |
|
1765 | - return $this->query('DateTimeFormatter'); |
|
1766 | - } |
|
1767 | - |
|
1768 | - /** |
|
1769 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1770 | - */ |
|
1771 | - public function getMountProviderCollection() { |
|
1772 | - return $this->query('MountConfigManager'); |
|
1773 | - } |
|
1774 | - |
|
1775 | - /** |
|
1776 | - * Get the IniWrapper |
|
1777 | - * |
|
1778 | - * @return IniGetWrapper |
|
1779 | - */ |
|
1780 | - public function getIniWrapper() { |
|
1781 | - return $this->query('IniWrapper'); |
|
1782 | - } |
|
1783 | - |
|
1784 | - /** |
|
1785 | - * @return \OCP\Command\IBus |
|
1786 | - */ |
|
1787 | - public function getCommandBus() { |
|
1788 | - return $this->query('AsyncCommandBus'); |
|
1789 | - } |
|
1790 | - |
|
1791 | - /** |
|
1792 | - * Get the trusted domain helper |
|
1793 | - * |
|
1794 | - * @return TrustedDomainHelper |
|
1795 | - */ |
|
1796 | - public function getTrustedDomainHelper() { |
|
1797 | - return $this->query('TrustedDomainHelper'); |
|
1798 | - } |
|
1799 | - |
|
1800 | - /** |
|
1801 | - * Get the locking provider |
|
1802 | - * |
|
1803 | - * @return \OCP\Lock\ILockingProvider |
|
1804 | - * @since 8.1.0 |
|
1805 | - */ |
|
1806 | - public function getLockingProvider() { |
|
1807 | - return $this->query('LockingProvider'); |
|
1808 | - } |
|
1809 | - |
|
1810 | - /** |
|
1811 | - * @return \OCP\Files\Mount\IMountManager |
|
1812 | - **/ |
|
1813 | - function getMountManager() { |
|
1814 | - return $this->query('MountManager'); |
|
1815 | - } |
|
1816 | - |
|
1817 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1818 | - function getUserMountCache() { |
|
1819 | - return $this->query('UserMountCache'); |
|
1820 | - } |
|
1821 | - |
|
1822 | - /** |
|
1823 | - * Get the MimeTypeDetector |
|
1824 | - * |
|
1825 | - * @return \OCP\Files\IMimeTypeDetector |
|
1826 | - */ |
|
1827 | - public function getMimeTypeDetector() { |
|
1828 | - return $this->query('MimeTypeDetector'); |
|
1829 | - } |
|
1830 | - |
|
1831 | - /** |
|
1832 | - * Get the MimeTypeLoader |
|
1833 | - * |
|
1834 | - * @return \OCP\Files\IMimeTypeLoader |
|
1835 | - */ |
|
1836 | - public function getMimeTypeLoader() { |
|
1837 | - return $this->query('MimeTypeLoader'); |
|
1838 | - } |
|
1839 | - |
|
1840 | - /** |
|
1841 | - * Get the manager of all the capabilities |
|
1842 | - * |
|
1843 | - * @return \OC\CapabilitiesManager |
|
1844 | - */ |
|
1845 | - public function getCapabilitiesManager() { |
|
1846 | - return $this->query('CapabilitiesManager'); |
|
1847 | - } |
|
1848 | - |
|
1849 | - /** |
|
1850 | - * Get the EventDispatcher |
|
1851 | - * |
|
1852 | - * @return EventDispatcherInterface |
|
1853 | - * @since 8.2.0 |
|
1854 | - */ |
|
1855 | - public function getEventDispatcher() { |
|
1856 | - return $this->query('EventDispatcher'); |
|
1857 | - } |
|
1858 | - |
|
1859 | - /** |
|
1860 | - * Get the Notification Manager |
|
1861 | - * |
|
1862 | - * @return \OCP\Notification\IManager |
|
1863 | - * @since 8.2.0 |
|
1864 | - */ |
|
1865 | - public function getNotificationManager() { |
|
1866 | - return $this->query('NotificationManager'); |
|
1867 | - } |
|
1868 | - |
|
1869 | - /** |
|
1870 | - * @return \OCP\Comments\ICommentsManager |
|
1871 | - */ |
|
1872 | - public function getCommentsManager() { |
|
1873 | - return $this->query('CommentsManager'); |
|
1874 | - } |
|
1875 | - |
|
1876 | - /** |
|
1877 | - * @return \OCA\Theming\ThemingDefaults |
|
1878 | - */ |
|
1879 | - public function getThemingDefaults() { |
|
1880 | - return $this->query('ThemingDefaults'); |
|
1881 | - } |
|
1882 | - |
|
1883 | - /** |
|
1884 | - * @return \OC\IntegrityCheck\Checker |
|
1885 | - */ |
|
1886 | - public function getIntegrityCodeChecker() { |
|
1887 | - return $this->query('IntegrityCodeChecker'); |
|
1888 | - } |
|
1889 | - |
|
1890 | - /** |
|
1891 | - * @return \OC\Session\CryptoWrapper |
|
1892 | - */ |
|
1893 | - public function getSessionCryptoWrapper() { |
|
1894 | - return $this->query('CryptoWrapper'); |
|
1895 | - } |
|
1896 | - |
|
1897 | - /** |
|
1898 | - * @return CsrfTokenManager |
|
1899 | - */ |
|
1900 | - public function getCsrfTokenManager() { |
|
1901 | - return $this->query('CsrfTokenManager'); |
|
1902 | - } |
|
1903 | - |
|
1904 | - /** |
|
1905 | - * @return Throttler |
|
1906 | - */ |
|
1907 | - public function getBruteForceThrottler() { |
|
1908 | - return $this->query('Throttler'); |
|
1909 | - } |
|
1910 | - |
|
1911 | - /** |
|
1912 | - * @return IContentSecurityPolicyManager |
|
1913 | - */ |
|
1914 | - public function getContentSecurityPolicyManager() { |
|
1915 | - return $this->query('ContentSecurityPolicyManager'); |
|
1916 | - } |
|
1917 | - |
|
1918 | - /** |
|
1919 | - * @return ContentSecurityPolicyNonceManager |
|
1920 | - */ |
|
1921 | - public function getContentSecurityPolicyNonceManager() { |
|
1922 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1923 | - } |
|
1924 | - |
|
1925 | - /** |
|
1926 | - * Not a public API as of 8.2, wait for 9.0 |
|
1927 | - * |
|
1928 | - * @return \OCA\Files_External\Service\BackendService |
|
1929 | - */ |
|
1930 | - public function getStoragesBackendService() { |
|
1931 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1932 | - } |
|
1933 | - |
|
1934 | - /** |
|
1935 | - * Not a public API as of 8.2, wait for 9.0 |
|
1936 | - * |
|
1937 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1938 | - */ |
|
1939 | - public function getGlobalStoragesService() { |
|
1940 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1941 | - } |
|
1942 | - |
|
1943 | - /** |
|
1944 | - * Not a public API as of 8.2, wait for 9.0 |
|
1945 | - * |
|
1946 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1947 | - */ |
|
1948 | - public function getUserGlobalStoragesService() { |
|
1949 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1950 | - } |
|
1951 | - |
|
1952 | - /** |
|
1953 | - * Not a public API as of 8.2, wait for 9.0 |
|
1954 | - * |
|
1955 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1956 | - */ |
|
1957 | - public function getUserStoragesService() { |
|
1958 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1959 | - } |
|
1960 | - |
|
1961 | - /** |
|
1962 | - * @return \OCP\Share\IManager |
|
1963 | - */ |
|
1964 | - public function getShareManager() { |
|
1965 | - return $this->query('ShareManager'); |
|
1966 | - } |
|
1967 | - |
|
1968 | - /** |
|
1969 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
1970 | - */ |
|
1971 | - public function getCollaboratorSearch() { |
|
1972 | - return $this->query('CollaboratorSearch'); |
|
1973 | - } |
|
1974 | - |
|
1975 | - /** |
|
1976 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
1977 | - */ |
|
1978 | - public function getAutoCompleteManager(){ |
|
1979 | - return $this->query(IManager::class); |
|
1980 | - } |
|
1981 | - |
|
1982 | - /** |
|
1983 | - * Returns the LDAP Provider |
|
1984 | - * |
|
1985 | - * @return \OCP\LDAP\ILDAPProvider |
|
1986 | - */ |
|
1987 | - public function getLDAPProvider() { |
|
1988 | - return $this->query('LDAPProvider'); |
|
1989 | - } |
|
1990 | - |
|
1991 | - /** |
|
1992 | - * @return \OCP\Settings\IManager |
|
1993 | - */ |
|
1994 | - public function getSettingsManager() { |
|
1995 | - return $this->query('SettingsManager'); |
|
1996 | - } |
|
1997 | - |
|
1998 | - /** |
|
1999 | - * @return \OCP\Files\IAppData |
|
2000 | - */ |
|
2001 | - public function getAppDataDir($app) { |
|
2002 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
2003 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
2004 | - return $factory->get($app); |
|
2005 | - } |
|
2006 | - |
|
2007 | - /** |
|
2008 | - * @return \OCP\Lockdown\ILockdownManager |
|
2009 | - */ |
|
2010 | - public function getLockdownManager() { |
|
2011 | - return $this->query('LockdownManager'); |
|
2012 | - } |
|
2013 | - |
|
2014 | - /** |
|
2015 | - * @return \OCP\Federation\ICloudIdManager |
|
2016 | - */ |
|
2017 | - public function getCloudIdManager() { |
|
2018 | - return $this->query(ICloudIdManager::class); |
|
2019 | - } |
|
2020 | - |
|
2021 | - /** |
|
2022 | - * @return \OCP\GlobalScale\IConfig |
|
2023 | - */ |
|
2024 | - public function getGlobalScaleConfig() { |
|
2025 | - return $this->query(IConfig::class); |
|
2026 | - } |
|
2027 | - |
|
2028 | - /** |
|
2029 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
2030 | - */ |
|
2031 | - public function getCloudFederationProviderManager() { |
|
2032 | - return $this->query(ICloudFederationProviderManager::class); |
|
2033 | - } |
|
2034 | - |
|
2035 | - /** |
|
2036 | - * @return \OCP\Remote\Api\IApiFactory |
|
2037 | - */ |
|
2038 | - public function getRemoteApiFactory() { |
|
2039 | - return $this->query(IApiFactory::class); |
|
2040 | - } |
|
2041 | - |
|
2042 | - /** |
|
2043 | - * @return \OCP\Federation\ICloudFederationFactory |
|
2044 | - */ |
|
2045 | - public function getCloudFederationFactory() { |
|
2046 | - return $this->query(ICloudFederationFactory::class); |
|
2047 | - } |
|
2048 | - |
|
2049 | - /** |
|
2050 | - * @return \OCP\Remote\IInstanceFactory |
|
2051 | - */ |
|
2052 | - public function getRemoteInstanceFactory() { |
|
2053 | - return $this->query(IInstanceFactory::class); |
|
2054 | - } |
|
2055 | - |
|
2056 | - /** |
|
2057 | - * @return IStorageFactory |
|
2058 | - */ |
|
2059 | - public function getStorageFactory() { |
|
2060 | - return $this->query(IStorageFactory::class); |
|
2061 | - } |
|
949 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
950 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
951 | + $classExists = true; |
|
952 | + } else { |
|
953 | + $classExists = false; |
|
954 | + } |
|
955 | + |
|
956 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
957 | + return new ThemingDefaults( |
|
958 | + $c->getConfig(), |
|
959 | + $c->getL10N('theming'), |
|
960 | + $c->getURLGenerator(), |
|
961 | + $c->getMemCacheFactory(), |
|
962 | + new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
963 | + new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
964 | + $c->getAppManager(), |
|
965 | + $c->getNavigationManager() |
|
966 | + ); |
|
967 | + } |
|
968 | + return new \OC_Defaults(); |
|
969 | + }); |
|
970 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
971 | + return new SCSSCacher( |
|
972 | + $c->getLogger(), |
|
973 | + $c->query(\OC\Files\AppData\Factory::class), |
|
974 | + $c->getURLGenerator(), |
|
975 | + $c->getConfig(), |
|
976 | + $c->getThemingDefaults(), |
|
977 | + \OC::$SERVERROOT, |
|
978 | + $this->getMemCacheFactory(), |
|
979 | + $c->query(IconsCacher::class), |
|
980 | + new TimeFactory() |
|
981 | + ); |
|
982 | + }); |
|
983 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
984 | + return new JSCombiner( |
|
985 | + $c->getAppDataDir('js'), |
|
986 | + $c->getURLGenerator(), |
|
987 | + $this->getMemCacheFactory(), |
|
988 | + $c->getSystemConfig(), |
|
989 | + $c->getLogger() |
|
990 | + ); |
|
991 | + }); |
|
992 | + $this->registerService(EventDispatcher::class, function () { |
|
993 | + return new EventDispatcher(); |
|
994 | + }); |
|
995 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
996 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
997 | + |
|
998 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
999 | + // FIXME: Instantiiated here due to cyclic dependency |
|
1000 | + $request = new Request( |
|
1001 | + [ |
|
1002 | + 'get' => $_GET, |
|
1003 | + 'post' => $_POST, |
|
1004 | + 'files' => $_FILES, |
|
1005 | + 'server' => $_SERVER, |
|
1006 | + 'env' => $_ENV, |
|
1007 | + 'cookies' => $_COOKIE, |
|
1008 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1009 | + ? $_SERVER['REQUEST_METHOD'] |
|
1010 | + : null, |
|
1011 | + ], |
|
1012 | + $c->getSecureRandom(), |
|
1013 | + $c->getConfig() |
|
1014 | + ); |
|
1015 | + |
|
1016 | + return new CryptoWrapper( |
|
1017 | + $c->getConfig(), |
|
1018 | + $c->getCrypto(), |
|
1019 | + $c->getSecureRandom(), |
|
1020 | + $request |
|
1021 | + ); |
|
1022 | + }); |
|
1023 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1024 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
1025 | + |
|
1026 | + return new CsrfTokenManager( |
|
1027 | + $tokenGenerator, |
|
1028 | + $c->query(SessionStorage::class) |
|
1029 | + ); |
|
1030 | + }); |
|
1031 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
1032 | + return new SessionStorage($c->getSession()); |
|
1033 | + }); |
|
1034 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1035 | + return new ContentSecurityPolicyManager(); |
|
1036 | + }); |
|
1037 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
1038 | + |
|
1039 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1040 | + return new ContentSecurityPolicyNonceManager( |
|
1041 | + $c->getCsrfTokenManager(), |
|
1042 | + $c->getRequest() |
|
1043 | + ); |
|
1044 | + }); |
|
1045 | + |
|
1046 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1047 | + $config = $c->getConfig(); |
|
1048 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1049 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1050 | + $factory = new $factoryClass($this); |
|
1051 | + |
|
1052 | + $manager = new \OC\Share20\Manager( |
|
1053 | + $c->getLogger(), |
|
1054 | + $c->getConfig(), |
|
1055 | + $c->getSecureRandom(), |
|
1056 | + $c->getHasher(), |
|
1057 | + $c->getMountManager(), |
|
1058 | + $c->getGroupManager(), |
|
1059 | + $c->getL10N('lib'), |
|
1060 | + $c->getL10NFactory(), |
|
1061 | + $factory, |
|
1062 | + $c->getUserManager(), |
|
1063 | + $c->getLazyRootFolder(), |
|
1064 | + $c->getEventDispatcher(), |
|
1065 | + $c->getMailer(), |
|
1066 | + $c->getURLGenerator(), |
|
1067 | + $c->getThemingDefaults() |
|
1068 | + ); |
|
1069 | + |
|
1070 | + return $manager; |
|
1071 | + }); |
|
1072 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1073 | + |
|
1074 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1075 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1076 | + |
|
1077 | + // register default plugins |
|
1078 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1079 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1080 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1081 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1082 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1083 | + |
|
1084 | + return $instance; |
|
1085 | + }); |
|
1086 | + $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1087 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1088 | + |
|
1089 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1090 | + |
|
1091 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1092 | + |
|
1093 | + $this->registerService('SettingsManager', function (Server $c) { |
|
1094 | + $manager = new \OC\Settings\Manager( |
|
1095 | + $c->getLogger(), |
|
1096 | + $c->getL10N('lib'), |
|
1097 | + $c->getURLGenerator(), |
|
1098 | + $c |
|
1099 | + ); |
|
1100 | + return $manager; |
|
1101 | + }); |
|
1102 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1103 | + return new \OC\Files\AppData\Factory( |
|
1104 | + $c->getRootFolder(), |
|
1105 | + $c->getSystemConfig() |
|
1106 | + ); |
|
1107 | + }); |
|
1108 | + |
|
1109 | + $this->registerService('LockdownManager', function (Server $c) { |
|
1110 | + return new LockdownManager(function () use ($c) { |
|
1111 | + return $c->getSession(); |
|
1112 | + }); |
|
1113 | + }); |
|
1114 | + |
|
1115 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1116 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1117 | + }); |
|
1118 | + |
|
1119 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1120 | + return new CloudIdManager(); |
|
1121 | + }); |
|
1122 | + |
|
1123 | + $this->registerService(IConfig::class, function (Server $c) { |
|
1124 | + return new GlobalScale\Config($c->getConfig()); |
|
1125 | + }); |
|
1126 | + |
|
1127 | + $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1128 | + return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
1129 | + }); |
|
1130 | + |
|
1131 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1132 | + return new CloudFederationFactory(); |
|
1133 | + }); |
|
1134 | + |
|
1135 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1136 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1137 | + |
|
1138 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1139 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1140 | + |
|
1141 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1142 | + return new Defaults( |
|
1143 | + $c->getThemingDefaults() |
|
1144 | + ); |
|
1145 | + }); |
|
1146 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1147 | + |
|
1148 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1149 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1150 | + }); |
|
1151 | + |
|
1152 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
1153 | + return new ShareHelper( |
|
1154 | + $c->query(\OCP\Share\IManager::class) |
|
1155 | + ); |
|
1156 | + }); |
|
1157 | + |
|
1158 | + $this->registerService(Installer::class, function(Server $c) { |
|
1159 | + return new Installer( |
|
1160 | + $c->getAppFetcher(), |
|
1161 | + $c->getHTTPClientService(), |
|
1162 | + $c->getTempManager(), |
|
1163 | + $c->getLogger(), |
|
1164 | + $c->getConfig() |
|
1165 | + ); |
|
1166 | + }); |
|
1167 | + |
|
1168 | + $this->registerService(IApiFactory::class, function(Server $c) { |
|
1169 | + return new ApiFactory($c->getHTTPClientService()); |
|
1170 | + }); |
|
1171 | + |
|
1172 | + $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
1173 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
1174 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
1175 | + }); |
|
1176 | + |
|
1177 | + $this->registerService(IContactsStore::class, function(Server $c) { |
|
1178 | + return new ContactsStore( |
|
1179 | + $c->getContactsManager(), |
|
1180 | + $c->getConfig(), |
|
1181 | + $c->getUserManager(), |
|
1182 | + $c->getGroupManager() |
|
1183 | + ); |
|
1184 | + }); |
|
1185 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1186 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1187 | + |
|
1188 | + $this->registerService(IStorageFactory::class, function() { |
|
1189 | + return new StorageFactory(); |
|
1190 | + }); |
|
1191 | + |
|
1192 | + $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
1193 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1194 | + |
|
1195 | + $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) { |
|
1196 | + return new \OC\Security\IdentityProof\Manager( |
|
1197 | + $c->query(\OC\Files\AppData\Factory::class), |
|
1198 | + $c->getCrypto(), |
|
1199 | + $c->getConfig() |
|
1200 | + ); |
|
1201 | + }); |
|
1202 | + |
|
1203 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1204 | + |
|
1205 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1206 | + |
|
1207 | + $this->connectDispatcher(); |
|
1208 | + } |
|
1209 | + |
|
1210 | + /** |
|
1211 | + * @return \OCP\Calendar\IManager |
|
1212 | + */ |
|
1213 | + public function getCalendarManager() { |
|
1214 | + return $this->query('CalendarManager'); |
|
1215 | + } |
|
1216 | + |
|
1217 | + /** |
|
1218 | + * @return \OCP\Calendar\Resource\IManager |
|
1219 | + */ |
|
1220 | + public function getCalendarResourceBackendManager() { |
|
1221 | + return $this->query('CalendarResourceBackendManager'); |
|
1222 | + } |
|
1223 | + |
|
1224 | + /** |
|
1225 | + * @return \OCP\Calendar\Room\IManager |
|
1226 | + */ |
|
1227 | + public function getCalendarRoomBackendManager() { |
|
1228 | + return $this->query('CalendarRoomBackendManager'); |
|
1229 | + } |
|
1230 | + |
|
1231 | + private function connectDispatcher() { |
|
1232 | + $dispatcher = $this->getEventDispatcher(); |
|
1233 | + |
|
1234 | + // Delete avatar on user deletion |
|
1235 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1236 | + $logger = $this->getLogger(); |
|
1237 | + $manager = $this->getAvatarManager(); |
|
1238 | + /** @var IUser $user */ |
|
1239 | + $user = $e->getSubject(); |
|
1240 | + |
|
1241 | + try { |
|
1242 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1243 | + $avatar->remove(); |
|
1244 | + } catch (NotFoundException $e) { |
|
1245 | + // no avatar to remove |
|
1246 | + } catch (\Exception $e) { |
|
1247 | + // Ignore exceptions |
|
1248 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1249 | + } |
|
1250 | + }); |
|
1251 | + |
|
1252 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1253 | + $manager = $this->getAvatarManager(); |
|
1254 | + /** @var IUser $user */ |
|
1255 | + $user = $e->getSubject(); |
|
1256 | + $feature = $e->getArgument('feature'); |
|
1257 | + $oldValue = $e->getArgument('oldValue'); |
|
1258 | + $value = $e->getArgument('value'); |
|
1259 | + |
|
1260 | + try { |
|
1261 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1262 | + $avatar->userChanged($feature, $oldValue, $value); |
|
1263 | + } catch (NotFoundException $e) { |
|
1264 | + // no avatar to remove |
|
1265 | + } |
|
1266 | + }); |
|
1267 | + } |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * @return \OCP\Contacts\IManager |
|
1271 | + */ |
|
1272 | + public function getContactsManager() { |
|
1273 | + return $this->query('ContactsManager'); |
|
1274 | + } |
|
1275 | + |
|
1276 | + /** |
|
1277 | + * @return \OC\Encryption\Manager |
|
1278 | + */ |
|
1279 | + public function getEncryptionManager() { |
|
1280 | + return $this->query('EncryptionManager'); |
|
1281 | + } |
|
1282 | + |
|
1283 | + /** |
|
1284 | + * @return \OC\Encryption\File |
|
1285 | + */ |
|
1286 | + public function getEncryptionFilesHelper() { |
|
1287 | + return $this->query('EncryptionFileHelper'); |
|
1288 | + } |
|
1289 | + |
|
1290 | + /** |
|
1291 | + * @return \OCP\Encryption\Keys\IStorage |
|
1292 | + */ |
|
1293 | + public function getEncryptionKeyStorage() { |
|
1294 | + return $this->query('EncryptionKeyStorage'); |
|
1295 | + } |
|
1296 | + |
|
1297 | + /** |
|
1298 | + * The current request object holding all information about the request |
|
1299 | + * currently being processed is returned from this method. |
|
1300 | + * In case the current execution was not initiated by a web request null is returned |
|
1301 | + * |
|
1302 | + * @return \OCP\IRequest |
|
1303 | + */ |
|
1304 | + public function getRequest() { |
|
1305 | + return $this->query('Request'); |
|
1306 | + } |
|
1307 | + |
|
1308 | + /** |
|
1309 | + * Returns the preview manager which can create preview images for a given file |
|
1310 | + * |
|
1311 | + * @return \OCP\IPreview |
|
1312 | + */ |
|
1313 | + public function getPreviewManager() { |
|
1314 | + return $this->query('PreviewManager'); |
|
1315 | + } |
|
1316 | + |
|
1317 | + /** |
|
1318 | + * Returns the tag manager which can get and set tags for different object types |
|
1319 | + * |
|
1320 | + * @see \OCP\ITagManager::load() |
|
1321 | + * @return \OCP\ITagManager |
|
1322 | + */ |
|
1323 | + public function getTagManager() { |
|
1324 | + return $this->query('TagManager'); |
|
1325 | + } |
|
1326 | + |
|
1327 | + /** |
|
1328 | + * Returns the system-tag manager |
|
1329 | + * |
|
1330 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1331 | + * |
|
1332 | + * @since 9.0.0 |
|
1333 | + */ |
|
1334 | + public function getSystemTagManager() { |
|
1335 | + return $this->query('SystemTagManager'); |
|
1336 | + } |
|
1337 | + |
|
1338 | + /** |
|
1339 | + * Returns the system-tag object mapper |
|
1340 | + * |
|
1341 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1342 | + * |
|
1343 | + * @since 9.0.0 |
|
1344 | + */ |
|
1345 | + public function getSystemTagObjectMapper() { |
|
1346 | + return $this->query('SystemTagObjectMapper'); |
|
1347 | + } |
|
1348 | + |
|
1349 | + /** |
|
1350 | + * Returns the avatar manager, used for avatar functionality |
|
1351 | + * |
|
1352 | + * @return \OCP\IAvatarManager |
|
1353 | + */ |
|
1354 | + public function getAvatarManager() { |
|
1355 | + return $this->query('AvatarManager'); |
|
1356 | + } |
|
1357 | + |
|
1358 | + /** |
|
1359 | + * Returns the root folder of ownCloud's data directory |
|
1360 | + * |
|
1361 | + * @return \OCP\Files\IRootFolder |
|
1362 | + */ |
|
1363 | + public function getRootFolder() { |
|
1364 | + return $this->query('LazyRootFolder'); |
|
1365 | + } |
|
1366 | + |
|
1367 | + /** |
|
1368 | + * Returns the root folder of ownCloud's data directory |
|
1369 | + * This is the lazy variant so this gets only initialized once it |
|
1370 | + * is actually used. |
|
1371 | + * |
|
1372 | + * @return \OCP\Files\IRootFolder |
|
1373 | + */ |
|
1374 | + public function getLazyRootFolder() { |
|
1375 | + return $this->query('LazyRootFolder'); |
|
1376 | + } |
|
1377 | + |
|
1378 | + /** |
|
1379 | + * Returns a view to ownCloud's files folder |
|
1380 | + * |
|
1381 | + * @param string $userId user ID |
|
1382 | + * @return \OCP\Files\Folder|null |
|
1383 | + */ |
|
1384 | + public function getUserFolder($userId = null) { |
|
1385 | + if ($userId === null) { |
|
1386 | + $user = $this->getUserSession()->getUser(); |
|
1387 | + if (!$user) { |
|
1388 | + return null; |
|
1389 | + } |
|
1390 | + $userId = $user->getUID(); |
|
1391 | + } |
|
1392 | + $root = $this->getRootFolder(); |
|
1393 | + return $root->getUserFolder($userId); |
|
1394 | + } |
|
1395 | + |
|
1396 | + /** |
|
1397 | + * Returns an app-specific view in ownClouds data directory |
|
1398 | + * |
|
1399 | + * @return \OCP\Files\Folder |
|
1400 | + * @deprecated since 9.2.0 use IAppData |
|
1401 | + */ |
|
1402 | + public function getAppFolder() { |
|
1403 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1404 | + $root = $this->getRootFolder(); |
|
1405 | + if (!$root->nodeExists($dir)) { |
|
1406 | + $folder = $root->newFolder($dir); |
|
1407 | + } else { |
|
1408 | + $folder = $root->get($dir); |
|
1409 | + } |
|
1410 | + return $folder; |
|
1411 | + } |
|
1412 | + |
|
1413 | + /** |
|
1414 | + * @return \OC\User\Manager |
|
1415 | + */ |
|
1416 | + public function getUserManager() { |
|
1417 | + return $this->query('UserManager'); |
|
1418 | + } |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * @return \OC\Group\Manager |
|
1422 | + */ |
|
1423 | + public function getGroupManager() { |
|
1424 | + return $this->query('GroupManager'); |
|
1425 | + } |
|
1426 | + |
|
1427 | + /** |
|
1428 | + * @return \OC\User\Session |
|
1429 | + */ |
|
1430 | + public function getUserSession() { |
|
1431 | + return $this->query('UserSession'); |
|
1432 | + } |
|
1433 | + |
|
1434 | + /** |
|
1435 | + * @return \OCP\ISession |
|
1436 | + */ |
|
1437 | + public function getSession() { |
|
1438 | + return $this->query('UserSession')->getSession(); |
|
1439 | + } |
|
1440 | + |
|
1441 | + /** |
|
1442 | + * @param \OCP\ISession $session |
|
1443 | + */ |
|
1444 | + public function setSession(\OCP\ISession $session) { |
|
1445 | + $this->query(SessionStorage::class)->setSession($session); |
|
1446 | + $this->query('UserSession')->setSession($session); |
|
1447 | + $this->query(Store::class)->setSession($session); |
|
1448 | + } |
|
1449 | + |
|
1450 | + /** |
|
1451 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1452 | + */ |
|
1453 | + public function getTwoFactorAuthManager() { |
|
1454 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1455 | + } |
|
1456 | + |
|
1457 | + /** |
|
1458 | + * @return \OC\NavigationManager |
|
1459 | + */ |
|
1460 | + public function getNavigationManager() { |
|
1461 | + return $this->query('NavigationManager'); |
|
1462 | + } |
|
1463 | + |
|
1464 | + /** |
|
1465 | + * @return \OCP\IConfig |
|
1466 | + */ |
|
1467 | + public function getConfig() { |
|
1468 | + return $this->query('AllConfig'); |
|
1469 | + } |
|
1470 | + |
|
1471 | + /** |
|
1472 | + * @return \OC\SystemConfig |
|
1473 | + */ |
|
1474 | + public function getSystemConfig() { |
|
1475 | + return $this->query('SystemConfig'); |
|
1476 | + } |
|
1477 | + |
|
1478 | + /** |
|
1479 | + * Returns the app config manager |
|
1480 | + * |
|
1481 | + * @return \OCP\IAppConfig |
|
1482 | + */ |
|
1483 | + public function getAppConfig() { |
|
1484 | + return $this->query('AppConfig'); |
|
1485 | + } |
|
1486 | + |
|
1487 | + /** |
|
1488 | + * @return \OCP\L10N\IFactory |
|
1489 | + */ |
|
1490 | + public function getL10NFactory() { |
|
1491 | + return $this->query('L10NFactory'); |
|
1492 | + } |
|
1493 | + |
|
1494 | + /** |
|
1495 | + * get an L10N instance |
|
1496 | + * |
|
1497 | + * @param string $app appid |
|
1498 | + * @param string $lang |
|
1499 | + * @return IL10N |
|
1500 | + */ |
|
1501 | + public function getL10N($app, $lang = null) { |
|
1502 | + return $this->getL10NFactory()->get($app, $lang); |
|
1503 | + } |
|
1504 | + |
|
1505 | + /** |
|
1506 | + * @return \OCP\IURLGenerator |
|
1507 | + */ |
|
1508 | + public function getURLGenerator() { |
|
1509 | + return $this->query('URLGenerator'); |
|
1510 | + } |
|
1511 | + |
|
1512 | + /** |
|
1513 | + * @return AppFetcher |
|
1514 | + */ |
|
1515 | + public function getAppFetcher() { |
|
1516 | + return $this->query(AppFetcher::class); |
|
1517 | + } |
|
1518 | + |
|
1519 | + /** |
|
1520 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1521 | + * getMemCacheFactory() instead. |
|
1522 | + * |
|
1523 | + * @return \OCP\ICache |
|
1524 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1525 | + */ |
|
1526 | + public function getCache() { |
|
1527 | + return $this->query('UserCache'); |
|
1528 | + } |
|
1529 | + |
|
1530 | + /** |
|
1531 | + * Returns an \OCP\CacheFactory instance |
|
1532 | + * |
|
1533 | + * @return \OCP\ICacheFactory |
|
1534 | + */ |
|
1535 | + public function getMemCacheFactory() { |
|
1536 | + return $this->query('MemCacheFactory'); |
|
1537 | + } |
|
1538 | + |
|
1539 | + /** |
|
1540 | + * Returns an \OC\RedisFactory instance |
|
1541 | + * |
|
1542 | + * @return \OC\RedisFactory |
|
1543 | + */ |
|
1544 | + public function getGetRedisFactory() { |
|
1545 | + return $this->query('RedisFactory'); |
|
1546 | + } |
|
1547 | + |
|
1548 | + |
|
1549 | + /** |
|
1550 | + * Returns the current session |
|
1551 | + * |
|
1552 | + * @return \OCP\IDBConnection |
|
1553 | + */ |
|
1554 | + public function getDatabaseConnection() { |
|
1555 | + return $this->query('DatabaseConnection'); |
|
1556 | + } |
|
1557 | + |
|
1558 | + /** |
|
1559 | + * Returns the activity manager |
|
1560 | + * |
|
1561 | + * @return \OCP\Activity\IManager |
|
1562 | + */ |
|
1563 | + public function getActivityManager() { |
|
1564 | + return $this->query('ActivityManager'); |
|
1565 | + } |
|
1566 | + |
|
1567 | + /** |
|
1568 | + * Returns an job list for controlling background jobs |
|
1569 | + * |
|
1570 | + * @return \OCP\BackgroundJob\IJobList |
|
1571 | + */ |
|
1572 | + public function getJobList() { |
|
1573 | + return $this->query('JobList'); |
|
1574 | + } |
|
1575 | + |
|
1576 | + /** |
|
1577 | + * Returns a logger instance |
|
1578 | + * |
|
1579 | + * @return \OCP\ILogger |
|
1580 | + */ |
|
1581 | + public function getLogger() { |
|
1582 | + return $this->query('Logger'); |
|
1583 | + } |
|
1584 | + |
|
1585 | + /** |
|
1586 | + * @return ILogFactory |
|
1587 | + * @throws \OCP\AppFramework\QueryException |
|
1588 | + */ |
|
1589 | + public function getLogFactory() { |
|
1590 | + return $this->query(ILogFactory::class); |
|
1591 | + } |
|
1592 | + |
|
1593 | + /** |
|
1594 | + * Returns a router for generating and matching urls |
|
1595 | + * |
|
1596 | + * @return \OCP\Route\IRouter |
|
1597 | + */ |
|
1598 | + public function getRouter() { |
|
1599 | + return $this->query('Router'); |
|
1600 | + } |
|
1601 | + |
|
1602 | + /** |
|
1603 | + * Returns a search instance |
|
1604 | + * |
|
1605 | + * @return \OCP\ISearch |
|
1606 | + */ |
|
1607 | + public function getSearch() { |
|
1608 | + return $this->query('Search'); |
|
1609 | + } |
|
1610 | + |
|
1611 | + /** |
|
1612 | + * Returns a SecureRandom instance |
|
1613 | + * |
|
1614 | + * @return \OCP\Security\ISecureRandom |
|
1615 | + */ |
|
1616 | + public function getSecureRandom() { |
|
1617 | + return $this->query('SecureRandom'); |
|
1618 | + } |
|
1619 | + |
|
1620 | + /** |
|
1621 | + * Returns a Crypto instance |
|
1622 | + * |
|
1623 | + * @return \OCP\Security\ICrypto |
|
1624 | + */ |
|
1625 | + public function getCrypto() { |
|
1626 | + return $this->query('Crypto'); |
|
1627 | + } |
|
1628 | + |
|
1629 | + /** |
|
1630 | + * Returns a Hasher instance |
|
1631 | + * |
|
1632 | + * @return \OCP\Security\IHasher |
|
1633 | + */ |
|
1634 | + public function getHasher() { |
|
1635 | + return $this->query('Hasher'); |
|
1636 | + } |
|
1637 | + |
|
1638 | + /** |
|
1639 | + * Returns a CredentialsManager instance |
|
1640 | + * |
|
1641 | + * @return \OCP\Security\ICredentialsManager |
|
1642 | + */ |
|
1643 | + public function getCredentialsManager() { |
|
1644 | + return $this->query('CredentialsManager'); |
|
1645 | + } |
|
1646 | + |
|
1647 | + /** |
|
1648 | + * Get the certificate manager for the user |
|
1649 | + * |
|
1650 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1651 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1652 | + */ |
|
1653 | + public function getCertificateManager($userId = '') { |
|
1654 | + if ($userId === '') { |
|
1655 | + $userSession = $this->getUserSession(); |
|
1656 | + $user = $userSession->getUser(); |
|
1657 | + if (is_null($user)) { |
|
1658 | + return null; |
|
1659 | + } |
|
1660 | + $userId = $user->getUID(); |
|
1661 | + } |
|
1662 | + return new CertificateManager( |
|
1663 | + $userId, |
|
1664 | + new View(), |
|
1665 | + $this->getConfig(), |
|
1666 | + $this->getLogger(), |
|
1667 | + $this->getSecureRandom() |
|
1668 | + ); |
|
1669 | + } |
|
1670 | + |
|
1671 | + /** |
|
1672 | + * Returns an instance of the HTTP client service |
|
1673 | + * |
|
1674 | + * @return \OCP\Http\Client\IClientService |
|
1675 | + */ |
|
1676 | + public function getHTTPClientService() { |
|
1677 | + return $this->query('HttpClientService'); |
|
1678 | + } |
|
1679 | + |
|
1680 | + /** |
|
1681 | + * Create a new event source |
|
1682 | + * |
|
1683 | + * @return \OCP\IEventSource |
|
1684 | + */ |
|
1685 | + public function createEventSource() { |
|
1686 | + return new \OC_EventSource(); |
|
1687 | + } |
|
1688 | + |
|
1689 | + /** |
|
1690 | + * Get the active event logger |
|
1691 | + * |
|
1692 | + * The returned logger only logs data when debug mode is enabled |
|
1693 | + * |
|
1694 | + * @return \OCP\Diagnostics\IEventLogger |
|
1695 | + */ |
|
1696 | + public function getEventLogger() { |
|
1697 | + return $this->query('EventLogger'); |
|
1698 | + } |
|
1699 | + |
|
1700 | + /** |
|
1701 | + * Get the active query logger |
|
1702 | + * |
|
1703 | + * The returned logger only logs data when debug mode is enabled |
|
1704 | + * |
|
1705 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1706 | + */ |
|
1707 | + public function getQueryLogger() { |
|
1708 | + return $this->query('QueryLogger'); |
|
1709 | + } |
|
1710 | + |
|
1711 | + /** |
|
1712 | + * Get the manager for temporary files and folders |
|
1713 | + * |
|
1714 | + * @return \OCP\ITempManager |
|
1715 | + */ |
|
1716 | + public function getTempManager() { |
|
1717 | + return $this->query('TempManager'); |
|
1718 | + } |
|
1719 | + |
|
1720 | + /** |
|
1721 | + * Get the app manager |
|
1722 | + * |
|
1723 | + * @return \OCP\App\IAppManager |
|
1724 | + */ |
|
1725 | + public function getAppManager() { |
|
1726 | + return $this->query('AppManager'); |
|
1727 | + } |
|
1728 | + |
|
1729 | + /** |
|
1730 | + * Creates a new mailer |
|
1731 | + * |
|
1732 | + * @return \OCP\Mail\IMailer |
|
1733 | + */ |
|
1734 | + public function getMailer() { |
|
1735 | + return $this->query('Mailer'); |
|
1736 | + } |
|
1737 | + |
|
1738 | + /** |
|
1739 | + * Get the webroot |
|
1740 | + * |
|
1741 | + * @return string |
|
1742 | + */ |
|
1743 | + public function getWebRoot() { |
|
1744 | + return $this->webRoot; |
|
1745 | + } |
|
1746 | + |
|
1747 | + /** |
|
1748 | + * @return \OC\OCSClient |
|
1749 | + */ |
|
1750 | + public function getOcsClient() { |
|
1751 | + return $this->query('OcsClient'); |
|
1752 | + } |
|
1753 | + |
|
1754 | + /** |
|
1755 | + * @return \OCP\IDateTimeZone |
|
1756 | + */ |
|
1757 | + public function getDateTimeZone() { |
|
1758 | + return $this->query('DateTimeZone'); |
|
1759 | + } |
|
1760 | + |
|
1761 | + /** |
|
1762 | + * @return \OCP\IDateTimeFormatter |
|
1763 | + */ |
|
1764 | + public function getDateTimeFormatter() { |
|
1765 | + return $this->query('DateTimeFormatter'); |
|
1766 | + } |
|
1767 | + |
|
1768 | + /** |
|
1769 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1770 | + */ |
|
1771 | + public function getMountProviderCollection() { |
|
1772 | + return $this->query('MountConfigManager'); |
|
1773 | + } |
|
1774 | + |
|
1775 | + /** |
|
1776 | + * Get the IniWrapper |
|
1777 | + * |
|
1778 | + * @return IniGetWrapper |
|
1779 | + */ |
|
1780 | + public function getIniWrapper() { |
|
1781 | + return $this->query('IniWrapper'); |
|
1782 | + } |
|
1783 | + |
|
1784 | + /** |
|
1785 | + * @return \OCP\Command\IBus |
|
1786 | + */ |
|
1787 | + public function getCommandBus() { |
|
1788 | + return $this->query('AsyncCommandBus'); |
|
1789 | + } |
|
1790 | + |
|
1791 | + /** |
|
1792 | + * Get the trusted domain helper |
|
1793 | + * |
|
1794 | + * @return TrustedDomainHelper |
|
1795 | + */ |
|
1796 | + public function getTrustedDomainHelper() { |
|
1797 | + return $this->query('TrustedDomainHelper'); |
|
1798 | + } |
|
1799 | + |
|
1800 | + /** |
|
1801 | + * Get the locking provider |
|
1802 | + * |
|
1803 | + * @return \OCP\Lock\ILockingProvider |
|
1804 | + * @since 8.1.0 |
|
1805 | + */ |
|
1806 | + public function getLockingProvider() { |
|
1807 | + return $this->query('LockingProvider'); |
|
1808 | + } |
|
1809 | + |
|
1810 | + /** |
|
1811 | + * @return \OCP\Files\Mount\IMountManager |
|
1812 | + **/ |
|
1813 | + function getMountManager() { |
|
1814 | + return $this->query('MountManager'); |
|
1815 | + } |
|
1816 | + |
|
1817 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1818 | + function getUserMountCache() { |
|
1819 | + return $this->query('UserMountCache'); |
|
1820 | + } |
|
1821 | + |
|
1822 | + /** |
|
1823 | + * Get the MimeTypeDetector |
|
1824 | + * |
|
1825 | + * @return \OCP\Files\IMimeTypeDetector |
|
1826 | + */ |
|
1827 | + public function getMimeTypeDetector() { |
|
1828 | + return $this->query('MimeTypeDetector'); |
|
1829 | + } |
|
1830 | + |
|
1831 | + /** |
|
1832 | + * Get the MimeTypeLoader |
|
1833 | + * |
|
1834 | + * @return \OCP\Files\IMimeTypeLoader |
|
1835 | + */ |
|
1836 | + public function getMimeTypeLoader() { |
|
1837 | + return $this->query('MimeTypeLoader'); |
|
1838 | + } |
|
1839 | + |
|
1840 | + /** |
|
1841 | + * Get the manager of all the capabilities |
|
1842 | + * |
|
1843 | + * @return \OC\CapabilitiesManager |
|
1844 | + */ |
|
1845 | + public function getCapabilitiesManager() { |
|
1846 | + return $this->query('CapabilitiesManager'); |
|
1847 | + } |
|
1848 | + |
|
1849 | + /** |
|
1850 | + * Get the EventDispatcher |
|
1851 | + * |
|
1852 | + * @return EventDispatcherInterface |
|
1853 | + * @since 8.2.0 |
|
1854 | + */ |
|
1855 | + public function getEventDispatcher() { |
|
1856 | + return $this->query('EventDispatcher'); |
|
1857 | + } |
|
1858 | + |
|
1859 | + /** |
|
1860 | + * Get the Notification Manager |
|
1861 | + * |
|
1862 | + * @return \OCP\Notification\IManager |
|
1863 | + * @since 8.2.0 |
|
1864 | + */ |
|
1865 | + public function getNotificationManager() { |
|
1866 | + return $this->query('NotificationManager'); |
|
1867 | + } |
|
1868 | + |
|
1869 | + /** |
|
1870 | + * @return \OCP\Comments\ICommentsManager |
|
1871 | + */ |
|
1872 | + public function getCommentsManager() { |
|
1873 | + return $this->query('CommentsManager'); |
|
1874 | + } |
|
1875 | + |
|
1876 | + /** |
|
1877 | + * @return \OCA\Theming\ThemingDefaults |
|
1878 | + */ |
|
1879 | + public function getThemingDefaults() { |
|
1880 | + return $this->query('ThemingDefaults'); |
|
1881 | + } |
|
1882 | + |
|
1883 | + /** |
|
1884 | + * @return \OC\IntegrityCheck\Checker |
|
1885 | + */ |
|
1886 | + public function getIntegrityCodeChecker() { |
|
1887 | + return $this->query('IntegrityCodeChecker'); |
|
1888 | + } |
|
1889 | + |
|
1890 | + /** |
|
1891 | + * @return \OC\Session\CryptoWrapper |
|
1892 | + */ |
|
1893 | + public function getSessionCryptoWrapper() { |
|
1894 | + return $this->query('CryptoWrapper'); |
|
1895 | + } |
|
1896 | + |
|
1897 | + /** |
|
1898 | + * @return CsrfTokenManager |
|
1899 | + */ |
|
1900 | + public function getCsrfTokenManager() { |
|
1901 | + return $this->query('CsrfTokenManager'); |
|
1902 | + } |
|
1903 | + |
|
1904 | + /** |
|
1905 | + * @return Throttler |
|
1906 | + */ |
|
1907 | + public function getBruteForceThrottler() { |
|
1908 | + return $this->query('Throttler'); |
|
1909 | + } |
|
1910 | + |
|
1911 | + /** |
|
1912 | + * @return IContentSecurityPolicyManager |
|
1913 | + */ |
|
1914 | + public function getContentSecurityPolicyManager() { |
|
1915 | + return $this->query('ContentSecurityPolicyManager'); |
|
1916 | + } |
|
1917 | + |
|
1918 | + /** |
|
1919 | + * @return ContentSecurityPolicyNonceManager |
|
1920 | + */ |
|
1921 | + public function getContentSecurityPolicyNonceManager() { |
|
1922 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1923 | + } |
|
1924 | + |
|
1925 | + /** |
|
1926 | + * Not a public API as of 8.2, wait for 9.0 |
|
1927 | + * |
|
1928 | + * @return \OCA\Files_External\Service\BackendService |
|
1929 | + */ |
|
1930 | + public function getStoragesBackendService() { |
|
1931 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1932 | + } |
|
1933 | + |
|
1934 | + /** |
|
1935 | + * Not a public API as of 8.2, wait for 9.0 |
|
1936 | + * |
|
1937 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1938 | + */ |
|
1939 | + public function getGlobalStoragesService() { |
|
1940 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1941 | + } |
|
1942 | + |
|
1943 | + /** |
|
1944 | + * Not a public API as of 8.2, wait for 9.0 |
|
1945 | + * |
|
1946 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1947 | + */ |
|
1948 | + public function getUserGlobalStoragesService() { |
|
1949 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1950 | + } |
|
1951 | + |
|
1952 | + /** |
|
1953 | + * Not a public API as of 8.2, wait for 9.0 |
|
1954 | + * |
|
1955 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1956 | + */ |
|
1957 | + public function getUserStoragesService() { |
|
1958 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1959 | + } |
|
1960 | + |
|
1961 | + /** |
|
1962 | + * @return \OCP\Share\IManager |
|
1963 | + */ |
|
1964 | + public function getShareManager() { |
|
1965 | + return $this->query('ShareManager'); |
|
1966 | + } |
|
1967 | + |
|
1968 | + /** |
|
1969 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
1970 | + */ |
|
1971 | + public function getCollaboratorSearch() { |
|
1972 | + return $this->query('CollaboratorSearch'); |
|
1973 | + } |
|
1974 | + |
|
1975 | + /** |
|
1976 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
1977 | + */ |
|
1978 | + public function getAutoCompleteManager(){ |
|
1979 | + return $this->query(IManager::class); |
|
1980 | + } |
|
1981 | + |
|
1982 | + /** |
|
1983 | + * Returns the LDAP Provider |
|
1984 | + * |
|
1985 | + * @return \OCP\LDAP\ILDAPProvider |
|
1986 | + */ |
|
1987 | + public function getLDAPProvider() { |
|
1988 | + return $this->query('LDAPProvider'); |
|
1989 | + } |
|
1990 | + |
|
1991 | + /** |
|
1992 | + * @return \OCP\Settings\IManager |
|
1993 | + */ |
|
1994 | + public function getSettingsManager() { |
|
1995 | + return $this->query('SettingsManager'); |
|
1996 | + } |
|
1997 | + |
|
1998 | + /** |
|
1999 | + * @return \OCP\Files\IAppData |
|
2000 | + */ |
|
2001 | + public function getAppDataDir($app) { |
|
2002 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
2003 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
2004 | + return $factory->get($app); |
|
2005 | + } |
|
2006 | + |
|
2007 | + /** |
|
2008 | + * @return \OCP\Lockdown\ILockdownManager |
|
2009 | + */ |
|
2010 | + public function getLockdownManager() { |
|
2011 | + return $this->query('LockdownManager'); |
|
2012 | + } |
|
2013 | + |
|
2014 | + /** |
|
2015 | + * @return \OCP\Federation\ICloudIdManager |
|
2016 | + */ |
|
2017 | + public function getCloudIdManager() { |
|
2018 | + return $this->query(ICloudIdManager::class); |
|
2019 | + } |
|
2020 | + |
|
2021 | + /** |
|
2022 | + * @return \OCP\GlobalScale\IConfig |
|
2023 | + */ |
|
2024 | + public function getGlobalScaleConfig() { |
|
2025 | + return $this->query(IConfig::class); |
|
2026 | + } |
|
2027 | + |
|
2028 | + /** |
|
2029 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
2030 | + */ |
|
2031 | + public function getCloudFederationProviderManager() { |
|
2032 | + return $this->query(ICloudFederationProviderManager::class); |
|
2033 | + } |
|
2034 | + |
|
2035 | + /** |
|
2036 | + * @return \OCP\Remote\Api\IApiFactory |
|
2037 | + */ |
|
2038 | + public function getRemoteApiFactory() { |
|
2039 | + return $this->query(IApiFactory::class); |
|
2040 | + } |
|
2041 | + |
|
2042 | + /** |
|
2043 | + * @return \OCP\Federation\ICloudFederationFactory |
|
2044 | + */ |
|
2045 | + public function getCloudFederationFactory() { |
|
2046 | + return $this->query(ICloudFederationFactory::class); |
|
2047 | + } |
|
2048 | + |
|
2049 | + /** |
|
2050 | + * @return \OCP\Remote\IInstanceFactory |
|
2051 | + */ |
|
2052 | + public function getRemoteInstanceFactory() { |
|
2053 | + return $this->query(IInstanceFactory::class); |
|
2054 | + } |
|
2055 | + |
|
2056 | + /** |
|
2057 | + * @return IStorageFactory |
|
2058 | + */ |
|
2059 | + public function getStorageFactory() { |
|
2060 | + return $this->query(IStorageFactory::class); |
|
2061 | + } |
|
2062 | 2062 | } |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | // To find out if we are running from CLI or not |
185 | 185 | $this->registerParameter('isCLI', \OC::$CLI); |
186 | 186 | |
187 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
187 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
188 | 188 | return $c; |
189 | 189 | }); |
190 | 190 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
204 | 204 | |
205 | 205 | |
206 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
206 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
207 | 207 | return new PreviewManager( |
208 | 208 | $c->getConfig(), |
209 | 209 | $c->getRootFolder(), |
@@ -214,13 +214,13 @@ discard block |
||
214 | 214 | }); |
215 | 215 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
216 | 216 | |
217 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
217 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
218 | 218 | return new \OC\Preview\Watcher( |
219 | 219 | $c->getAppDataDir('preview') |
220 | 220 | ); |
221 | 221 | }); |
222 | 222 | |
223 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
223 | + $this->registerService(\OCP\Encryption\IManager::class, function(Server $c) { |
|
224 | 224 | $view = new View(); |
225 | 225 | $util = new Encryption\Util( |
226 | 226 | $view, |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | }); |
240 | 240 | $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
241 | 241 | |
242 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
242 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
243 | 243 | $util = new Encryption\Util( |
244 | 244 | new View(), |
245 | 245 | $c->getUserManager(), |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | ); |
254 | 254 | }); |
255 | 255 | |
256 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
256 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
257 | 257 | $view = new View(); |
258 | 258 | $util = new Encryption\Util( |
259 | 259 | $view, |
@@ -264,30 +264,30 @@ discard block |
||
264 | 264 | |
265 | 265 | return new Encryption\Keys\Storage($view, $util); |
266 | 266 | }); |
267 | - $this->registerService('TagMapper', function (Server $c) { |
|
267 | + $this->registerService('TagMapper', function(Server $c) { |
|
268 | 268 | return new TagMapper($c->getDatabaseConnection()); |
269 | 269 | }); |
270 | 270 | |
271 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
271 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
272 | 272 | $tagMapper = $c->query('TagMapper'); |
273 | 273 | return new TagManager($tagMapper, $c->getUserSession()); |
274 | 274 | }); |
275 | 275 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
276 | 276 | |
277 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
277 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
278 | 278 | $config = $c->getConfig(); |
279 | 279 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
280 | 280 | return new $factoryClass($this); |
281 | 281 | }); |
282 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
282 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
283 | 283 | return $c->query('SystemTagManagerFactory')->getManager(); |
284 | 284 | }); |
285 | 285 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
286 | 286 | |
287 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
287 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
288 | 288 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
289 | 289 | }); |
290 | - $this->registerService('RootFolder', function (Server $c) { |
|
290 | + $this->registerService('RootFolder', function(Server $c) { |
|
291 | 291 | $manager = \OC\Files\Filesystem::getMountManager(null); |
292 | 292 | $view = new View(); |
293 | 293 | $root = new Root( |
@@ -308,37 +308,37 @@ discard block |
||
308 | 308 | }); |
309 | 309 | $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
310 | 310 | |
311 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
312 | - return new LazyRoot(function () use ($c) { |
|
311 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
312 | + return new LazyRoot(function() use ($c) { |
|
313 | 313 | return $c->query('RootFolder'); |
314 | 314 | }); |
315 | 315 | }); |
316 | 316 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
317 | 317 | |
318 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
318 | + $this->registerService(\OC\User\Manager::class, function(Server $c) { |
|
319 | 319 | return new \OC\User\Manager($c->getConfig(), $c->getEventDispatcher()); |
320 | 320 | }); |
321 | 321 | $this->registerAlias('UserManager', \OC\User\Manager::class); |
322 | 322 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
323 | 323 | |
324 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
324 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
325 | 325 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
326 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
326 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
327 | 327 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
328 | 328 | }); |
329 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
329 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
330 | 330 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
331 | 331 | }); |
332 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
332 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
333 | 333 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
334 | 334 | }); |
335 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
335 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
336 | 336 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
337 | 337 | }); |
338 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
338 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
339 | 339 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
340 | 340 | }); |
341 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
341 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
342 | 342 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
343 | 343 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
344 | 344 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | }); |
348 | 348 | $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
349 | 349 | |
350 | - $this->registerService(Store::class, function (Server $c) { |
|
350 | + $this->registerService(Store::class, function(Server $c) { |
|
351 | 351 | $session = $c->getSession(); |
352 | 352 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
353 | 353 | $tokenProvider = $c->query(IProvider::class); |
@@ -358,13 +358,13 @@ discard block |
||
358 | 358 | return new Store($session, $logger, $tokenProvider); |
359 | 359 | }); |
360 | 360 | $this->registerAlias(IStore::class, Store::class); |
361 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
361 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function(Server $c) { |
|
362 | 362 | $dbConnection = $c->getDatabaseConnection(); |
363 | 363 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
364 | 364 | }); |
365 | 365 | $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
366 | 366 | |
367 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
367 | + $this->registerService(\OC\User\Session::class, function(Server $c) { |
|
368 | 368 | $manager = $c->getUserManager(); |
369 | 369 | $session = new \OC\Session\Memory(''); |
370 | 370 | $timeFactory = new TimeFactory(); |
@@ -388,45 +388,45 @@ discard block |
||
388 | 388 | $c->getLockdownManager(), |
389 | 389 | $c->getLogger() |
390 | 390 | ); |
391 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
391 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
392 | 392 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
393 | 393 | }); |
394 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
394 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
395 | 395 | /** @var $user \OC\User\User */ |
396 | 396 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
397 | 397 | }); |
398 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
398 | + $userSession->listen('\OC\User', 'preDelete', function($user) use ($dispatcher) { |
|
399 | 399 | /** @var $user \OC\User\User */ |
400 | 400 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
401 | 401 | $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
402 | 402 | }); |
403 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
403 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
404 | 404 | /** @var $user \OC\User\User */ |
405 | 405 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
406 | 406 | }); |
407 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
407 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
408 | 408 | /** @var $user \OC\User\User */ |
409 | 409 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
410 | 410 | }); |
411 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
411 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
412 | 412 | /** @var $user \OC\User\User */ |
413 | 413 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
414 | 414 | }); |
415 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
415 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
416 | 416 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
417 | 417 | }); |
418 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
418 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password, $isTokenLogin) { |
|
419 | 419 | /** @var $user \OC\User\User */ |
420 | 420 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin)); |
421 | 421 | }); |
422 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
422 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
423 | 423 | /** @var $user \OC\User\User */ |
424 | 424 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
425 | 425 | }); |
426 | - $userSession->listen('\OC\User', 'logout', function () { |
|
426 | + $userSession->listen('\OC\User', 'logout', function() { |
|
427 | 427 | \OC_Hook::emit('OC_User', 'logout', array()); |
428 | 428 | }); |
429 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
429 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
430 | 430 | /** @var $user \OC\User\User */ |
431 | 431 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
432 | 432 | $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
442 | 442 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
443 | 443 | |
444 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
444 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
445 | 445 | return new \OC\AllConfig( |
446 | 446 | $c->getSystemConfig() |
447 | 447 | ); |
@@ -449,17 +449,17 @@ discard block |
||
449 | 449 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
450 | 450 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
451 | 451 | |
452 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
452 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
453 | 453 | return new \OC\SystemConfig($config); |
454 | 454 | }); |
455 | 455 | |
456 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
456 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
457 | 457 | return new \OC\AppConfig($c->getDatabaseConnection()); |
458 | 458 | }); |
459 | 459 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
460 | 460 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
461 | 461 | |
462 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
462 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
463 | 463 | return new \OC\L10N\Factory( |
464 | 464 | $c->getConfig(), |
465 | 465 | $c->getRequest(), |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | }); |
470 | 470 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
471 | 471 | |
472 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
472 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
473 | 473 | $config = $c->getConfig(); |
474 | 474 | $cacheFactory = $c->getMemCacheFactory(); |
475 | 475 | $request = $c->getRequest(); |
@@ -484,12 +484,12 @@ discard block |
||
484 | 484 | $this->registerAlias('AppFetcher', AppFetcher::class); |
485 | 485 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
486 | 486 | |
487 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
487 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
488 | 488 | return new Cache\File(); |
489 | 489 | }); |
490 | 490 | $this->registerAlias('UserCache', \OCP\ICache::class); |
491 | 491 | |
492 | - $this->registerService(Factory::class, function (Server $c) { |
|
492 | + $this->registerService(Factory::class, function(Server $c) { |
|
493 | 493 | |
494 | 494 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
495 | 495 | ArrayCache::class, |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | $version = implode(',', $v); |
505 | 505 | $instanceId = \OC_Util::getInstanceId(); |
506 | 506 | $path = \OC::$SERVERROOT; |
507 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
507 | + $prefix = md5($instanceId.'-'.$version.'-'.$path); |
|
508 | 508 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
509 | 509 | $config->getSystemValue('memcache.local', null), |
510 | 510 | $config->getSystemValue('memcache.distributed', null), |
@@ -517,12 +517,12 @@ discard block |
||
517 | 517 | $this->registerAlias('MemCacheFactory', Factory::class); |
518 | 518 | $this->registerAlias(ICacheFactory::class, Factory::class); |
519 | 519 | |
520 | - $this->registerService('RedisFactory', function (Server $c) { |
|
520 | + $this->registerService('RedisFactory', function(Server $c) { |
|
521 | 521 | $systemConfig = $c->getSystemConfig(); |
522 | 522 | return new RedisFactory($systemConfig); |
523 | 523 | }); |
524 | 524 | |
525 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
525 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
526 | 526 | return new \OC\Activity\Manager( |
527 | 527 | $c->getRequest(), |
528 | 528 | $c->getUserSession(), |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | }); |
533 | 533 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
534 | 534 | |
535 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
535 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
536 | 536 | return new \OC\Activity\EventMerger( |
537 | 537 | $c->getL10N('lib') |
538 | 538 | ); |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | |
554 | 554 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
555 | 555 | |
556 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
556 | + $this->registerService(\OC\Log::class, function(Server $c) { |
|
557 | 557 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
558 | 558 | $factory = new LogFactory($c, $this->getSystemConfig()); |
559 | 559 | $logger = $factory->get($logType); |
@@ -564,11 +564,11 @@ discard block |
||
564 | 564 | $this->registerAlias(\OCP\ILogger::class, \OC\Log::class); |
565 | 565 | $this->registerAlias('Logger', \OC\Log::class); |
566 | 566 | |
567 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
567 | + $this->registerService(ILogFactory::class, function(Server $c) { |
|
568 | 568 | return new LogFactory($c, $this->getSystemConfig()); |
569 | 569 | }); |
570 | 570 | |
571 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
571 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
572 | 572 | $config = $c->getConfig(); |
573 | 573 | return new \OC\BackgroundJob\JobList( |
574 | 574 | $c->getDatabaseConnection(), |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | }); |
579 | 579 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
580 | 580 | |
581 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
581 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
582 | 582 | $cacheFactory = $c->getMemCacheFactory(); |
583 | 583 | $logger = $c->getLogger(); |
584 | 584 | if ($cacheFactory->isLocalCacheAvailable()) { |
@@ -590,12 +590,12 @@ discard block |
||
590 | 590 | }); |
591 | 591 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
592 | 592 | |
593 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
593 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
594 | 594 | return new Search(); |
595 | 595 | }); |
596 | 596 | $this->registerAlias('Search', \OCP\ISearch::class); |
597 | 597 | |
598 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
598 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function(Server $c) { |
|
599 | 599 | return new \OC\Security\RateLimiting\Limiter( |
600 | 600 | $this->getUserSession(), |
601 | 601 | $this->getRequest(), |
@@ -603,34 +603,34 @@ discard block |
||
603 | 603 | $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
604 | 604 | ); |
605 | 605 | }); |
606 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
606 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
607 | 607 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
608 | 608 | $this->getMemCacheFactory(), |
609 | 609 | new \OC\AppFramework\Utility\TimeFactory() |
610 | 610 | ); |
611 | 611 | }); |
612 | 612 | |
613 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
613 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
614 | 614 | return new SecureRandom(); |
615 | 615 | }); |
616 | 616 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
617 | 617 | |
618 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
618 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
619 | 619 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
620 | 620 | }); |
621 | 621 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
622 | 622 | |
623 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
623 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
624 | 624 | return new Hasher($c->getConfig()); |
625 | 625 | }); |
626 | 626 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
627 | 627 | |
628 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
628 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
629 | 629 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
630 | 630 | }); |
631 | 631 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
632 | 632 | |
633 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
633 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
634 | 634 | $systemConfig = $c->getSystemConfig(); |
635 | 635 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
636 | 636 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
646 | 646 | |
647 | 647 | |
648 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
648 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
649 | 649 | $user = \OC_User::getUser(); |
650 | 650 | $uid = $user ? $user : null; |
651 | 651 | return new ClientService( |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | ); |
661 | 661 | }); |
662 | 662 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
663 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
663 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
664 | 664 | $eventLogger = new EventLogger(); |
665 | 665 | if ($c->getSystemConfig()->getValue('debug', false)) { |
666 | 666 | // In debug mode, module is being activated by default |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | }); |
671 | 671 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
672 | 672 | |
673 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
673 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
674 | 674 | $queryLogger = new QueryLogger(); |
675 | 675 | if ($c->getSystemConfig()->getValue('debug', false)) { |
676 | 676 | // In debug mode, module is being activated by default |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | }); |
681 | 681 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
682 | 682 | |
683 | - $this->registerService(TempManager::class, function (Server $c) { |
|
683 | + $this->registerService(TempManager::class, function(Server $c) { |
|
684 | 684 | return new TempManager( |
685 | 685 | $c->getLogger(), |
686 | 686 | $c->getConfig() |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | $this->registerAlias('TempManager', TempManager::class); |
690 | 690 | $this->registerAlias(ITempManager::class, TempManager::class); |
691 | 691 | |
692 | - $this->registerService(AppManager::class, function (Server $c) { |
|
692 | + $this->registerService(AppManager::class, function(Server $c) { |
|
693 | 693 | return new \OC\App\AppManager( |
694 | 694 | $c->getUserSession(), |
695 | 695 | $c->query(\OC\AppConfig::class), |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | $this->registerAlias('AppManager', AppManager::class); |
702 | 702 | $this->registerAlias(IAppManager::class, AppManager::class); |
703 | 703 | |
704 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
704 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
705 | 705 | return new DateTimeZone( |
706 | 706 | $c->getConfig(), |
707 | 707 | $c->getSession() |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | }); |
710 | 710 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
711 | 711 | |
712 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
712 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
713 | 713 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
714 | 714 | |
715 | 715 | return new DateTimeFormatter( |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | }); |
720 | 720 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
721 | 721 | |
722 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
722 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
723 | 723 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
724 | 724 | $listener = new UserMountCacheListener($mountCache); |
725 | 725 | $listener->listen($c->getUserManager()); |
@@ -727,7 +727,7 @@ discard block |
||
727 | 727 | }); |
728 | 728 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
729 | 729 | |
730 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
730 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
731 | 731 | $loader = \OC\Files\Filesystem::getLoader(); |
732 | 732 | $mountCache = $c->query('UserMountCache'); |
733 | 733 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -743,10 +743,10 @@ discard block |
||
743 | 743 | }); |
744 | 744 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
745 | 745 | |
746 | - $this->registerService('IniWrapper', function ($c) { |
|
746 | + $this->registerService('IniWrapper', function($c) { |
|
747 | 747 | return new IniGetWrapper(); |
748 | 748 | }); |
749 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
749 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
750 | 750 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
751 | 751 | if ($busClass) { |
752 | 752 | list($app, $class) = explode('::', $busClass, 2); |
@@ -761,10 +761,10 @@ discard block |
||
761 | 761 | return new CronBus($jobList); |
762 | 762 | } |
763 | 763 | }); |
764 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
764 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
765 | 765 | return new TrustedDomainHelper($this->getConfig()); |
766 | 766 | }); |
767 | - $this->registerService(Throttler::class, function (Server $c) { |
|
767 | + $this->registerService(Throttler::class, function(Server $c) { |
|
768 | 768 | return new Throttler( |
769 | 769 | $c->getDatabaseConnection(), |
770 | 770 | new TimeFactory(), |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | ); |
774 | 774 | }); |
775 | 775 | $this->registerAlias('Throttler', Throttler::class); |
776 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
776 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
777 | 777 | // IConfig and IAppManager requires a working database. This code |
778 | 778 | // might however be called when ownCloud is not yet setup. |
779 | 779 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
@@ -794,7 +794,7 @@ discard block |
||
794 | 794 | $c->getTempManager() |
795 | 795 | ); |
796 | 796 | }); |
797 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
797 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
798 | 798 | if (isset($this['urlParams'])) { |
799 | 799 | $urlParams = $this['urlParams']; |
800 | 800 | } else { |
@@ -830,7 +830,7 @@ discard block |
||
830 | 830 | }); |
831 | 831 | $this->registerAlias('Request', \OCP\IRequest::class); |
832 | 832 | |
833 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
833 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
834 | 834 | return new Mailer( |
835 | 835 | $c->getConfig(), |
836 | 836 | $c->getLogger(), |
@@ -841,7 +841,7 @@ discard block |
||
841 | 841 | }); |
842 | 842 | $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
843 | 843 | |
844 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
844 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
845 | 845 | $config = $c->getConfig(); |
846 | 846 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
847 | 847 | if (is_null($factoryClass)) { |
@@ -851,7 +851,7 @@ discard block |
||
851 | 851 | $factory = new $factoryClass($this); |
852 | 852 | return $factory->getLDAPProvider(); |
853 | 853 | }); |
854 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
854 | + $this->registerService(ILockingProvider::class, function(Server $c) { |
|
855 | 855 | $ini = $c->getIniWrapper(); |
856 | 856 | $config = $c->getConfig(); |
857 | 857 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -874,49 +874,49 @@ discard block |
||
874 | 874 | }); |
875 | 875 | $this->registerAlias('LockingProvider', ILockingProvider::class); |
876 | 876 | |
877 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
877 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
878 | 878 | return new \OC\Files\Mount\Manager(); |
879 | 879 | }); |
880 | 880 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
881 | 881 | |
882 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
882 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
883 | 883 | return new \OC\Files\Type\Detection( |
884 | 884 | $c->getURLGenerator(), |
885 | 885 | \OC::$configDir, |
886 | - \OC::$SERVERROOT . '/resources/config/' |
|
886 | + \OC::$SERVERROOT.'/resources/config/' |
|
887 | 887 | ); |
888 | 888 | }); |
889 | 889 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
890 | 890 | |
891 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
891 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
892 | 892 | return new \OC\Files\Type\Loader( |
893 | 893 | $c->getDatabaseConnection() |
894 | 894 | ); |
895 | 895 | }); |
896 | 896 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
897 | - $this->registerService(BundleFetcher::class, function () { |
|
897 | + $this->registerService(BundleFetcher::class, function() { |
|
898 | 898 | return new BundleFetcher($this->getL10N('lib')); |
899 | 899 | }); |
900 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
900 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
901 | 901 | return new Manager( |
902 | 902 | $c->query(IValidator::class) |
903 | 903 | ); |
904 | 904 | }); |
905 | 905 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
906 | 906 | |
907 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
907 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
908 | 908 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
909 | - $manager->registerCapability(function () use ($c) { |
|
909 | + $manager->registerCapability(function() use ($c) { |
|
910 | 910 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
911 | 911 | }); |
912 | - $manager->registerCapability(function () use ($c) { |
|
912 | + $manager->registerCapability(function() use ($c) { |
|
913 | 913 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
914 | 914 | }); |
915 | 915 | return $manager; |
916 | 916 | }); |
917 | 917 | $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
918 | 918 | |
919 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
919 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
920 | 920 | $config = $c->getConfig(); |
921 | 921 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
922 | 922 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
@@ -926,7 +926,7 @@ discard block |
||
926 | 926 | $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
927 | 927 | $manager = $c->getUserManager(); |
928 | 928 | $user = $manager->get($id); |
929 | - if(is_null($user)) { |
|
929 | + if (is_null($user)) { |
|
930 | 930 | $l = $c->getL10N('core'); |
931 | 931 | $displayName = $l->t('Unknown user'); |
932 | 932 | } else { |
@@ -939,7 +939,7 @@ discard block |
||
939 | 939 | }); |
940 | 940 | $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
941 | 941 | |
942 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
942 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
943 | 943 | /* |
944 | 944 | * Dark magic for autoloader. |
945 | 945 | * If we do a class_exists it will try to load the class which will |
@@ -967,7 +967,7 @@ discard block |
||
967 | 967 | } |
968 | 968 | return new \OC_Defaults(); |
969 | 969 | }); |
970 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
970 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
971 | 971 | return new SCSSCacher( |
972 | 972 | $c->getLogger(), |
973 | 973 | $c->query(\OC\Files\AppData\Factory::class), |
@@ -980,7 +980,7 @@ discard block |
||
980 | 980 | new TimeFactory() |
981 | 981 | ); |
982 | 982 | }); |
983 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
983 | + $this->registerService(JSCombiner::class, function(Server $c) { |
|
984 | 984 | return new JSCombiner( |
985 | 985 | $c->getAppDataDir('js'), |
986 | 986 | $c->getURLGenerator(), |
@@ -989,13 +989,13 @@ discard block |
||
989 | 989 | $c->getLogger() |
990 | 990 | ); |
991 | 991 | }); |
992 | - $this->registerService(EventDispatcher::class, function () { |
|
992 | + $this->registerService(EventDispatcher::class, function() { |
|
993 | 993 | return new EventDispatcher(); |
994 | 994 | }); |
995 | 995 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
996 | 996 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
997 | 997 | |
998 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
998 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
999 | 999 | // FIXME: Instantiiated here due to cyclic dependency |
1000 | 1000 | $request = new Request( |
1001 | 1001 | [ |
@@ -1020,7 +1020,7 @@ discard block |
||
1020 | 1020 | $request |
1021 | 1021 | ); |
1022 | 1022 | }); |
1023 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
1023 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
1024 | 1024 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
1025 | 1025 | |
1026 | 1026 | return new CsrfTokenManager( |
@@ -1028,22 +1028,22 @@ discard block |
||
1028 | 1028 | $c->query(SessionStorage::class) |
1029 | 1029 | ); |
1030 | 1030 | }); |
1031 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
1031 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
1032 | 1032 | return new SessionStorage($c->getSession()); |
1033 | 1033 | }); |
1034 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
1034 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
1035 | 1035 | return new ContentSecurityPolicyManager(); |
1036 | 1036 | }); |
1037 | 1037 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
1038 | 1038 | |
1039 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
1039 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
1040 | 1040 | return new ContentSecurityPolicyNonceManager( |
1041 | 1041 | $c->getCsrfTokenManager(), |
1042 | 1042 | $c->getRequest() |
1043 | 1043 | ); |
1044 | 1044 | }); |
1045 | 1045 | |
1046 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
1046 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
1047 | 1047 | $config = $c->getConfig(); |
1048 | 1048 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
1049 | 1049 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1090,7 +1090,7 @@ discard block |
||
1090 | 1090 | |
1091 | 1091 | $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
1092 | 1092 | |
1093 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1093 | + $this->registerService('SettingsManager', function(Server $c) { |
|
1094 | 1094 | $manager = new \OC\Settings\Manager( |
1095 | 1095 | $c->getLogger(), |
1096 | 1096 | $c->getL10N('lib'), |
@@ -1099,36 +1099,36 @@ discard block |
||
1099 | 1099 | ); |
1100 | 1100 | return $manager; |
1101 | 1101 | }); |
1102 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1102 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
1103 | 1103 | return new \OC\Files\AppData\Factory( |
1104 | 1104 | $c->getRootFolder(), |
1105 | 1105 | $c->getSystemConfig() |
1106 | 1106 | ); |
1107 | 1107 | }); |
1108 | 1108 | |
1109 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1110 | - return new LockdownManager(function () use ($c) { |
|
1109 | + $this->registerService('LockdownManager', function(Server $c) { |
|
1110 | + return new LockdownManager(function() use ($c) { |
|
1111 | 1111 | return $c->getSession(); |
1112 | 1112 | }); |
1113 | 1113 | }); |
1114 | 1114 | |
1115 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1115 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
1116 | 1116 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
1117 | 1117 | }); |
1118 | 1118 | |
1119 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1119 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
1120 | 1120 | return new CloudIdManager(); |
1121 | 1121 | }); |
1122 | 1122 | |
1123 | - $this->registerService(IConfig::class, function (Server $c) { |
|
1123 | + $this->registerService(IConfig::class, function(Server $c) { |
|
1124 | 1124 | return new GlobalScale\Config($c->getConfig()); |
1125 | 1125 | }); |
1126 | 1126 | |
1127 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
1127 | + $this->registerService(ICloudFederationProviderManager::class, function(Server $c) { |
|
1128 | 1128 | return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
1129 | 1129 | }); |
1130 | 1130 | |
1131 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1131 | + $this->registerService(ICloudFederationFactory::class, function(Server $c) { |
|
1132 | 1132 | return new CloudFederationFactory(); |
1133 | 1133 | }); |
1134 | 1134 | |
@@ -1138,18 +1138,18 @@ discard block |
||
1138 | 1138 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
1139 | 1139 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
1140 | 1140 | |
1141 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1141 | + $this->registerService(Defaults::class, function(Server $c) { |
|
1142 | 1142 | return new Defaults( |
1143 | 1143 | $c->getThemingDefaults() |
1144 | 1144 | ); |
1145 | 1145 | }); |
1146 | 1146 | $this->registerAlias('Defaults', \OCP\Defaults::class); |
1147 | 1147 | |
1148 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1148 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
1149 | 1149 | return $c->query(\OCP\IUserSession::class)->getSession(); |
1150 | 1150 | }); |
1151 | 1151 | |
1152 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1152 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
1153 | 1153 | return new ShareHelper( |
1154 | 1154 | $c->query(\OCP\Share\IManager::class) |
1155 | 1155 | ); |
@@ -1192,7 +1192,7 @@ discard block |
||
1192 | 1192 | $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
1193 | 1193 | $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
1194 | 1194 | |
1195 | - $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) { |
|
1195 | + $this->registerService(\OC\Security\IdentityProof\Manager::class, function(Server $c) { |
|
1196 | 1196 | return new \OC\Security\IdentityProof\Manager( |
1197 | 1197 | $c->query(\OC\Files\AppData\Factory::class), |
1198 | 1198 | $c->getCrypto(), |
@@ -1245,11 +1245,11 @@ discard block |
||
1245 | 1245 | // no avatar to remove |
1246 | 1246 | } catch (\Exception $e) { |
1247 | 1247 | // Ignore exceptions |
1248 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1248 | + $logger->info('Could not cleanup avatar of '.$user->getUID()); |
|
1249 | 1249 | } |
1250 | 1250 | }); |
1251 | 1251 | |
1252 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1252 | + $dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) { |
|
1253 | 1253 | $manager = $this->getAvatarManager(); |
1254 | 1254 | /** @var IUser $user */ |
1255 | 1255 | $user = $e->getSubject(); |
@@ -1400,7 +1400,7 @@ discard block |
||
1400 | 1400 | * @deprecated since 9.2.0 use IAppData |
1401 | 1401 | */ |
1402 | 1402 | public function getAppFolder() { |
1403 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1403 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
1404 | 1404 | $root = $this->getRootFolder(); |
1405 | 1405 | if (!$root->nodeExists($dir)) { |
1406 | 1406 | $folder = $root->newFolder($dir); |
@@ -1975,7 +1975,7 @@ discard block |
||
1975 | 1975 | /** |
1976 | 1976 | * @return \OCP\Collaboration\AutoComplete\IManager |
1977 | 1977 | */ |
1978 | - public function getAutoCompleteManager(){ |
|
1978 | + public function getAutoCompleteManager() { |
|
1979 | 1979 | return $this->query(IManager::class); |
1980 | 1980 | } |
1981 | 1981 |
@@ -31,132 +31,132 @@ |
||
31 | 31 | use OCP\IDBConnection; |
32 | 32 | |
33 | 33 | class PostgreSQL extends AbstractDatabase { |
34 | - public $dbprettyname = 'PostgreSQL'; |
|
34 | + public $dbprettyname = 'PostgreSQL'; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $username |
|
38 | - * @throws \OC\DatabaseSetupException |
|
39 | - * @suppress SqlInjectionChecker |
|
40 | - */ |
|
41 | - public function setupDatabase($username) { |
|
42 | - try { |
|
43 | - $connection = $this->connect([ |
|
44 | - 'dbname' => 'postgres' |
|
45 | - ]); |
|
46 | - //check for roles creation rights in postgresql |
|
47 | - $builder = $connection->getQueryBuilder(); |
|
48 | - $builder->automaticTablePrefix(false); |
|
49 | - $query = $builder |
|
50 | - ->select('rolname') |
|
51 | - ->from('pg_roles') |
|
52 | - ->where($builder->expr()->eq('rolcreaterole', new Literal('TRUE'))) |
|
53 | - ->andWhere($builder->expr()->eq('rolname', $builder->createNamedParameter($this->dbUser))); |
|
36 | + /** |
|
37 | + * @param string $username |
|
38 | + * @throws \OC\DatabaseSetupException |
|
39 | + * @suppress SqlInjectionChecker |
|
40 | + */ |
|
41 | + public function setupDatabase($username) { |
|
42 | + try { |
|
43 | + $connection = $this->connect([ |
|
44 | + 'dbname' => 'postgres' |
|
45 | + ]); |
|
46 | + //check for roles creation rights in postgresql |
|
47 | + $builder = $connection->getQueryBuilder(); |
|
48 | + $builder->automaticTablePrefix(false); |
|
49 | + $query = $builder |
|
50 | + ->select('rolname') |
|
51 | + ->from('pg_roles') |
|
52 | + ->where($builder->expr()->eq('rolcreaterole', new Literal('TRUE'))) |
|
53 | + ->andWhere($builder->expr()->eq('rolname', $builder->createNamedParameter($this->dbUser))); |
|
54 | 54 | |
55 | - try { |
|
56 | - $result = $query->execute(); |
|
57 | - $canCreateRoles = $result->rowCount() > 0; |
|
58 | - } catch (DatabaseException $e) { |
|
59 | - $canCreateRoles = false; |
|
60 | - } |
|
55 | + try { |
|
56 | + $result = $query->execute(); |
|
57 | + $canCreateRoles = $result->rowCount() > 0; |
|
58 | + } catch (DatabaseException $e) { |
|
59 | + $canCreateRoles = false; |
|
60 | + } |
|
61 | 61 | |
62 | - if ($canCreateRoles) { |
|
63 | - //use the admin login data for the new database user |
|
62 | + if ($canCreateRoles) { |
|
63 | + //use the admin login data for the new database user |
|
64 | 64 | |
65 | - //add prefix to the postgresql user name to prevent collisions |
|
66 | - $this->dbUser = 'oc_' . strtolower($username); |
|
67 | - //create a new password so we don't need to store the admin config in the config file |
|
68 | - $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
65 | + //add prefix to the postgresql user name to prevent collisions |
|
66 | + $this->dbUser = 'oc_' . strtolower($username); |
|
67 | + //create a new password so we don't need to store the admin config in the config file |
|
68 | + $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
69 | 69 | |
70 | - $this->createDBUser($connection); |
|
71 | - } |
|
70 | + $this->createDBUser($connection); |
|
71 | + } |
|
72 | 72 | |
73 | - $this->config->setValues([ |
|
74 | - 'dbuser' => $this->dbUser, |
|
75 | - 'dbpassword' => $this->dbPassword, |
|
76 | - ]); |
|
73 | + $this->config->setValues([ |
|
74 | + 'dbuser' => $this->dbUser, |
|
75 | + 'dbpassword' => $this->dbPassword, |
|
76 | + ]); |
|
77 | 77 | |
78 | - //create the database |
|
79 | - $this->createDatabase($connection); |
|
80 | - // the connection to dbname=postgres is not needed anymore |
|
81 | - $connection->close(); |
|
82 | - } catch (\Exception $e) { |
|
83 | - $this->logger->logException($e); |
|
84 | - $this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created'); |
|
85 | - $this->config->setValues([ |
|
86 | - 'dbuser' => $this->dbUser, |
|
87 | - 'dbpassword' => $this->dbPassword, |
|
88 | - ]); |
|
89 | - } |
|
78 | + //create the database |
|
79 | + $this->createDatabase($connection); |
|
80 | + // the connection to dbname=postgres is not needed anymore |
|
81 | + $connection->close(); |
|
82 | + } catch (\Exception $e) { |
|
83 | + $this->logger->logException($e); |
|
84 | + $this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created'); |
|
85 | + $this->config->setValues([ |
|
86 | + 'dbuser' => $this->dbUser, |
|
87 | + 'dbpassword' => $this->dbPassword, |
|
88 | + ]); |
|
89 | + } |
|
90 | 90 | |
91 | - // connect to the database (dbname=$this->dbname) and check if it needs to be filled |
|
92 | - $this->dbUser = $this->config->getValue('dbuser'); |
|
93 | - $this->dbPassword = $this->config->getValue('dbpassword'); |
|
94 | - $connection = $this->connect(); |
|
95 | - try { |
|
96 | - $connection->connect(); |
|
97 | - } catch (\Exception $e) { |
|
98 | - $this->logger->logException($e); |
|
99 | - throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'), |
|
100 | - $this->trans->t('You need to enter details of an existing account.')); |
|
101 | - } |
|
102 | - } |
|
91 | + // connect to the database (dbname=$this->dbname) and check if it needs to be filled |
|
92 | + $this->dbUser = $this->config->getValue('dbuser'); |
|
93 | + $this->dbPassword = $this->config->getValue('dbpassword'); |
|
94 | + $connection = $this->connect(); |
|
95 | + try { |
|
96 | + $connection->connect(); |
|
97 | + } catch (\Exception $e) { |
|
98 | + $this->logger->logException($e); |
|
99 | + throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'), |
|
100 | + $this->trans->t('You need to enter details of an existing account.')); |
|
101 | + } |
|
102 | + } |
|
103 | 103 | |
104 | - private function createDatabase(IDBConnection $connection) { |
|
105 | - if (!$this->databaseExists($connection)) { |
|
106 | - //The database does not exists... let's create it |
|
107 | - $query = $connection->prepare("CREATE DATABASE " . addslashes($this->dbName) . " OWNER " . addslashes($this->dbUser)); |
|
108 | - try { |
|
109 | - $query->execute(); |
|
110 | - } catch (DatabaseException $e) { |
|
111 | - $this->logger->error('Error while trying to create database'); |
|
112 | - $this->logger->logException($e); |
|
113 | - } |
|
114 | - } else { |
|
115 | - $query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC"); |
|
116 | - try { |
|
117 | - $query->execute(); |
|
118 | - } catch (DatabaseException $e) { |
|
119 | - $this->logger->error('Error while trying to restrict database permissions'); |
|
120 | - $this->logger->logException($e); |
|
121 | - } |
|
122 | - } |
|
123 | - } |
|
104 | + private function createDatabase(IDBConnection $connection) { |
|
105 | + if (!$this->databaseExists($connection)) { |
|
106 | + //The database does not exists... let's create it |
|
107 | + $query = $connection->prepare("CREATE DATABASE " . addslashes($this->dbName) . " OWNER " . addslashes($this->dbUser)); |
|
108 | + try { |
|
109 | + $query->execute(); |
|
110 | + } catch (DatabaseException $e) { |
|
111 | + $this->logger->error('Error while trying to create database'); |
|
112 | + $this->logger->logException($e); |
|
113 | + } |
|
114 | + } else { |
|
115 | + $query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC"); |
|
116 | + try { |
|
117 | + $query->execute(); |
|
118 | + } catch (DatabaseException $e) { |
|
119 | + $this->logger->error('Error while trying to restrict database permissions'); |
|
120 | + $this->logger->logException($e); |
|
121 | + } |
|
122 | + } |
|
123 | + } |
|
124 | 124 | |
125 | - private function userExists(IDBConnection $connection) { |
|
126 | - $builder = $connection->getQueryBuilder(); |
|
127 | - $builder->automaticTablePrefix(false); |
|
128 | - $query = $builder->select('*') |
|
129 | - ->from('pg_roles') |
|
130 | - ->where($builder->expr()->eq('rolname', $builder->createNamedParameter($this->dbUser))); |
|
131 | - $result = $query->execute(); |
|
132 | - return $result->rowCount() > 0; |
|
133 | - } |
|
125 | + private function userExists(IDBConnection $connection) { |
|
126 | + $builder = $connection->getQueryBuilder(); |
|
127 | + $builder->automaticTablePrefix(false); |
|
128 | + $query = $builder->select('*') |
|
129 | + ->from('pg_roles') |
|
130 | + ->where($builder->expr()->eq('rolname', $builder->createNamedParameter($this->dbUser))); |
|
131 | + $result = $query->execute(); |
|
132 | + return $result->rowCount() > 0; |
|
133 | + } |
|
134 | 134 | |
135 | - private function databaseExists(IDBConnection $connection) { |
|
136 | - $builder = $connection->getQueryBuilder(); |
|
137 | - $builder->automaticTablePrefix(false); |
|
138 | - $query = $builder->select('datname') |
|
139 | - ->from('pg_database') |
|
140 | - ->where($builder->expr()->eq('datname', $builder->createNamedParameter($this->dbName))); |
|
141 | - $result = $query->execute(); |
|
142 | - return $result->rowCount() > 0; |
|
143 | - } |
|
135 | + private function databaseExists(IDBConnection $connection) { |
|
136 | + $builder = $connection->getQueryBuilder(); |
|
137 | + $builder->automaticTablePrefix(false); |
|
138 | + $query = $builder->select('datname') |
|
139 | + ->from('pg_database') |
|
140 | + ->where($builder->expr()->eq('datname', $builder->createNamedParameter($this->dbName))); |
|
141 | + $result = $query->execute(); |
|
142 | + return $result->rowCount() > 0; |
|
143 | + } |
|
144 | 144 | |
145 | - private function createDBUser(IDBConnection $connection) { |
|
146 | - $dbUser = $this->dbUser; |
|
147 | - try { |
|
148 | - $i = 1; |
|
149 | - while ($this->userExists($connection)) { |
|
150 | - $i++; |
|
151 | - $this->dbUser = $dbUser . $i; |
|
152 | - } |
|
145 | + private function createDBUser(IDBConnection $connection) { |
|
146 | + $dbUser = $this->dbUser; |
|
147 | + try { |
|
148 | + $i = 1; |
|
149 | + while ($this->userExists($connection)) { |
|
150 | + $i++; |
|
151 | + $this->dbUser = $dbUser . $i; |
|
152 | + } |
|
153 | 153 | |
154 | - // create the user |
|
155 | - $query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'"); |
|
156 | - $query->execute(); |
|
157 | - } catch (DatabaseException $e) { |
|
158 | - $this->logger->error('Error while trying to create database user'); |
|
159 | - $this->logger->logException($e); |
|
160 | - } |
|
161 | - } |
|
154 | + // create the user |
|
155 | + $query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'"); |
|
156 | + $query->execute(); |
|
157 | + } catch (DatabaseException $e) { |
|
158 | + $this->logger->error('Error while trying to create database user'); |
|
159 | + $this->logger->logException($e); |
|
160 | + } |
|
161 | + } |
|
162 | 162 | } |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | //use the admin login data for the new database user |
64 | 64 | |
65 | 65 | //add prefix to the postgresql user name to prevent collisions |
66 | - $this->dbUser = 'oc_' . strtolower($username); |
|
66 | + $this->dbUser = 'oc_'.strtolower($username); |
|
67 | 67 | //create a new password so we don't need to store the admin config in the config file |
68 | - $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
68 | + $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
69 | 69 | |
70 | 70 | $this->createDBUser($connection); |
71 | 71 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | private function createDatabase(IDBConnection $connection) { |
105 | 105 | if (!$this->databaseExists($connection)) { |
106 | 106 | //The database does not exists... let's create it |
107 | - $query = $connection->prepare("CREATE DATABASE " . addslashes($this->dbName) . " OWNER " . addslashes($this->dbUser)); |
|
107 | + $query = $connection->prepare("CREATE DATABASE ".addslashes($this->dbName)." OWNER ".addslashes($this->dbUser)); |
|
108 | 108 | try { |
109 | 109 | $query->execute(); |
110 | 110 | } catch (DatabaseException $e) { |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $this->logger->logException($e); |
113 | 113 | } |
114 | 114 | } else { |
115 | - $query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC"); |
|
115 | + $query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE ".addslashes($this->dbName)." FROM PUBLIC"); |
|
116 | 116 | try { |
117 | 117 | $query->execute(); |
118 | 118 | } catch (DatabaseException $e) { |
@@ -148,11 +148,11 @@ discard block |
||
148 | 148 | $i = 1; |
149 | 149 | while ($this->userExists($connection)) { |
150 | 150 | $i++; |
151 | - $this->dbUser = $dbUser . $i; |
|
151 | + $this->dbUser = $dbUser.$i; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // create the user |
155 | - $query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'"); |
|
155 | + $query = $connection->prepare("CREATE USER ".addslashes($this->dbUser)." CREATEDB PASSWORD '".addslashes($this->dbPassword)."'"); |
|
156 | 156 | $query->execute(); |
157 | 157 | } catch (DatabaseException $e) { |
158 | 158 | $this->logger->error('Error while trying to create database user'); |
@@ -32,43 +32,43 @@ |
||
32 | 32 | use OCP\Share; |
33 | 33 | |
34 | 34 | class RemoteGroupPlugin implements ISearchPlugin { |
35 | - protected $shareeEnumeration; |
|
35 | + protected $shareeEnumeration; |
|
36 | 36 | |
37 | - /** @var ICloudIdManager */ |
|
38 | - private $cloudIdManager; |
|
39 | - /** @var bool */ |
|
40 | - private $enabled = false; |
|
37 | + /** @var ICloudIdManager */ |
|
38 | + private $cloudIdManager; |
|
39 | + /** @var bool */ |
|
40 | + private $enabled = false; |
|
41 | 41 | |
42 | - public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager, ICloudIdManager $cloudIdManager) { |
|
43 | - try { |
|
44 | - $fileSharingProvider = $cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
45 | - $supportedShareTypes = $fileSharingProvider->getSupportedShareTypes(); |
|
46 | - if (in_array('group', $supportedShareTypes)) { |
|
47 | - $this->enabled = true; |
|
48 | - } |
|
49 | - } catch (\Exception $e) { |
|
50 | - // do nothing, just don't enable federated group shares |
|
51 | - } |
|
52 | - $this->cloudIdManager = $cloudIdManager; |
|
53 | - } |
|
42 | + public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager, ICloudIdManager $cloudIdManager) { |
|
43 | + try { |
|
44 | + $fileSharingProvider = $cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
45 | + $supportedShareTypes = $fileSharingProvider->getSupportedShareTypes(); |
|
46 | + if (in_array('group', $supportedShareTypes)) { |
|
47 | + $this->enabled = true; |
|
48 | + } |
|
49 | + } catch (\Exception $e) { |
|
50 | + // do nothing, just don't enable federated group shares |
|
51 | + } |
|
52 | + $this->cloudIdManager = $cloudIdManager; |
|
53 | + } |
|
54 | 54 | |
55 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
56 | - $result = ['wide' => [], 'exact' => []]; |
|
57 | - $resultType = new SearchResultType('remote_groups'); |
|
55 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
56 | + $result = ['wide' => [], 'exact' => []]; |
|
57 | + $resultType = new SearchResultType('remote_groups'); |
|
58 | 58 | |
59 | - if ($this->enabled && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { |
|
60 | - $result['exact'][] = [ |
|
61 | - 'label' => $search, |
|
62 | - 'value' => [ |
|
63 | - 'shareType' => Share::SHARE_TYPE_REMOTE_GROUP, |
|
64 | - 'shareWith' => $search, |
|
65 | - ], |
|
66 | - ]; |
|
67 | - } |
|
59 | + if ($this->enabled && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { |
|
60 | + $result['exact'][] = [ |
|
61 | + 'label' => $search, |
|
62 | + 'value' => [ |
|
63 | + 'shareType' => Share::SHARE_TYPE_REMOTE_GROUP, |
|
64 | + 'shareWith' => $search, |
|
65 | + ], |
|
66 | + ]; |
|
67 | + } |
|
68 | 68 | |
69 | - $searchResult->addResultSet($resultType, $result['wide'], $result['exact']); |
|
69 | + $searchResult->addResultSet($resultType, $result['wide'], $result['exact']); |
|
70 | 70 | |
71 | - return true; |
|
72 | - } |
|
71 | + return true; |
|
72 | + } |
|
73 | 73 | |
74 | 74 | } |
@@ -31,110 +31,110 @@ |
||
31 | 31 | namespace OC\Archive; |
32 | 32 | |
33 | 33 | abstract class Archive { |
34 | - /** |
|
35 | - * @param $source |
|
36 | - */ |
|
37 | - public abstract function __construct($source); |
|
38 | - /** |
|
39 | - * add an empty folder to the archive |
|
40 | - * @param string $path |
|
41 | - * @return bool |
|
42 | - */ |
|
43 | - public abstract function addFolder($path); |
|
44 | - /** |
|
45 | - * add a file to the archive |
|
46 | - * @param string $path |
|
47 | - * @param string $source either a local file or string data |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public abstract function addFile($path, $source=''); |
|
51 | - /** |
|
52 | - * rename a file or folder in the archive |
|
53 | - * @param string $source |
|
54 | - * @param string $dest |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public abstract function rename($source, $dest); |
|
58 | - /** |
|
59 | - * get the uncompressed size of a file in the archive |
|
60 | - * @param string $path |
|
61 | - * @return int |
|
62 | - */ |
|
63 | - public abstract function filesize($path); |
|
64 | - /** |
|
65 | - * get the last modified time of a file in the archive |
|
66 | - * @param string $path |
|
67 | - * @return int |
|
68 | - */ |
|
69 | - public abstract function mtime($path); |
|
70 | - /** |
|
71 | - * get the files in a folder |
|
72 | - * @param string $path |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - public abstract function getFolder($path); |
|
76 | - /** |
|
77 | - * get all files in the archive |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - public abstract function getFiles(); |
|
81 | - /** |
|
82 | - * get the content of a file |
|
83 | - * @param string $path |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public abstract function getFile($path); |
|
87 | - /** |
|
88 | - * extract a single file from the archive |
|
89 | - * @param string $path |
|
90 | - * @param string $dest |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - public abstract function extractFile($path, $dest); |
|
94 | - /** |
|
95 | - * extract the archive |
|
96 | - * @param string $dest |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public abstract function extract($dest); |
|
100 | - /** |
|
101 | - * check if a file or folder exists in the archive |
|
102 | - * @param string $path |
|
103 | - * @return bool |
|
104 | - */ |
|
105 | - public abstract function fileExists($path); |
|
106 | - /** |
|
107 | - * remove a file or folder from the archive |
|
108 | - * @param string $path |
|
109 | - * @return bool |
|
110 | - */ |
|
111 | - public abstract function remove($path); |
|
112 | - /** |
|
113 | - * get a file handler |
|
114 | - * @param string $path |
|
115 | - * @param string $mode |
|
116 | - * @return resource |
|
117 | - */ |
|
118 | - public abstract function getStream($path, $mode); |
|
119 | - /** |
|
120 | - * add a folder and all its content |
|
121 | - * @param string $path |
|
122 | - * @param string $source |
|
123 | - */ |
|
124 | - public function addRecursive($path, $source) { |
|
125 | - $dh = opendir($source); |
|
126 | - if(is_resource($dh)) { |
|
127 | - $this->addFolder($path); |
|
128 | - while (($file = readdir($dh)) !== false) { |
|
129 | - if($file === '.' || $file === '..') { |
|
130 | - continue; |
|
131 | - } |
|
132 | - if(is_dir($source.'/'.$file)) { |
|
133 | - $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
|
134 | - }else{ |
|
135 | - $this->addFile($path.'/'.$file, $source.'/'.$file); |
|
136 | - } |
|
137 | - } |
|
138 | - } |
|
139 | - } |
|
34 | + /** |
|
35 | + * @param $source |
|
36 | + */ |
|
37 | + public abstract function __construct($source); |
|
38 | + /** |
|
39 | + * add an empty folder to the archive |
|
40 | + * @param string $path |
|
41 | + * @return bool |
|
42 | + */ |
|
43 | + public abstract function addFolder($path); |
|
44 | + /** |
|
45 | + * add a file to the archive |
|
46 | + * @param string $path |
|
47 | + * @param string $source either a local file or string data |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public abstract function addFile($path, $source=''); |
|
51 | + /** |
|
52 | + * rename a file or folder in the archive |
|
53 | + * @param string $source |
|
54 | + * @param string $dest |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public abstract function rename($source, $dest); |
|
58 | + /** |
|
59 | + * get the uncompressed size of a file in the archive |
|
60 | + * @param string $path |
|
61 | + * @return int |
|
62 | + */ |
|
63 | + public abstract function filesize($path); |
|
64 | + /** |
|
65 | + * get the last modified time of a file in the archive |
|
66 | + * @param string $path |
|
67 | + * @return int |
|
68 | + */ |
|
69 | + public abstract function mtime($path); |
|
70 | + /** |
|
71 | + * get the files in a folder |
|
72 | + * @param string $path |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + public abstract function getFolder($path); |
|
76 | + /** |
|
77 | + * get all files in the archive |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + public abstract function getFiles(); |
|
81 | + /** |
|
82 | + * get the content of a file |
|
83 | + * @param string $path |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public abstract function getFile($path); |
|
87 | + /** |
|
88 | + * extract a single file from the archive |
|
89 | + * @param string $path |
|
90 | + * @param string $dest |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + public abstract function extractFile($path, $dest); |
|
94 | + /** |
|
95 | + * extract the archive |
|
96 | + * @param string $dest |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public abstract function extract($dest); |
|
100 | + /** |
|
101 | + * check if a file or folder exists in the archive |
|
102 | + * @param string $path |
|
103 | + * @return bool |
|
104 | + */ |
|
105 | + public abstract function fileExists($path); |
|
106 | + /** |
|
107 | + * remove a file or folder from the archive |
|
108 | + * @param string $path |
|
109 | + * @return bool |
|
110 | + */ |
|
111 | + public abstract function remove($path); |
|
112 | + /** |
|
113 | + * get a file handler |
|
114 | + * @param string $path |
|
115 | + * @param string $mode |
|
116 | + * @return resource |
|
117 | + */ |
|
118 | + public abstract function getStream($path, $mode); |
|
119 | + /** |
|
120 | + * add a folder and all its content |
|
121 | + * @param string $path |
|
122 | + * @param string $source |
|
123 | + */ |
|
124 | + public function addRecursive($path, $source) { |
|
125 | + $dh = opendir($source); |
|
126 | + if(is_resource($dh)) { |
|
127 | + $this->addFolder($path); |
|
128 | + while (($file = readdir($dh)) !== false) { |
|
129 | + if($file === '.' || $file === '..') { |
|
130 | + continue; |
|
131 | + } |
|
132 | + if(is_dir($source.'/'.$file)) { |
|
133 | + $this->addRecursive($path.'/'.$file, $source.'/'.$file); |
|
134 | + }else{ |
|
135 | + $this->addFile($path.'/'.$file, $source.'/'.$file); |
|
136 | + } |
|
137 | + } |
|
138 | + } |
|
139 | + } |
|
140 | 140 | } |
@@ -31,160 +31,160 @@ |
||
31 | 31 | use OCP\Defaults; |
32 | 32 | |
33 | 33 | class Base { |
34 | - private $template; // The template |
|
35 | - private $vars; // Vars |
|
36 | - |
|
37 | - /** @var \OCP\IL10N */ |
|
38 | - private $l10n; |
|
39 | - |
|
40 | - /** @var Defaults */ |
|
41 | - private $theme; |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $template |
|
45 | - * @param string $requestToken |
|
46 | - * @param \OCP\IL10N $l10n |
|
47 | - * @param Defaults $theme |
|
48 | - */ |
|
49 | - public function __construct($template, $requestToken, $l10n, $theme ) { |
|
50 | - $this->vars = array(); |
|
51 | - $this->vars['requesttoken'] = $requestToken; |
|
52 | - $this->l10n = $l10n; |
|
53 | - $this->template = $template; |
|
54 | - $this->theme = $theme; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $serverRoot |
|
59 | - * @param string|false $app_dir |
|
60 | - * @param string $theme |
|
61 | - * @param string $app |
|
62 | - * @return string[] |
|
63 | - */ |
|
64 | - protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) { |
|
65 | - // Check if the app is in the app folder or in the root |
|
66 | - if( file_exists($app_dir.'/templates/' )) { |
|
67 | - return [ |
|
68 | - $serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/', |
|
69 | - $app_dir.'/templates/', |
|
70 | - ]; |
|
71 | - } |
|
72 | - return [ |
|
73 | - $serverRoot.'/themes/'.$theme.'/'.$app.'/templates/', |
|
74 | - $serverRoot.'/'.$app.'/templates/', |
|
75 | - ]; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @param string $serverRoot |
|
80 | - * @param string $theme |
|
81 | - * @return string[] |
|
82 | - */ |
|
83 | - protected function getCoreTemplateDirs($theme, $serverRoot) { |
|
84 | - return [ |
|
85 | - $serverRoot.'/themes/'.$theme.'/core/templates/', |
|
86 | - $serverRoot.'/core/templates/', |
|
87 | - ]; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Assign variables |
|
92 | - * @param string $key key |
|
93 | - * @param array|bool|integer|string $value value |
|
94 | - * @return bool |
|
95 | - * |
|
96 | - * This function assigns a variable. It can be accessed via $_[$key] in |
|
97 | - * the template. |
|
98 | - * |
|
99 | - * If the key existed before, it will be overwritten |
|
100 | - */ |
|
101 | - public function assign( $key, $value) { |
|
102 | - $this->vars[$key] = $value; |
|
103 | - return true; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Appends a variable |
|
108 | - * @param string $key key |
|
109 | - * @param mixed $value value |
|
110 | - * |
|
111 | - * This function assigns a variable in an array context. If the key already |
|
112 | - * exists, the value will be appended. It can be accessed via |
|
113 | - * $_[$key][$position] in the template. |
|
114 | - */ |
|
115 | - public function append( $key, $value ) { |
|
116 | - if( array_key_exists( $key, $this->vars )) { |
|
117 | - $this->vars[$key][] = $value; |
|
118 | - } |
|
119 | - else{ |
|
120 | - $this->vars[$key] = array( $value ); |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Prints the proceeded template |
|
126 | - * @return bool |
|
127 | - * |
|
128 | - * This function proceeds the template and prints its output. |
|
129 | - */ |
|
130 | - public function printPage() { |
|
131 | - $data = $this->fetchPage(); |
|
132 | - if( $data === false ) { |
|
133 | - return false; |
|
134 | - } |
|
135 | - else{ |
|
136 | - print $data; |
|
137 | - return true; |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Process the template |
|
143 | - * |
|
144 | - * @param array|null $additionalParams |
|
145 | - * @return string This function processes the template. |
|
146 | - * |
|
147 | - * This function processes the template. |
|
148 | - */ |
|
149 | - public function fetchPage($additionalParams = null) { |
|
150 | - return $this->load($this->template, $additionalParams); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * doing the actual work |
|
155 | - * |
|
156 | - * @param string $file |
|
157 | - * @param array|null $additionalParams |
|
158 | - * @return string content |
|
159 | - * |
|
160 | - * Includes the template file, fetches its output |
|
161 | - */ |
|
162 | - protected function load($file, $additionalParams = null) { |
|
163 | - // Register the variables |
|
164 | - $_ = $this->vars; |
|
165 | - $l = $this->l10n; |
|
166 | - $theme = $this->theme; |
|
167 | - |
|
168 | - if(!is_null($additionalParams)) { |
|
169 | - $_ = array_merge( $additionalParams, $this->vars ); |
|
170 | - foreach ($_ as $var => $value) { |
|
171 | - ${$var} = $value; |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - // Include |
|
176 | - ob_start(); |
|
177 | - try { |
|
178 | - include $file; |
|
179 | - $data = ob_get_contents(); |
|
180 | - } catch (\Exception $e) { |
|
181 | - @ob_end_clean(); |
|
182 | - throw $e; |
|
183 | - } |
|
184 | - @ob_end_clean(); |
|
185 | - |
|
186 | - // Return data |
|
187 | - return $data; |
|
188 | - } |
|
34 | + private $template; // The template |
|
35 | + private $vars; // Vars |
|
36 | + |
|
37 | + /** @var \OCP\IL10N */ |
|
38 | + private $l10n; |
|
39 | + |
|
40 | + /** @var Defaults */ |
|
41 | + private $theme; |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $template |
|
45 | + * @param string $requestToken |
|
46 | + * @param \OCP\IL10N $l10n |
|
47 | + * @param Defaults $theme |
|
48 | + */ |
|
49 | + public function __construct($template, $requestToken, $l10n, $theme ) { |
|
50 | + $this->vars = array(); |
|
51 | + $this->vars['requesttoken'] = $requestToken; |
|
52 | + $this->l10n = $l10n; |
|
53 | + $this->template = $template; |
|
54 | + $this->theme = $theme; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $serverRoot |
|
59 | + * @param string|false $app_dir |
|
60 | + * @param string $theme |
|
61 | + * @param string $app |
|
62 | + * @return string[] |
|
63 | + */ |
|
64 | + protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) { |
|
65 | + // Check if the app is in the app folder or in the root |
|
66 | + if( file_exists($app_dir.'/templates/' )) { |
|
67 | + return [ |
|
68 | + $serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/', |
|
69 | + $app_dir.'/templates/', |
|
70 | + ]; |
|
71 | + } |
|
72 | + return [ |
|
73 | + $serverRoot.'/themes/'.$theme.'/'.$app.'/templates/', |
|
74 | + $serverRoot.'/'.$app.'/templates/', |
|
75 | + ]; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @param string $serverRoot |
|
80 | + * @param string $theme |
|
81 | + * @return string[] |
|
82 | + */ |
|
83 | + protected function getCoreTemplateDirs($theme, $serverRoot) { |
|
84 | + return [ |
|
85 | + $serverRoot.'/themes/'.$theme.'/core/templates/', |
|
86 | + $serverRoot.'/core/templates/', |
|
87 | + ]; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Assign variables |
|
92 | + * @param string $key key |
|
93 | + * @param array|bool|integer|string $value value |
|
94 | + * @return bool |
|
95 | + * |
|
96 | + * This function assigns a variable. It can be accessed via $_[$key] in |
|
97 | + * the template. |
|
98 | + * |
|
99 | + * If the key existed before, it will be overwritten |
|
100 | + */ |
|
101 | + public function assign( $key, $value) { |
|
102 | + $this->vars[$key] = $value; |
|
103 | + return true; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Appends a variable |
|
108 | + * @param string $key key |
|
109 | + * @param mixed $value value |
|
110 | + * |
|
111 | + * This function assigns a variable in an array context. If the key already |
|
112 | + * exists, the value will be appended. It can be accessed via |
|
113 | + * $_[$key][$position] in the template. |
|
114 | + */ |
|
115 | + public function append( $key, $value ) { |
|
116 | + if( array_key_exists( $key, $this->vars )) { |
|
117 | + $this->vars[$key][] = $value; |
|
118 | + } |
|
119 | + else{ |
|
120 | + $this->vars[$key] = array( $value ); |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Prints the proceeded template |
|
126 | + * @return bool |
|
127 | + * |
|
128 | + * This function proceeds the template and prints its output. |
|
129 | + */ |
|
130 | + public function printPage() { |
|
131 | + $data = $this->fetchPage(); |
|
132 | + if( $data === false ) { |
|
133 | + return false; |
|
134 | + } |
|
135 | + else{ |
|
136 | + print $data; |
|
137 | + return true; |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Process the template |
|
143 | + * |
|
144 | + * @param array|null $additionalParams |
|
145 | + * @return string This function processes the template. |
|
146 | + * |
|
147 | + * This function processes the template. |
|
148 | + */ |
|
149 | + public function fetchPage($additionalParams = null) { |
|
150 | + return $this->load($this->template, $additionalParams); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * doing the actual work |
|
155 | + * |
|
156 | + * @param string $file |
|
157 | + * @param array|null $additionalParams |
|
158 | + * @return string content |
|
159 | + * |
|
160 | + * Includes the template file, fetches its output |
|
161 | + */ |
|
162 | + protected function load($file, $additionalParams = null) { |
|
163 | + // Register the variables |
|
164 | + $_ = $this->vars; |
|
165 | + $l = $this->l10n; |
|
166 | + $theme = $this->theme; |
|
167 | + |
|
168 | + if(!is_null($additionalParams)) { |
|
169 | + $_ = array_merge( $additionalParams, $this->vars ); |
|
170 | + foreach ($_ as $var => $value) { |
|
171 | + ${$var} = $value; |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + // Include |
|
176 | + ob_start(); |
|
177 | + try { |
|
178 | + include $file; |
|
179 | + $data = ob_get_contents(); |
|
180 | + } catch (\Exception $e) { |
|
181 | + @ob_end_clean(); |
|
182 | + throw $e; |
|
183 | + } |
|
184 | + @ob_end_clean(); |
|
185 | + |
|
186 | + // Return data |
|
187 | + return $data; |
|
188 | + } |
|
189 | 189 | |
190 | 190 | } |