@@ -46,1140 +46,1140 @@ |
||
46 | 46 | */ |
47 | 47 | class DefaultShareProvider implements IShareProvider { |
48 | 48 | |
49 | - // Special share type for user modified group shares |
|
50 | - const SHARE_TYPE_USERGROUP = 2; |
|
51 | - |
|
52 | - /** @var IDBConnection */ |
|
53 | - private $dbConn; |
|
54 | - |
|
55 | - /** @var IUserManager */ |
|
56 | - private $userManager; |
|
57 | - |
|
58 | - /** @var IGroupManager */ |
|
59 | - private $groupManager; |
|
60 | - |
|
61 | - /** @var IRootFolder */ |
|
62 | - private $rootFolder; |
|
63 | - |
|
64 | - /** |
|
65 | - * DefaultShareProvider constructor. |
|
66 | - * |
|
67 | - * @param IDBConnection $connection |
|
68 | - * @param IUserManager $userManager |
|
69 | - * @param IGroupManager $groupManager |
|
70 | - * @param IRootFolder $rootFolder |
|
71 | - */ |
|
72 | - public function __construct( |
|
73 | - IDBConnection $connection, |
|
74 | - IUserManager $userManager, |
|
75 | - IGroupManager $groupManager, |
|
76 | - IRootFolder $rootFolder) { |
|
77 | - $this->dbConn = $connection; |
|
78 | - $this->userManager = $userManager; |
|
79 | - $this->groupManager = $groupManager; |
|
80 | - $this->rootFolder = $rootFolder; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Return the identifier of this provider. |
|
85 | - * |
|
86 | - * @return string Containing only [a-zA-Z0-9] |
|
87 | - */ |
|
88 | - public function identifier() { |
|
89 | - return 'ocinternal'; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Share a path |
|
94 | - * |
|
95 | - * @param \OCP\Share\IShare $share |
|
96 | - * @return \OCP\Share\IShare The share object |
|
97 | - * @throws ShareNotFound |
|
98 | - * @throws \Exception |
|
99 | - */ |
|
100 | - public function create(\OCP\Share\IShare $share) { |
|
101 | - $qb = $this->dbConn->getQueryBuilder(); |
|
102 | - |
|
103 | - $qb->insert('share'); |
|
104 | - $qb->setValue('share_type', $qb->createNamedParameter($share->getShareType())); |
|
105 | - |
|
106 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
107 | - //Set the UID of the user we share with |
|
108 | - $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
109 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
110 | - //Set the GID of the group we share with |
|
111 | - $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
112 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
113 | - //Set the token of the share |
|
114 | - $qb->setValue('token', $qb->createNamedParameter($share->getToken())); |
|
115 | - |
|
116 | - //If a password is set store it |
|
117 | - if ($share->getPassword() !== null) { |
|
118 | - $qb->setValue('password', $qb->createNamedParameter($share->getPassword())); |
|
119 | - } |
|
120 | - |
|
121 | - //If an expiration date is set store it |
|
122 | - if ($share->getExpirationDate() !== null) { |
|
123 | - $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime')); |
|
124 | - } |
|
125 | - |
|
126 | - if (method_exists($share, 'getParent')) { |
|
127 | - $qb->setValue('parent', $qb->createNamedParameter($share->getParent())); |
|
128 | - } |
|
129 | - } else { |
|
130 | - throw new \Exception('invalid share type!'); |
|
131 | - } |
|
132 | - |
|
133 | - // Set what is shares |
|
134 | - $qb->setValue('item_type', $qb->createParameter('itemType')); |
|
135 | - if ($share->getNode() instanceof \OCP\Files\File) { |
|
136 | - $qb->setParameter('itemType', 'file'); |
|
137 | - } else { |
|
138 | - $qb->setParameter('itemType', 'folder'); |
|
139 | - } |
|
140 | - |
|
141 | - // Set the file id |
|
142 | - $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
143 | - $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
144 | - |
|
145 | - // set the permissions |
|
146 | - $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions())); |
|
147 | - |
|
148 | - // Set who created this share |
|
149 | - $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy())); |
|
150 | - |
|
151 | - // Set who is the owner of this file/folder (and this the owner of the share) |
|
152 | - $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner())); |
|
153 | - |
|
154 | - // Set the file target |
|
155 | - $qb->setValue('file_target', $qb->createNamedParameter($share->getTarget())); |
|
156 | - |
|
157 | - // Set the time this share was created |
|
158 | - $qb->setValue('stime', $qb->createNamedParameter(time())); |
|
159 | - |
|
160 | - // insert the data and fetch the id of the share |
|
161 | - $this->dbConn->beginTransaction(); |
|
162 | - $qb->execute(); |
|
163 | - $id = $this->dbConn->lastInsertId('*PREFIX*share'); |
|
164 | - |
|
165 | - // Now fetch the inserted share and create a complete share object |
|
166 | - $qb = $this->dbConn->getQueryBuilder(); |
|
167 | - $qb->select('*') |
|
168 | - ->from('share') |
|
169 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
170 | - |
|
171 | - $cursor = $qb->execute(); |
|
172 | - $data = $cursor->fetch(); |
|
173 | - $this->dbConn->commit(); |
|
174 | - $cursor->closeCursor(); |
|
175 | - |
|
176 | - if ($data === false) { |
|
177 | - throw new ShareNotFound(); |
|
178 | - } |
|
179 | - |
|
180 | - $share = $this->createShare($data); |
|
181 | - return $share; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Update a share |
|
186 | - * |
|
187 | - * @param \OCP\Share\IShare $share |
|
188 | - * @return \OCP\Share\IShare The share object |
|
189 | - */ |
|
190 | - public function update(\OCP\Share\IShare $share) { |
|
191 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
192 | - /* |
|
49 | + // Special share type for user modified group shares |
|
50 | + const SHARE_TYPE_USERGROUP = 2; |
|
51 | + |
|
52 | + /** @var IDBConnection */ |
|
53 | + private $dbConn; |
|
54 | + |
|
55 | + /** @var IUserManager */ |
|
56 | + private $userManager; |
|
57 | + |
|
58 | + /** @var IGroupManager */ |
|
59 | + private $groupManager; |
|
60 | + |
|
61 | + /** @var IRootFolder */ |
|
62 | + private $rootFolder; |
|
63 | + |
|
64 | + /** |
|
65 | + * DefaultShareProvider constructor. |
|
66 | + * |
|
67 | + * @param IDBConnection $connection |
|
68 | + * @param IUserManager $userManager |
|
69 | + * @param IGroupManager $groupManager |
|
70 | + * @param IRootFolder $rootFolder |
|
71 | + */ |
|
72 | + public function __construct( |
|
73 | + IDBConnection $connection, |
|
74 | + IUserManager $userManager, |
|
75 | + IGroupManager $groupManager, |
|
76 | + IRootFolder $rootFolder) { |
|
77 | + $this->dbConn = $connection; |
|
78 | + $this->userManager = $userManager; |
|
79 | + $this->groupManager = $groupManager; |
|
80 | + $this->rootFolder = $rootFolder; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Return the identifier of this provider. |
|
85 | + * |
|
86 | + * @return string Containing only [a-zA-Z0-9] |
|
87 | + */ |
|
88 | + public function identifier() { |
|
89 | + return 'ocinternal'; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Share a path |
|
94 | + * |
|
95 | + * @param \OCP\Share\IShare $share |
|
96 | + * @return \OCP\Share\IShare The share object |
|
97 | + * @throws ShareNotFound |
|
98 | + * @throws \Exception |
|
99 | + */ |
|
100 | + public function create(\OCP\Share\IShare $share) { |
|
101 | + $qb = $this->dbConn->getQueryBuilder(); |
|
102 | + |
|
103 | + $qb->insert('share'); |
|
104 | + $qb->setValue('share_type', $qb->createNamedParameter($share->getShareType())); |
|
105 | + |
|
106 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
107 | + //Set the UID of the user we share with |
|
108 | + $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
109 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
110 | + //Set the GID of the group we share with |
|
111 | + $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
112 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
113 | + //Set the token of the share |
|
114 | + $qb->setValue('token', $qb->createNamedParameter($share->getToken())); |
|
115 | + |
|
116 | + //If a password is set store it |
|
117 | + if ($share->getPassword() !== null) { |
|
118 | + $qb->setValue('password', $qb->createNamedParameter($share->getPassword())); |
|
119 | + } |
|
120 | + |
|
121 | + //If an expiration date is set store it |
|
122 | + if ($share->getExpirationDate() !== null) { |
|
123 | + $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime')); |
|
124 | + } |
|
125 | + |
|
126 | + if (method_exists($share, 'getParent')) { |
|
127 | + $qb->setValue('parent', $qb->createNamedParameter($share->getParent())); |
|
128 | + } |
|
129 | + } else { |
|
130 | + throw new \Exception('invalid share type!'); |
|
131 | + } |
|
132 | + |
|
133 | + // Set what is shares |
|
134 | + $qb->setValue('item_type', $qb->createParameter('itemType')); |
|
135 | + if ($share->getNode() instanceof \OCP\Files\File) { |
|
136 | + $qb->setParameter('itemType', 'file'); |
|
137 | + } else { |
|
138 | + $qb->setParameter('itemType', 'folder'); |
|
139 | + } |
|
140 | + |
|
141 | + // Set the file id |
|
142 | + $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
143 | + $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
144 | + |
|
145 | + // set the permissions |
|
146 | + $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions())); |
|
147 | + |
|
148 | + // Set who created this share |
|
149 | + $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy())); |
|
150 | + |
|
151 | + // Set who is the owner of this file/folder (and this the owner of the share) |
|
152 | + $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner())); |
|
153 | + |
|
154 | + // Set the file target |
|
155 | + $qb->setValue('file_target', $qb->createNamedParameter($share->getTarget())); |
|
156 | + |
|
157 | + // Set the time this share was created |
|
158 | + $qb->setValue('stime', $qb->createNamedParameter(time())); |
|
159 | + |
|
160 | + // insert the data and fetch the id of the share |
|
161 | + $this->dbConn->beginTransaction(); |
|
162 | + $qb->execute(); |
|
163 | + $id = $this->dbConn->lastInsertId('*PREFIX*share'); |
|
164 | + |
|
165 | + // Now fetch the inserted share and create a complete share object |
|
166 | + $qb = $this->dbConn->getQueryBuilder(); |
|
167 | + $qb->select('*') |
|
168 | + ->from('share') |
|
169 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
170 | + |
|
171 | + $cursor = $qb->execute(); |
|
172 | + $data = $cursor->fetch(); |
|
173 | + $this->dbConn->commit(); |
|
174 | + $cursor->closeCursor(); |
|
175 | + |
|
176 | + if ($data === false) { |
|
177 | + throw new ShareNotFound(); |
|
178 | + } |
|
179 | + |
|
180 | + $share = $this->createShare($data); |
|
181 | + return $share; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Update a share |
|
186 | + * |
|
187 | + * @param \OCP\Share\IShare $share |
|
188 | + * @return \OCP\Share\IShare The share object |
|
189 | + */ |
|
190 | + public function update(\OCP\Share\IShare $share) { |
|
191 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
192 | + /* |
|
193 | 193 | * We allow updating the recipient on user shares. |
194 | 194 | */ |
195 | - $qb = $this->dbConn->getQueryBuilder(); |
|
196 | - $qb->update('share') |
|
197 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
198 | - ->set('share_with', $qb->createNamedParameter($share->getSharedWith())) |
|
199 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
200 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
201 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
202 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
203 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
204 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
205 | - ->execute(); |
|
206 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
207 | - $qb = $this->dbConn->getQueryBuilder(); |
|
208 | - $qb->update('share') |
|
209 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
210 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
211 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
212 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
213 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
214 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
215 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
216 | - ->execute(); |
|
217 | - |
|
218 | - /* |
|
195 | + $qb = $this->dbConn->getQueryBuilder(); |
|
196 | + $qb->update('share') |
|
197 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
198 | + ->set('share_with', $qb->createNamedParameter($share->getSharedWith())) |
|
199 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
200 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
201 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
202 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
203 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
204 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
205 | + ->execute(); |
|
206 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
207 | + $qb = $this->dbConn->getQueryBuilder(); |
|
208 | + $qb->update('share') |
|
209 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
210 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
211 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
212 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
213 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
214 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
215 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
216 | + ->execute(); |
|
217 | + |
|
218 | + /* |
|
219 | 219 | * Update all user defined group shares |
220 | 220 | */ |
221 | - $qb = $this->dbConn->getQueryBuilder(); |
|
222 | - $qb->update('share') |
|
223 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
224 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
225 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
226 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
227 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
228 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
229 | - ->execute(); |
|
230 | - |
|
231 | - /* |
|
221 | + $qb = $this->dbConn->getQueryBuilder(); |
|
222 | + $qb->update('share') |
|
223 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
224 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
225 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
226 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
227 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
228 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
229 | + ->execute(); |
|
230 | + |
|
231 | + /* |
|
232 | 232 | * Now update the permissions for all children that have not set it to 0 |
233 | 233 | */ |
234 | - $qb = $this->dbConn->getQueryBuilder(); |
|
235 | - $qb->update('share') |
|
236 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
237 | - ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0))) |
|
238 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
239 | - ->execute(); |
|
240 | - |
|
241 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
242 | - $qb = $this->dbConn->getQueryBuilder(); |
|
243 | - $qb->update('share') |
|
244 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
245 | - ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
246 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
247 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
248 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
249 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
250 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
251 | - ->set('token', $qb->createNamedParameter($share->getToken())) |
|
252 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
253 | - ->execute(); |
|
254 | - } |
|
255 | - |
|
256 | - return $share; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Get all children of this share |
|
261 | - * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
262 | - * |
|
263 | - * @param \OCP\Share\IShare $parent |
|
264 | - * @return \OCP\Share\IShare[] |
|
265 | - */ |
|
266 | - public function getChildren(\OCP\Share\IShare $parent) { |
|
267 | - $children = []; |
|
268 | - |
|
269 | - $qb = $this->dbConn->getQueryBuilder(); |
|
270 | - $qb->select('*') |
|
271 | - ->from('share') |
|
272 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
273 | - ->andWhere( |
|
274 | - $qb->expr()->in( |
|
275 | - 'share_type', |
|
276 | - $qb->createNamedParameter([ |
|
277 | - \OCP\Share::SHARE_TYPE_USER, |
|
278 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
279 | - \OCP\Share::SHARE_TYPE_LINK, |
|
280 | - ], IQueryBuilder::PARAM_INT_ARRAY) |
|
281 | - ) |
|
282 | - ) |
|
283 | - ->andWhere($qb->expr()->orX( |
|
284 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
285 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
286 | - )) |
|
287 | - ->orderBy('id'); |
|
288 | - |
|
289 | - $cursor = $qb->execute(); |
|
290 | - while($data = $cursor->fetch()) { |
|
291 | - $children[] = $this->createShare($data); |
|
292 | - } |
|
293 | - $cursor->closeCursor(); |
|
294 | - |
|
295 | - return $children; |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Delete a share |
|
300 | - * |
|
301 | - * @param \OCP\Share\IShare $share |
|
302 | - */ |
|
303 | - public function delete(\OCP\Share\IShare $share) { |
|
304 | - $qb = $this->dbConn->getQueryBuilder(); |
|
305 | - $qb->delete('share') |
|
306 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))); |
|
307 | - |
|
308 | - /* |
|
234 | + $qb = $this->dbConn->getQueryBuilder(); |
|
235 | + $qb->update('share') |
|
236 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
237 | + ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0))) |
|
238 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
239 | + ->execute(); |
|
240 | + |
|
241 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
242 | + $qb = $this->dbConn->getQueryBuilder(); |
|
243 | + $qb->update('share') |
|
244 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
245 | + ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
246 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
247 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
248 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
249 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
250 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
251 | + ->set('token', $qb->createNamedParameter($share->getToken())) |
|
252 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
253 | + ->execute(); |
|
254 | + } |
|
255 | + |
|
256 | + return $share; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Get all children of this share |
|
261 | + * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
262 | + * |
|
263 | + * @param \OCP\Share\IShare $parent |
|
264 | + * @return \OCP\Share\IShare[] |
|
265 | + */ |
|
266 | + public function getChildren(\OCP\Share\IShare $parent) { |
|
267 | + $children = []; |
|
268 | + |
|
269 | + $qb = $this->dbConn->getQueryBuilder(); |
|
270 | + $qb->select('*') |
|
271 | + ->from('share') |
|
272 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
273 | + ->andWhere( |
|
274 | + $qb->expr()->in( |
|
275 | + 'share_type', |
|
276 | + $qb->createNamedParameter([ |
|
277 | + \OCP\Share::SHARE_TYPE_USER, |
|
278 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
279 | + \OCP\Share::SHARE_TYPE_LINK, |
|
280 | + ], IQueryBuilder::PARAM_INT_ARRAY) |
|
281 | + ) |
|
282 | + ) |
|
283 | + ->andWhere($qb->expr()->orX( |
|
284 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
285 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
286 | + )) |
|
287 | + ->orderBy('id'); |
|
288 | + |
|
289 | + $cursor = $qb->execute(); |
|
290 | + while($data = $cursor->fetch()) { |
|
291 | + $children[] = $this->createShare($data); |
|
292 | + } |
|
293 | + $cursor->closeCursor(); |
|
294 | + |
|
295 | + return $children; |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Delete a share |
|
300 | + * |
|
301 | + * @param \OCP\Share\IShare $share |
|
302 | + */ |
|
303 | + public function delete(\OCP\Share\IShare $share) { |
|
304 | + $qb = $this->dbConn->getQueryBuilder(); |
|
305 | + $qb->delete('share') |
|
306 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))); |
|
307 | + |
|
308 | + /* |
|
309 | 309 | * If the share is a group share delete all possible |
310 | 310 | * user defined groups shares. |
311 | 311 | */ |
312 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
313 | - $qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))); |
|
314 | - } |
|
315 | - |
|
316 | - $qb->execute(); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Unshare a share from the recipient. If this is a group share |
|
321 | - * this means we need a special entry in the share db. |
|
322 | - * |
|
323 | - * @param \OCP\Share\IShare $share |
|
324 | - * @param string $recipient UserId of recipient |
|
325 | - * @throws BackendError |
|
326 | - * @throws ProviderException |
|
327 | - */ |
|
328 | - public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) { |
|
329 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
330 | - |
|
331 | - $group = $this->groupManager->get($share->getSharedWith()); |
|
332 | - $user = $this->userManager->get($recipient); |
|
333 | - |
|
334 | - if (is_null($group)) { |
|
335 | - throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
336 | - } |
|
337 | - |
|
338 | - if (!$group->inGroup($user)) { |
|
339 | - throw new ProviderException('Recipient not in receiving group'); |
|
340 | - } |
|
341 | - |
|
342 | - // Try to fetch user specific share |
|
343 | - $qb = $this->dbConn->getQueryBuilder(); |
|
344 | - $stmt = $qb->select('*') |
|
345 | - ->from('share') |
|
346 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
347 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
348 | - ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
349 | - ->andWhere($qb->expr()->orX( |
|
350 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
351 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
352 | - )) |
|
353 | - ->execute(); |
|
354 | - |
|
355 | - $data = $stmt->fetch(); |
|
356 | - |
|
357 | - /* |
|
312 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
313 | + $qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))); |
|
314 | + } |
|
315 | + |
|
316 | + $qb->execute(); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Unshare a share from the recipient. If this is a group share |
|
321 | + * this means we need a special entry in the share db. |
|
322 | + * |
|
323 | + * @param \OCP\Share\IShare $share |
|
324 | + * @param string $recipient UserId of recipient |
|
325 | + * @throws BackendError |
|
326 | + * @throws ProviderException |
|
327 | + */ |
|
328 | + public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) { |
|
329 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
330 | + |
|
331 | + $group = $this->groupManager->get($share->getSharedWith()); |
|
332 | + $user = $this->userManager->get($recipient); |
|
333 | + |
|
334 | + if (is_null($group)) { |
|
335 | + throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
336 | + } |
|
337 | + |
|
338 | + if (!$group->inGroup($user)) { |
|
339 | + throw new ProviderException('Recipient not in receiving group'); |
|
340 | + } |
|
341 | + |
|
342 | + // Try to fetch user specific share |
|
343 | + $qb = $this->dbConn->getQueryBuilder(); |
|
344 | + $stmt = $qb->select('*') |
|
345 | + ->from('share') |
|
346 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
347 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
348 | + ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
349 | + ->andWhere($qb->expr()->orX( |
|
350 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
351 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
352 | + )) |
|
353 | + ->execute(); |
|
354 | + |
|
355 | + $data = $stmt->fetch(); |
|
356 | + |
|
357 | + /* |
|
358 | 358 | * Check if there already is a user specific group share. |
359 | 359 | * If there is update it (if required). |
360 | 360 | */ |
361 | - if ($data === false) { |
|
362 | - $qb = $this->dbConn->getQueryBuilder(); |
|
363 | - |
|
364 | - $type = $share->getNodeType(); |
|
365 | - |
|
366 | - //Insert new share |
|
367 | - $qb->insert('share') |
|
368 | - ->values([ |
|
369 | - 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
370 | - 'share_with' => $qb->createNamedParameter($recipient), |
|
371 | - 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
372 | - 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
373 | - 'parent' => $qb->createNamedParameter($share->getId()), |
|
374 | - 'item_type' => $qb->createNamedParameter($type), |
|
375 | - 'item_source' => $qb->createNamedParameter($share->getNodeId()), |
|
376 | - 'file_source' => $qb->createNamedParameter($share->getNodeId()), |
|
377 | - 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
378 | - 'permissions' => $qb->createNamedParameter(0), |
|
379 | - 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
380 | - ])->execute(); |
|
381 | - |
|
382 | - } else if ($data['permissions'] !== 0) { |
|
383 | - |
|
384 | - // Update existing usergroup share |
|
385 | - $qb = $this->dbConn->getQueryBuilder(); |
|
386 | - $qb->update('share') |
|
387 | - ->set('permissions', $qb->createNamedParameter(0)) |
|
388 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
389 | - ->execute(); |
|
390 | - } |
|
391 | - |
|
392 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
393 | - |
|
394 | - if ($share->getSharedWith() !== $recipient) { |
|
395 | - throw new ProviderException('Recipient does not match'); |
|
396 | - } |
|
397 | - |
|
398 | - // We can just delete user and link shares |
|
399 | - $this->delete($share); |
|
400 | - } else { |
|
401 | - throw new ProviderException('Invalid shareType'); |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * @inheritdoc |
|
407 | - */ |
|
408 | - public function move(\OCP\Share\IShare $share, $recipient) { |
|
409 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
410 | - // Just update the target |
|
411 | - $qb = $this->dbConn->getQueryBuilder(); |
|
412 | - $qb->update('share') |
|
413 | - ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
414 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
415 | - ->execute(); |
|
416 | - |
|
417 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
418 | - |
|
419 | - // Check if there is a usergroup share |
|
420 | - $qb = $this->dbConn->getQueryBuilder(); |
|
421 | - $stmt = $qb->select('id') |
|
422 | - ->from('share') |
|
423 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
424 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
425 | - ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
426 | - ->andWhere($qb->expr()->orX( |
|
427 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
428 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
429 | - )) |
|
430 | - ->setMaxResults(1) |
|
431 | - ->execute(); |
|
432 | - |
|
433 | - $data = $stmt->fetch(); |
|
434 | - $stmt->closeCursor(); |
|
435 | - |
|
436 | - if ($data === false) { |
|
437 | - // No usergroup share yet. Create one. |
|
438 | - $qb = $this->dbConn->getQueryBuilder(); |
|
439 | - $qb->insert('share') |
|
440 | - ->values([ |
|
441 | - 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
442 | - 'share_with' => $qb->createNamedParameter($recipient), |
|
443 | - 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
444 | - 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
445 | - 'parent' => $qb->createNamedParameter($share->getId()), |
|
446 | - 'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'), |
|
447 | - 'item_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
448 | - 'file_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
449 | - 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
450 | - 'permissions' => $qb->createNamedParameter($share->getPermissions()), |
|
451 | - 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
452 | - ])->execute(); |
|
453 | - } else { |
|
454 | - // Already a usergroup share. Update it. |
|
455 | - $qb = $this->dbConn->getQueryBuilder(); |
|
456 | - $qb->update('share') |
|
457 | - ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
458 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
459 | - ->execute(); |
|
460 | - } |
|
461 | - } |
|
462 | - |
|
463 | - return $share; |
|
464 | - } |
|
465 | - |
|
466 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
467 | - $qb = $this->dbConn->getQueryBuilder(); |
|
468 | - $qb->select('*') |
|
469 | - ->from('share', 's') |
|
470 | - ->andWhere($qb->expr()->orX( |
|
471 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
472 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
473 | - )); |
|
474 | - |
|
475 | - $qb->andWhere($qb->expr()->orX( |
|
476 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
477 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
478 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
479 | - )); |
|
480 | - |
|
481 | - /** |
|
482 | - * Reshares for this user are shares where they are the owner. |
|
483 | - */ |
|
484 | - if ($reshares === false) { |
|
485 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
486 | - } else { |
|
487 | - $qb->andWhere( |
|
488 | - $qb->expr()->orX( |
|
489 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
490 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
491 | - ) |
|
492 | - ); |
|
493 | - } |
|
494 | - |
|
495 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
496 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
497 | - |
|
498 | - $qb->orderBy('id'); |
|
499 | - |
|
500 | - $cursor = $qb->execute(); |
|
501 | - $shares = []; |
|
502 | - while ($data = $cursor->fetch()) { |
|
503 | - $shares[$data['fileid']][] = $this->createShare($data); |
|
504 | - } |
|
505 | - $cursor->closeCursor(); |
|
506 | - |
|
507 | - return $shares; |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * @inheritdoc |
|
512 | - */ |
|
513 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
514 | - $qb = $this->dbConn->getQueryBuilder(); |
|
515 | - $qb->select('*') |
|
516 | - ->from('share') |
|
517 | - ->andWhere($qb->expr()->orX( |
|
518 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
519 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
520 | - )); |
|
521 | - |
|
522 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType))); |
|
523 | - |
|
524 | - /** |
|
525 | - * Reshares for this user are shares where they are the owner. |
|
526 | - */ |
|
527 | - if ($reshares === false) { |
|
528 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
529 | - } else { |
|
530 | - $qb->andWhere( |
|
531 | - $qb->expr()->orX( |
|
532 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
533 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
534 | - ) |
|
535 | - ); |
|
536 | - } |
|
537 | - |
|
538 | - if ($node !== null) { |
|
539 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
540 | - } |
|
541 | - |
|
542 | - if ($limit !== -1) { |
|
543 | - $qb->setMaxResults($limit); |
|
544 | - } |
|
545 | - |
|
546 | - $qb->setFirstResult($offset); |
|
547 | - $qb->orderBy('id'); |
|
548 | - |
|
549 | - $cursor = $qb->execute(); |
|
550 | - $shares = []; |
|
551 | - while($data = $cursor->fetch()) { |
|
552 | - $shares[] = $this->createShare($data); |
|
553 | - } |
|
554 | - $cursor->closeCursor(); |
|
555 | - |
|
556 | - return $shares; |
|
557 | - } |
|
558 | - |
|
559 | - /** |
|
560 | - * @inheritdoc |
|
561 | - */ |
|
562 | - public function getShareById($id, $recipientId = null) { |
|
563 | - $qb = $this->dbConn->getQueryBuilder(); |
|
564 | - |
|
565 | - $qb->select('*') |
|
566 | - ->from('share') |
|
567 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
568 | - ->andWhere( |
|
569 | - $qb->expr()->in( |
|
570 | - 'share_type', |
|
571 | - $qb->createNamedParameter([ |
|
572 | - \OCP\Share::SHARE_TYPE_USER, |
|
573 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
574 | - \OCP\Share::SHARE_TYPE_LINK, |
|
575 | - ], IQueryBuilder::PARAM_INT_ARRAY) |
|
576 | - ) |
|
577 | - ) |
|
578 | - ->andWhere($qb->expr()->orX( |
|
579 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
580 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
581 | - )); |
|
582 | - |
|
583 | - $cursor = $qb->execute(); |
|
584 | - $data = $cursor->fetch(); |
|
585 | - $cursor->closeCursor(); |
|
586 | - |
|
587 | - if ($data === false) { |
|
588 | - throw new ShareNotFound(); |
|
589 | - } |
|
590 | - |
|
591 | - try { |
|
592 | - $share = $this->createShare($data); |
|
593 | - } catch (InvalidShare $e) { |
|
594 | - throw new ShareNotFound(); |
|
595 | - } |
|
596 | - |
|
597 | - // If the recipient is set for a group share resolve to that user |
|
598 | - if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
599 | - $share = $this->resolveGroupShares([$share], $recipientId)[0]; |
|
600 | - } |
|
601 | - |
|
602 | - return $share; |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Get shares for a given path |
|
607 | - * |
|
608 | - * @param \OCP\Files\Node $path |
|
609 | - * @return \OCP\Share\IShare[] |
|
610 | - */ |
|
611 | - public function getSharesByPath(Node $path) { |
|
612 | - $qb = $this->dbConn->getQueryBuilder(); |
|
613 | - |
|
614 | - $cursor = $qb->select('*') |
|
615 | - ->from('share') |
|
616 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
617 | - ->andWhere( |
|
618 | - $qb->expr()->orX( |
|
619 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
620 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)) |
|
621 | - ) |
|
622 | - ) |
|
623 | - ->andWhere($qb->expr()->orX( |
|
624 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
625 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
626 | - )) |
|
627 | - ->execute(); |
|
628 | - |
|
629 | - $shares = []; |
|
630 | - while($data = $cursor->fetch()) { |
|
631 | - $shares[] = $this->createShare($data); |
|
632 | - } |
|
633 | - $cursor->closeCursor(); |
|
634 | - |
|
635 | - return $shares; |
|
636 | - } |
|
637 | - |
|
638 | - /** |
|
639 | - * Returns whether the given database result can be interpreted as |
|
640 | - * a share with accessible file (not trashed, not deleted) |
|
641 | - */ |
|
642 | - private function isAccessibleResult($data) { |
|
643 | - // exclude shares leading to deleted file entries |
|
644 | - if ($data['fileid'] === null) { |
|
645 | - return false; |
|
646 | - } |
|
647 | - |
|
648 | - // exclude shares leading to trashbin on home storages |
|
649 | - $pathSections = explode('/', $data['path'], 2); |
|
650 | - // FIXME: would not detect rare md5'd home storage case properly |
|
651 | - if ($pathSections[0] !== 'files' |
|
652 | - && in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) { |
|
653 | - return false; |
|
654 | - } |
|
655 | - return true; |
|
656 | - } |
|
657 | - |
|
658 | - /** |
|
659 | - * @inheritdoc |
|
660 | - */ |
|
661 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
662 | - /** @var Share[] $shares */ |
|
663 | - $shares = []; |
|
664 | - |
|
665 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
666 | - //Get shares directly with this user |
|
667 | - $qb = $this->dbConn->getQueryBuilder(); |
|
668 | - $qb->select('s.*', |
|
669 | - 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
670 | - 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
671 | - 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
672 | - ) |
|
673 | - ->selectAlias('st.id', 'storage_string_id') |
|
674 | - ->from('share', 's') |
|
675 | - ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
676 | - ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')); |
|
677 | - |
|
678 | - // Order by id |
|
679 | - $qb->orderBy('s.id'); |
|
680 | - |
|
681 | - // Set limit and offset |
|
682 | - if ($limit !== -1) { |
|
683 | - $qb->setMaxResults($limit); |
|
684 | - } |
|
685 | - $qb->setFirstResult($offset); |
|
686 | - |
|
687 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))) |
|
688 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
689 | - ->andWhere($qb->expr()->orX( |
|
690 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
691 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
692 | - )); |
|
693 | - |
|
694 | - // Filter by node if provided |
|
695 | - if ($node !== null) { |
|
696 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
697 | - } |
|
698 | - |
|
699 | - $cursor = $qb->execute(); |
|
700 | - |
|
701 | - while($data = $cursor->fetch()) { |
|
702 | - if ($this->isAccessibleResult($data)) { |
|
703 | - $shares[] = $this->createShare($data); |
|
704 | - } |
|
705 | - } |
|
706 | - $cursor->closeCursor(); |
|
707 | - |
|
708 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
709 | - $user = $this->userManager->get($userId); |
|
710 | - $allGroups = $this->groupManager->getUserGroups($user); |
|
711 | - |
|
712 | - /** @var Share[] $shares2 */ |
|
713 | - $shares2 = []; |
|
714 | - |
|
715 | - $start = 0; |
|
716 | - while(true) { |
|
717 | - $groups = array_slice($allGroups, $start, 100); |
|
718 | - $start += 100; |
|
719 | - |
|
720 | - if ($groups === []) { |
|
721 | - break; |
|
722 | - } |
|
723 | - |
|
724 | - $qb = $this->dbConn->getQueryBuilder(); |
|
725 | - $qb->select('s.*', |
|
726 | - 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
727 | - 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
728 | - 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
729 | - ) |
|
730 | - ->selectAlias('st.id', 'storage_string_id') |
|
731 | - ->from('share', 's') |
|
732 | - ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
733 | - ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')) |
|
734 | - ->orderBy('s.id') |
|
735 | - ->setFirstResult(0); |
|
736 | - |
|
737 | - if ($limit !== -1) { |
|
738 | - $qb->setMaxResults($limit - count($shares)); |
|
739 | - } |
|
740 | - |
|
741 | - // Filter by node if provided |
|
742 | - if ($node !== null) { |
|
743 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
744 | - } |
|
745 | - |
|
746 | - |
|
747 | - $groups = array_filter($groups, function($group) { return $group instanceof IGroup; }); |
|
748 | - $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); |
|
749 | - |
|
750 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
751 | - ->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter( |
|
752 | - $groups, |
|
753 | - IQueryBuilder::PARAM_STR_ARRAY |
|
754 | - ))) |
|
755 | - ->andWhere($qb->expr()->orX( |
|
756 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
757 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
758 | - )); |
|
759 | - |
|
760 | - $cursor = $qb->execute(); |
|
761 | - while($data = $cursor->fetch()) { |
|
762 | - if ($offset > 0) { |
|
763 | - $offset--; |
|
764 | - continue; |
|
765 | - } |
|
766 | - |
|
767 | - if ($this->isAccessibleResult($data)) { |
|
768 | - $shares2[] = $this->createShare($data); |
|
769 | - } |
|
770 | - } |
|
771 | - $cursor->closeCursor(); |
|
772 | - } |
|
773 | - |
|
774 | - /* |
|
361 | + if ($data === false) { |
|
362 | + $qb = $this->dbConn->getQueryBuilder(); |
|
363 | + |
|
364 | + $type = $share->getNodeType(); |
|
365 | + |
|
366 | + //Insert new share |
|
367 | + $qb->insert('share') |
|
368 | + ->values([ |
|
369 | + 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
370 | + 'share_with' => $qb->createNamedParameter($recipient), |
|
371 | + 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
372 | + 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
373 | + 'parent' => $qb->createNamedParameter($share->getId()), |
|
374 | + 'item_type' => $qb->createNamedParameter($type), |
|
375 | + 'item_source' => $qb->createNamedParameter($share->getNodeId()), |
|
376 | + 'file_source' => $qb->createNamedParameter($share->getNodeId()), |
|
377 | + 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
378 | + 'permissions' => $qb->createNamedParameter(0), |
|
379 | + 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
380 | + ])->execute(); |
|
381 | + |
|
382 | + } else if ($data['permissions'] !== 0) { |
|
383 | + |
|
384 | + // Update existing usergroup share |
|
385 | + $qb = $this->dbConn->getQueryBuilder(); |
|
386 | + $qb->update('share') |
|
387 | + ->set('permissions', $qb->createNamedParameter(0)) |
|
388 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
389 | + ->execute(); |
|
390 | + } |
|
391 | + |
|
392 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
393 | + |
|
394 | + if ($share->getSharedWith() !== $recipient) { |
|
395 | + throw new ProviderException('Recipient does not match'); |
|
396 | + } |
|
397 | + |
|
398 | + // We can just delete user and link shares |
|
399 | + $this->delete($share); |
|
400 | + } else { |
|
401 | + throw new ProviderException('Invalid shareType'); |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * @inheritdoc |
|
407 | + */ |
|
408 | + public function move(\OCP\Share\IShare $share, $recipient) { |
|
409 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
410 | + // Just update the target |
|
411 | + $qb = $this->dbConn->getQueryBuilder(); |
|
412 | + $qb->update('share') |
|
413 | + ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
414 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
415 | + ->execute(); |
|
416 | + |
|
417 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
418 | + |
|
419 | + // Check if there is a usergroup share |
|
420 | + $qb = $this->dbConn->getQueryBuilder(); |
|
421 | + $stmt = $qb->select('id') |
|
422 | + ->from('share') |
|
423 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
424 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
425 | + ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
426 | + ->andWhere($qb->expr()->orX( |
|
427 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
428 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
429 | + )) |
|
430 | + ->setMaxResults(1) |
|
431 | + ->execute(); |
|
432 | + |
|
433 | + $data = $stmt->fetch(); |
|
434 | + $stmt->closeCursor(); |
|
435 | + |
|
436 | + if ($data === false) { |
|
437 | + // No usergroup share yet. Create one. |
|
438 | + $qb = $this->dbConn->getQueryBuilder(); |
|
439 | + $qb->insert('share') |
|
440 | + ->values([ |
|
441 | + 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
442 | + 'share_with' => $qb->createNamedParameter($recipient), |
|
443 | + 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
444 | + 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
445 | + 'parent' => $qb->createNamedParameter($share->getId()), |
|
446 | + 'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'), |
|
447 | + 'item_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
448 | + 'file_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
449 | + 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
450 | + 'permissions' => $qb->createNamedParameter($share->getPermissions()), |
|
451 | + 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
452 | + ])->execute(); |
|
453 | + } else { |
|
454 | + // Already a usergroup share. Update it. |
|
455 | + $qb = $this->dbConn->getQueryBuilder(); |
|
456 | + $qb->update('share') |
|
457 | + ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
458 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
459 | + ->execute(); |
|
460 | + } |
|
461 | + } |
|
462 | + |
|
463 | + return $share; |
|
464 | + } |
|
465 | + |
|
466 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
467 | + $qb = $this->dbConn->getQueryBuilder(); |
|
468 | + $qb->select('*') |
|
469 | + ->from('share', 's') |
|
470 | + ->andWhere($qb->expr()->orX( |
|
471 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
472 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
473 | + )); |
|
474 | + |
|
475 | + $qb->andWhere($qb->expr()->orX( |
|
476 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
477 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
478 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
479 | + )); |
|
480 | + |
|
481 | + /** |
|
482 | + * Reshares for this user are shares where they are the owner. |
|
483 | + */ |
|
484 | + if ($reshares === false) { |
|
485 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
486 | + } else { |
|
487 | + $qb->andWhere( |
|
488 | + $qb->expr()->orX( |
|
489 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
490 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
491 | + ) |
|
492 | + ); |
|
493 | + } |
|
494 | + |
|
495 | + $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
496 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
497 | + |
|
498 | + $qb->orderBy('id'); |
|
499 | + |
|
500 | + $cursor = $qb->execute(); |
|
501 | + $shares = []; |
|
502 | + while ($data = $cursor->fetch()) { |
|
503 | + $shares[$data['fileid']][] = $this->createShare($data); |
|
504 | + } |
|
505 | + $cursor->closeCursor(); |
|
506 | + |
|
507 | + return $shares; |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * @inheritdoc |
|
512 | + */ |
|
513 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
514 | + $qb = $this->dbConn->getQueryBuilder(); |
|
515 | + $qb->select('*') |
|
516 | + ->from('share') |
|
517 | + ->andWhere($qb->expr()->orX( |
|
518 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
519 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
520 | + )); |
|
521 | + |
|
522 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType))); |
|
523 | + |
|
524 | + /** |
|
525 | + * Reshares for this user are shares where they are the owner. |
|
526 | + */ |
|
527 | + if ($reshares === false) { |
|
528 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
529 | + } else { |
|
530 | + $qb->andWhere( |
|
531 | + $qb->expr()->orX( |
|
532 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
533 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
534 | + ) |
|
535 | + ); |
|
536 | + } |
|
537 | + |
|
538 | + if ($node !== null) { |
|
539 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
540 | + } |
|
541 | + |
|
542 | + if ($limit !== -1) { |
|
543 | + $qb->setMaxResults($limit); |
|
544 | + } |
|
545 | + |
|
546 | + $qb->setFirstResult($offset); |
|
547 | + $qb->orderBy('id'); |
|
548 | + |
|
549 | + $cursor = $qb->execute(); |
|
550 | + $shares = []; |
|
551 | + while($data = $cursor->fetch()) { |
|
552 | + $shares[] = $this->createShare($data); |
|
553 | + } |
|
554 | + $cursor->closeCursor(); |
|
555 | + |
|
556 | + return $shares; |
|
557 | + } |
|
558 | + |
|
559 | + /** |
|
560 | + * @inheritdoc |
|
561 | + */ |
|
562 | + public function getShareById($id, $recipientId = null) { |
|
563 | + $qb = $this->dbConn->getQueryBuilder(); |
|
564 | + |
|
565 | + $qb->select('*') |
|
566 | + ->from('share') |
|
567 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
568 | + ->andWhere( |
|
569 | + $qb->expr()->in( |
|
570 | + 'share_type', |
|
571 | + $qb->createNamedParameter([ |
|
572 | + \OCP\Share::SHARE_TYPE_USER, |
|
573 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
574 | + \OCP\Share::SHARE_TYPE_LINK, |
|
575 | + ], IQueryBuilder::PARAM_INT_ARRAY) |
|
576 | + ) |
|
577 | + ) |
|
578 | + ->andWhere($qb->expr()->orX( |
|
579 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
580 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
581 | + )); |
|
582 | + |
|
583 | + $cursor = $qb->execute(); |
|
584 | + $data = $cursor->fetch(); |
|
585 | + $cursor->closeCursor(); |
|
586 | + |
|
587 | + if ($data === false) { |
|
588 | + throw new ShareNotFound(); |
|
589 | + } |
|
590 | + |
|
591 | + try { |
|
592 | + $share = $this->createShare($data); |
|
593 | + } catch (InvalidShare $e) { |
|
594 | + throw new ShareNotFound(); |
|
595 | + } |
|
596 | + |
|
597 | + // If the recipient is set for a group share resolve to that user |
|
598 | + if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
599 | + $share = $this->resolveGroupShares([$share], $recipientId)[0]; |
|
600 | + } |
|
601 | + |
|
602 | + return $share; |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Get shares for a given path |
|
607 | + * |
|
608 | + * @param \OCP\Files\Node $path |
|
609 | + * @return \OCP\Share\IShare[] |
|
610 | + */ |
|
611 | + public function getSharesByPath(Node $path) { |
|
612 | + $qb = $this->dbConn->getQueryBuilder(); |
|
613 | + |
|
614 | + $cursor = $qb->select('*') |
|
615 | + ->from('share') |
|
616 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
617 | + ->andWhere( |
|
618 | + $qb->expr()->orX( |
|
619 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
620 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)) |
|
621 | + ) |
|
622 | + ) |
|
623 | + ->andWhere($qb->expr()->orX( |
|
624 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
625 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
626 | + )) |
|
627 | + ->execute(); |
|
628 | + |
|
629 | + $shares = []; |
|
630 | + while($data = $cursor->fetch()) { |
|
631 | + $shares[] = $this->createShare($data); |
|
632 | + } |
|
633 | + $cursor->closeCursor(); |
|
634 | + |
|
635 | + return $shares; |
|
636 | + } |
|
637 | + |
|
638 | + /** |
|
639 | + * Returns whether the given database result can be interpreted as |
|
640 | + * a share with accessible file (not trashed, not deleted) |
|
641 | + */ |
|
642 | + private function isAccessibleResult($data) { |
|
643 | + // exclude shares leading to deleted file entries |
|
644 | + if ($data['fileid'] === null) { |
|
645 | + return false; |
|
646 | + } |
|
647 | + |
|
648 | + // exclude shares leading to trashbin on home storages |
|
649 | + $pathSections = explode('/', $data['path'], 2); |
|
650 | + // FIXME: would not detect rare md5'd home storage case properly |
|
651 | + if ($pathSections[0] !== 'files' |
|
652 | + && in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) { |
|
653 | + return false; |
|
654 | + } |
|
655 | + return true; |
|
656 | + } |
|
657 | + |
|
658 | + /** |
|
659 | + * @inheritdoc |
|
660 | + */ |
|
661 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
662 | + /** @var Share[] $shares */ |
|
663 | + $shares = []; |
|
664 | + |
|
665 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
666 | + //Get shares directly with this user |
|
667 | + $qb = $this->dbConn->getQueryBuilder(); |
|
668 | + $qb->select('s.*', |
|
669 | + 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
670 | + 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
671 | + 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
672 | + ) |
|
673 | + ->selectAlias('st.id', 'storage_string_id') |
|
674 | + ->from('share', 's') |
|
675 | + ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
676 | + ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')); |
|
677 | + |
|
678 | + // Order by id |
|
679 | + $qb->orderBy('s.id'); |
|
680 | + |
|
681 | + // Set limit and offset |
|
682 | + if ($limit !== -1) { |
|
683 | + $qb->setMaxResults($limit); |
|
684 | + } |
|
685 | + $qb->setFirstResult($offset); |
|
686 | + |
|
687 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))) |
|
688 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
689 | + ->andWhere($qb->expr()->orX( |
|
690 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
691 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
692 | + )); |
|
693 | + |
|
694 | + // Filter by node if provided |
|
695 | + if ($node !== null) { |
|
696 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
697 | + } |
|
698 | + |
|
699 | + $cursor = $qb->execute(); |
|
700 | + |
|
701 | + while($data = $cursor->fetch()) { |
|
702 | + if ($this->isAccessibleResult($data)) { |
|
703 | + $shares[] = $this->createShare($data); |
|
704 | + } |
|
705 | + } |
|
706 | + $cursor->closeCursor(); |
|
707 | + |
|
708 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
709 | + $user = $this->userManager->get($userId); |
|
710 | + $allGroups = $this->groupManager->getUserGroups($user); |
|
711 | + |
|
712 | + /** @var Share[] $shares2 */ |
|
713 | + $shares2 = []; |
|
714 | + |
|
715 | + $start = 0; |
|
716 | + while(true) { |
|
717 | + $groups = array_slice($allGroups, $start, 100); |
|
718 | + $start += 100; |
|
719 | + |
|
720 | + if ($groups === []) { |
|
721 | + break; |
|
722 | + } |
|
723 | + |
|
724 | + $qb = $this->dbConn->getQueryBuilder(); |
|
725 | + $qb->select('s.*', |
|
726 | + 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
727 | + 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
728 | + 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
729 | + ) |
|
730 | + ->selectAlias('st.id', 'storage_string_id') |
|
731 | + ->from('share', 's') |
|
732 | + ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
733 | + ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')) |
|
734 | + ->orderBy('s.id') |
|
735 | + ->setFirstResult(0); |
|
736 | + |
|
737 | + if ($limit !== -1) { |
|
738 | + $qb->setMaxResults($limit - count($shares)); |
|
739 | + } |
|
740 | + |
|
741 | + // Filter by node if provided |
|
742 | + if ($node !== null) { |
|
743 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
744 | + } |
|
745 | + |
|
746 | + |
|
747 | + $groups = array_filter($groups, function($group) { return $group instanceof IGroup; }); |
|
748 | + $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); |
|
749 | + |
|
750 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
751 | + ->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter( |
|
752 | + $groups, |
|
753 | + IQueryBuilder::PARAM_STR_ARRAY |
|
754 | + ))) |
|
755 | + ->andWhere($qb->expr()->orX( |
|
756 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
757 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
758 | + )); |
|
759 | + |
|
760 | + $cursor = $qb->execute(); |
|
761 | + while($data = $cursor->fetch()) { |
|
762 | + if ($offset > 0) { |
|
763 | + $offset--; |
|
764 | + continue; |
|
765 | + } |
|
766 | + |
|
767 | + if ($this->isAccessibleResult($data)) { |
|
768 | + $shares2[] = $this->createShare($data); |
|
769 | + } |
|
770 | + } |
|
771 | + $cursor->closeCursor(); |
|
772 | + } |
|
773 | + |
|
774 | + /* |
|
775 | 775 | * Resolve all group shares to user specific shares |
776 | 776 | */ |
777 | - $shares = $this->resolveGroupShares($shares2, $userId); |
|
778 | - } else { |
|
779 | - throw new BackendError('Invalid backend'); |
|
780 | - } |
|
781 | - |
|
782 | - |
|
783 | - return $shares; |
|
784 | - } |
|
785 | - |
|
786 | - /** |
|
787 | - * Get a share by token |
|
788 | - * |
|
789 | - * @param string $token |
|
790 | - * @return \OCP\Share\IShare |
|
791 | - * @throws ShareNotFound |
|
792 | - */ |
|
793 | - public function getShareByToken($token) { |
|
794 | - $qb = $this->dbConn->getQueryBuilder(); |
|
795 | - |
|
796 | - $cursor = $qb->select('*') |
|
797 | - ->from('share') |
|
798 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))) |
|
799 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
800 | - ->andWhere($qb->expr()->orX( |
|
801 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
802 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
803 | - )) |
|
804 | - ->execute(); |
|
805 | - |
|
806 | - $data = $cursor->fetch(); |
|
807 | - |
|
808 | - if ($data === false) { |
|
809 | - throw new ShareNotFound(); |
|
810 | - } |
|
811 | - |
|
812 | - try { |
|
813 | - $share = $this->createShare($data); |
|
814 | - } catch (InvalidShare $e) { |
|
815 | - throw new ShareNotFound(); |
|
816 | - } |
|
817 | - |
|
818 | - return $share; |
|
819 | - } |
|
820 | - |
|
821 | - /** |
|
822 | - * Create a share object from an database row |
|
823 | - * |
|
824 | - * @param mixed[] $data |
|
825 | - * @return \OCP\Share\IShare |
|
826 | - * @throws InvalidShare |
|
827 | - */ |
|
828 | - private function createShare($data) { |
|
829 | - $share = new Share($this->rootFolder, $this->userManager); |
|
830 | - $share->setId((int)$data['id']) |
|
831 | - ->setShareType((int)$data['share_type']) |
|
832 | - ->setPermissions((int)$data['permissions']) |
|
833 | - ->setTarget($data['file_target']) |
|
834 | - ->setMailSend(true); |
|
835 | - |
|
836 | - $shareTime = new \DateTime(); |
|
837 | - $shareTime->setTimestamp((int)$data['stime']); |
|
838 | - $share->setShareTime($shareTime); |
|
839 | - |
|
840 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
841 | - $share->setSharedWith($data['share_with']); |
|
842 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
843 | - $share->setSharedWith($data['share_with']); |
|
844 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
845 | - $share->setPassword($data['password']); |
|
846 | - $share->setToken($data['token']); |
|
847 | - } |
|
848 | - |
|
849 | - $share->setSharedBy($data['uid_initiator']); |
|
850 | - $share->setShareOwner($data['uid_owner']); |
|
851 | - |
|
852 | - $share->setNodeId((int)$data['file_source']); |
|
853 | - $share->setNodeType($data['item_type']); |
|
854 | - |
|
855 | - if ($data['expiration'] !== null) { |
|
856 | - $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
857 | - $share->setExpirationDate($expiration); |
|
858 | - } |
|
859 | - |
|
860 | - if (isset($data['f_permissions'])) { |
|
861 | - $entryData = $data; |
|
862 | - $entryData['permissions'] = $entryData['f_permissions']; |
|
863 | - $entryData['parent'] = $entryData['f_parent']; |
|
864 | - $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, |
|
865 | - \OC::$server->getMimeTypeLoader())); |
|
866 | - } |
|
867 | - |
|
868 | - $share->setProviderId($this->identifier()); |
|
869 | - |
|
870 | - return $share; |
|
871 | - } |
|
872 | - |
|
873 | - /** |
|
874 | - * @param Share[] $shares |
|
875 | - * @param $userId |
|
876 | - * @return Share[] The updates shares if no update is found for a share return the original |
|
877 | - */ |
|
878 | - private function resolveGroupShares($shares, $userId) { |
|
879 | - $result = []; |
|
880 | - |
|
881 | - $start = 0; |
|
882 | - while(true) { |
|
883 | - /** @var Share[] $shareSlice */ |
|
884 | - $shareSlice = array_slice($shares, $start, 100); |
|
885 | - $start += 100; |
|
886 | - |
|
887 | - if ($shareSlice === []) { |
|
888 | - break; |
|
889 | - } |
|
890 | - |
|
891 | - /** @var int[] $ids */ |
|
892 | - $ids = []; |
|
893 | - /** @var Share[] $shareMap */ |
|
894 | - $shareMap = []; |
|
895 | - |
|
896 | - foreach ($shareSlice as $share) { |
|
897 | - $ids[] = (int)$share->getId(); |
|
898 | - $shareMap[$share->getId()] = $share; |
|
899 | - } |
|
900 | - |
|
901 | - $qb = $this->dbConn->getQueryBuilder(); |
|
902 | - |
|
903 | - $query = $qb->select('*') |
|
904 | - ->from('share') |
|
905 | - ->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
906 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
907 | - ->andWhere($qb->expr()->orX( |
|
908 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
909 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
910 | - )); |
|
911 | - |
|
912 | - $stmt = $query->execute(); |
|
913 | - |
|
914 | - while($data = $stmt->fetch()) { |
|
915 | - $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
916 | - $shareMap[$data['parent']]->setTarget($data['file_target']); |
|
917 | - } |
|
918 | - |
|
919 | - $stmt->closeCursor(); |
|
920 | - |
|
921 | - foreach ($shareMap as $share) { |
|
922 | - $result[] = $share; |
|
923 | - } |
|
924 | - } |
|
925 | - |
|
926 | - return $result; |
|
927 | - } |
|
928 | - |
|
929 | - /** |
|
930 | - * A user is deleted from the system |
|
931 | - * So clean up the relevant shares. |
|
932 | - * |
|
933 | - * @param string $uid |
|
934 | - * @param int $shareType |
|
935 | - */ |
|
936 | - public function userDeleted($uid, $shareType) { |
|
937 | - $qb = $this->dbConn->getQueryBuilder(); |
|
938 | - |
|
939 | - $qb->delete('share'); |
|
940 | - |
|
941 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
942 | - /* |
|
777 | + $shares = $this->resolveGroupShares($shares2, $userId); |
|
778 | + } else { |
|
779 | + throw new BackendError('Invalid backend'); |
|
780 | + } |
|
781 | + |
|
782 | + |
|
783 | + return $shares; |
|
784 | + } |
|
785 | + |
|
786 | + /** |
|
787 | + * Get a share by token |
|
788 | + * |
|
789 | + * @param string $token |
|
790 | + * @return \OCP\Share\IShare |
|
791 | + * @throws ShareNotFound |
|
792 | + */ |
|
793 | + public function getShareByToken($token) { |
|
794 | + $qb = $this->dbConn->getQueryBuilder(); |
|
795 | + |
|
796 | + $cursor = $qb->select('*') |
|
797 | + ->from('share') |
|
798 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))) |
|
799 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
800 | + ->andWhere($qb->expr()->orX( |
|
801 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
802 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
803 | + )) |
|
804 | + ->execute(); |
|
805 | + |
|
806 | + $data = $cursor->fetch(); |
|
807 | + |
|
808 | + if ($data === false) { |
|
809 | + throw new ShareNotFound(); |
|
810 | + } |
|
811 | + |
|
812 | + try { |
|
813 | + $share = $this->createShare($data); |
|
814 | + } catch (InvalidShare $e) { |
|
815 | + throw new ShareNotFound(); |
|
816 | + } |
|
817 | + |
|
818 | + return $share; |
|
819 | + } |
|
820 | + |
|
821 | + /** |
|
822 | + * Create a share object from an database row |
|
823 | + * |
|
824 | + * @param mixed[] $data |
|
825 | + * @return \OCP\Share\IShare |
|
826 | + * @throws InvalidShare |
|
827 | + */ |
|
828 | + private function createShare($data) { |
|
829 | + $share = new Share($this->rootFolder, $this->userManager); |
|
830 | + $share->setId((int)$data['id']) |
|
831 | + ->setShareType((int)$data['share_type']) |
|
832 | + ->setPermissions((int)$data['permissions']) |
|
833 | + ->setTarget($data['file_target']) |
|
834 | + ->setMailSend(true); |
|
835 | + |
|
836 | + $shareTime = new \DateTime(); |
|
837 | + $shareTime->setTimestamp((int)$data['stime']); |
|
838 | + $share->setShareTime($shareTime); |
|
839 | + |
|
840 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
841 | + $share->setSharedWith($data['share_with']); |
|
842 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
843 | + $share->setSharedWith($data['share_with']); |
|
844 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
845 | + $share->setPassword($data['password']); |
|
846 | + $share->setToken($data['token']); |
|
847 | + } |
|
848 | + |
|
849 | + $share->setSharedBy($data['uid_initiator']); |
|
850 | + $share->setShareOwner($data['uid_owner']); |
|
851 | + |
|
852 | + $share->setNodeId((int)$data['file_source']); |
|
853 | + $share->setNodeType($data['item_type']); |
|
854 | + |
|
855 | + if ($data['expiration'] !== null) { |
|
856 | + $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
857 | + $share->setExpirationDate($expiration); |
|
858 | + } |
|
859 | + |
|
860 | + if (isset($data['f_permissions'])) { |
|
861 | + $entryData = $data; |
|
862 | + $entryData['permissions'] = $entryData['f_permissions']; |
|
863 | + $entryData['parent'] = $entryData['f_parent']; |
|
864 | + $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, |
|
865 | + \OC::$server->getMimeTypeLoader())); |
|
866 | + } |
|
867 | + |
|
868 | + $share->setProviderId($this->identifier()); |
|
869 | + |
|
870 | + return $share; |
|
871 | + } |
|
872 | + |
|
873 | + /** |
|
874 | + * @param Share[] $shares |
|
875 | + * @param $userId |
|
876 | + * @return Share[] The updates shares if no update is found for a share return the original |
|
877 | + */ |
|
878 | + private function resolveGroupShares($shares, $userId) { |
|
879 | + $result = []; |
|
880 | + |
|
881 | + $start = 0; |
|
882 | + while(true) { |
|
883 | + /** @var Share[] $shareSlice */ |
|
884 | + $shareSlice = array_slice($shares, $start, 100); |
|
885 | + $start += 100; |
|
886 | + |
|
887 | + if ($shareSlice === []) { |
|
888 | + break; |
|
889 | + } |
|
890 | + |
|
891 | + /** @var int[] $ids */ |
|
892 | + $ids = []; |
|
893 | + /** @var Share[] $shareMap */ |
|
894 | + $shareMap = []; |
|
895 | + |
|
896 | + foreach ($shareSlice as $share) { |
|
897 | + $ids[] = (int)$share->getId(); |
|
898 | + $shareMap[$share->getId()] = $share; |
|
899 | + } |
|
900 | + |
|
901 | + $qb = $this->dbConn->getQueryBuilder(); |
|
902 | + |
|
903 | + $query = $qb->select('*') |
|
904 | + ->from('share') |
|
905 | + ->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
906 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
907 | + ->andWhere($qb->expr()->orX( |
|
908 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
909 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
910 | + )); |
|
911 | + |
|
912 | + $stmt = $query->execute(); |
|
913 | + |
|
914 | + while($data = $stmt->fetch()) { |
|
915 | + $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
916 | + $shareMap[$data['parent']]->setTarget($data['file_target']); |
|
917 | + } |
|
918 | + |
|
919 | + $stmt->closeCursor(); |
|
920 | + |
|
921 | + foreach ($shareMap as $share) { |
|
922 | + $result[] = $share; |
|
923 | + } |
|
924 | + } |
|
925 | + |
|
926 | + return $result; |
|
927 | + } |
|
928 | + |
|
929 | + /** |
|
930 | + * A user is deleted from the system |
|
931 | + * So clean up the relevant shares. |
|
932 | + * |
|
933 | + * @param string $uid |
|
934 | + * @param int $shareType |
|
935 | + */ |
|
936 | + public function userDeleted($uid, $shareType) { |
|
937 | + $qb = $this->dbConn->getQueryBuilder(); |
|
938 | + |
|
939 | + $qb->delete('share'); |
|
940 | + |
|
941 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
942 | + /* |
|
943 | 943 | * Delete all user shares that are owned by this user |
944 | 944 | * or that are received by this user |
945 | 945 | */ |
946 | 946 | |
947 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))); |
|
947 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))); |
|
948 | 948 | |
949 | - $qb->andWhere( |
|
950 | - $qb->expr()->orX( |
|
951 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
952 | - $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
953 | - ) |
|
954 | - ); |
|
955 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
956 | - /* |
|
949 | + $qb->andWhere( |
|
950 | + $qb->expr()->orX( |
|
951 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
952 | + $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
953 | + ) |
|
954 | + ); |
|
955 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
956 | + /* |
|
957 | 957 | * Delete all group shares that are owned by this user |
958 | 958 | * Or special user group shares that are received by this user |
959 | 959 | */ |
960 | - $qb->where( |
|
961 | - $qb->expr()->andX( |
|
962 | - $qb->expr()->orX( |
|
963 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
964 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)) |
|
965 | - ), |
|
966 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)) |
|
967 | - ) |
|
968 | - ); |
|
969 | - |
|
970 | - $qb->orWhere( |
|
971 | - $qb->expr()->andX( |
|
972 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)), |
|
973 | - $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
974 | - ) |
|
975 | - ); |
|
976 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
977 | - /* |
|
960 | + $qb->where( |
|
961 | + $qb->expr()->andX( |
|
962 | + $qb->expr()->orX( |
|
963 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
964 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)) |
|
965 | + ), |
|
966 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)) |
|
967 | + ) |
|
968 | + ); |
|
969 | + |
|
970 | + $qb->orWhere( |
|
971 | + $qb->expr()->andX( |
|
972 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)), |
|
973 | + $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
974 | + ) |
|
975 | + ); |
|
976 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
977 | + /* |
|
978 | 978 | * Delete all link shares owned by this user. |
979 | 979 | * And all link shares initiated by this user (until #22327 is in) |
980 | 980 | */ |
981 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))); |
|
982 | - |
|
983 | - $qb->andWhere( |
|
984 | - $qb->expr()->orX( |
|
985 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
986 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid)) |
|
987 | - ) |
|
988 | - ); |
|
989 | - } |
|
990 | - |
|
991 | - $qb->execute(); |
|
992 | - } |
|
993 | - |
|
994 | - /** |
|
995 | - * Delete all shares received by this group. As well as any custom group |
|
996 | - * shares for group members. |
|
997 | - * |
|
998 | - * @param string $gid |
|
999 | - */ |
|
1000 | - public function groupDeleted($gid) { |
|
1001 | - /* |
|
981 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))); |
|
982 | + |
|
983 | + $qb->andWhere( |
|
984 | + $qb->expr()->orX( |
|
985 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
986 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid)) |
|
987 | + ) |
|
988 | + ); |
|
989 | + } |
|
990 | + |
|
991 | + $qb->execute(); |
|
992 | + } |
|
993 | + |
|
994 | + /** |
|
995 | + * Delete all shares received by this group. As well as any custom group |
|
996 | + * shares for group members. |
|
997 | + * |
|
998 | + * @param string $gid |
|
999 | + */ |
|
1000 | + public function groupDeleted($gid) { |
|
1001 | + /* |
|
1002 | 1002 | * First delete all custom group shares for group members |
1003 | 1003 | */ |
1004 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1005 | - $qb->select('id') |
|
1006 | - ->from('share') |
|
1007 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1008 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1009 | - |
|
1010 | - $cursor = $qb->execute(); |
|
1011 | - $ids = []; |
|
1012 | - while($row = $cursor->fetch()) { |
|
1013 | - $ids[] = (int)$row['id']; |
|
1014 | - } |
|
1015 | - $cursor->closeCursor(); |
|
1016 | - |
|
1017 | - if (!empty($ids)) { |
|
1018 | - $chunks = array_chunk($ids, 100); |
|
1019 | - foreach ($chunks as $chunk) { |
|
1020 | - $qb->delete('share') |
|
1021 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1022 | - ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1023 | - $qb->execute(); |
|
1024 | - } |
|
1025 | - } |
|
1026 | - |
|
1027 | - /* |
|
1004 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1005 | + $qb->select('id') |
|
1006 | + ->from('share') |
|
1007 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1008 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1009 | + |
|
1010 | + $cursor = $qb->execute(); |
|
1011 | + $ids = []; |
|
1012 | + while($row = $cursor->fetch()) { |
|
1013 | + $ids[] = (int)$row['id']; |
|
1014 | + } |
|
1015 | + $cursor->closeCursor(); |
|
1016 | + |
|
1017 | + if (!empty($ids)) { |
|
1018 | + $chunks = array_chunk($ids, 100); |
|
1019 | + foreach ($chunks as $chunk) { |
|
1020 | + $qb->delete('share') |
|
1021 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1022 | + ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1023 | + $qb->execute(); |
|
1024 | + } |
|
1025 | + } |
|
1026 | + |
|
1027 | + /* |
|
1028 | 1028 | * Now delete all the group shares |
1029 | 1029 | */ |
1030 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1031 | - $qb->delete('share') |
|
1032 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1033 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1034 | - $qb->execute(); |
|
1035 | - } |
|
1036 | - |
|
1037 | - /** |
|
1038 | - * Delete custom group shares to this group for this user |
|
1039 | - * |
|
1040 | - * @param string $uid |
|
1041 | - * @param string $gid |
|
1042 | - */ |
|
1043 | - public function userDeletedFromGroup($uid, $gid) { |
|
1044 | - /* |
|
1030 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1031 | + $qb->delete('share') |
|
1032 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1033 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1034 | + $qb->execute(); |
|
1035 | + } |
|
1036 | + |
|
1037 | + /** |
|
1038 | + * Delete custom group shares to this group for this user |
|
1039 | + * |
|
1040 | + * @param string $uid |
|
1041 | + * @param string $gid |
|
1042 | + */ |
|
1043 | + public function userDeletedFromGroup($uid, $gid) { |
|
1044 | + /* |
|
1045 | 1045 | * Get all group shares |
1046 | 1046 | */ |
1047 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1048 | - $qb->select('id') |
|
1049 | - ->from('share') |
|
1050 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1051 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1052 | - |
|
1053 | - $cursor = $qb->execute(); |
|
1054 | - $ids = []; |
|
1055 | - while($row = $cursor->fetch()) { |
|
1056 | - $ids[] = (int)$row['id']; |
|
1057 | - } |
|
1058 | - $cursor->closeCursor(); |
|
1059 | - |
|
1060 | - if (!empty($ids)) { |
|
1061 | - $chunks = array_chunk($ids, 100); |
|
1062 | - foreach ($chunks as $chunk) { |
|
1063 | - /* |
|
1047 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1048 | + $qb->select('id') |
|
1049 | + ->from('share') |
|
1050 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1051 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1052 | + |
|
1053 | + $cursor = $qb->execute(); |
|
1054 | + $ids = []; |
|
1055 | + while($row = $cursor->fetch()) { |
|
1056 | + $ids[] = (int)$row['id']; |
|
1057 | + } |
|
1058 | + $cursor->closeCursor(); |
|
1059 | + |
|
1060 | + if (!empty($ids)) { |
|
1061 | + $chunks = array_chunk($ids, 100); |
|
1062 | + foreach ($chunks as $chunk) { |
|
1063 | + /* |
|
1064 | 1064 | * Delete all special shares wit this users for the found group shares |
1065 | 1065 | */ |
1066 | - $qb->delete('share') |
|
1067 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1068 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid))) |
|
1069 | - ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1070 | - $qb->execute(); |
|
1071 | - } |
|
1072 | - } |
|
1073 | - } |
|
1074 | - |
|
1075 | - /** |
|
1076 | - * @inheritdoc |
|
1077 | - */ |
|
1078 | - public function getAccessList($nodes, $currentAccess) { |
|
1079 | - $ids = []; |
|
1080 | - foreach ($nodes as $node) { |
|
1081 | - $ids[] = $node->getId(); |
|
1082 | - } |
|
1083 | - |
|
1084 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1085 | - |
|
1086 | - $or = $qb->expr()->orX( |
|
1087 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
1088 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
1089 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
1090 | - ); |
|
1091 | - |
|
1092 | - if ($currentAccess) { |
|
1093 | - $or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))); |
|
1094 | - } |
|
1095 | - |
|
1096 | - $qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions') |
|
1097 | - ->from('share') |
|
1098 | - ->where( |
|
1099 | - $or |
|
1100 | - ) |
|
1101 | - ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1102 | - ->andWhere($qb->expr()->orX( |
|
1103 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1104 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1105 | - )); |
|
1106 | - $cursor = $qb->execute(); |
|
1107 | - |
|
1108 | - $users = []; |
|
1109 | - $link = false; |
|
1110 | - while($row = $cursor->fetch()) { |
|
1111 | - $type = (int)$row['share_type']; |
|
1112 | - if ($type === \OCP\Share::SHARE_TYPE_USER) { |
|
1113 | - $uid = $row['share_with']; |
|
1114 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1115 | - $users[$uid][$row['id']] = $row; |
|
1116 | - } else if ($type === \OCP\Share::SHARE_TYPE_GROUP) { |
|
1117 | - $gid = $row['share_with']; |
|
1118 | - $group = $this->groupManager->get($gid); |
|
1119 | - |
|
1120 | - if ($group === null) { |
|
1121 | - continue; |
|
1122 | - } |
|
1123 | - |
|
1124 | - $userList = $group->getUsers(); |
|
1125 | - foreach ($userList as $user) { |
|
1126 | - $uid = $user->getUID(); |
|
1127 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1128 | - $users[$uid][$row['id']] = $row; |
|
1129 | - } |
|
1130 | - } else if ($type === \OCP\Share::SHARE_TYPE_LINK) { |
|
1131 | - $link = true; |
|
1132 | - } else if ($type === self::SHARE_TYPE_USERGROUP && $currentAccess === true) { |
|
1133 | - $uid = $row['share_with']; |
|
1134 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1135 | - $users[$uid][$row['id']] = $row; |
|
1136 | - } |
|
1137 | - } |
|
1138 | - $cursor->closeCursor(); |
|
1139 | - |
|
1140 | - if ($currentAccess === true) { |
|
1141 | - $users = array_map([$this, 'filterSharesOfUser'], $users); |
|
1142 | - $users = array_filter($users); |
|
1143 | - } else { |
|
1144 | - $users = array_keys($users); |
|
1145 | - } |
|
1146 | - |
|
1147 | - return ['users' => $users, 'public' => $link]; |
|
1148 | - } |
|
1149 | - |
|
1150 | - /** |
|
1151 | - * For each user the path with the fewest slashes is returned |
|
1152 | - * @param array $shares |
|
1153 | - * @return array |
|
1154 | - */ |
|
1155 | - protected function filterSharesOfUser(array $shares) { |
|
1156 | - // Group shares when the user has a share exception |
|
1157 | - foreach ($shares as $id => $share) { |
|
1158 | - $type = (int) $share['share_type']; |
|
1159 | - $permissions = (int) $share['permissions']; |
|
1160 | - |
|
1161 | - if ($type === self::SHARE_TYPE_USERGROUP) { |
|
1162 | - unset($shares[$share['parent']]); |
|
1163 | - |
|
1164 | - if ($permissions === 0) { |
|
1165 | - unset($shares[$id]); |
|
1166 | - } |
|
1167 | - } |
|
1168 | - } |
|
1169 | - |
|
1170 | - $best = []; |
|
1171 | - $bestDepth = 0; |
|
1172 | - foreach ($shares as $id => $share) { |
|
1173 | - $depth = substr_count($share['file_target'], '/'); |
|
1174 | - if (empty($best) || $depth < $bestDepth) { |
|
1175 | - $bestDepth = $depth; |
|
1176 | - $best = [ |
|
1177 | - 'node_id' => $share['file_source'], |
|
1178 | - 'node_path' => $share['file_target'], |
|
1179 | - ]; |
|
1180 | - } |
|
1181 | - } |
|
1182 | - |
|
1183 | - return $best; |
|
1184 | - } |
|
1066 | + $qb->delete('share') |
|
1067 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1068 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid))) |
|
1069 | + ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1070 | + $qb->execute(); |
|
1071 | + } |
|
1072 | + } |
|
1073 | + } |
|
1074 | + |
|
1075 | + /** |
|
1076 | + * @inheritdoc |
|
1077 | + */ |
|
1078 | + public function getAccessList($nodes, $currentAccess) { |
|
1079 | + $ids = []; |
|
1080 | + foreach ($nodes as $node) { |
|
1081 | + $ids[] = $node->getId(); |
|
1082 | + } |
|
1083 | + |
|
1084 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1085 | + |
|
1086 | + $or = $qb->expr()->orX( |
|
1087 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
1088 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
1089 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
1090 | + ); |
|
1091 | + |
|
1092 | + if ($currentAccess) { |
|
1093 | + $or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))); |
|
1094 | + } |
|
1095 | + |
|
1096 | + $qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions') |
|
1097 | + ->from('share') |
|
1098 | + ->where( |
|
1099 | + $or |
|
1100 | + ) |
|
1101 | + ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1102 | + ->andWhere($qb->expr()->orX( |
|
1103 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1104 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1105 | + )); |
|
1106 | + $cursor = $qb->execute(); |
|
1107 | + |
|
1108 | + $users = []; |
|
1109 | + $link = false; |
|
1110 | + while($row = $cursor->fetch()) { |
|
1111 | + $type = (int)$row['share_type']; |
|
1112 | + if ($type === \OCP\Share::SHARE_TYPE_USER) { |
|
1113 | + $uid = $row['share_with']; |
|
1114 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1115 | + $users[$uid][$row['id']] = $row; |
|
1116 | + } else if ($type === \OCP\Share::SHARE_TYPE_GROUP) { |
|
1117 | + $gid = $row['share_with']; |
|
1118 | + $group = $this->groupManager->get($gid); |
|
1119 | + |
|
1120 | + if ($group === null) { |
|
1121 | + continue; |
|
1122 | + } |
|
1123 | + |
|
1124 | + $userList = $group->getUsers(); |
|
1125 | + foreach ($userList as $user) { |
|
1126 | + $uid = $user->getUID(); |
|
1127 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1128 | + $users[$uid][$row['id']] = $row; |
|
1129 | + } |
|
1130 | + } else if ($type === \OCP\Share::SHARE_TYPE_LINK) { |
|
1131 | + $link = true; |
|
1132 | + } else if ($type === self::SHARE_TYPE_USERGROUP && $currentAccess === true) { |
|
1133 | + $uid = $row['share_with']; |
|
1134 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1135 | + $users[$uid][$row['id']] = $row; |
|
1136 | + } |
|
1137 | + } |
|
1138 | + $cursor->closeCursor(); |
|
1139 | + |
|
1140 | + if ($currentAccess === true) { |
|
1141 | + $users = array_map([$this, 'filterSharesOfUser'], $users); |
|
1142 | + $users = array_filter($users); |
|
1143 | + } else { |
|
1144 | + $users = array_keys($users); |
|
1145 | + } |
|
1146 | + |
|
1147 | + return ['users' => $users, 'public' => $link]; |
|
1148 | + } |
|
1149 | + |
|
1150 | + /** |
|
1151 | + * For each user the path with the fewest slashes is returned |
|
1152 | + * @param array $shares |
|
1153 | + * @return array |
|
1154 | + */ |
|
1155 | + protected function filterSharesOfUser(array $shares) { |
|
1156 | + // Group shares when the user has a share exception |
|
1157 | + foreach ($shares as $id => $share) { |
|
1158 | + $type = (int) $share['share_type']; |
|
1159 | + $permissions = (int) $share['permissions']; |
|
1160 | + |
|
1161 | + if ($type === self::SHARE_TYPE_USERGROUP) { |
|
1162 | + unset($shares[$share['parent']]); |
|
1163 | + |
|
1164 | + if ($permissions === 0) { |
|
1165 | + unset($shares[$id]); |
|
1166 | + } |
|
1167 | + } |
|
1168 | + } |
|
1169 | + |
|
1170 | + $best = []; |
|
1171 | + $bestDepth = 0; |
|
1172 | + foreach ($shares as $id => $share) { |
|
1173 | + $depth = substr_count($share['file_target'], '/'); |
|
1174 | + if (empty($best) || $depth < $bestDepth) { |
|
1175 | + $bestDepth = $depth; |
|
1176 | + $best = [ |
|
1177 | + 'node_id' => $share['file_source'], |
|
1178 | + 'node_path' => $share['file_target'], |
|
1179 | + ]; |
|
1180 | + } |
|
1181 | + } |
|
1182 | + |
|
1183 | + return $best; |
|
1184 | + } |
|
1185 | 1185 | } |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | ->orderBy('id'); |
288 | 288 | |
289 | 289 | $cursor = $qb->execute(); |
290 | - while($data = $cursor->fetch()) { |
|
290 | + while ($data = $cursor->fetch()) { |
|
291 | 291 | $children[] = $this->createShare($data); |
292 | 292 | } |
293 | 293 | $cursor->closeCursor(); |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | $user = $this->userManager->get($recipient); |
333 | 333 | |
334 | 334 | if (is_null($group)) { |
335 | - throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
335 | + throw new ProviderException('Group "'.$share->getSharedWith().'" does not exist'); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | if (!$group->inGroup($user)) { |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | ); |
493 | 493 | } |
494 | 494 | |
495 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
495 | + $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
496 | 496 | $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
497 | 497 | |
498 | 498 | $qb->orderBy('id'); |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | |
549 | 549 | $cursor = $qb->execute(); |
550 | 550 | $shares = []; |
551 | - while($data = $cursor->fetch()) { |
|
551 | + while ($data = $cursor->fetch()) { |
|
552 | 552 | $shares[] = $this->createShare($data); |
553 | 553 | } |
554 | 554 | $cursor->closeCursor(); |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | ->execute(); |
628 | 628 | |
629 | 629 | $shares = []; |
630 | - while($data = $cursor->fetch()) { |
|
630 | + while ($data = $cursor->fetch()) { |
|
631 | 631 | $shares[] = $this->createShare($data); |
632 | 632 | } |
633 | 633 | $cursor->closeCursor(); |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | |
699 | 699 | $cursor = $qb->execute(); |
700 | 700 | |
701 | - while($data = $cursor->fetch()) { |
|
701 | + while ($data = $cursor->fetch()) { |
|
702 | 702 | if ($this->isAccessibleResult($data)) { |
703 | 703 | $shares[] = $this->createShare($data); |
704 | 704 | } |
@@ -713,7 +713,7 @@ discard block |
||
713 | 713 | $shares2 = []; |
714 | 714 | |
715 | 715 | $start = 0; |
716 | - while(true) { |
|
716 | + while (true) { |
|
717 | 717 | $groups = array_slice($allGroups, $start, 100); |
718 | 718 | $start += 100; |
719 | 719 | |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | )); |
759 | 759 | |
760 | 760 | $cursor = $qb->execute(); |
761 | - while($data = $cursor->fetch()) { |
|
761 | + while ($data = $cursor->fetch()) { |
|
762 | 762 | if ($offset > 0) { |
763 | 763 | $offset--; |
764 | 764 | continue; |
@@ -827,14 +827,14 @@ discard block |
||
827 | 827 | */ |
828 | 828 | private function createShare($data) { |
829 | 829 | $share = new Share($this->rootFolder, $this->userManager); |
830 | - $share->setId((int)$data['id']) |
|
831 | - ->setShareType((int)$data['share_type']) |
|
832 | - ->setPermissions((int)$data['permissions']) |
|
830 | + $share->setId((int) $data['id']) |
|
831 | + ->setShareType((int) $data['share_type']) |
|
832 | + ->setPermissions((int) $data['permissions']) |
|
833 | 833 | ->setTarget($data['file_target']) |
834 | 834 | ->setMailSend(true); |
835 | 835 | |
836 | 836 | $shareTime = new \DateTime(); |
837 | - $shareTime->setTimestamp((int)$data['stime']); |
|
837 | + $shareTime->setTimestamp((int) $data['stime']); |
|
838 | 838 | $share->setShareTime($shareTime); |
839 | 839 | |
840 | 840 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
@@ -849,7 +849,7 @@ discard block |
||
849 | 849 | $share->setSharedBy($data['uid_initiator']); |
850 | 850 | $share->setShareOwner($data['uid_owner']); |
851 | 851 | |
852 | - $share->setNodeId((int)$data['file_source']); |
|
852 | + $share->setNodeId((int) $data['file_source']); |
|
853 | 853 | $share->setNodeType($data['item_type']); |
854 | 854 | |
855 | 855 | if ($data['expiration'] !== null) { |
@@ -879,7 +879,7 @@ discard block |
||
879 | 879 | $result = []; |
880 | 880 | |
881 | 881 | $start = 0; |
882 | - while(true) { |
|
882 | + while (true) { |
|
883 | 883 | /** @var Share[] $shareSlice */ |
884 | 884 | $shareSlice = array_slice($shares, $start, 100); |
885 | 885 | $start += 100; |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | $shareMap = []; |
895 | 895 | |
896 | 896 | foreach ($shareSlice as $share) { |
897 | - $ids[] = (int)$share->getId(); |
|
897 | + $ids[] = (int) $share->getId(); |
|
898 | 898 | $shareMap[$share->getId()] = $share; |
899 | 899 | } |
900 | 900 | |
@@ -911,8 +911,8 @@ discard block |
||
911 | 911 | |
912 | 912 | $stmt = $query->execute(); |
913 | 913 | |
914 | - while($data = $stmt->fetch()) { |
|
915 | - $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
914 | + while ($data = $stmt->fetch()) { |
|
915 | + $shareMap[$data['parent']]->setPermissions((int) $data['permissions']); |
|
916 | 916 | $shareMap[$data['parent']]->setTarget($data['file_target']); |
917 | 917 | } |
918 | 918 | |
@@ -1009,8 +1009,8 @@ discard block |
||
1009 | 1009 | |
1010 | 1010 | $cursor = $qb->execute(); |
1011 | 1011 | $ids = []; |
1012 | - while($row = $cursor->fetch()) { |
|
1013 | - $ids[] = (int)$row['id']; |
|
1012 | + while ($row = $cursor->fetch()) { |
|
1013 | + $ids[] = (int) $row['id']; |
|
1014 | 1014 | } |
1015 | 1015 | $cursor->closeCursor(); |
1016 | 1016 | |
@@ -1052,8 +1052,8 @@ discard block |
||
1052 | 1052 | |
1053 | 1053 | $cursor = $qb->execute(); |
1054 | 1054 | $ids = []; |
1055 | - while($row = $cursor->fetch()) { |
|
1056 | - $ids[] = (int)$row['id']; |
|
1055 | + while ($row = $cursor->fetch()) { |
|
1056 | + $ids[] = (int) $row['id']; |
|
1057 | 1057 | } |
1058 | 1058 | $cursor->closeCursor(); |
1059 | 1059 | |
@@ -1107,8 +1107,8 @@ discard block |
||
1107 | 1107 | |
1108 | 1108 | $users = []; |
1109 | 1109 | $link = false; |
1110 | - while($row = $cursor->fetch()) { |
|
1111 | - $type = (int)$row['share_type']; |
|
1110 | + while ($row = $cursor->fetch()) { |
|
1111 | + $type = (int) $row['share_type']; |
|
1112 | 1112 | if ($type === \OCP\Share::SHARE_TYPE_USER) { |
1113 | 1113 | $uid = $row['share_with']; |
1114 | 1114 | $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
@@ -60,1489 +60,1489 @@ |
||
60 | 60 | */ |
61 | 61 | class Manager implements IManager { |
62 | 62 | |
63 | - /** @var IProviderFactory */ |
|
64 | - private $factory; |
|
65 | - /** @var ILogger */ |
|
66 | - private $logger; |
|
67 | - /** @var IConfig */ |
|
68 | - private $config; |
|
69 | - /** @var ISecureRandom */ |
|
70 | - private $secureRandom; |
|
71 | - /** @var IHasher */ |
|
72 | - private $hasher; |
|
73 | - /** @var IMountManager */ |
|
74 | - private $mountManager; |
|
75 | - /** @var IGroupManager */ |
|
76 | - private $groupManager; |
|
77 | - /** @var IL10N */ |
|
78 | - private $l; |
|
79 | - /** @var IFactory */ |
|
80 | - private $l10nFactory; |
|
81 | - /** @var IUserManager */ |
|
82 | - private $userManager; |
|
83 | - /** @var IRootFolder */ |
|
84 | - private $rootFolder; |
|
85 | - /** @var CappedMemoryCache */ |
|
86 | - private $sharingDisabledForUsersCache; |
|
87 | - /** @var EventDispatcher */ |
|
88 | - private $eventDispatcher; |
|
89 | - /** @var LegacyHooks */ |
|
90 | - private $legacyHooks; |
|
91 | - /** @var IMailer */ |
|
92 | - private $mailer; |
|
93 | - /** @var IURLGenerator */ |
|
94 | - private $urlGenerator; |
|
95 | - /** @var \OC_Defaults */ |
|
96 | - private $defaults; |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Manager constructor. |
|
101 | - * |
|
102 | - * @param ILogger $logger |
|
103 | - * @param IConfig $config |
|
104 | - * @param ISecureRandom $secureRandom |
|
105 | - * @param IHasher $hasher |
|
106 | - * @param IMountManager $mountManager |
|
107 | - * @param IGroupManager $groupManager |
|
108 | - * @param IL10N $l |
|
109 | - * @param IFactory $l10nFactory |
|
110 | - * @param IProviderFactory $factory |
|
111 | - * @param IUserManager $userManager |
|
112 | - * @param IRootFolder $rootFolder |
|
113 | - * @param EventDispatcher $eventDispatcher |
|
114 | - * @param IMailer $mailer |
|
115 | - * @param IURLGenerator $urlGenerator |
|
116 | - * @param \OC_Defaults $defaults |
|
117 | - */ |
|
118 | - public function __construct( |
|
119 | - ILogger $logger, |
|
120 | - IConfig $config, |
|
121 | - ISecureRandom $secureRandom, |
|
122 | - IHasher $hasher, |
|
123 | - IMountManager $mountManager, |
|
124 | - IGroupManager $groupManager, |
|
125 | - IL10N $l, |
|
126 | - IFactory $l10nFactory, |
|
127 | - IProviderFactory $factory, |
|
128 | - IUserManager $userManager, |
|
129 | - IRootFolder $rootFolder, |
|
130 | - EventDispatcher $eventDispatcher, |
|
131 | - IMailer $mailer, |
|
132 | - IURLGenerator $urlGenerator, |
|
133 | - \OC_Defaults $defaults |
|
134 | - ) { |
|
135 | - $this->logger = $logger; |
|
136 | - $this->config = $config; |
|
137 | - $this->secureRandom = $secureRandom; |
|
138 | - $this->hasher = $hasher; |
|
139 | - $this->mountManager = $mountManager; |
|
140 | - $this->groupManager = $groupManager; |
|
141 | - $this->l = $l; |
|
142 | - $this->l10nFactory = $l10nFactory; |
|
143 | - $this->factory = $factory; |
|
144 | - $this->userManager = $userManager; |
|
145 | - $this->rootFolder = $rootFolder; |
|
146 | - $this->eventDispatcher = $eventDispatcher; |
|
147 | - $this->sharingDisabledForUsersCache = new CappedMemoryCache(); |
|
148 | - $this->legacyHooks = new LegacyHooks($this->eventDispatcher); |
|
149 | - $this->mailer = $mailer; |
|
150 | - $this->urlGenerator = $urlGenerator; |
|
151 | - $this->defaults = $defaults; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Convert from a full share id to a tuple (providerId, shareId) |
|
156 | - * |
|
157 | - * @param string $id |
|
158 | - * @return string[] |
|
159 | - */ |
|
160 | - private function splitFullId($id) { |
|
161 | - return explode(':', $id, 2); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Verify if a password meets all requirements |
|
166 | - * |
|
167 | - * @param string $password |
|
168 | - * @throws \Exception |
|
169 | - */ |
|
170 | - protected function verifyPassword($password) { |
|
171 | - if ($password === null) { |
|
172 | - // No password is set, check if this is allowed. |
|
173 | - if ($this->shareApiLinkEnforcePassword()) { |
|
174 | - throw new \InvalidArgumentException('Passwords are enforced for link shares'); |
|
175 | - } |
|
176 | - |
|
177 | - return; |
|
178 | - } |
|
179 | - |
|
180 | - // Let others verify the password |
|
181 | - try { |
|
182 | - $event = new GenericEvent($password); |
|
183 | - $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
184 | - } catch (HintException $e) { |
|
185 | - throw new \Exception($e->getHint()); |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Check for generic requirements before creating a share |
|
191 | - * |
|
192 | - * @param \OCP\Share\IShare $share |
|
193 | - * @throws \InvalidArgumentException |
|
194 | - * @throws GenericShareException |
|
195 | - * |
|
196 | - * @suppress PhanUndeclaredClassMethod |
|
197 | - */ |
|
198 | - protected function generalCreateChecks(\OCP\Share\IShare $share) { |
|
199 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
200 | - // We expect a valid user as sharedWith for user shares |
|
201 | - if (!$this->userManager->userExists($share->getSharedWith())) { |
|
202 | - throw new \InvalidArgumentException('SharedWith is not a valid user'); |
|
203 | - } |
|
204 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
205 | - // We expect a valid group as sharedWith for group shares |
|
206 | - if (!$this->groupManager->groupExists($share->getSharedWith())) { |
|
207 | - throw new \InvalidArgumentException('SharedWith is not a valid group'); |
|
208 | - } |
|
209 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
210 | - if ($share->getSharedWith() !== null) { |
|
211 | - throw new \InvalidArgumentException('SharedWith should be empty'); |
|
212 | - } |
|
213 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
214 | - if ($share->getSharedWith() === null) { |
|
215 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
216 | - } |
|
217 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
218 | - if ($share->getSharedWith() === null) { |
|
219 | - throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
220 | - } |
|
221 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
222 | - $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($share->getSharedWith()); |
|
223 | - if ($circle === null) { |
|
224 | - throw new \InvalidArgumentException('SharedWith is not a valid circle'); |
|
225 | - } |
|
226 | - } else { |
|
227 | - // We can't handle other types yet |
|
228 | - throw new \InvalidArgumentException('unknown share type'); |
|
229 | - } |
|
230 | - |
|
231 | - // Verify the initiator of the share is set |
|
232 | - if ($share->getSharedBy() === null) { |
|
233 | - throw new \InvalidArgumentException('SharedBy should be set'); |
|
234 | - } |
|
235 | - |
|
236 | - // Cannot share with yourself |
|
237 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
238 | - $share->getSharedWith() === $share->getSharedBy()) { |
|
239 | - throw new \InvalidArgumentException('Can’t share with yourself'); |
|
240 | - } |
|
241 | - |
|
242 | - // The path should be set |
|
243 | - if ($share->getNode() === null) { |
|
244 | - throw new \InvalidArgumentException('Path should be set'); |
|
245 | - } |
|
246 | - |
|
247 | - // And it should be a file or a folder |
|
248 | - if (!($share->getNode() instanceof \OCP\Files\File) && |
|
249 | - !($share->getNode() instanceof \OCP\Files\Folder)) { |
|
250 | - throw new \InvalidArgumentException('Path should be either a file or a folder'); |
|
251 | - } |
|
252 | - |
|
253 | - // And you can't share your rootfolder |
|
254 | - if ($this->userManager->userExists($share->getSharedBy())) { |
|
255 | - $sharedPath = $this->rootFolder->getUserFolder($share->getSharedBy())->getPath(); |
|
256 | - } else { |
|
257 | - $sharedPath = $this->rootFolder->getUserFolder($share->getShareOwner())->getPath(); |
|
258 | - } |
|
259 | - if ($sharedPath === $share->getNode()->getPath()) { |
|
260 | - throw new \InvalidArgumentException('You can’t share your root folder'); |
|
261 | - } |
|
262 | - |
|
263 | - // Check if we actually have share permissions |
|
264 | - if (!$share->getNode()->isShareable()) { |
|
265 | - $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]); |
|
266 | - throw new GenericShareException($message_t, $message_t, 404); |
|
267 | - } |
|
268 | - |
|
269 | - // Permissions should be set |
|
270 | - if ($share->getPermissions() === null) { |
|
271 | - throw new \InvalidArgumentException('A share requires permissions'); |
|
272 | - } |
|
273 | - |
|
274 | - /* |
|
63 | + /** @var IProviderFactory */ |
|
64 | + private $factory; |
|
65 | + /** @var ILogger */ |
|
66 | + private $logger; |
|
67 | + /** @var IConfig */ |
|
68 | + private $config; |
|
69 | + /** @var ISecureRandom */ |
|
70 | + private $secureRandom; |
|
71 | + /** @var IHasher */ |
|
72 | + private $hasher; |
|
73 | + /** @var IMountManager */ |
|
74 | + private $mountManager; |
|
75 | + /** @var IGroupManager */ |
|
76 | + private $groupManager; |
|
77 | + /** @var IL10N */ |
|
78 | + private $l; |
|
79 | + /** @var IFactory */ |
|
80 | + private $l10nFactory; |
|
81 | + /** @var IUserManager */ |
|
82 | + private $userManager; |
|
83 | + /** @var IRootFolder */ |
|
84 | + private $rootFolder; |
|
85 | + /** @var CappedMemoryCache */ |
|
86 | + private $sharingDisabledForUsersCache; |
|
87 | + /** @var EventDispatcher */ |
|
88 | + private $eventDispatcher; |
|
89 | + /** @var LegacyHooks */ |
|
90 | + private $legacyHooks; |
|
91 | + /** @var IMailer */ |
|
92 | + private $mailer; |
|
93 | + /** @var IURLGenerator */ |
|
94 | + private $urlGenerator; |
|
95 | + /** @var \OC_Defaults */ |
|
96 | + private $defaults; |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Manager constructor. |
|
101 | + * |
|
102 | + * @param ILogger $logger |
|
103 | + * @param IConfig $config |
|
104 | + * @param ISecureRandom $secureRandom |
|
105 | + * @param IHasher $hasher |
|
106 | + * @param IMountManager $mountManager |
|
107 | + * @param IGroupManager $groupManager |
|
108 | + * @param IL10N $l |
|
109 | + * @param IFactory $l10nFactory |
|
110 | + * @param IProviderFactory $factory |
|
111 | + * @param IUserManager $userManager |
|
112 | + * @param IRootFolder $rootFolder |
|
113 | + * @param EventDispatcher $eventDispatcher |
|
114 | + * @param IMailer $mailer |
|
115 | + * @param IURLGenerator $urlGenerator |
|
116 | + * @param \OC_Defaults $defaults |
|
117 | + */ |
|
118 | + public function __construct( |
|
119 | + ILogger $logger, |
|
120 | + IConfig $config, |
|
121 | + ISecureRandom $secureRandom, |
|
122 | + IHasher $hasher, |
|
123 | + IMountManager $mountManager, |
|
124 | + IGroupManager $groupManager, |
|
125 | + IL10N $l, |
|
126 | + IFactory $l10nFactory, |
|
127 | + IProviderFactory $factory, |
|
128 | + IUserManager $userManager, |
|
129 | + IRootFolder $rootFolder, |
|
130 | + EventDispatcher $eventDispatcher, |
|
131 | + IMailer $mailer, |
|
132 | + IURLGenerator $urlGenerator, |
|
133 | + \OC_Defaults $defaults |
|
134 | + ) { |
|
135 | + $this->logger = $logger; |
|
136 | + $this->config = $config; |
|
137 | + $this->secureRandom = $secureRandom; |
|
138 | + $this->hasher = $hasher; |
|
139 | + $this->mountManager = $mountManager; |
|
140 | + $this->groupManager = $groupManager; |
|
141 | + $this->l = $l; |
|
142 | + $this->l10nFactory = $l10nFactory; |
|
143 | + $this->factory = $factory; |
|
144 | + $this->userManager = $userManager; |
|
145 | + $this->rootFolder = $rootFolder; |
|
146 | + $this->eventDispatcher = $eventDispatcher; |
|
147 | + $this->sharingDisabledForUsersCache = new CappedMemoryCache(); |
|
148 | + $this->legacyHooks = new LegacyHooks($this->eventDispatcher); |
|
149 | + $this->mailer = $mailer; |
|
150 | + $this->urlGenerator = $urlGenerator; |
|
151 | + $this->defaults = $defaults; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Convert from a full share id to a tuple (providerId, shareId) |
|
156 | + * |
|
157 | + * @param string $id |
|
158 | + * @return string[] |
|
159 | + */ |
|
160 | + private function splitFullId($id) { |
|
161 | + return explode(':', $id, 2); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Verify if a password meets all requirements |
|
166 | + * |
|
167 | + * @param string $password |
|
168 | + * @throws \Exception |
|
169 | + */ |
|
170 | + protected function verifyPassword($password) { |
|
171 | + if ($password === null) { |
|
172 | + // No password is set, check if this is allowed. |
|
173 | + if ($this->shareApiLinkEnforcePassword()) { |
|
174 | + throw new \InvalidArgumentException('Passwords are enforced for link shares'); |
|
175 | + } |
|
176 | + |
|
177 | + return; |
|
178 | + } |
|
179 | + |
|
180 | + // Let others verify the password |
|
181 | + try { |
|
182 | + $event = new GenericEvent($password); |
|
183 | + $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
184 | + } catch (HintException $e) { |
|
185 | + throw new \Exception($e->getHint()); |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Check for generic requirements before creating a share |
|
191 | + * |
|
192 | + * @param \OCP\Share\IShare $share |
|
193 | + * @throws \InvalidArgumentException |
|
194 | + * @throws GenericShareException |
|
195 | + * |
|
196 | + * @suppress PhanUndeclaredClassMethod |
|
197 | + */ |
|
198 | + protected function generalCreateChecks(\OCP\Share\IShare $share) { |
|
199 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
200 | + // We expect a valid user as sharedWith for user shares |
|
201 | + if (!$this->userManager->userExists($share->getSharedWith())) { |
|
202 | + throw new \InvalidArgumentException('SharedWith is not a valid user'); |
|
203 | + } |
|
204 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
205 | + // We expect a valid group as sharedWith for group shares |
|
206 | + if (!$this->groupManager->groupExists($share->getSharedWith())) { |
|
207 | + throw new \InvalidArgumentException('SharedWith is not a valid group'); |
|
208 | + } |
|
209 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
210 | + if ($share->getSharedWith() !== null) { |
|
211 | + throw new \InvalidArgumentException('SharedWith should be empty'); |
|
212 | + } |
|
213 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
214 | + if ($share->getSharedWith() === null) { |
|
215 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
216 | + } |
|
217 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
218 | + if ($share->getSharedWith() === null) { |
|
219 | + throw new \InvalidArgumentException('SharedWith should not be empty'); |
|
220 | + } |
|
221 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
222 | + $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($share->getSharedWith()); |
|
223 | + if ($circle === null) { |
|
224 | + throw new \InvalidArgumentException('SharedWith is not a valid circle'); |
|
225 | + } |
|
226 | + } else { |
|
227 | + // We can't handle other types yet |
|
228 | + throw new \InvalidArgumentException('unknown share type'); |
|
229 | + } |
|
230 | + |
|
231 | + // Verify the initiator of the share is set |
|
232 | + if ($share->getSharedBy() === null) { |
|
233 | + throw new \InvalidArgumentException('SharedBy should be set'); |
|
234 | + } |
|
235 | + |
|
236 | + // Cannot share with yourself |
|
237 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
238 | + $share->getSharedWith() === $share->getSharedBy()) { |
|
239 | + throw new \InvalidArgumentException('Can’t share with yourself'); |
|
240 | + } |
|
241 | + |
|
242 | + // The path should be set |
|
243 | + if ($share->getNode() === null) { |
|
244 | + throw new \InvalidArgumentException('Path should be set'); |
|
245 | + } |
|
246 | + |
|
247 | + // And it should be a file or a folder |
|
248 | + if (!($share->getNode() instanceof \OCP\Files\File) && |
|
249 | + !($share->getNode() instanceof \OCP\Files\Folder)) { |
|
250 | + throw new \InvalidArgumentException('Path should be either a file or a folder'); |
|
251 | + } |
|
252 | + |
|
253 | + // And you can't share your rootfolder |
|
254 | + if ($this->userManager->userExists($share->getSharedBy())) { |
|
255 | + $sharedPath = $this->rootFolder->getUserFolder($share->getSharedBy())->getPath(); |
|
256 | + } else { |
|
257 | + $sharedPath = $this->rootFolder->getUserFolder($share->getShareOwner())->getPath(); |
|
258 | + } |
|
259 | + if ($sharedPath === $share->getNode()->getPath()) { |
|
260 | + throw new \InvalidArgumentException('You can’t share your root folder'); |
|
261 | + } |
|
262 | + |
|
263 | + // Check if we actually have share permissions |
|
264 | + if (!$share->getNode()->isShareable()) { |
|
265 | + $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]); |
|
266 | + throw new GenericShareException($message_t, $message_t, 404); |
|
267 | + } |
|
268 | + |
|
269 | + // Permissions should be set |
|
270 | + if ($share->getPermissions() === null) { |
|
271 | + throw new \InvalidArgumentException('A share requires permissions'); |
|
272 | + } |
|
273 | + |
|
274 | + /* |
|
275 | 275 | * Quick fix for #23536 |
276 | 276 | * Non moveable mount points do not have update and delete permissions |
277 | 277 | * while we 'most likely' do have that on the storage. |
278 | 278 | */ |
279 | - $permissions = $share->getNode()->getPermissions(); |
|
280 | - $mount = $share->getNode()->getMountPoint(); |
|
281 | - if (!($mount instanceof MoveableMount)) { |
|
282 | - $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
283 | - } |
|
284 | - |
|
285 | - // Check that we do not share with more permissions than we have |
|
286 | - if ($share->getPermissions() & ~$permissions) { |
|
287 | - $message_t = $this->l->t('Can’t increase permissions of %s', [$share->getNode()->getPath()]); |
|
288 | - throw new GenericShareException($message_t, $message_t, 404); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - // Check that read permissions are always set |
|
293 | - // Link shares are allowed to have no read permissions to allow upload to hidden folders |
|
294 | - $noReadPermissionRequired = $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK |
|
295 | - || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL; |
|
296 | - if (!$noReadPermissionRequired && |
|
297 | - ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
|
298 | - throw new \InvalidArgumentException('Shares need at least read permissions'); |
|
299 | - } |
|
300 | - |
|
301 | - if ($share->getNode() instanceof \OCP\Files\File) { |
|
302 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
303 | - $message_t = $this->l->t('Files can’t be shared with delete permissions'); |
|
304 | - throw new GenericShareException($message_t); |
|
305 | - } |
|
306 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
307 | - $message_t = $this->l->t('Files can’t be shared with create permissions'); |
|
308 | - throw new GenericShareException($message_t); |
|
309 | - } |
|
310 | - } |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * Validate if the expiration date fits the system settings |
|
315 | - * |
|
316 | - * @param \OCP\Share\IShare $share The share to validate the expiration date of |
|
317 | - * @return \OCP\Share\IShare The modified share object |
|
318 | - * @throws GenericShareException |
|
319 | - * @throws \InvalidArgumentException |
|
320 | - * @throws \Exception |
|
321 | - */ |
|
322 | - protected function validateExpirationDate(\OCP\Share\IShare $share) { |
|
323 | - |
|
324 | - $expirationDate = $share->getExpirationDate(); |
|
325 | - |
|
326 | - if ($expirationDate !== null) { |
|
327 | - //Make sure the expiration date is a date |
|
328 | - $expirationDate->setTime(0, 0, 0); |
|
329 | - |
|
330 | - $date = new \DateTime(); |
|
331 | - $date->setTime(0, 0, 0); |
|
332 | - if ($date >= $expirationDate) { |
|
333 | - $message = $this->l->t('Expiration date is in the past'); |
|
334 | - throw new GenericShareException($message, $message, 404); |
|
335 | - } |
|
336 | - } |
|
337 | - |
|
338 | - // If expiredate is empty set a default one if there is a default |
|
339 | - $fullId = null; |
|
340 | - try { |
|
341 | - $fullId = $share->getFullId(); |
|
342 | - } catch (\UnexpectedValueException $e) { |
|
343 | - // This is a new share |
|
344 | - } |
|
345 | - |
|
346 | - if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
|
347 | - $expirationDate = new \DateTime(); |
|
348 | - $expirationDate->setTime(0,0,0); |
|
349 | - $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
350 | - } |
|
351 | - |
|
352 | - // If we enforce the expiration date check that is does not exceed |
|
353 | - if ($this->shareApiLinkDefaultExpireDateEnforced()) { |
|
354 | - if ($expirationDate === null) { |
|
355 | - throw new \InvalidArgumentException('Expiration date is enforced'); |
|
356 | - } |
|
357 | - |
|
358 | - $date = new \DateTime(); |
|
359 | - $date->setTime(0, 0, 0); |
|
360 | - $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
361 | - if ($date < $expirationDate) { |
|
362 | - $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
|
363 | - throw new GenericShareException($message, $message, 404); |
|
364 | - } |
|
365 | - } |
|
366 | - |
|
367 | - $accepted = true; |
|
368 | - $message = ''; |
|
369 | - \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
370 | - 'expirationDate' => &$expirationDate, |
|
371 | - 'accepted' => &$accepted, |
|
372 | - 'message' => &$message, |
|
373 | - 'passwordSet' => $share->getPassword() !== null, |
|
374 | - ]); |
|
375 | - |
|
376 | - if (!$accepted) { |
|
377 | - throw new \Exception($message); |
|
378 | - } |
|
379 | - |
|
380 | - $share->setExpirationDate($expirationDate); |
|
381 | - |
|
382 | - return $share; |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * Check for pre share requirements for user shares |
|
387 | - * |
|
388 | - * @param \OCP\Share\IShare $share |
|
389 | - * @throws \Exception |
|
390 | - */ |
|
391 | - protected function userCreateChecks(\OCP\Share\IShare $share) { |
|
392 | - // Check if we can share with group members only |
|
393 | - if ($this->shareWithGroupMembersOnly()) { |
|
394 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
395 | - $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
396 | - // Verify we can share with this user |
|
397 | - $groups = array_intersect( |
|
398 | - $this->groupManager->getUserGroupIds($sharedBy), |
|
399 | - $this->groupManager->getUserGroupIds($sharedWith) |
|
400 | - ); |
|
401 | - if (empty($groups)) { |
|
402 | - throw new \Exception('Sharing is only allowed with group members'); |
|
403 | - } |
|
404 | - } |
|
405 | - |
|
406 | - /* |
|
279 | + $permissions = $share->getNode()->getPermissions(); |
|
280 | + $mount = $share->getNode()->getMountPoint(); |
|
281 | + if (!($mount instanceof MoveableMount)) { |
|
282 | + $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
283 | + } |
|
284 | + |
|
285 | + // Check that we do not share with more permissions than we have |
|
286 | + if ($share->getPermissions() & ~$permissions) { |
|
287 | + $message_t = $this->l->t('Can’t increase permissions of %s', [$share->getNode()->getPath()]); |
|
288 | + throw new GenericShareException($message_t, $message_t, 404); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + // Check that read permissions are always set |
|
293 | + // Link shares are allowed to have no read permissions to allow upload to hidden folders |
|
294 | + $noReadPermissionRequired = $share->getShareType() === \OCP\Share::SHARE_TYPE_LINK |
|
295 | + || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL; |
|
296 | + if (!$noReadPermissionRequired && |
|
297 | + ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
|
298 | + throw new \InvalidArgumentException('Shares need at least read permissions'); |
|
299 | + } |
|
300 | + |
|
301 | + if ($share->getNode() instanceof \OCP\Files\File) { |
|
302 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
303 | + $message_t = $this->l->t('Files can’t be shared with delete permissions'); |
|
304 | + throw new GenericShareException($message_t); |
|
305 | + } |
|
306 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
307 | + $message_t = $this->l->t('Files can’t be shared with create permissions'); |
|
308 | + throw new GenericShareException($message_t); |
|
309 | + } |
|
310 | + } |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * Validate if the expiration date fits the system settings |
|
315 | + * |
|
316 | + * @param \OCP\Share\IShare $share The share to validate the expiration date of |
|
317 | + * @return \OCP\Share\IShare The modified share object |
|
318 | + * @throws GenericShareException |
|
319 | + * @throws \InvalidArgumentException |
|
320 | + * @throws \Exception |
|
321 | + */ |
|
322 | + protected function validateExpirationDate(\OCP\Share\IShare $share) { |
|
323 | + |
|
324 | + $expirationDate = $share->getExpirationDate(); |
|
325 | + |
|
326 | + if ($expirationDate !== null) { |
|
327 | + //Make sure the expiration date is a date |
|
328 | + $expirationDate->setTime(0, 0, 0); |
|
329 | + |
|
330 | + $date = new \DateTime(); |
|
331 | + $date->setTime(0, 0, 0); |
|
332 | + if ($date >= $expirationDate) { |
|
333 | + $message = $this->l->t('Expiration date is in the past'); |
|
334 | + throw new GenericShareException($message, $message, 404); |
|
335 | + } |
|
336 | + } |
|
337 | + |
|
338 | + // If expiredate is empty set a default one if there is a default |
|
339 | + $fullId = null; |
|
340 | + try { |
|
341 | + $fullId = $share->getFullId(); |
|
342 | + } catch (\UnexpectedValueException $e) { |
|
343 | + // This is a new share |
|
344 | + } |
|
345 | + |
|
346 | + if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
|
347 | + $expirationDate = new \DateTime(); |
|
348 | + $expirationDate->setTime(0,0,0); |
|
349 | + $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
350 | + } |
|
351 | + |
|
352 | + // If we enforce the expiration date check that is does not exceed |
|
353 | + if ($this->shareApiLinkDefaultExpireDateEnforced()) { |
|
354 | + if ($expirationDate === null) { |
|
355 | + throw new \InvalidArgumentException('Expiration date is enforced'); |
|
356 | + } |
|
357 | + |
|
358 | + $date = new \DateTime(); |
|
359 | + $date->setTime(0, 0, 0); |
|
360 | + $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
361 | + if ($date < $expirationDate) { |
|
362 | + $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
|
363 | + throw new GenericShareException($message, $message, 404); |
|
364 | + } |
|
365 | + } |
|
366 | + |
|
367 | + $accepted = true; |
|
368 | + $message = ''; |
|
369 | + \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
|
370 | + 'expirationDate' => &$expirationDate, |
|
371 | + 'accepted' => &$accepted, |
|
372 | + 'message' => &$message, |
|
373 | + 'passwordSet' => $share->getPassword() !== null, |
|
374 | + ]); |
|
375 | + |
|
376 | + if (!$accepted) { |
|
377 | + throw new \Exception($message); |
|
378 | + } |
|
379 | + |
|
380 | + $share->setExpirationDate($expirationDate); |
|
381 | + |
|
382 | + return $share; |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * Check for pre share requirements for user shares |
|
387 | + * |
|
388 | + * @param \OCP\Share\IShare $share |
|
389 | + * @throws \Exception |
|
390 | + */ |
|
391 | + protected function userCreateChecks(\OCP\Share\IShare $share) { |
|
392 | + // Check if we can share with group members only |
|
393 | + if ($this->shareWithGroupMembersOnly()) { |
|
394 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
395 | + $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
396 | + // Verify we can share with this user |
|
397 | + $groups = array_intersect( |
|
398 | + $this->groupManager->getUserGroupIds($sharedBy), |
|
399 | + $this->groupManager->getUserGroupIds($sharedWith) |
|
400 | + ); |
|
401 | + if (empty($groups)) { |
|
402 | + throw new \Exception('Sharing is only allowed with group members'); |
|
403 | + } |
|
404 | + } |
|
405 | + |
|
406 | + /* |
|
407 | 407 | * TODO: Could be costly, fix |
408 | 408 | * |
409 | 409 | * Also this is not what we want in the future.. then we want to squash identical shares. |
410 | 410 | */ |
411 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); |
|
412 | - $existingShares = $provider->getSharesByPath($share->getNode()); |
|
413 | - foreach($existingShares as $existingShare) { |
|
414 | - // Ignore if it is the same share |
|
415 | - try { |
|
416 | - if ($existingShare->getFullId() === $share->getFullId()) { |
|
417 | - continue; |
|
418 | - } |
|
419 | - } catch (\UnexpectedValueException $e) { |
|
420 | - //Shares are not identical |
|
421 | - } |
|
422 | - |
|
423 | - // Identical share already existst |
|
424 | - if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
425 | - throw new \Exception('Path is already shared with this user'); |
|
426 | - } |
|
427 | - |
|
428 | - // The share is already shared with this user via a group share |
|
429 | - if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
430 | - $group = $this->groupManager->get($existingShare->getSharedWith()); |
|
431 | - if (!is_null($group)) { |
|
432 | - $user = $this->userManager->get($share->getSharedWith()); |
|
433 | - |
|
434 | - if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
|
435 | - throw new \Exception('Path is already shared with this user'); |
|
436 | - } |
|
437 | - } |
|
438 | - } |
|
439 | - } |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Check for pre share requirements for group shares |
|
444 | - * |
|
445 | - * @param \OCP\Share\IShare $share |
|
446 | - * @throws \Exception |
|
447 | - */ |
|
448 | - protected function groupCreateChecks(\OCP\Share\IShare $share) { |
|
449 | - // Verify group shares are allowed |
|
450 | - if (!$this->allowGroupSharing()) { |
|
451 | - throw new \Exception('Group sharing is now allowed'); |
|
452 | - } |
|
453 | - |
|
454 | - // Verify if the user can share with this group |
|
455 | - if ($this->shareWithGroupMembersOnly()) { |
|
456 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
457 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
458 | - if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) { |
|
459 | - throw new \Exception('Sharing is only allowed within your own groups'); |
|
460 | - } |
|
461 | - } |
|
462 | - |
|
463 | - /* |
|
411 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); |
|
412 | + $existingShares = $provider->getSharesByPath($share->getNode()); |
|
413 | + foreach($existingShares as $existingShare) { |
|
414 | + // Ignore if it is the same share |
|
415 | + try { |
|
416 | + if ($existingShare->getFullId() === $share->getFullId()) { |
|
417 | + continue; |
|
418 | + } |
|
419 | + } catch (\UnexpectedValueException $e) { |
|
420 | + //Shares are not identical |
|
421 | + } |
|
422 | + |
|
423 | + // Identical share already existst |
|
424 | + if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
425 | + throw new \Exception('Path is already shared with this user'); |
|
426 | + } |
|
427 | + |
|
428 | + // The share is already shared with this user via a group share |
|
429 | + if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
430 | + $group = $this->groupManager->get($existingShare->getSharedWith()); |
|
431 | + if (!is_null($group)) { |
|
432 | + $user = $this->userManager->get($share->getSharedWith()); |
|
433 | + |
|
434 | + if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
|
435 | + throw new \Exception('Path is already shared with this user'); |
|
436 | + } |
|
437 | + } |
|
438 | + } |
|
439 | + } |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Check for pre share requirements for group shares |
|
444 | + * |
|
445 | + * @param \OCP\Share\IShare $share |
|
446 | + * @throws \Exception |
|
447 | + */ |
|
448 | + protected function groupCreateChecks(\OCP\Share\IShare $share) { |
|
449 | + // Verify group shares are allowed |
|
450 | + if (!$this->allowGroupSharing()) { |
|
451 | + throw new \Exception('Group sharing is now allowed'); |
|
452 | + } |
|
453 | + |
|
454 | + // Verify if the user can share with this group |
|
455 | + if ($this->shareWithGroupMembersOnly()) { |
|
456 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
457 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
458 | + if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) { |
|
459 | + throw new \Exception('Sharing is only allowed within your own groups'); |
|
460 | + } |
|
461 | + } |
|
462 | + |
|
463 | + /* |
|
464 | 464 | * TODO: Could be costly, fix |
465 | 465 | * |
466 | 466 | * Also this is not what we want in the future.. then we want to squash identical shares. |
467 | 467 | */ |
468 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
469 | - $existingShares = $provider->getSharesByPath($share->getNode()); |
|
470 | - foreach($existingShares as $existingShare) { |
|
471 | - try { |
|
472 | - if ($existingShare->getFullId() === $share->getFullId()) { |
|
473 | - continue; |
|
474 | - } |
|
475 | - } catch (\UnexpectedValueException $e) { |
|
476 | - //It is a new share so just continue |
|
477 | - } |
|
478 | - |
|
479 | - if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
480 | - throw new \Exception('Path is already shared with this group'); |
|
481 | - } |
|
482 | - } |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * Check for pre share requirements for link shares |
|
487 | - * |
|
488 | - * @param \OCP\Share\IShare $share |
|
489 | - * @throws \Exception |
|
490 | - */ |
|
491 | - protected function linkCreateChecks(\OCP\Share\IShare $share) { |
|
492 | - // Are link shares allowed? |
|
493 | - if (!$this->shareApiAllowLinks()) { |
|
494 | - throw new \Exception('Link sharing is not allowed'); |
|
495 | - } |
|
496 | - |
|
497 | - // Link shares by definition can't have share permissions |
|
498 | - if ($share->getPermissions() & \OCP\Constants::PERMISSION_SHARE) { |
|
499 | - throw new \InvalidArgumentException('Link shares can’t have reshare permissions'); |
|
500 | - } |
|
501 | - |
|
502 | - // Check if public upload is allowed |
|
503 | - if (!$this->shareApiLinkAllowPublicUpload() && |
|
504 | - ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
|
505 | - throw new \InvalidArgumentException('Public upload is not allowed'); |
|
506 | - } |
|
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * To make sure we don't get invisible link shares we set the parent |
|
511 | - * of a link if it is a reshare. This is a quick word around |
|
512 | - * until we can properly display multiple link shares in the UI |
|
513 | - * |
|
514 | - * See: https://github.com/owncloud/core/issues/22295 |
|
515 | - * |
|
516 | - * FIXME: Remove once multiple link shares can be properly displayed |
|
517 | - * |
|
518 | - * @param \OCP\Share\IShare $share |
|
519 | - */ |
|
520 | - protected function setLinkParent(\OCP\Share\IShare $share) { |
|
521 | - |
|
522 | - // No sense in checking if the method is not there. |
|
523 | - if (method_exists($share, 'setParent')) { |
|
524 | - $storage = $share->getNode()->getStorage(); |
|
525 | - if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
526 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
527 | - $share->setParent($storage->getShareId()); |
|
528 | - } |
|
529 | - }; |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * @param File|Folder $path |
|
534 | - */ |
|
535 | - protected function pathCreateChecks($path) { |
|
536 | - // Make sure that we do not share a path that contains a shared mountpoint |
|
537 | - if ($path instanceof \OCP\Files\Folder) { |
|
538 | - $mounts = $this->mountManager->findIn($path->getPath()); |
|
539 | - foreach($mounts as $mount) { |
|
540 | - if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
541 | - throw new \InvalidArgumentException('Path contains files shared with you'); |
|
542 | - } |
|
543 | - } |
|
544 | - } |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * Check if the user that is sharing can actually share |
|
549 | - * |
|
550 | - * @param \OCP\Share\IShare $share |
|
551 | - * @throws \Exception |
|
552 | - */ |
|
553 | - protected function canShare(\OCP\Share\IShare $share) { |
|
554 | - if (!$this->shareApiEnabled()) { |
|
555 | - throw new \Exception('Sharing is disabled'); |
|
556 | - } |
|
557 | - |
|
558 | - if ($this->sharingDisabledForUser($share->getSharedBy())) { |
|
559 | - throw new \Exception('Sharing is disabled for you'); |
|
560 | - } |
|
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * Share a path |
|
565 | - * |
|
566 | - * @param \OCP\Share\IShare $share |
|
567 | - * @return Share The share object |
|
568 | - * @throws \Exception |
|
569 | - * |
|
570 | - * TODO: handle link share permissions or check them |
|
571 | - */ |
|
572 | - public function createShare(\OCP\Share\IShare $share) { |
|
573 | - $this->canShare($share); |
|
574 | - |
|
575 | - $this->generalCreateChecks($share); |
|
576 | - |
|
577 | - // Verify if there are any issues with the path |
|
578 | - $this->pathCreateChecks($share->getNode()); |
|
579 | - |
|
580 | - /* |
|
468 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
469 | + $existingShares = $provider->getSharesByPath($share->getNode()); |
|
470 | + foreach($existingShares as $existingShare) { |
|
471 | + try { |
|
472 | + if ($existingShare->getFullId() === $share->getFullId()) { |
|
473 | + continue; |
|
474 | + } |
|
475 | + } catch (\UnexpectedValueException $e) { |
|
476 | + //It is a new share so just continue |
|
477 | + } |
|
478 | + |
|
479 | + if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
|
480 | + throw new \Exception('Path is already shared with this group'); |
|
481 | + } |
|
482 | + } |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * Check for pre share requirements for link shares |
|
487 | + * |
|
488 | + * @param \OCP\Share\IShare $share |
|
489 | + * @throws \Exception |
|
490 | + */ |
|
491 | + protected function linkCreateChecks(\OCP\Share\IShare $share) { |
|
492 | + // Are link shares allowed? |
|
493 | + if (!$this->shareApiAllowLinks()) { |
|
494 | + throw new \Exception('Link sharing is not allowed'); |
|
495 | + } |
|
496 | + |
|
497 | + // Link shares by definition can't have share permissions |
|
498 | + if ($share->getPermissions() & \OCP\Constants::PERMISSION_SHARE) { |
|
499 | + throw new \InvalidArgumentException('Link shares can’t have reshare permissions'); |
|
500 | + } |
|
501 | + |
|
502 | + // Check if public upload is allowed |
|
503 | + if (!$this->shareApiLinkAllowPublicUpload() && |
|
504 | + ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
|
505 | + throw new \InvalidArgumentException('Public upload is not allowed'); |
|
506 | + } |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * To make sure we don't get invisible link shares we set the parent |
|
511 | + * of a link if it is a reshare. This is a quick word around |
|
512 | + * until we can properly display multiple link shares in the UI |
|
513 | + * |
|
514 | + * See: https://github.com/owncloud/core/issues/22295 |
|
515 | + * |
|
516 | + * FIXME: Remove once multiple link shares can be properly displayed |
|
517 | + * |
|
518 | + * @param \OCP\Share\IShare $share |
|
519 | + */ |
|
520 | + protected function setLinkParent(\OCP\Share\IShare $share) { |
|
521 | + |
|
522 | + // No sense in checking if the method is not there. |
|
523 | + if (method_exists($share, 'setParent')) { |
|
524 | + $storage = $share->getNode()->getStorage(); |
|
525 | + if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
526 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
527 | + $share->setParent($storage->getShareId()); |
|
528 | + } |
|
529 | + }; |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * @param File|Folder $path |
|
534 | + */ |
|
535 | + protected function pathCreateChecks($path) { |
|
536 | + // Make sure that we do not share a path that contains a shared mountpoint |
|
537 | + if ($path instanceof \OCP\Files\Folder) { |
|
538 | + $mounts = $this->mountManager->findIn($path->getPath()); |
|
539 | + foreach($mounts as $mount) { |
|
540 | + if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
|
541 | + throw new \InvalidArgumentException('Path contains files shared with you'); |
|
542 | + } |
|
543 | + } |
|
544 | + } |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * Check if the user that is sharing can actually share |
|
549 | + * |
|
550 | + * @param \OCP\Share\IShare $share |
|
551 | + * @throws \Exception |
|
552 | + */ |
|
553 | + protected function canShare(\OCP\Share\IShare $share) { |
|
554 | + if (!$this->shareApiEnabled()) { |
|
555 | + throw new \Exception('Sharing is disabled'); |
|
556 | + } |
|
557 | + |
|
558 | + if ($this->sharingDisabledForUser($share->getSharedBy())) { |
|
559 | + throw new \Exception('Sharing is disabled for you'); |
|
560 | + } |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * Share a path |
|
565 | + * |
|
566 | + * @param \OCP\Share\IShare $share |
|
567 | + * @return Share The share object |
|
568 | + * @throws \Exception |
|
569 | + * |
|
570 | + * TODO: handle link share permissions or check them |
|
571 | + */ |
|
572 | + public function createShare(\OCP\Share\IShare $share) { |
|
573 | + $this->canShare($share); |
|
574 | + |
|
575 | + $this->generalCreateChecks($share); |
|
576 | + |
|
577 | + // Verify if there are any issues with the path |
|
578 | + $this->pathCreateChecks($share->getNode()); |
|
579 | + |
|
580 | + /* |
|
581 | 581 | * On creation of a share the owner is always the owner of the path |
582 | 582 | * Except for mounted federated shares. |
583 | 583 | */ |
584 | - $storage = $share->getNode()->getStorage(); |
|
585 | - if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
586 | - $parent = $share->getNode()->getParent(); |
|
587 | - while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
588 | - $parent = $parent->getParent(); |
|
589 | - } |
|
590 | - $share->setShareOwner($parent->getOwner()->getUID()); |
|
591 | - } else { |
|
592 | - $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
|
593 | - } |
|
594 | - |
|
595 | - //Verify share type |
|
596 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
597 | - $this->userCreateChecks($share); |
|
598 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
599 | - $this->groupCreateChecks($share); |
|
600 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
601 | - $this->linkCreateChecks($share); |
|
602 | - $this->setLinkParent($share); |
|
603 | - |
|
604 | - /* |
|
584 | + $storage = $share->getNode()->getStorage(); |
|
585 | + if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
586 | + $parent = $share->getNode()->getParent(); |
|
587 | + while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
588 | + $parent = $parent->getParent(); |
|
589 | + } |
|
590 | + $share->setShareOwner($parent->getOwner()->getUID()); |
|
591 | + } else { |
|
592 | + $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
|
593 | + } |
|
594 | + |
|
595 | + //Verify share type |
|
596 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
597 | + $this->userCreateChecks($share); |
|
598 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
599 | + $this->groupCreateChecks($share); |
|
600 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
601 | + $this->linkCreateChecks($share); |
|
602 | + $this->setLinkParent($share); |
|
603 | + |
|
604 | + /* |
|
605 | 605 | * For now ignore a set token. |
606 | 606 | */ |
607 | - $share->setToken( |
|
608 | - $this->secureRandom->generate( |
|
609 | - \OC\Share\Constants::TOKEN_LENGTH, |
|
610 | - \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE |
|
611 | - ) |
|
612 | - ); |
|
613 | - |
|
614 | - //Verify the expiration date |
|
615 | - $this->validateExpirationDate($share); |
|
616 | - |
|
617 | - //Verify the password |
|
618 | - $this->verifyPassword($share->getPassword()); |
|
619 | - |
|
620 | - // If a password is set. Hash it! |
|
621 | - if ($share->getPassword() !== null) { |
|
622 | - $share->setPassword($this->hasher->hash($share->getPassword())); |
|
623 | - } |
|
624 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
625 | - $share->setToken( |
|
626 | - $this->secureRandom->generate( |
|
627 | - \OC\Share\Constants::TOKEN_LENGTH, |
|
628 | - \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE |
|
629 | - ) |
|
630 | - ); |
|
631 | - } |
|
632 | - |
|
633 | - // Cannot share with the owner |
|
634 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
635 | - $share->getSharedWith() === $share->getShareOwner()) { |
|
636 | - throw new \InvalidArgumentException('Can’t share with the share owner'); |
|
637 | - } |
|
638 | - |
|
639 | - // Generate the target |
|
640 | - $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
|
641 | - $target = \OC\Files\Filesystem::normalizePath($target); |
|
642 | - $share->setTarget($target); |
|
643 | - |
|
644 | - // Pre share event |
|
645 | - $event = new GenericEvent($share); |
|
646 | - $a = $this->eventDispatcher->dispatch('OCP\Share::preShare', $event); |
|
647 | - if ($event->isPropagationStopped() && $event->hasArgument('error')) { |
|
648 | - throw new \Exception($event->getArgument('error')); |
|
649 | - } |
|
650 | - |
|
651 | - $oldShare = $share; |
|
652 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
653 | - $share = $provider->create($share); |
|
654 | - //reuse the node we already have |
|
655 | - $share->setNode($oldShare->getNode()); |
|
656 | - |
|
657 | - // Post share event |
|
658 | - $event = new GenericEvent($share); |
|
659 | - $this->eventDispatcher->dispatch('OCP\Share::postShare', $event); |
|
660 | - |
|
661 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
662 | - $mailSend = $share->getMailSend(); |
|
663 | - if($mailSend === true) { |
|
664 | - $user = $this->userManager->get($share->getSharedWith()); |
|
665 | - if ($user !== null) { |
|
666 | - $emailAddress = $user->getEMailAddress(); |
|
667 | - if ($emailAddress !== null && $emailAddress !== '') { |
|
668 | - $userLang = $this->config->getUserValue($share->getSharedWith(), 'core', 'lang', null); |
|
669 | - $l = $this->l10nFactory->get('lib', $userLang); |
|
670 | - $this->sendMailNotification( |
|
671 | - $l, |
|
672 | - $share->getNode()->getName(), |
|
673 | - $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]), |
|
674 | - $share->getSharedBy(), |
|
675 | - $emailAddress, |
|
676 | - $share->getExpirationDate() |
|
677 | - ); |
|
678 | - $this->logger->debug('Send share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); |
|
679 | - } else { |
|
680 | - $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); |
|
681 | - } |
|
682 | - } else { |
|
683 | - $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); |
|
684 | - } |
|
685 | - } else { |
|
686 | - $this->logger->debug('Share notification not send because mailsend is false.', ['app' => 'share']); |
|
687 | - } |
|
688 | - } |
|
689 | - |
|
690 | - return $share; |
|
691 | - } |
|
692 | - |
|
693 | - /** |
|
694 | - * @param IL10N $l Language of the recipient |
|
695 | - * @param string $filename file/folder name |
|
696 | - * @param string $link link to the file/folder |
|
697 | - * @param string $initiator user ID of share sender |
|
698 | - * @param string $shareWith email address of share receiver |
|
699 | - * @param \DateTime|null $expiration |
|
700 | - * @throws \Exception If mail couldn't be sent |
|
701 | - */ |
|
702 | - protected function sendMailNotification(IL10N $l, |
|
703 | - $filename, |
|
704 | - $link, |
|
705 | - $initiator, |
|
706 | - $shareWith, |
|
707 | - \DateTime $expiration = null) { |
|
708 | - $initiatorUser = $this->userManager->get($initiator); |
|
709 | - $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
710 | - $subject = $l->t('%s shared »%s« with you', array($initiatorDisplayName, $filename)); |
|
711 | - |
|
712 | - $message = $this->mailer->createMessage(); |
|
713 | - |
|
714 | - $emailTemplate = $this->mailer->createEMailTemplate('files_sharing.RecipientNotification', [ |
|
715 | - 'filename' => $filename, |
|
716 | - 'link' => $link, |
|
717 | - 'initiator' => $initiatorDisplayName, |
|
718 | - 'expiration' => $expiration, |
|
719 | - 'shareWith' => $shareWith, |
|
720 | - ]); |
|
721 | - |
|
722 | - $emailTemplate->addHeader(); |
|
723 | - $emailTemplate->addHeading($l->t('%s shared »%s« with you', [$initiatorDisplayName, $filename]), false); |
|
724 | - $text = $l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]); |
|
725 | - |
|
726 | - $emailTemplate->addBodyText( |
|
727 | - $text . ' ' . $l->t('Click the button below to open it.'), |
|
728 | - $text |
|
729 | - ); |
|
730 | - $emailTemplate->addBodyButton( |
|
731 | - $l->t('Open »%s«', [$filename]), |
|
732 | - $link |
|
733 | - ); |
|
734 | - |
|
735 | - $message->setTo([$shareWith]); |
|
736 | - |
|
737 | - // The "From" contains the sharers name |
|
738 | - $instanceName = $this->defaults->getName(); |
|
739 | - $senderName = $l->t( |
|
740 | - '%s via %s', |
|
741 | - [ |
|
742 | - $initiatorDisplayName, |
|
743 | - $instanceName |
|
744 | - ] |
|
745 | - ); |
|
746 | - $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
747 | - |
|
748 | - // The "Reply-To" is set to the sharer if an mail address is configured |
|
749 | - // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
750 | - $initiatorEmail = $initiatorUser->getEMailAddress(); |
|
751 | - if($initiatorEmail !== null) { |
|
752 | - $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
|
753 | - $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
754 | - } else { |
|
755 | - $emailTemplate->addFooter(); |
|
756 | - } |
|
757 | - |
|
758 | - $message->setSubject($subject); |
|
759 | - $message->setPlainBody($emailTemplate->renderText()); |
|
760 | - $message->setHtmlBody($emailTemplate->renderHtml()); |
|
761 | - $this->mailer->send($message); |
|
762 | - } |
|
763 | - |
|
764 | - /** |
|
765 | - * Update a share |
|
766 | - * |
|
767 | - * @param \OCP\Share\IShare $share |
|
768 | - * @return \OCP\Share\IShare The share object |
|
769 | - * @throws \InvalidArgumentException |
|
770 | - */ |
|
771 | - public function updateShare(\OCP\Share\IShare $share) { |
|
772 | - $expirationDateUpdated = false; |
|
773 | - |
|
774 | - $this->canShare($share); |
|
775 | - |
|
776 | - try { |
|
777 | - $originalShare = $this->getShareById($share->getFullId()); |
|
778 | - } catch (\UnexpectedValueException $e) { |
|
779 | - throw new \InvalidArgumentException('Share does not have a full id'); |
|
780 | - } |
|
781 | - |
|
782 | - // We can't change the share type! |
|
783 | - if ($share->getShareType() !== $originalShare->getShareType()) { |
|
784 | - throw new \InvalidArgumentException('Can’t change share type'); |
|
785 | - } |
|
786 | - |
|
787 | - // We can only change the recipient on user shares |
|
788 | - if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
|
789 | - $share->getShareType() !== \OCP\Share::SHARE_TYPE_USER) { |
|
790 | - throw new \InvalidArgumentException('Can only update recipient on user shares'); |
|
791 | - } |
|
792 | - |
|
793 | - // Cannot share with the owner |
|
794 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
795 | - $share->getSharedWith() === $share->getShareOwner()) { |
|
796 | - throw new \InvalidArgumentException('Can’t share with the share owner'); |
|
797 | - } |
|
798 | - |
|
799 | - $this->generalCreateChecks($share); |
|
800 | - |
|
801 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
802 | - $this->userCreateChecks($share); |
|
803 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
804 | - $this->groupCreateChecks($share); |
|
805 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
806 | - $this->linkCreateChecks($share); |
|
807 | - |
|
808 | - $this->updateSharePasswordIfNeeded($share, $originalShare); |
|
809 | - |
|
810 | - if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
811 | - //Verify the expiration date |
|
812 | - $this->validateExpirationDate($share); |
|
813 | - $expirationDateUpdated = true; |
|
814 | - } |
|
815 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
816 | - $plainTextPassword = $share->getPassword(); |
|
817 | - if (!$this->updateSharePasswordIfNeeded($share, $originalShare)) { |
|
818 | - $plainTextPassword = null; |
|
819 | - } |
|
820 | - } |
|
821 | - |
|
822 | - $this->pathCreateChecks($share->getNode()); |
|
823 | - |
|
824 | - // Now update the share! |
|
825 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
826 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
827 | - $share = $provider->update($share, $plainTextPassword); |
|
828 | - } else { |
|
829 | - $share = $provider->update($share); |
|
830 | - } |
|
831 | - |
|
832 | - if ($expirationDateUpdated === true) { |
|
833 | - \OC_Hook::emit('OCP\Share', 'post_set_expiration_date', [ |
|
834 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
835 | - 'itemSource' => $share->getNode()->getId(), |
|
836 | - 'date' => $share->getExpirationDate(), |
|
837 | - 'uidOwner' => $share->getSharedBy(), |
|
838 | - ]); |
|
839 | - } |
|
840 | - |
|
841 | - if ($share->getPassword() !== $originalShare->getPassword()) { |
|
842 | - \OC_Hook::emit('OCP\Share', 'post_update_password', [ |
|
843 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
844 | - 'itemSource' => $share->getNode()->getId(), |
|
845 | - 'uidOwner' => $share->getSharedBy(), |
|
846 | - 'token' => $share->getToken(), |
|
847 | - 'disabled' => is_null($share->getPassword()), |
|
848 | - ]); |
|
849 | - } |
|
850 | - |
|
851 | - if ($share->getPermissions() !== $originalShare->getPermissions()) { |
|
852 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
853 | - $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
854 | - } else { |
|
855 | - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
856 | - } |
|
857 | - \OC_Hook::emit('OCP\Share', 'post_update_permissions', array( |
|
858 | - 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
859 | - 'itemSource' => $share->getNode()->getId(), |
|
860 | - 'shareType' => $share->getShareType(), |
|
861 | - 'shareWith' => $share->getSharedWith(), |
|
862 | - 'uidOwner' => $share->getSharedBy(), |
|
863 | - 'permissions' => $share->getPermissions(), |
|
864 | - 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
|
865 | - )); |
|
866 | - } |
|
867 | - |
|
868 | - return $share; |
|
869 | - } |
|
870 | - |
|
871 | - /** |
|
872 | - * Updates the password of the given share if it is not the same as the |
|
873 | - * password of the original share. |
|
874 | - * |
|
875 | - * @param \OCP\Share\IShare $share the share to update its password. |
|
876 | - * @param \OCP\Share\IShare $originalShare the original share to compare its |
|
877 | - * password with. |
|
878 | - * @return boolean whether the password was updated or not. |
|
879 | - */ |
|
880 | - private function updateSharePasswordIfNeeded(\OCP\Share\IShare $share, \OCP\Share\IShare $originalShare) { |
|
881 | - // Password updated. |
|
882 | - if ($share->getPassword() !== $originalShare->getPassword()) { |
|
883 | - //Verify the password |
|
884 | - $this->verifyPassword($share->getPassword()); |
|
885 | - |
|
886 | - // If a password is set. Hash it! |
|
887 | - if ($share->getPassword() !== null) { |
|
888 | - $share->setPassword($this->hasher->hash($share->getPassword())); |
|
889 | - |
|
890 | - return true; |
|
891 | - } |
|
892 | - } |
|
893 | - |
|
894 | - return false; |
|
895 | - } |
|
896 | - |
|
897 | - /** |
|
898 | - * Delete all the children of this share |
|
899 | - * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
900 | - * |
|
901 | - * @param \OCP\Share\IShare $share |
|
902 | - * @return \OCP\Share\IShare[] List of deleted shares |
|
903 | - */ |
|
904 | - protected function deleteChildren(\OCP\Share\IShare $share) { |
|
905 | - $deletedShares = []; |
|
906 | - |
|
907 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
908 | - |
|
909 | - foreach ($provider->getChildren($share) as $child) { |
|
910 | - $deletedChildren = $this->deleteChildren($child); |
|
911 | - $deletedShares = array_merge($deletedShares, $deletedChildren); |
|
912 | - |
|
913 | - $provider->delete($child); |
|
914 | - $deletedShares[] = $child; |
|
915 | - } |
|
916 | - |
|
917 | - return $deletedShares; |
|
918 | - } |
|
919 | - |
|
920 | - /** |
|
921 | - * Delete a share |
|
922 | - * |
|
923 | - * @param \OCP\Share\IShare $share |
|
924 | - * @throws ShareNotFound |
|
925 | - * @throws \InvalidArgumentException |
|
926 | - */ |
|
927 | - public function deleteShare(\OCP\Share\IShare $share) { |
|
928 | - |
|
929 | - try { |
|
930 | - $share->getFullId(); |
|
931 | - } catch (\UnexpectedValueException $e) { |
|
932 | - throw new \InvalidArgumentException('Share does not have a full id'); |
|
933 | - } |
|
934 | - |
|
935 | - $event = new GenericEvent($share); |
|
936 | - $this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event); |
|
937 | - |
|
938 | - // Get all children and delete them as well |
|
939 | - $deletedShares = $this->deleteChildren($share); |
|
940 | - |
|
941 | - // Do the actual delete |
|
942 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
943 | - $provider->delete($share); |
|
944 | - |
|
945 | - // All the deleted shares caused by this delete |
|
946 | - $deletedShares[] = $share; |
|
947 | - |
|
948 | - // Emit post hook |
|
949 | - $event->setArgument('deletedShares', $deletedShares); |
|
950 | - $this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event); |
|
951 | - } |
|
952 | - |
|
953 | - |
|
954 | - /** |
|
955 | - * Unshare a file as the recipient. |
|
956 | - * This can be different from a regular delete for example when one of |
|
957 | - * the users in a groups deletes that share. But the provider should |
|
958 | - * handle this. |
|
959 | - * |
|
960 | - * @param \OCP\Share\IShare $share |
|
961 | - * @param string $recipientId |
|
962 | - */ |
|
963 | - public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
|
964 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
965 | - $provider = $this->factory->getProvider($providerId); |
|
966 | - |
|
967 | - $provider->deleteFromSelf($share, $recipientId); |
|
968 | - $event = new GenericEvent($share); |
|
969 | - $this->eventDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event); |
|
970 | - } |
|
971 | - |
|
972 | - /** |
|
973 | - * @inheritdoc |
|
974 | - */ |
|
975 | - public function moveShare(\OCP\Share\IShare $share, $recipientId) { |
|
976 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
977 | - throw new \InvalidArgumentException('Can’t change target of link share'); |
|
978 | - } |
|
979 | - |
|
980 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) { |
|
981 | - throw new \InvalidArgumentException('Invalid recipient'); |
|
982 | - } |
|
983 | - |
|
984 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
985 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
986 | - if (is_null($sharedWith)) { |
|
987 | - throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
988 | - } |
|
989 | - $recipient = $this->userManager->get($recipientId); |
|
990 | - if (!$sharedWith->inGroup($recipient)) { |
|
991 | - throw new \InvalidArgumentException('Invalid recipient'); |
|
992 | - } |
|
993 | - } |
|
994 | - |
|
995 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
996 | - $provider = $this->factory->getProvider($providerId); |
|
997 | - |
|
998 | - $provider->move($share, $recipientId); |
|
999 | - } |
|
1000 | - |
|
1001 | - public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
|
1002 | - $providers = $this->factory->getAllProviders(); |
|
1003 | - |
|
1004 | - return array_reduce($providers, function($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
1005 | - $newShares = $provider->getSharesInFolder($userId, $node, $reshares); |
|
1006 | - foreach ($newShares as $fid => $data) { |
|
1007 | - if (!isset($shares[$fid])) { |
|
1008 | - $shares[$fid] = []; |
|
1009 | - } |
|
1010 | - |
|
1011 | - $shares[$fid] = array_merge($shares[$fid], $data); |
|
1012 | - } |
|
1013 | - return $shares; |
|
1014 | - }, []); |
|
1015 | - } |
|
1016 | - |
|
1017 | - /** |
|
1018 | - * @inheritdoc |
|
1019 | - */ |
|
1020 | - public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { |
|
1021 | - if ($path !== null && |
|
1022 | - !($path instanceof \OCP\Files\File) && |
|
1023 | - !($path instanceof \OCP\Files\Folder)) { |
|
1024 | - throw new \InvalidArgumentException('invalid path'); |
|
1025 | - } |
|
1026 | - |
|
1027 | - try { |
|
1028 | - $provider = $this->factory->getProviderForType($shareType); |
|
1029 | - } catch (ProviderException $e) { |
|
1030 | - return []; |
|
1031 | - } |
|
1032 | - |
|
1033 | - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
1034 | - |
|
1035 | - /* |
|
607 | + $share->setToken( |
|
608 | + $this->secureRandom->generate( |
|
609 | + \OC\Share\Constants::TOKEN_LENGTH, |
|
610 | + \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE |
|
611 | + ) |
|
612 | + ); |
|
613 | + |
|
614 | + //Verify the expiration date |
|
615 | + $this->validateExpirationDate($share); |
|
616 | + |
|
617 | + //Verify the password |
|
618 | + $this->verifyPassword($share->getPassword()); |
|
619 | + |
|
620 | + // If a password is set. Hash it! |
|
621 | + if ($share->getPassword() !== null) { |
|
622 | + $share->setPassword($this->hasher->hash($share->getPassword())); |
|
623 | + } |
|
624 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
625 | + $share->setToken( |
|
626 | + $this->secureRandom->generate( |
|
627 | + \OC\Share\Constants::TOKEN_LENGTH, |
|
628 | + \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE |
|
629 | + ) |
|
630 | + ); |
|
631 | + } |
|
632 | + |
|
633 | + // Cannot share with the owner |
|
634 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
635 | + $share->getSharedWith() === $share->getShareOwner()) { |
|
636 | + throw new \InvalidArgumentException('Can’t share with the share owner'); |
|
637 | + } |
|
638 | + |
|
639 | + // Generate the target |
|
640 | + $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
|
641 | + $target = \OC\Files\Filesystem::normalizePath($target); |
|
642 | + $share->setTarget($target); |
|
643 | + |
|
644 | + // Pre share event |
|
645 | + $event = new GenericEvent($share); |
|
646 | + $a = $this->eventDispatcher->dispatch('OCP\Share::preShare', $event); |
|
647 | + if ($event->isPropagationStopped() && $event->hasArgument('error')) { |
|
648 | + throw new \Exception($event->getArgument('error')); |
|
649 | + } |
|
650 | + |
|
651 | + $oldShare = $share; |
|
652 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
653 | + $share = $provider->create($share); |
|
654 | + //reuse the node we already have |
|
655 | + $share->setNode($oldShare->getNode()); |
|
656 | + |
|
657 | + // Post share event |
|
658 | + $event = new GenericEvent($share); |
|
659 | + $this->eventDispatcher->dispatch('OCP\Share::postShare', $event); |
|
660 | + |
|
661 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
662 | + $mailSend = $share->getMailSend(); |
|
663 | + if($mailSend === true) { |
|
664 | + $user = $this->userManager->get($share->getSharedWith()); |
|
665 | + if ($user !== null) { |
|
666 | + $emailAddress = $user->getEMailAddress(); |
|
667 | + if ($emailAddress !== null && $emailAddress !== '') { |
|
668 | + $userLang = $this->config->getUserValue($share->getSharedWith(), 'core', 'lang', null); |
|
669 | + $l = $this->l10nFactory->get('lib', $userLang); |
|
670 | + $this->sendMailNotification( |
|
671 | + $l, |
|
672 | + $share->getNode()->getName(), |
|
673 | + $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $share->getNode()->getId()]), |
|
674 | + $share->getSharedBy(), |
|
675 | + $emailAddress, |
|
676 | + $share->getExpirationDate() |
|
677 | + ); |
|
678 | + $this->logger->debug('Send share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); |
|
679 | + } else { |
|
680 | + $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); |
|
681 | + } |
|
682 | + } else { |
|
683 | + $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); |
|
684 | + } |
|
685 | + } else { |
|
686 | + $this->logger->debug('Share notification not send because mailsend is false.', ['app' => 'share']); |
|
687 | + } |
|
688 | + } |
|
689 | + |
|
690 | + return $share; |
|
691 | + } |
|
692 | + |
|
693 | + /** |
|
694 | + * @param IL10N $l Language of the recipient |
|
695 | + * @param string $filename file/folder name |
|
696 | + * @param string $link link to the file/folder |
|
697 | + * @param string $initiator user ID of share sender |
|
698 | + * @param string $shareWith email address of share receiver |
|
699 | + * @param \DateTime|null $expiration |
|
700 | + * @throws \Exception If mail couldn't be sent |
|
701 | + */ |
|
702 | + protected function sendMailNotification(IL10N $l, |
|
703 | + $filename, |
|
704 | + $link, |
|
705 | + $initiator, |
|
706 | + $shareWith, |
|
707 | + \DateTime $expiration = null) { |
|
708 | + $initiatorUser = $this->userManager->get($initiator); |
|
709 | + $initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator; |
|
710 | + $subject = $l->t('%s shared »%s« with you', array($initiatorDisplayName, $filename)); |
|
711 | + |
|
712 | + $message = $this->mailer->createMessage(); |
|
713 | + |
|
714 | + $emailTemplate = $this->mailer->createEMailTemplate('files_sharing.RecipientNotification', [ |
|
715 | + 'filename' => $filename, |
|
716 | + 'link' => $link, |
|
717 | + 'initiator' => $initiatorDisplayName, |
|
718 | + 'expiration' => $expiration, |
|
719 | + 'shareWith' => $shareWith, |
|
720 | + ]); |
|
721 | + |
|
722 | + $emailTemplate->addHeader(); |
|
723 | + $emailTemplate->addHeading($l->t('%s shared »%s« with you', [$initiatorDisplayName, $filename]), false); |
|
724 | + $text = $l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]); |
|
725 | + |
|
726 | + $emailTemplate->addBodyText( |
|
727 | + $text . ' ' . $l->t('Click the button below to open it.'), |
|
728 | + $text |
|
729 | + ); |
|
730 | + $emailTemplate->addBodyButton( |
|
731 | + $l->t('Open »%s«', [$filename]), |
|
732 | + $link |
|
733 | + ); |
|
734 | + |
|
735 | + $message->setTo([$shareWith]); |
|
736 | + |
|
737 | + // The "From" contains the sharers name |
|
738 | + $instanceName = $this->defaults->getName(); |
|
739 | + $senderName = $l->t( |
|
740 | + '%s via %s', |
|
741 | + [ |
|
742 | + $initiatorDisplayName, |
|
743 | + $instanceName |
|
744 | + ] |
|
745 | + ); |
|
746 | + $message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]); |
|
747 | + |
|
748 | + // The "Reply-To" is set to the sharer if an mail address is configured |
|
749 | + // also the default footer contains a "Do not reply" which needs to be adjusted. |
|
750 | + $initiatorEmail = $initiatorUser->getEMailAddress(); |
|
751 | + if($initiatorEmail !== null) { |
|
752 | + $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
|
753 | + $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
754 | + } else { |
|
755 | + $emailTemplate->addFooter(); |
|
756 | + } |
|
757 | + |
|
758 | + $message->setSubject($subject); |
|
759 | + $message->setPlainBody($emailTemplate->renderText()); |
|
760 | + $message->setHtmlBody($emailTemplate->renderHtml()); |
|
761 | + $this->mailer->send($message); |
|
762 | + } |
|
763 | + |
|
764 | + /** |
|
765 | + * Update a share |
|
766 | + * |
|
767 | + * @param \OCP\Share\IShare $share |
|
768 | + * @return \OCP\Share\IShare The share object |
|
769 | + * @throws \InvalidArgumentException |
|
770 | + */ |
|
771 | + public function updateShare(\OCP\Share\IShare $share) { |
|
772 | + $expirationDateUpdated = false; |
|
773 | + |
|
774 | + $this->canShare($share); |
|
775 | + |
|
776 | + try { |
|
777 | + $originalShare = $this->getShareById($share->getFullId()); |
|
778 | + } catch (\UnexpectedValueException $e) { |
|
779 | + throw new \InvalidArgumentException('Share does not have a full id'); |
|
780 | + } |
|
781 | + |
|
782 | + // We can't change the share type! |
|
783 | + if ($share->getShareType() !== $originalShare->getShareType()) { |
|
784 | + throw new \InvalidArgumentException('Can’t change share type'); |
|
785 | + } |
|
786 | + |
|
787 | + // We can only change the recipient on user shares |
|
788 | + if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
|
789 | + $share->getShareType() !== \OCP\Share::SHARE_TYPE_USER) { |
|
790 | + throw new \InvalidArgumentException('Can only update recipient on user shares'); |
|
791 | + } |
|
792 | + |
|
793 | + // Cannot share with the owner |
|
794 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
795 | + $share->getSharedWith() === $share->getShareOwner()) { |
|
796 | + throw new \InvalidArgumentException('Can’t share with the share owner'); |
|
797 | + } |
|
798 | + |
|
799 | + $this->generalCreateChecks($share); |
|
800 | + |
|
801 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
802 | + $this->userCreateChecks($share); |
|
803 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
804 | + $this->groupCreateChecks($share); |
|
805 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
806 | + $this->linkCreateChecks($share); |
|
807 | + |
|
808 | + $this->updateSharePasswordIfNeeded($share, $originalShare); |
|
809 | + |
|
810 | + if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
|
811 | + //Verify the expiration date |
|
812 | + $this->validateExpirationDate($share); |
|
813 | + $expirationDateUpdated = true; |
|
814 | + } |
|
815 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
816 | + $plainTextPassword = $share->getPassword(); |
|
817 | + if (!$this->updateSharePasswordIfNeeded($share, $originalShare)) { |
|
818 | + $plainTextPassword = null; |
|
819 | + } |
|
820 | + } |
|
821 | + |
|
822 | + $this->pathCreateChecks($share->getNode()); |
|
823 | + |
|
824 | + // Now update the share! |
|
825 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
826 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
827 | + $share = $provider->update($share, $plainTextPassword); |
|
828 | + } else { |
|
829 | + $share = $provider->update($share); |
|
830 | + } |
|
831 | + |
|
832 | + if ($expirationDateUpdated === true) { |
|
833 | + \OC_Hook::emit('OCP\Share', 'post_set_expiration_date', [ |
|
834 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
835 | + 'itemSource' => $share->getNode()->getId(), |
|
836 | + 'date' => $share->getExpirationDate(), |
|
837 | + 'uidOwner' => $share->getSharedBy(), |
|
838 | + ]); |
|
839 | + } |
|
840 | + |
|
841 | + if ($share->getPassword() !== $originalShare->getPassword()) { |
|
842 | + \OC_Hook::emit('OCP\Share', 'post_update_password', [ |
|
843 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
844 | + 'itemSource' => $share->getNode()->getId(), |
|
845 | + 'uidOwner' => $share->getSharedBy(), |
|
846 | + 'token' => $share->getToken(), |
|
847 | + 'disabled' => is_null($share->getPassword()), |
|
848 | + ]); |
|
849 | + } |
|
850 | + |
|
851 | + if ($share->getPermissions() !== $originalShare->getPermissions()) { |
|
852 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
853 | + $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
|
854 | + } else { |
|
855 | + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
|
856 | + } |
|
857 | + \OC_Hook::emit('OCP\Share', 'post_update_permissions', array( |
|
858 | + 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
|
859 | + 'itemSource' => $share->getNode()->getId(), |
|
860 | + 'shareType' => $share->getShareType(), |
|
861 | + 'shareWith' => $share->getSharedWith(), |
|
862 | + 'uidOwner' => $share->getSharedBy(), |
|
863 | + 'permissions' => $share->getPermissions(), |
|
864 | + 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
|
865 | + )); |
|
866 | + } |
|
867 | + |
|
868 | + return $share; |
|
869 | + } |
|
870 | + |
|
871 | + /** |
|
872 | + * Updates the password of the given share if it is not the same as the |
|
873 | + * password of the original share. |
|
874 | + * |
|
875 | + * @param \OCP\Share\IShare $share the share to update its password. |
|
876 | + * @param \OCP\Share\IShare $originalShare the original share to compare its |
|
877 | + * password with. |
|
878 | + * @return boolean whether the password was updated or not. |
|
879 | + */ |
|
880 | + private function updateSharePasswordIfNeeded(\OCP\Share\IShare $share, \OCP\Share\IShare $originalShare) { |
|
881 | + // Password updated. |
|
882 | + if ($share->getPassword() !== $originalShare->getPassword()) { |
|
883 | + //Verify the password |
|
884 | + $this->verifyPassword($share->getPassword()); |
|
885 | + |
|
886 | + // If a password is set. Hash it! |
|
887 | + if ($share->getPassword() !== null) { |
|
888 | + $share->setPassword($this->hasher->hash($share->getPassword())); |
|
889 | + |
|
890 | + return true; |
|
891 | + } |
|
892 | + } |
|
893 | + |
|
894 | + return false; |
|
895 | + } |
|
896 | + |
|
897 | + /** |
|
898 | + * Delete all the children of this share |
|
899 | + * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
900 | + * |
|
901 | + * @param \OCP\Share\IShare $share |
|
902 | + * @return \OCP\Share\IShare[] List of deleted shares |
|
903 | + */ |
|
904 | + protected function deleteChildren(\OCP\Share\IShare $share) { |
|
905 | + $deletedShares = []; |
|
906 | + |
|
907 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
908 | + |
|
909 | + foreach ($provider->getChildren($share) as $child) { |
|
910 | + $deletedChildren = $this->deleteChildren($child); |
|
911 | + $deletedShares = array_merge($deletedShares, $deletedChildren); |
|
912 | + |
|
913 | + $provider->delete($child); |
|
914 | + $deletedShares[] = $child; |
|
915 | + } |
|
916 | + |
|
917 | + return $deletedShares; |
|
918 | + } |
|
919 | + |
|
920 | + /** |
|
921 | + * Delete a share |
|
922 | + * |
|
923 | + * @param \OCP\Share\IShare $share |
|
924 | + * @throws ShareNotFound |
|
925 | + * @throws \InvalidArgumentException |
|
926 | + */ |
|
927 | + public function deleteShare(\OCP\Share\IShare $share) { |
|
928 | + |
|
929 | + try { |
|
930 | + $share->getFullId(); |
|
931 | + } catch (\UnexpectedValueException $e) { |
|
932 | + throw new \InvalidArgumentException('Share does not have a full id'); |
|
933 | + } |
|
934 | + |
|
935 | + $event = new GenericEvent($share); |
|
936 | + $this->eventDispatcher->dispatch('OCP\Share::preUnshare', $event); |
|
937 | + |
|
938 | + // Get all children and delete them as well |
|
939 | + $deletedShares = $this->deleteChildren($share); |
|
940 | + |
|
941 | + // Do the actual delete |
|
942 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
943 | + $provider->delete($share); |
|
944 | + |
|
945 | + // All the deleted shares caused by this delete |
|
946 | + $deletedShares[] = $share; |
|
947 | + |
|
948 | + // Emit post hook |
|
949 | + $event->setArgument('deletedShares', $deletedShares); |
|
950 | + $this->eventDispatcher->dispatch('OCP\Share::postUnshare', $event); |
|
951 | + } |
|
952 | + |
|
953 | + |
|
954 | + /** |
|
955 | + * Unshare a file as the recipient. |
|
956 | + * This can be different from a regular delete for example when one of |
|
957 | + * the users in a groups deletes that share. But the provider should |
|
958 | + * handle this. |
|
959 | + * |
|
960 | + * @param \OCP\Share\IShare $share |
|
961 | + * @param string $recipientId |
|
962 | + */ |
|
963 | + public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
|
964 | + list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
965 | + $provider = $this->factory->getProvider($providerId); |
|
966 | + |
|
967 | + $provider->deleteFromSelf($share, $recipientId); |
|
968 | + $event = new GenericEvent($share); |
|
969 | + $this->eventDispatcher->dispatch('OCP\Share::postUnshareFromSelf', $event); |
|
970 | + } |
|
971 | + |
|
972 | + /** |
|
973 | + * @inheritdoc |
|
974 | + */ |
|
975 | + public function moveShare(\OCP\Share\IShare $share, $recipientId) { |
|
976 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
977 | + throw new \InvalidArgumentException('Can’t change target of link share'); |
|
978 | + } |
|
979 | + |
|
980 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() !== $recipientId) { |
|
981 | + throw new \InvalidArgumentException('Invalid recipient'); |
|
982 | + } |
|
983 | + |
|
984 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
985 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
986 | + if (is_null($sharedWith)) { |
|
987 | + throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
988 | + } |
|
989 | + $recipient = $this->userManager->get($recipientId); |
|
990 | + if (!$sharedWith->inGroup($recipient)) { |
|
991 | + throw new \InvalidArgumentException('Invalid recipient'); |
|
992 | + } |
|
993 | + } |
|
994 | + |
|
995 | + list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
996 | + $provider = $this->factory->getProvider($providerId); |
|
997 | + |
|
998 | + $provider->move($share, $recipientId); |
|
999 | + } |
|
1000 | + |
|
1001 | + public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
|
1002 | + $providers = $this->factory->getAllProviders(); |
|
1003 | + |
|
1004 | + return array_reduce($providers, function($shares, IShareProvider $provider) use ($userId, $node, $reshares) { |
|
1005 | + $newShares = $provider->getSharesInFolder($userId, $node, $reshares); |
|
1006 | + foreach ($newShares as $fid => $data) { |
|
1007 | + if (!isset($shares[$fid])) { |
|
1008 | + $shares[$fid] = []; |
|
1009 | + } |
|
1010 | + |
|
1011 | + $shares[$fid] = array_merge($shares[$fid], $data); |
|
1012 | + } |
|
1013 | + return $shares; |
|
1014 | + }, []); |
|
1015 | + } |
|
1016 | + |
|
1017 | + /** |
|
1018 | + * @inheritdoc |
|
1019 | + */ |
|
1020 | + public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { |
|
1021 | + if ($path !== null && |
|
1022 | + !($path instanceof \OCP\Files\File) && |
|
1023 | + !($path instanceof \OCP\Files\Folder)) { |
|
1024 | + throw new \InvalidArgumentException('invalid path'); |
|
1025 | + } |
|
1026 | + |
|
1027 | + try { |
|
1028 | + $provider = $this->factory->getProviderForType($shareType); |
|
1029 | + } catch (ProviderException $e) { |
|
1030 | + return []; |
|
1031 | + } |
|
1032 | + |
|
1033 | + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
1034 | + |
|
1035 | + /* |
|
1036 | 1036 | * Work around so we don't return expired shares but still follow |
1037 | 1037 | * proper pagination. |
1038 | 1038 | */ |
1039 | 1039 | |
1040 | - $shares2 = []; |
|
1041 | - |
|
1042 | - while(true) { |
|
1043 | - $added = 0; |
|
1044 | - foreach ($shares as $share) { |
|
1045 | - |
|
1046 | - try { |
|
1047 | - $this->checkExpireDate($share); |
|
1048 | - } catch (ShareNotFound $e) { |
|
1049 | - //Ignore since this basically means the share is deleted |
|
1050 | - continue; |
|
1051 | - } |
|
1052 | - |
|
1053 | - $added++; |
|
1054 | - $shares2[] = $share; |
|
1055 | - |
|
1056 | - if (count($shares2) === $limit) { |
|
1057 | - break; |
|
1058 | - } |
|
1059 | - } |
|
1060 | - |
|
1061 | - if (count($shares2) === $limit) { |
|
1062 | - break; |
|
1063 | - } |
|
1064 | - |
|
1065 | - // If there was no limit on the select we are done |
|
1066 | - if ($limit === -1) { |
|
1067 | - break; |
|
1068 | - } |
|
1069 | - |
|
1070 | - $offset += $added; |
|
1071 | - |
|
1072 | - // Fetch again $limit shares |
|
1073 | - $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
1074 | - |
|
1075 | - // No more shares means we are done |
|
1076 | - if (empty($shares)) { |
|
1077 | - break; |
|
1078 | - } |
|
1079 | - } |
|
1080 | - |
|
1081 | - $shares = $shares2; |
|
1082 | - |
|
1083 | - return $shares; |
|
1084 | - } |
|
1085 | - |
|
1086 | - /** |
|
1087 | - * @inheritdoc |
|
1088 | - */ |
|
1089 | - public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
1090 | - try { |
|
1091 | - $provider = $this->factory->getProviderForType($shareType); |
|
1092 | - } catch (ProviderException $e) { |
|
1093 | - return []; |
|
1094 | - } |
|
1095 | - |
|
1096 | - $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
1097 | - |
|
1098 | - // remove all shares which are already expired |
|
1099 | - foreach ($shares as $key => $share) { |
|
1100 | - try { |
|
1101 | - $this->checkExpireDate($share); |
|
1102 | - } catch (ShareNotFound $e) { |
|
1103 | - unset($shares[$key]); |
|
1104 | - } |
|
1105 | - } |
|
1106 | - |
|
1107 | - return $shares; |
|
1108 | - } |
|
1109 | - |
|
1110 | - /** |
|
1111 | - * @inheritdoc |
|
1112 | - */ |
|
1113 | - public function getShareById($id, $recipient = null) { |
|
1114 | - if ($id === null) { |
|
1115 | - throw new ShareNotFound(); |
|
1116 | - } |
|
1117 | - |
|
1118 | - list($providerId, $id) = $this->splitFullId($id); |
|
1119 | - |
|
1120 | - try { |
|
1121 | - $provider = $this->factory->getProvider($providerId); |
|
1122 | - } catch (ProviderException $e) { |
|
1123 | - throw new ShareNotFound(); |
|
1124 | - } |
|
1125 | - |
|
1126 | - $share = $provider->getShareById($id, $recipient); |
|
1127 | - |
|
1128 | - $this->checkExpireDate($share); |
|
1129 | - |
|
1130 | - return $share; |
|
1131 | - } |
|
1132 | - |
|
1133 | - /** |
|
1134 | - * Get all the shares for a given path |
|
1135 | - * |
|
1136 | - * @param \OCP\Files\Node $path |
|
1137 | - * @param int $page |
|
1138 | - * @param int $perPage |
|
1139 | - * |
|
1140 | - * @return Share[] |
|
1141 | - */ |
|
1142 | - public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
|
1143 | - return []; |
|
1144 | - } |
|
1145 | - |
|
1146 | - /** |
|
1147 | - * Get the share by token possible with password |
|
1148 | - * |
|
1149 | - * @param string $token |
|
1150 | - * @return Share |
|
1151 | - * |
|
1152 | - * @throws ShareNotFound |
|
1153 | - */ |
|
1154 | - public function getShareByToken($token) { |
|
1155 | - $share = null; |
|
1156 | - try { |
|
1157 | - if($this->shareApiAllowLinks()) { |
|
1158 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK); |
|
1159 | - $share = $provider->getShareByToken($token); |
|
1160 | - } |
|
1161 | - } catch (ProviderException $e) { |
|
1162 | - } catch (ShareNotFound $e) { |
|
1163 | - } |
|
1164 | - |
|
1165 | - |
|
1166 | - // If it is not a link share try to fetch a federated share by token |
|
1167 | - if ($share === null) { |
|
1168 | - try { |
|
1169 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE); |
|
1170 | - $share = $provider->getShareByToken($token); |
|
1171 | - } catch (ProviderException $e) { |
|
1172 | - } catch (ShareNotFound $e) { |
|
1173 | - } |
|
1174 | - } |
|
1175 | - |
|
1176 | - // If it is not a link share try to fetch a mail share by token |
|
1177 | - if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
1178 | - try { |
|
1179 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_EMAIL); |
|
1180 | - $share = $provider->getShareByToken($token); |
|
1181 | - } catch (ProviderException $e) { |
|
1182 | - } catch (ShareNotFound $e) { |
|
1183 | - } |
|
1184 | - } |
|
1185 | - |
|
1186 | - if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
1187 | - try { |
|
1188 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_CIRCLE); |
|
1189 | - $share = $provider->getShareByToken($token); |
|
1190 | - } catch (ProviderException $e) { |
|
1191 | - } catch (ShareNotFound $e) { |
|
1192 | - } |
|
1193 | - } |
|
1194 | - |
|
1195 | - if ($share === null) { |
|
1196 | - throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
1197 | - } |
|
1198 | - |
|
1199 | - $this->checkExpireDate($share); |
|
1200 | - |
|
1201 | - /* |
|
1040 | + $shares2 = []; |
|
1041 | + |
|
1042 | + while(true) { |
|
1043 | + $added = 0; |
|
1044 | + foreach ($shares as $share) { |
|
1045 | + |
|
1046 | + try { |
|
1047 | + $this->checkExpireDate($share); |
|
1048 | + } catch (ShareNotFound $e) { |
|
1049 | + //Ignore since this basically means the share is deleted |
|
1050 | + continue; |
|
1051 | + } |
|
1052 | + |
|
1053 | + $added++; |
|
1054 | + $shares2[] = $share; |
|
1055 | + |
|
1056 | + if (count($shares2) === $limit) { |
|
1057 | + break; |
|
1058 | + } |
|
1059 | + } |
|
1060 | + |
|
1061 | + if (count($shares2) === $limit) { |
|
1062 | + break; |
|
1063 | + } |
|
1064 | + |
|
1065 | + // If there was no limit on the select we are done |
|
1066 | + if ($limit === -1) { |
|
1067 | + break; |
|
1068 | + } |
|
1069 | + |
|
1070 | + $offset += $added; |
|
1071 | + |
|
1072 | + // Fetch again $limit shares |
|
1073 | + $shares = $provider->getSharesBy($userId, $shareType, $path, $reshares, $limit, $offset); |
|
1074 | + |
|
1075 | + // No more shares means we are done |
|
1076 | + if (empty($shares)) { |
|
1077 | + break; |
|
1078 | + } |
|
1079 | + } |
|
1080 | + |
|
1081 | + $shares = $shares2; |
|
1082 | + |
|
1083 | + return $shares; |
|
1084 | + } |
|
1085 | + |
|
1086 | + /** |
|
1087 | + * @inheritdoc |
|
1088 | + */ |
|
1089 | + public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
|
1090 | + try { |
|
1091 | + $provider = $this->factory->getProviderForType($shareType); |
|
1092 | + } catch (ProviderException $e) { |
|
1093 | + return []; |
|
1094 | + } |
|
1095 | + |
|
1096 | + $shares = $provider->getSharedWith($userId, $shareType, $node, $limit, $offset); |
|
1097 | + |
|
1098 | + // remove all shares which are already expired |
|
1099 | + foreach ($shares as $key => $share) { |
|
1100 | + try { |
|
1101 | + $this->checkExpireDate($share); |
|
1102 | + } catch (ShareNotFound $e) { |
|
1103 | + unset($shares[$key]); |
|
1104 | + } |
|
1105 | + } |
|
1106 | + |
|
1107 | + return $shares; |
|
1108 | + } |
|
1109 | + |
|
1110 | + /** |
|
1111 | + * @inheritdoc |
|
1112 | + */ |
|
1113 | + public function getShareById($id, $recipient = null) { |
|
1114 | + if ($id === null) { |
|
1115 | + throw new ShareNotFound(); |
|
1116 | + } |
|
1117 | + |
|
1118 | + list($providerId, $id) = $this->splitFullId($id); |
|
1119 | + |
|
1120 | + try { |
|
1121 | + $provider = $this->factory->getProvider($providerId); |
|
1122 | + } catch (ProviderException $e) { |
|
1123 | + throw new ShareNotFound(); |
|
1124 | + } |
|
1125 | + |
|
1126 | + $share = $provider->getShareById($id, $recipient); |
|
1127 | + |
|
1128 | + $this->checkExpireDate($share); |
|
1129 | + |
|
1130 | + return $share; |
|
1131 | + } |
|
1132 | + |
|
1133 | + /** |
|
1134 | + * Get all the shares for a given path |
|
1135 | + * |
|
1136 | + * @param \OCP\Files\Node $path |
|
1137 | + * @param int $page |
|
1138 | + * @param int $perPage |
|
1139 | + * |
|
1140 | + * @return Share[] |
|
1141 | + */ |
|
1142 | + public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
|
1143 | + return []; |
|
1144 | + } |
|
1145 | + |
|
1146 | + /** |
|
1147 | + * Get the share by token possible with password |
|
1148 | + * |
|
1149 | + * @param string $token |
|
1150 | + * @return Share |
|
1151 | + * |
|
1152 | + * @throws ShareNotFound |
|
1153 | + */ |
|
1154 | + public function getShareByToken($token) { |
|
1155 | + $share = null; |
|
1156 | + try { |
|
1157 | + if($this->shareApiAllowLinks()) { |
|
1158 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK); |
|
1159 | + $share = $provider->getShareByToken($token); |
|
1160 | + } |
|
1161 | + } catch (ProviderException $e) { |
|
1162 | + } catch (ShareNotFound $e) { |
|
1163 | + } |
|
1164 | + |
|
1165 | + |
|
1166 | + // If it is not a link share try to fetch a federated share by token |
|
1167 | + if ($share === null) { |
|
1168 | + try { |
|
1169 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_REMOTE); |
|
1170 | + $share = $provider->getShareByToken($token); |
|
1171 | + } catch (ProviderException $e) { |
|
1172 | + } catch (ShareNotFound $e) { |
|
1173 | + } |
|
1174 | + } |
|
1175 | + |
|
1176 | + // If it is not a link share try to fetch a mail share by token |
|
1177 | + if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
1178 | + try { |
|
1179 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_EMAIL); |
|
1180 | + $share = $provider->getShareByToken($token); |
|
1181 | + } catch (ProviderException $e) { |
|
1182 | + } catch (ShareNotFound $e) { |
|
1183 | + } |
|
1184 | + } |
|
1185 | + |
|
1186 | + if ($share === null && $this->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
1187 | + try { |
|
1188 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_CIRCLE); |
|
1189 | + $share = $provider->getShareByToken($token); |
|
1190 | + } catch (ProviderException $e) { |
|
1191 | + } catch (ShareNotFound $e) { |
|
1192 | + } |
|
1193 | + } |
|
1194 | + |
|
1195 | + if ($share === null) { |
|
1196 | + throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
1197 | + } |
|
1198 | + |
|
1199 | + $this->checkExpireDate($share); |
|
1200 | + |
|
1201 | + /* |
|
1202 | 1202 | * Reduce the permissions for link shares if public upload is not enabled |
1203 | 1203 | */ |
1204 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && |
|
1205 | - !$this->shareApiLinkAllowPublicUpload()) { |
|
1206 | - $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); |
|
1207 | - } |
|
1208 | - |
|
1209 | - return $share; |
|
1210 | - } |
|
1211 | - |
|
1212 | - protected function checkExpireDate($share) { |
|
1213 | - if ($share->getExpirationDate() !== null && |
|
1214 | - $share->getExpirationDate() <= new \DateTime()) { |
|
1215 | - $this->deleteShare($share); |
|
1216 | - throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
1217 | - } |
|
1218 | - |
|
1219 | - } |
|
1220 | - |
|
1221 | - /** |
|
1222 | - * Verify the password of a public share |
|
1223 | - * |
|
1224 | - * @param \OCP\Share\IShare $share |
|
1225 | - * @param string $password |
|
1226 | - * @return bool |
|
1227 | - */ |
|
1228 | - public function checkPassword(\OCP\Share\IShare $share, $password) { |
|
1229 | - $passwordProtected = $share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK |
|
1230 | - || $share->getShareType() !== \OCP\Share::SHARE_TYPE_EMAIL; |
|
1231 | - if (!$passwordProtected) { |
|
1232 | - //TODO maybe exception? |
|
1233 | - return false; |
|
1234 | - } |
|
1235 | - |
|
1236 | - if ($password === null || $share->getPassword() === null) { |
|
1237 | - return false; |
|
1238 | - } |
|
1239 | - |
|
1240 | - $newHash = ''; |
|
1241 | - if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) { |
|
1242 | - return false; |
|
1243 | - } |
|
1244 | - |
|
1245 | - if (!empty($newHash)) { |
|
1246 | - $share->setPassword($newHash); |
|
1247 | - $provider = $this->factory->getProviderForType($share->getShareType()); |
|
1248 | - $provider->update($share); |
|
1249 | - } |
|
1250 | - |
|
1251 | - return true; |
|
1252 | - } |
|
1253 | - |
|
1254 | - /** |
|
1255 | - * @inheritdoc |
|
1256 | - */ |
|
1257 | - public function userDeleted($uid) { |
|
1258 | - $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]; |
|
1259 | - |
|
1260 | - foreach ($types as $type) { |
|
1261 | - try { |
|
1262 | - $provider = $this->factory->getProviderForType($type); |
|
1263 | - } catch (ProviderException $e) { |
|
1264 | - continue; |
|
1265 | - } |
|
1266 | - $provider->userDeleted($uid, $type); |
|
1267 | - } |
|
1268 | - } |
|
1269 | - |
|
1270 | - /** |
|
1271 | - * @inheritdoc |
|
1272 | - */ |
|
1273 | - public function groupDeleted($gid) { |
|
1274 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
1275 | - $provider->groupDeleted($gid); |
|
1276 | - } |
|
1277 | - |
|
1278 | - /** |
|
1279 | - * @inheritdoc |
|
1280 | - */ |
|
1281 | - public function userDeletedFromGroup($uid, $gid) { |
|
1282 | - $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
1283 | - $provider->userDeletedFromGroup($uid, $gid); |
|
1284 | - } |
|
1285 | - |
|
1286 | - /** |
|
1287 | - * Get access list to a path. This means |
|
1288 | - * all the users that can access a given path. |
|
1289 | - * |
|
1290 | - * Consider: |
|
1291 | - * -root |
|
1292 | - * |-folder1 (23) |
|
1293 | - * |-folder2 (32) |
|
1294 | - * |-fileA (42) |
|
1295 | - * |
|
1296 | - * fileA is shared with user1 and user1@server1 |
|
1297 | - * folder2 is shared with group2 (user4 is a member of group2) |
|
1298 | - * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
1299 | - * |
|
1300 | - * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
1301 | - * [ |
|
1302 | - * users => [ |
|
1303 | - * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
1304 | - * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
1305 | - * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
1306 | - * ], |
|
1307 | - * remote => [ |
|
1308 | - * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
1309 | - * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
1310 | - * ], |
|
1311 | - * public => bool |
|
1312 | - * mail => bool |
|
1313 | - * ] |
|
1314 | - * |
|
1315 | - * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
1316 | - * [ |
|
1317 | - * users => ['user1', 'user2', 'user4'], |
|
1318 | - * remote => bool, |
|
1319 | - * public => bool |
|
1320 | - * mail => bool |
|
1321 | - * ] |
|
1322 | - * |
|
1323 | - * This is required for encryption/activity |
|
1324 | - * |
|
1325 | - * @param \OCP\Files\Node $path |
|
1326 | - * @param bool $recursive Should we check all parent folders as well |
|
1327 | - * @param bool $currentAccess Should the user have currently access to the file |
|
1328 | - * @return array |
|
1329 | - */ |
|
1330 | - public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { |
|
1331 | - $owner = $path->getOwner()->getUID(); |
|
1332 | - |
|
1333 | - if ($currentAccess) { |
|
1334 | - $al = ['users' => [], 'remote' => [], 'public' => false]; |
|
1335 | - } else { |
|
1336 | - $al = ['users' => [], 'remote' => false, 'public' => false]; |
|
1337 | - } |
|
1338 | - if (!$this->userManager->userExists($owner)) { |
|
1339 | - return $al; |
|
1340 | - } |
|
1341 | - |
|
1342 | - //Get node for the owner |
|
1343 | - $userFolder = $this->rootFolder->getUserFolder($owner); |
|
1344 | - if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) { |
|
1345 | - $path = $userFolder->getById($path->getId())[0]; |
|
1346 | - } |
|
1347 | - |
|
1348 | - $providers = $this->factory->getAllProviders(); |
|
1349 | - |
|
1350 | - /** @var Node[] $nodes */ |
|
1351 | - $nodes = []; |
|
1352 | - |
|
1353 | - |
|
1354 | - if ($currentAccess) { |
|
1355 | - $ownerPath = $path->getPath(); |
|
1356 | - $ownerPath = explode('/', $ownerPath, 4); |
|
1357 | - if (count($ownerPath) < 4) { |
|
1358 | - $ownerPath = ''; |
|
1359 | - } else { |
|
1360 | - $ownerPath = $ownerPath[3]; |
|
1361 | - } |
|
1362 | - $al['users'][$owner] = [ |
|
1363 | - 'node_id' => $path->getId(), |
|
1364 | - 'node_path' => '/' . $ownerPath, |
|
1365 | - ]; |
|
1366 | - } else { |
|
1367 | - $al['users'][] = $owner; |
|
1368 | - } |
|
1369 | - |
|
1370 | - // Collect all the shares |
|
1371 | - while ($path->getPath() !== $userFolder->getPath()) { |
|
1372 | - $nodes[] = $path; |
|
1373 | - if (!$recursive) { |
|
1374 | - break; |
|
1375 | - } |
|
1376 | - $path = $path->getParent(); |
|
1377 | - } |
|
1378 | - |
|
1379 | - foreach ($providers as $provider) { |
|
1380 | - $tmp = $provider->getAccessList($nodes, $currentAccess); |
|
1381 | - |
|
1382 | - foreach ($tmp as $k => $v) { |
|
1383 | - if (isset($al[$k])) { |
|
1384 | - if (is_array($al[$k])) { |
|
1385 | - $al[$k] = array_merge($al[$k], $v); |
|
1386 | - } else { |
|
1387 | - $al[$k] = $al[$k] || $v; |
|
1388 | - } |
|
1389 | - } else { |
|
1390 | - $al[$k] = $v; |
|
1391 | - } |
|
1392 | - } |
|
1393 | - } |
|
1394 | - |
|
1395 | - return $al; |
|
1396 | - } |
|
1397 | - |
|
1398 | - /** |
|
1399 | - * Create a new share |
|
1400 | - * @return \OCP\Share\IShare; |
|
1401 | - */ |
|
1402 | - public function newShare() { |
|
1403 | - return new \OC\Share20\Share($this->rootFolder, $this->userManager); |
|
1404 | - } |
|
1405 | - |
|
1406 | - /** |
|
1407 | - * Is the share API enabled |
|
1408 | - * |
|
1409 | - * @return bool |
|
1410 | - */ |
|
1411 | - public function shareApiEnabled() { |
|
1412 | - return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; |
|
1413 | - } |
|
1414 | - |
|
1415 | - /** |
|
1416 | - * Is public link sharing enabled |
|
1417 | - * |
|
1418 | - * @return bool |
|
1419 | - */ |
|
1420 | - public function shareApiAllowLinks() { |
|
1421 | - return $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
1422 | - } |
|
1423 | - |
|
1424 | - /** |
|
1425 | - * Is password on public link requires |
|
1426 | - * |
|
1427 | - * @return bool |
|
1428 | - */ |
|
1429 | - public function shareApiLinkEnforcePassword() { |
|
1430 | - return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; |
|
1431 | - } |
|
1432 | - |
|
1433 | - /** |
|
1434 | - * Is default expire date enabled |
|
1435 | - * |
|
1436 | - * @return bool |
|
1437 | - */ |
|
1438 | - public function shareApiLinkDefaultExpireDate() { |
|
1439 | - return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
1440 | - } |
|
1441 | - |
|
1442 | - /** |
|
1443 | - * Is default expire date enforced |
|
1444 | - *` |
|
1445 | - * @return bool |
|
1446 | - */ |
|
1447 | - public function shareApiLinkDefaultExpireDateEnforced() { |
|
1448 | - return $this->shareApiLinkDefaultExpireDate() && |
|
1449 | - $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
1450 | - } |
|
1451 | - |
|
1452 | - /** |
|
1453 | - * Number of default expire days |
|
1454 | - *shareApiLinkAllowPublicUpload |
|
1455 | - * @return int |
|
1456 | - */ |
|
1457 | - public function shareApiLinkDefaultExpireDays() { |
|
1458 | - return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
1459 | - } |
|
1460 | - |
|
1461 | - /** |
|
1462 | - * Allow public upload on link shares |
|
1463 | - * |
|
1464 | - * @return bool |
|
1465 | - */ |
|
1466 | - public function shareApiLinkAllowPublicUpload() { |
|
1467 | - return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
1468 | - } |
|
1469 | - |
|
1470 | - /** |
|
1471 | - * check if user can only share with group members |
|
1472 | - * @return bool |
|
1473 | - */ |
|
1474 | - public function shareWithGroupMembersOnly() { |
|
1475 | - return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
1476 | - } |
|
1477 | - |
|
1478 | - /** |
|
1479 | - * Check if users can share with groups |
|
1480 | - * @return bool |
|
1481 | - */ |
|
1482 | - public function allowGroupSharing() { |
|
1483 | - return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
1484 | - } |
|
1485 | - |
|
1486 | - /** |
|
1487 | - * Copied from \OC_Util::isSharingDisabledForUser |
|
1488 | - * |
|
1489 | - * TODO: Deprecate fuction from OC_Util |
|
1490 | - * |
|
1491 | - * @param string $userId |
|
1492 | - * @return bool |
|
1493 | - */ |
|
1494 | - public function sharingDisabledForUser($userId) { |
|
1495 | - if ($userId === null) { |
|
1496 | - return false; |
|
1497 | - } |
|
1498 | - |
|
1499 | - if (isset($this->sharingDisabledForUsersCache[$userId])) { |
|
1500 | - return $this->sharingDisabledForUsersCache[$userId]; |
|
1501 | - } |
|
1502 | - |
|
1503 | - if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
1504 | - $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
1505 | - $excludedGroups = json_decode($groupsList); |
|
1506 | - if (is_null($excludedGroups)) { |
|
1507 | - $excludedGroups = explode(',', $groupsList); |
|
1508 | - $newValue = json_encode($excludedGroups); |
|
1509 | - $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
1510 | - } |
|
1511 | - $user = $this->userManager->get($userId); |
|
1512 | - $usersGroups = $this->groupManager->getUserGroupIds($user); |
|
1513 | - if (!empty($usersGroups)) { |
|
1514 | - $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
1515 | - // if the user is only in groups which are disabled for sharing then |
|
1516 | - // sharing is also disabled for the user |
|
1517 | - if (empty($remainingGroups)) { |
|
1518 | - $this->sharingDisabledForUsersCache[$userId] = true; |
|
1519 | - return true; |
|
1520 | - } |
|
1521 | - } |
|
1522 | - } |
|
1523 | - |
|
1524 | - $this->sharingDisabledForUsersCache[$userId] = false; |
|
1525 | - return false; |
|
1526 | - } |
|
1527 | - |
|
1528 | - /** |
|
1529 | - * @inheritdoc |
|
1530 | - */ |
|
1531 | - public function outgoingServer2ServerSharesAllowed() { |
|
1532 | - return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
1533 | - } |
|
1534 | - |
|
1535 | - /** |
|
1536 | - * @inheritdoc |
|
1537 | - */ |
|
1538 | - public function shareProviderExists($shareType) { |
|
1539 | - try { |
|
1540 | - $this->factory->getProviderForType($shareType); |
|
1541 | - } catch (ProviderException $e) { |
|
1542 | - return false; |
|
1543 | - } |
|
1544 | - |
|
1545 | - return true; |
|
1546 | - } |
|
1204 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK && |
|
1205 | + !$this->shareApiLinkAllowPublicUpload()) { |
|
1206 | + $share->setPermissions($share->getPermissions() & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE)); |
|
1207 | + } |
|
1208 | + |
|
1209 | + return $share; |
|
1210 | + } |
|
1211 | + |
|
1212 | + protected function checkExpireDate($share) { |
|
1213 | + if ($share->getExpirationDate() !== null && |
|
1214 | + $share->getExpirationDate() <= new \DateTime()) { |
|
1215 | + $this->deleteShare($share); |
|
1216 | + throw new ShareNotFound($this->l->t('The requested share does not exist anymore')); |
|
1217 | + } |
|
1218 | + |
|
1219 | + } |
|
1220 | + |
|
1221 | + /** |
|
1222 | + * Verify the password of a public share |
|
1223 | + * |
|
1224 | + * @param \OCP\Share\IShare $share |
|
1225 | + * @param string $password |
|
1226 | + * @return bool |
|
1227 | + */ |
|
1228 | + public function checkPassword(\OCP\Share\IShare $share, $password) { |
|
1229 | + $passwordProtected = $share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK |
|
1230 | + || $share->getShareType() !== \OCP\Share::SHARE_TYPE_EMAIL; |
|
1231 | + if (!$passwordProtected) { |
|
1232 | + //TODO maybe exception? |
|
1233 | + return false; |
|
1234 | + } |
|
1235 | + |
|
1236 | + if ($password === null || $share->getPassword() === null) { |
|
1237 | + return false; |
|
1238 | + } |
|
1239 | + |
|
1240 | + $newHash = ''; |
|
1241 | + if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) { |
|
1242 | + return false; |
|
1243 | + } |
|
1244 | + |
|
1245 | + if (!empty($newHash)) { |
|
1246 | + $share->setPassword($newHash); |
|
1247 | + $provider = $this->factory->getProviderForType($share->getShareType()); |
|
1248 | + $provider->update($share); |
|
1249 | + } |
|
1250 | + |
|
1251 | + return true; |
|
1252 | + } |
|
1253 | + |
|
1254 | + /** |
|
1255 | + * @inheritdoc |
|
1256 | + */ |
|
1257 | + public function userDeleted($uid) { |
|
1258 | + $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]; |
|
1259 | + |
|
1260 | + foreach ($types as $type) { |
|
1261 | + try { |
|
1262 | + $provider = $this->factory->getProviderForType($type); |
|
1263 | + } catch (ProviderException $e) { |
|
1264 | + continue; |
|
1265 | + } |
|
1266 | + $provider->userDeleted($uid, $type); |
|
1267 | + } |
|
1268 | + } |
|
1269 | + |
|
1270 | + /** |
|
1271 | + * @inheritdoc |
|
1272 | + */ |
|
1273 | + public function groupDeleted($gid) { |
|
1274 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
1275 | + $provider->groupDeleted($gid); |
|
1276 | + } |
|
1277 | + |
|
1278 | + /** |
|
1279 | + * @inheritdoc |
|
1280 | + */ |
|
1281 | + public function userDeletedFromGroup($uid, $gid) { |
|
1282 | + $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
|
1283 | + $provider->userDeletedFromGroup($uid, $gid); |
|
1284 | + } |
|
1285 | + |
|
1286 | + /** |
|
1287 | + * Get access list to a path. This means |
|
1288 | + * all the users that can access a given path. |
|
1289 | + * |
|
1290 | + * Consider: |
|
1291 | + * -root |
|
1292 | + * |-folder1 (23) |
|
1293 | + * |-folder2 (32) |
|
1294 | + * |-fileA (42) |
|
1295 | + * |
|
1296 | + * fileA is shared with user1 and user1@server1 |
|
1297 | + * folder2 is shared with group2 (user4 is a member of group2) |
|
1298 | + * folder1 is shared with user2 (renamed to "folder (1)") and user2@server2 |
|
1299 | + * |
|
1300 | + * Then the access list to '/folder1/folder2/fileA' with $currentAccess is: |
|
1301 | + * [ |
|
1302 | + * users => [ |
|
1303 | + * 'user1' => ['node_id' => 42, 'node_path' => '/fileA'], |
|
1304 | + * 'user4' => ['node_id' => 32, 'node_path' => '/folder2'], |
|
1305 | + * 'user2' => ['node_id' => 23, 'node_path' => '/folder (1)'], |
|
1306 | + * ], |
|
1307 | + * remote => [ |
|
1308 | + * 'user1@server1' => ['node_id' => 42, 'token' => 'SeCr3t'], |
|
1309 | + * 'user2@server2' => ['node_id' => 23, 'token' => 'FooBaR'], |
|
1310 | + * ], |
|
1311 | + * public => bool |
|
1312 | + * mail => bool |
|
1313 | + * ] |
|
1314 | + * |
|
1315 | + * The access list to '/folder1/folder2/fileA' **without** $currentAccess is: |
|
1316 | + * [ |
|
1317 | + * users => ['user1', 'user2', 'user4'], |
|
1318 | + * remote => bool, |
|
1319 | + * public => bool |
|
1320 | + * mail => bool |
|
1321 | + * ] |
|
1322 | + * |
|
1323 | + * This is required for encryption/activity |
|
1324 | + * |
|
1325 | + * @param \OCP\Files\Node $path |
|
1326 | + * @param bool $recursive Should we check all parent folders as well |
|
1327 | + * @param bool $currentAccess Should the user have currently access to the file |
|
1328 | + * @return array |
|
1329 | + */ |
|
1330 | + public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { |
|
1331 | + $owner = $path->getOwner()->getUID(); |
|
1332 | + |
|
1333 | + if ($currentAccess) { |
|
1334 | + $al = ['users' => [], 'remote' => [], 'public' => false]; |
|
1335 | + } else { |
|
1336 | + $al = ['users' => [], 'remote' => false, 'public' => false]; |
|
1337 | + } |
|
1338 | + if (!$this->userManager->userExists($owner)) { |
|
1339 | + return $al; |
|
1340 | + } |
|
1341 | + |
|
1342 | + //Get node for the owner |
|
1343 | + $userFolder = $this->rootFolder->getUserFolder($owner); |
|
1344 | + if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) { |
|
1345 | + $path = $userFolder->getById($path->getId())[0]; |
|
1346 | + } |
|
1347 | + |
|
1348 | + $providers = $this->factory->getAllProviders(); |
|
1349 | + |
|
1350 | + /** @var Node[] $nodes */ |
|
1351 | + $nodes = []; |
|
1352 | + |
|
1353 | + |
|
1354 | + if ($currentAccess) { |
|
1355 | + $ownerPath = $path->getPath(); |
|
1356 | + $ownerPath = explode('/', $ownerPath, 4); |
|
1357 | + if (count($ownerPath) < 4) { |
|
1358 | + $ownerPath = ''; |
|
1359 | + } else { |
|
1360 | + $ownerPath = $ownerPath[3]; |
|
1361 | + } |
|
1362 | + $al['users'][$owner] = [ |
|
1363 | + 'node_id' => $path->getId(), |
|
1364 | + 'node_path' => '/' . $ownerPath, |
|
1365 | + ]; |
|
1366 | + } else { |
|
1367 | + $al['users'][] = $owner; |
|
1368 | + } |
|
1369 | + |
|
1370 | + // Collect all the shares |
|
1371 | + while ($path->getPath() !== $userFolder->getPath()) { |
|
1372 | + $nodes[] = $path; |
|
1373 | + if (!$recursive) { |
|
1374 | + break; |
|
1375 | + } |
|
1376 | + $path = $path->getParent(); |
|
1377 | + } |
|
1378 | + |
|
1379 | + foreach ($providers as $provider) { |
|
1380 | + $tmp = $provider->getAccessList($nodes, $currentAccess); |
|
1381 | + |
|
1382 | + foreach ($tmp as $k => $v) { |
|
1383 | + if (isset($al[$k])) { |
|
1384 | + if (is_array($al[$k])) { |
|
1385 | + $al[$k] = array_merge($al[$k], $v); |
|
1386 | + } else { |
|
1387 | + $al[$k] = $al[$k] || $v; |
|
1388 | + } |
|
1389 | + } else { |
|
1390 | + $al[$k] = $v; |
|
1391 | + } |
|
1392 | + } |
|
1393 | + } |
|
1394 | + |
|
1395 | + return $al; |
|
1396 | + } |
|
1397 | + |
|
1398 | + /** |
|
1399 | + * Create a new share |
|
1400 | + * @return \OCP\Share\IShare; |
|
1401 | + */ |
|
1402 | + public function newShare() { |
|
1403 | + return new \OC\Share20\Share($this->rootFolder, $this->userManager); |
|
1404 | + } |
|
1405 | + |
|
1406 | + /** |
|
1407 | + * Is the share API enabled |
|
1408 | + * |
|
1409 | + * @return bool |
|
1410 | + */ |
|
1411 | + public function shareApiEnabled() { |
|
1412 | + return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; |
|
1413 | + } |
|
1414 | + |
|
1415 | + /** |
|
1416 | + * Is public link sharing enabled |
|
1417 | + * |
|
1418 | + * @return bool |
|
1419 | + */ |
|
1420 | + public function shareApiAllowLinks() { |
|
1421 | + return $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
1422 | + } |
|
1423 | + |
|
1424 | + /** |
|
1425 | + * Is password on public link requires |
|
1426 | + * |
|
1427 | + * @return bool |
|
1428 | + */ |
|
1429 | + public function shareApiLinkEnforcePassword() { |
|
1430 | + return $this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'; |
|
1431 | + } |
|
1432 | + |
|
1433 | + /** |
|
1434 | + * Is default expire date enabled |
|
1435 | + * |
|
1436 | + * @return bool |
|
1437 | + */ |
|
1438 | + public function shareApiLinkDefaultExpireDate() { |
|
1439 | + return $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
1440 | + } |
|
1441 | + |
|
1442 | + /** |
|
1443 | + * Is default expire date enforced |
|
1444 | + *` |
|
1445 | + * @return bool |
|
1446 | + */ |
|
1447 | + public function shareApiLinkDefaultExpireDateEnforced() { |
|
1448 | + return $this->shareApiLinkDefaultExpireDate() && |
|
1449 | + $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
1450 | + } |
|
1451 | + |
|
1452 | + /** |
|
1453 | + * Number of default expire days |
|
1454 | + *shareApiLinkAllowPublicUpload |
|
1455 | + * @return int |
|
1456 | + */ |
|
1457 | + public function shareApiLinkDefaultExpireDays() { |
|
1458 | + return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
1459 | + } |
|
1460 | + |
|
1461 | + /** |
|
1462 | + * Allow public upload on link shares |
|
1463 | + * |
|
1464 | + * @return bool |
|
1465 | + */ |
|
1466 | + public function shareApiLinkAllowPublicUpload() { |
|
1467 | + return $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
1468 | + } |
|
1469 | + |
|
1470 | + /** |
|
1471 | + * check if user can only share with group members |
|
1472 | + * @return bool |
|
1473 | + */ |
|
1474 | + public function shareWithGroupMembersOnly() { |
|
1475 | + return $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
1476 | + } |
|
1477 | + |
|
1478 | + /** |
|
1479 | + * Check if users can share with groups |
|
1480 | + * @return bool |
|
1481 | + */ |
|
1482 | + public function allowGroupSharing() { |
|
1483 | + return $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
1484 | + } |
|
1485 | + |
|
1486 | + /** |
|
1487 | + * Copied from \OC_Util::isSharingDisabledForUser |
|
1488 | + * |
|
1489 | + * TODO: Deprecate fuction from OC_Util |
|
1490 | + * |
|
1491 | + * @param string $userId |
|
1492 | + * @return bool |
|
1493 | + */ |
|
1494 | + public function sharingDisabledForUser($userId) { |
|
1495 | + if ($userId === null) { |
|
1496 | + return false; |
|
1497 | + } |
|
1498 | + |
|
1499 | + if (isset($this->sharingDisabledForUsersCache[$userId])) { |
|
1500 | + return $this->sharingDisabledForUsersCache[$userId]; |
|
1501 | + } |
|
1502 | + |
|
1503 | + if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') { |
|
1504 | + $groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
1505 | + $excludedGroups = json_decode($groupsList); |
|
1506 | + if (is_null($excludedGroups)) { |
|
1507 | + $excludedGroups = explode(',', $groupsList); |
|
1508 | + $newValue = json_encode($excludedGroups); |
|
1509 | + $this->config->setAppValue('core', 'shareapi_exclude_groups_list', $newValue); |
|
1510 | + } |
|
1511 | + $user = $this->userManager->get($userId); |
|
1512 | + $usersGroups = $this->groupManager->getUserGroupIds($user); |
|
1513 | + if (!empty($usersGroups)) { |
|
1514 | + $remainingGroups = array_diff($usersGroups, $excludedGroups); |
|
1515 | + // if the user is only in groups which are disabled for sharing then |
|
1516 | + // sharing is also disabled for the user |
|
1517 | + if (empty($remainingGroups)) { |
|
1518 | + $this->sharingDisabledForUsersCache[$userId] = true; |
|
1519 | + return true; |
|
1520 | + } |
|
1521 | + } |
|
1522 | + } |
|
1523 | + |
|
1524 | + $this->sharingDisabledForUsersCache[$userId] = false; |
|
1525 | + return false; |
|
1526 | + } |
|
1527 | + |
|
1528 | + /** |
|
1529 | + * @inheritdoc |
|
1530 | + */ |
|
1531 | + public function outgoingServer2ServerSharesAllowed() { |
|
1532 | + return $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
1533 | + } |
|
1534 | + |
|
1535 | + /** |
|
1536 | + * @inheritdoc |
|
1537 | + */ |
|
1538 | + public function shareProviderExists($shareType) { |
|
1539 | + try { |
|
1540 | + $this->factory->getProviderForType($shareType); |
|
1541 | + } catch (ProviderException $e) { |
|
1542 | + return false; |
|
1543 | + } |
|
1544 | + |
|
1545 | + return true; |
|
1546 | + } |
|
1547 | 1547 | |
1548 | 1548 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | |
346 | 346 | if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
347 | 347 | $expirationDate = new \DateTime(); |
348 | - $expirationDate->setTime(0,0,0); |
|
348 | + $expirationDate->setTime(0, 0, 0); |
|
349 | 349 | $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
350 | 350 | } |
351 | 351 | |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | |
358 | 358 | $date = new \DateTime(); |
359 | 359 | $date->setTime(0, 0, 0); |
360 | - $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
|
360 | + $date->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
|
361 | 361 | if ($date < $expirationDate) { |
362 | 362 | $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
363 | 363 | throw new GenericShareException($message, $message, 404); |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | */ |
411 | 411 | $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); |
412 | 412 | $existingShares = $provider->getSharesByPath($share->getNode()); |
413 | - foreach($existingShares as $existingShare) { |
|
413 | + foreach ($existingShares as $existingShare) { |
|
414 | 414 | // Ignore if it is the same share |
415 | 415 | try { |
416 | 416 | if ($existingShare->getFullId() === $share->getFullId()) { |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | */ |
468 | 468 | $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
469 | 469 | $existingShares = $provider->getSharesByPath($share->getNode()); |
470 | - foreach($existingShares as $existingShare) { |
|
470 | + foreach ($existingShares as $existingShare) { |
|
471 | 471 | try { |
472 | 472 | if ($existingShare->getFullId() === $share->getFullId()) { |
473 | 473 | continue; |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | // Make sure that we do not share a path that contains a shared mountpoint |
537 | 537 | if ($path instanceof \OCP\Files\Folder) { |
538 | 538 | $mounts = $this->mountManager->findIn($path->getPath()); |
539 | - foreach($mounts as $mount) { |
|
539 | + foreach ($mounts as $mount) { |
|
540 | 540 | if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
541 | 541 | throw new \InvalidArgumentException('Path contains files shared with you'); |
542 | 542 | } |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | $storage = $share->getNode()->getStorage(); |
585 | 585 | if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
586 | 586 | $parent = $share->getNode()->getParent(); |
587 | - while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
587 | + while ($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
588 | 588 | $parent = $parent->getParent(); |
589 | 589 | } |
590 | 590 | $share->setShareOwner($parent->getOwner()->getUID()); |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | } |
638 | 638 | |
639 | 639 | // Generate the target |
640 | - $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
|
640 | + $target = $this->config->getSystemValue('share_folder', '/').'/'.$share->getNode()->getName(); |
|
641 | 641 | $target = \OC\Files\Filesystem::normalizePath($target); |
642 | 642 | $share->setTarget($target); |
643 | 643 | |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | |
661 | 661 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
662 | 662 | $mailSend = $share->getMailSend(); |
663 | - if($mailSend === true) { |
|
663 | + if ($mailSend === true) { |
|
664 | 664 | $user = $this->userManager->get($share->getSharedWith()); |
665 | 665 | if ($user !== null) { |
666 | 666 | $emailAddress = $user->getEMailAddress(); |
@@ -675,12 +675,12 @@ discard block |
||
675 | 675 | $emailAddress, |
676 | 676 | $share->getExpirationDate() |
677 | 677 | ); |
678 | - $this->logger->debug('Send share notification to ' . $emailAddress . ' for share with ID ' . $share->getId(), ['app' => 'share']); |
|
678 | + $this->logger->debug('Send share notification to '.$emailAddress.' for share with ID '.$share->getId(), ['app' => 'share']); |
|
679 | 679 | } else { |
680 | - $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because email address is not set.', ['app' => 'share']); |
|
680 | + $this->logger->debug('Share notification not send to '.$share->getSharedWith().' because email address is not set.', ['app' => 'share']); |
|
681 | 681 | } |
682 | 682 | } else { |
683 | - $this->logger->debug('Share notification not send to ' . $share->getSharedWith() . ' because user could not be found.', ['app' => 'share']); |
|
683 | + $this->logger->debug('Share notification not send to '.$share->getSharedWith().' because user could not be found.', ['app' => 'share']); |
|
684 | 684 | } |
685 | 685 | } else { |
686 | 686 | $this->logger->debug('Share notification not send because mailsend is false.', ['app' => 'share']); |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | $text = $l->t('%s shared »%s« with you.', [$initiatorDisplayName, $filename]); |
725 | 725 | |
726 | 726 | $emailTemplate->addBodyText( |
727 | - $text . ' ' . $l->t('Click the button below to open it.'), |
|
727 | + $text.' '.$l->t('Click the button below to open it.'), |
|
728 | 728 | $text |
729 | 729 | ); |
730 | 730 | $emailTemplate->addBodyButton( |
@@ -748,9 +748,9 @@ discard block |
||
748 | 748 | // The "Reply-To" is set to the sharer if an mail address is configured |
749 | 749 | // also the default footer contains a "Do not reply" which needs to be adjusted. |
750 | 750 | $initiatorEmail = $initiatorUser->getEMailAddress(); |
751 | - if($initiatorEmail !== null) { |
|
751 | + if ($initiatorEmail !== null) { |
|
752 | 752 | $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); |
753 | - $emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan()); |
|
753 | + $emailTemplate->addFooter($instanceName.' - '.$this->defaults->getSlogan()); |
|
754 | 754 | } else { |
755 | 755 | $emailTemplate->addFooter(); |
756 | 756 | } |
@@ -961,7 +961,7 @@ discard block |
||
961 | 961 | * @param string $recipientId |
962 | 962 | */ |
963 | 963 | public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
964 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
964 | + list($providerId,) = $this->splitFullId($share->getFullId()); |
|
965 | 965 | $provider = $this->factory->getProvider($providerId); |
966 | 966 | |
967 | 967 | $provider->deleteFromSelf($share, $recipientId); |
@@ -984,7 +984,7 @@ discard block |
||
984 | 984 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
985 | 985 | $sharedWith = $this->groupManager->get($share->getSharedWith()); |
986 | 986 | if (is_null($sharedWith)) { |
987 | - throw new \InvalidArgumentException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
987 | + throw new \InvalidArgumentException('Group "'.$share->getSharedWith().'" does not exist'); |
|
988 | 988 | } |
989 | 989 | $recipient = $this->userManager->get($recipientId); |
990 | 990 | if (!$sharedWith->inGroup($recipient)) { |
@@ -992,7 +992,7 @@ discard block |
||
992 | 992 | } |
993 | 993 | } |
994 | 994 | |
995 | - list($providerId, ) = $this->splitFullId($share->getFullId()); |
|
995 | + list($providerId,) = $this->splitFullId($share->getFullId()); |
|
996 | 996 | $provider = $this->factory->getProvider($providerId); |
997 | 997 | |
998 | 998 | $provider->move($share, $recipientId); |
@@ -1039,7 +1039,7 @@ discard block |
||
1039 | 1039 | |
1040 | 1040 | $shares2 = []; |
1041 | 1041 | |
1042 | - while(true) { |
|
1042 | + while (true) { |
|
1043 | 1043 | $added = 0; |
1044 | 1044 | foreach ($shares as $share) { |
1045 | 1045 | |
@@ -1139,7 +1139,7 @@ discard block |
||
1139 | 1139 | * |
1140 | 1140 | * @return Share[] |
1141 | 1141 | */ |
1142 | - public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
|
1142 | + public function getSharesByPath(\OCP\Files\Node $path, $page = 0, $perPage = 50) { |
|
1143 | 1143 | return []; |
1144 | 1144 | } |
1145 | 1145 | |
@@ -1154,7 +1154,7 @@ discard block |
||
1154 | 1154 | public function getShareByToken($token) { |
1155 | 1155 | $share = null; |
1156 | 1156 | try { |
1157 | - if($this->shareApiAllowLinks()) { |
|
1157 | + if ($this->shareApiAllowLinks()) { |
|
1158 | 1158 | $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK); |
1159 | 1159 | $share = $provider->getShareByToken($token); |
1160 | 1160 | } |
@@ -1361,7 +1361,7 @@ discard block |
||
1361 | 1361 | } |
1362 | 1362 | $al['users'][$owner] = [ |
1363 | 1363 | 'node_id' => $path->getId(), |
1364 | - 'node_path' => '/' . $ownerPath, |
|
1364 | + 'node_path' => '/'.$ownerPath, |
|
1365 | 1365 | ]; |
1366 | 1366 | } else { |
1367 | 1367 | $al['users'][] = $owner; |
@@ -1455,7 +1455,7 @@ discard block |
||
1455 | 1455 | * @return int |
1456 | 1456 | */ |
1457 | 1457 | public function shareApiLinkDefaultExpireDays() { |
1458 | - return (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
1458 | + return (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
1459 | 1459 | } |
1460 | 1460 | |
1461 | 1461 | /** |