@@ -26,54 +26,54 @@ |
||
26 | 26 | use Sabre\Xml\XmlDeserializable; |
27 | 27 | |
28 | 28 | class ShareRequest implements XmlDeserializable { |
29 | - public $set = []; |
|
29 | + public $set = []; |
|
30 | 30 | |
31 | - public $remove = []; |
|
31 | + public $remove = []; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor |
|
35 | - * |
|
36 | - * @param array $set |
|
37 | - * @param array $remove |
|
38 | - */ |
|
39 | - public function __construct(array $set, array $remove) { |
|
40 | - $this->set = $set; |
|
41 | - $this->remove = $remove; |
|
42 | - } |
|
33 | + /** |
|
34 | + * Constructor |
|
35 | + * |
|
36 | + * @param array $set |
|
37 | + * @param array $remove |
|
38 | + */ |
|
39 | + public function __construct(array $set, array $remove) { |
|
40 | + $this->set = $set; |
|
41 | + $this->remove = $remove; |
|
42 | + } |
|
43 | 43 | |
44 | - public static function xmlDeserialize(Reader $reader) { |
|
45 | - $elements = $reader->parseInnerTree([ |
|
46 | - '{' . Plugin::NS_OWNCLOUD. '}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
47 | - '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
48 | - ]); |
|
44 | + public static function xmlDeserialize(Reader $reader) { |
|
45 | + $elements = $reader->parseInnerTree([ |
|
46 | + '{' . Plugin::NS_OWNCLOUD. '}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
47 | + '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
48 | + ]); |
|
49 | 49 | |
50 | - $set = []; |
|
51 | - $remove = []; |
|
50 | + $set = []; |
|
51 | + $remove = []; |
|
52 | 52 | |
53 | - foreach ($elements as $elem) { |
|
54 | - switch ($elem['name']) { |
|
53 | + foreach ($elements as $elem) { |
|
54 | + switch ($elem['name']) { |
|
55 | 55 | |
56 | - case '{' . Plugin::NS_OWNCLOUD . '}set': |
|
57 | - $sharee = $elem['value']; |
|
56 | + case '{' . Plugin::NS_OWNCLOUD . '}set': |
|
57 | + $sharee = $elem['value']; |
|
58 | 58 | |
59 | - $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary'; |
|
60 | - $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name'; |
|
59 | + $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary'; |
|
60 | + $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name'; |
|
61 | 61 | |
62 | - $set[] = [ |
|
63 | - 'href' => $sharee['{DAV:}href'], |
|
64 | - 'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null, |
|
65 | - 'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null, |
|
66 | - 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee), |
|
67 | - ]; |
|
68 | - break; |
|
62 | + $set[] = [ |
|
63 | + 'href' => $sharee['{DAV:}href'], |
|
64 | + 'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null, |
|
65 | + 'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null, |
|
66 | + 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee), |
|
67 | + ]; |
|
68 | + break; |
|
69 | 69 | |
70 | - case '{' . Plugin::NS_OWNCLOUD . '}remove': |
|
71 | - $remove[] = $elem['value']['{DAV:}href']; |
|
72 | - break; |
|
70 | + case '{' . Plugin::NS_OWNCLOUD . '}remove': |
|
71 | + $remove[] = $elem['value']['{DAV:}href']; |
|
72 | + break; |
|
73 | 73 | |
74 | - } |
|
75 | - } |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - return new self($set, $remove); |
|
78 | - } |
|
77 | + return new self($set, $remove); |
|
78 | + } |
|
79 | 79 | } |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | |
44 | 44 | public static function xmlDeserialize(Reader $reader) { |
45 | 45 | $elements = $reader->parseInnerTree([ |
46 | - '{' . Plugin::NS_OWNCLOUD. '}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
47 | - '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
46 | + '{'.Plugin::NS_OWNCLOUD.'}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
47 | + '{'.Plugin::NS_OWNCLOUD.'}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
48 | 48 | ]); |
49 | 49 | |
50 | 50 | $set = []; |
@@ -53,21 +53,21 @@ discard block |
||
53 | 53 | foreach ($elements as $elem) { |
54 | 54 | switch ($elem['name']) { |
55 | 55 | |
56 | - case '{' . Plugin::NS_OWNCLOUD . '}set': |
|
56 | + case '{'.Plugin::NS_OWNCLOUD.'}set': |
|
57 | 57 | $sharee = $elem['value']; |
58 | 58 | |
59 | - $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary'; |
|
60 | - $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name'; |
|
59 | + $sumElem = '{'.Plugin::NS_OWNCLOUD.'}summary'; |
|
60 | + $commonName = '{'.Plugin::NS_OWNCLOUD.'}common-name'; |
|
61 | 61 | |
62 | 62 | $set[] = [ |
63 | 63 | 'href' => $sharee['{DAV:}href'], |
64 | 64 | 'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null, |
65 | 65 | 'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null, |
66 | - 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee), |
|
66 | + 'readOnly' => !array_key_exists('{'.Plugin::NS_OWNCLOUD.'}read-write', $sharee), |
|
67 | 67 | ]; |
68 | 68 | break; |
69 | 69 | |
70 | - case '{' . Plugin::NS_OWNCLOUD . '}remove': |
|
70 | + case '{'.Plugin::NS_OWNCLOUD.'}remove': |
|
71 | 71 | $remove[] = $elem['value']['{DAV:}href']; |
72 | 72 | break; |
73 | 73 |
@@ -191,13 +191,13 @@ discard block |
||
191 | 191 | foreach ($shares as $share) { |
192 | 192 | $acl[] = [ |
193 | 193 | 'privilege' => '{DAV:}read', |
194 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
194 | + 'principal' => $share['{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}principal'], |
|
195 | 195 | 'protected' => true, |
196 | 196 | ]; |
197 | 197 | if (!$share['readOnly']) { |
198 | 198 | $acl[] = [ |
199 | 199 | 'privilege' => '{DAV:}write', |
200 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
200 | + 'principal' => $share['{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}principal'], |
|
201 | 201 | 'protected' => true, |
202 | 202 | ]; |
203 | 203 | } elseif ($this->resourceType === 'calendar') { |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | // so users can change the visibility. |
206 | 206 | $acl[] = [ |
207 | 207 | 'privilege' => '{DAV:}write-properties', |
208 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
208 | + 'principal' => $share['{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}principal'], |
|
209 | 209 | 'protected' => true, |
210 | 210 | ]; |
211 | 211 | } |
@@ -35,213 +35,213 @@ |
||
35 | 35 | |
36 | 36 | class Backend { |
37 | 37 | |
38 | - /** @var IDBConnection */ |
|
39 | - private $db; |
|
40 | - /** @var IUserManager */ |
|
41 | - private $userManager; |
|
42 | - /** @var IGroupManager */ |
|
43 | - private $groupManager; |
|
44 | - /** @var Principal */ |
|
45 | - private $principalBackend; |
|
46 | - /** @var string */ |
|
47 | - private $resourceType; |
|
48 | - |
|
49 | - public const ACCESS_OWNER = 1; |
|
50 | - public const ACCESS_READ_WRITE = 2; |
|
51 | - public const ACCESS_READ = 3; |
|
52 | - |
|
53 | - /** |
|
54 | - * @param IDBConnection $db |
|
55 | - * @param IUserManager $userManager |
|
56 | - * @param IGroupManager $groupManager |
|
57 | - * @param Principal $principalBackend |
|
58 | - * @param string $resourceType |
|
59 | - */ |
|
60 | - public function __construct(IDBConnection $db, IUserManager $userManager, IGroupManager $groupManager, Principal $principalBackend, $resourceType) { |
|
61 | - $this->db = $db; |
|
62 | - $this->userManager = $userManager; |
|
63 | - $this->groupManager = $groupManager; |
|
64 | - $this->principalBackend = $principalBackend; |
|
65 | - $this->resourceType = $resourceType; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @param IShareable $shareable |
|
70 | - * @param string[] $add |
|
71 | - * @param string[] $remove |
|
72 | - */ |
|
73 | - public function updateShares(IShareable $shareable, array $add, array $remove) { |
|
74 | - foreach ($add as $element) { |
|
75 | - $principal = $this->principalBackend->findByUri($element['href'], ''); |
|
76 | - if ($principal !== '') { |
|
77 | - $this->shareWith($shareable, $element); |
|
78 | - } |
|
79 | - } |
|
80 | - foreach ($remove as $element) { |
|
81 | - $principal = $this->principalBackend->findByUri($element, ''); |
|
82 | - if ($principal !== '') { |
|
83 | - $this->unshare($shareable, $element); |
|
84 | - } |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @param IShareable $shareable |
|
90 | - * @param string $element |
|
91 | - */ |
|
92 | - private function shareWith($shareable, $element) { |
|
93 | - $user = $element['href']; |
|
94 | - $parts = explode(':', $user, 2); |
|
95 | - if ($parts[0] !== 'principal') { |
|
96 | - return; |
|
97 | - } |
|
98 | - |
|
99 | - // don't share with owner |
|
100 | - if ($shareable->getOwner() === $parts[1]) { |
|
101 | - return; |
|
102 | - } |
|
103 | - |
|
104 | - $principal = explode('/', $parts[1], 3); |
|
105 | - if (count($principal) !== 3 || $principal[0] !== 'principals' || !in_array($principal[1], ['users', 'groups', 'circles'], true)) { |
|
106 | - // Invalid principal |
|
107 | - return; |
|
108 | - } |
|
109 | - |
|
110 | - if (($principal[1] === 'users' && !$this->userManager->userExists($principal[2])) || |
|
111 | - ($principal[1] === 'groups' && !$this->groupManager->groupExists($principal[2]))) { |
|
112 | - // User or group does not exist |
|
113 | - return; |
|
114 | - } |
|
115 | - |
|
116 | - // remove the share if it already exists |
|
117 | - $this->unshare($shareable, $element['href']); |
|
118 | - $access = self::ACCESS_READ; |
|
119 | - if (isset($element['readOnly'])) { |
|
120 | - $access = $element['readOnly'] ? self::ACCESS_READ : self::ACCESS_READ_WRITE; |
|
121 | - } |
|
122 | - |
|
123 | - $query = $this->db->getQueryBuilder(); |
|
124 | - $query->insert('dav_shares') |
|
125 | - ->values([ |
|
126 | - 'principaluri' => $query->createNamedParameter($parts[1]), |
|
127 | - 'type' => $query->createNamedParameter($this->resourceType), |
|
128 | - 'access' => $query->createNamedParameter($access), |
|
129 | - 'resourceid' => $query->createNamedParameter($shareable->getResourceId()) |
|
130 | - ]); |
|
131 | - $query->execute(); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @param $resourceId |
|
136 | - */ |
|
137 | - public function deleteAllShares($resourceId) { |
|
138 | - $query = $this->db->getQueryBuilder(); |
|
139 | - $query->delete('dav_shares') |
|
140 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId))) |
|
141 | - ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
142 | - ->execute(); |
|
143 | - } |
|
144 | - |
|
145 | - public function deleteAllSharesByUser($principaluri) { |
|
146 | - $query = $this->db->getQueryBuilder(); |
|
147 | - $query->delete('dav_shares') |
|
148 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principaluri))) |
|
149 | - ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
150 | - ->execute(); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @param IShareable $shareable |
|
155 | - * @param string $element |
|
156 | - */ |
|
157 | - private function unshare($shareable, $element) { |
|
158 | - $parts = explode(':', $element, 2); |
|
159 | - if ($parts[0] !== 'principal') { |
|
160 | - return; |
|
161 | - } |
|
162 | - |
|
163 | - // don't share with owner |
|
164 | - if ($shareable->getOwner() === $parts[1]) { |
|
165 | - return; |
|
166 | - } |
|
167 | - |
|
168 | - $query = $this->db->getQueryBuilder(); |
|
169 | - $query->delete('dav_shares') |
|
170 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($shareable->getResourceId()))) |
|
171 | - ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
172 | - ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($parts[1]))) |
|
173 | - ; |
|
174 | - $query->execute(); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Returns the list of people whom this resource is shared with. |
|
179 | - * |
|
180 | - * Every element in this array should have the following properties: |
|
181 | - * * href - Often a mailto: address |
|
182 | - * * commonName - Optional, for example a first + last name |
|
183 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
184 | - * * readOnly - boolean |
|
185 | - * * summary - Optional, a description for the share |
|
186 | - * |
|
187 | - * @param int $resourceId |
|
188 | - * @return array |
|
189 | - */ |
|
190 | - public function getShares($resourceId) { |
|
191 | - $query = $this->db->getQueryBuilder(); |
|
192 | - $result = $query->select(['principaluri', 'access']) |
|
193 | - ->from('dav_shares') |
|
194 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId))) |
|
195 | - ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
196 | - ->execute(); |
|
197 | - |
|
198 | - $shares = []; |
|
199 | - while ($row = $result->fetch()) { |
|
200 | - $p = $this->principalBackend->getPrincipalByPath($row['principaluri']); |
|
201 | - $shares[] = [ |
|
202 | - 'href' => "principal:${row['principaluri']}", |
|
203 | - 'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '', |
|
204 | - 'status' => 1, |
|
205 | - 'readOnly' => (int) $row['access'] === self::ACCESS_READ, |
|
206 | - '{http://owncloud.org/ns}principal' => $row['principaluri'], |
|
207 | - '{http://owncloud.org/ns}group-share' => is_null($p) |
|
208 | - ]; |
|
209 | - } |
|
210 | - |
|
211 | - return $shares; |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * For shared resources the sharee is set in the ACL of the resource |
|
216 | - * |
|
217 | - * @param int $resourceId |
|
218 | - * @param array $acl |
|
219 | - * @return array |
|
220 | - */ |
|
221 | - public function applyShareAcl($resourceId, $acl) { |
|
222 | - $shares = $this->getShares($resourceId); |
|
223 | - foreach ($shares as $share) { |
|
224 | - $acl[] = [ |
|
225 | - 'privilege' => '{DAV:}read', |
|
226 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
227 | - 'protected' => true, |
|
228 | - ]; |
|
229 | - if (!$share['readOnly']) { |
|
230 | - $acl[] = [ |
|
231 | - 'privilege' => '{DAV:}write', |
|
232 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
233 | - 'protected' => true, |
|
234 | - ]; |
|
235 | - } elseif ($this->resourceType === 'calendar') { |
|
236 | - // Allow changing the properties of read only calendars, |
|
237 | - // so users can change the visibility. |
|
238 | - $acl[] = [ |
|
239 | - 'privilege' => '{DAV:}write-properties', |
|
240 | - 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
241 | - 'protected' => true, |
|
242 | - ]; |
|
243 | - } |
|
244 | - } |
|
245 | - return $acl; |
|
246 | - } |
|
38 | + /** @var IDBConnection */ |
|
39 | + private $db; |
|
40 | + /** @var IUserManager */ |
|
41 | + private $userManager; |
|
42 | + /** @var IGroupManager */ |
|
43 | + private $groupManager; |
|
44 | + /** @var Principal */ |
|
45 | + private $principalBackend; |
|
46 | + /** @var string */ |
|
47 | + private $resourceType; |
|
48 | + |
|
49 | + public const ACCESS_OWNER = 1; |
|
50 | + public const ACCESS_READ_WRITE = 2; |
|
51 | + public const ACCESS_READ = 3; |
|
52 | + |
|
53 | + /** |
|
54 | + * @param IDBConnection $db |
|
55 | + * @param IUserManager $userManager |
|
56 | + * @param IGroupManager $groupManager |
|
57 | + * @param Principal $principalBackend |
|
58 | + * @param string $resourceType |
|
59 | + */ |
|
60 | + public function __construct(IDBConnection $db, IUserManager $userManager, IGroupManager $groupManager, Principal $principalBackend, $resourceType) { |
|
61 | + $this->db = $db; |
|
62 | + $this->userManager = $userManager; |
|
63 | + $this->groupManager = $groupManager; |
|
64 | + $this->principalBackend = $principalBackend; |
|
65 | + $this->resourceType = $resourceType; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @param IShareable $shareable |
|
70 | + * @param string[] $add |
|
71 | + * @param string[] $remove |
|
72 | + */ |
|
73 | + public function updateShares(IShareable $shareable, array $add, array $remove) { |
|
74 | + foreach ($add as $element) { |
|
75 | + $principal = $this->principalBackend->findByUri($element['href'], ''); |
|
76 | + if ($principal !== '') { |
|
77 | + $this->shareWith($shareable, $element); |
|
78 | + } |
|
79 | + } |
|
80 | + foreach ($remove as $element) { |
|
81 | + $principal = $this->principalBackend->findByUri($element, ''); |
|
82 | + if ($principal !== '') { |
|
83 | + $this->unshare($shareable, $element); |
|
84 | + } |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @param IShareable $shareable |
|
90 | + * @param string $element |
|
91 | + */ |
|
92 | + private function shareWith($shareable, $element) { |
|
93 | + $user = $element['href']; |
|
94 | + $parts = explode(':', $user, 2); |
|
95 | + if ($parts[0] !== 'principal') { |
|
96 | + return; |
|
97 | + } |
|
98 | + |
|
99 | + // don't share with owner |
|
100 | + if ($shareable->getOwner() === $parts[1]) { |
|
101 | + return; |
|
102 | + } |
|
103 | + |
|
104 | + $principal = explode('/', $parts[1], 3); |
|
105 | + if (count($principal) !== 3 || $principal[0] !== 'principals' || !in_array($principal[1], ['users', 'groups', 'circles'], true)) { |
|
106 | + // Invalid principal |
|
107 | + return; |
|
108 | + } |
|
109 | + |
|
110 | + if (($principal[1] === 'users' && !$this->userManager->userExists($principal[2])) || |
|
111 | + ($principal[1] === 'groups' && !$this->groupManager->groupExists($principal[2]))) { |
|
112 | + // User or group does not exist |
|
113 | + return; |
|
114 | + } |
|
115 | + |
|
116 | + // remove the share if it already exists |
|
117 | + $this->unshare($shareable, $element['href']); |
|
118 | + $access = self::ACCESS_READ; |
|
119 | + if (isset($element['readOnly'])) { |
|
120 | + $access = $element['readOnly'] ? self::ACCESS_READ : self::ACCESS_READ_WRITE; |
|
121 | + } |
|
122 | + |
|
123 | + $query = $this->db->getQueryBuilder(); |
|
124 | + $query->insert('dav_shares') |
|
125 | + ->values([ |
|
126 | + 'principaluri' => $query->createNamedParameter($parts[1]), |
|
127 | + 'type' => $query->createNamedParameter($this->resourceType), |
|
128 | + 'access' => $query->createNamedParameter($access), |
|
129 | + 'resourceid' => $query->createNamedParameter($shareable->getResourceId()) |
|
130 | + ]); |
|
131 | + $query->execute(); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @param $resourceId |
|
136 | + */ |
|
137 | + public function deleteAllShares($resourceId) { |
|
138 | + $query = $this->db->getQueryBuilder(); |
|
139 | + $query->delete('dav_shares') |
|
140 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId))) |
|
141 | + ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
142 | + ->execute(); |
|
143 | + } |
|
144 | + |
|
145 | + public function deleteAllSharesByUser($principaluri) { |
|
146 | + $query = $this->db->getQueryBuilder(); |
|
147 | + $query->delete('dav_shares') |
|
148 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principaluri))) |
|
149 | + ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
150 | + ->execute(); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @param IShareable $shareable |
|
155 | + * @param string $element |
|
156 | + */ |
|
157 | + private function unshare($shareable, $element) { |
|
158 | + $parts = explode(':', $element, 2); |
|
159 | + if ($parts[0] !== 'principal') { |
|
160 | + return; |
|
161 | + } |
|
162 | + |
|
163 | + // don't share with owner |
|
164 | + if ($shareable->getOwner() === $parts[1]) { |
|
165 | + return; |
|
166 | + } |
|
167 | + |
|
168 | + $query = $this->db->getQueryBuilder(); |
|
169 | + $query->delete('dav_shares') |
|
170 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($shareable->getResourceId()))) |
|
171 | + ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
172 | + ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($parts[1]))) |
|
173 | + ; |
|
174 | + $query->execute(); |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Returns the list of people whom this resource is shared with. |
|
179 | + * |
|
180 | + * Every element in this array should have the following properties: |
|
181 | + * * href - Often a mailto: address |
|
182 | + * * commonName - Optional, for example a first + last name |
|
183 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
184 | + * * readOnly - boolean |
|
185 | + * * summary - Optional, a description for the share |
|
186 | + * |
|
187 | + * @param int $resourceId |
|
188 | + * @return array |
|
189 | + */ |
|
190 | + public function getShares($resourceId) { |
|
191 | + $query = $this->db->getQueryBuilder(); |
|
192 | + $result = $query->select(['principaluri', 'access']) |
|
193 | + ->from('dav_shares') |
|
194 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId))) |
|
195 | + ->andWhere($query->expr()->eq('type', $query->createNamedParameter($this->resourceType))) |
|
196 | + ->execute(); |
|
197 | + |
|
198 | + $shares = []; |
|
199 | + while ($row = $result->fetch()) { |
|
200 | + $p = $this->principalBackend->getPrincipalByPath($row['principaluri']); |
|
201 | + $shares[] = [ |
|
202 | + 'href' => "principal:${row['principaluri']}", |
|
203 | + 'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '', |
|
204 | + 'status' => 1, |
|
205 | + 'readOnly' => (int) $row['access'] === self::ACCESS_READ, |
|
206 | + '{http://owncloud.org/ns}principal' => $row['principaluri'], |
|
207 | + '{http://owncloud.org/ns}group-share' => is_null($p) |
|
208 | + ]; |
|
209 | + } |
|
210 | + |
|
211 | + return $shares; |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * For shared resources the sharee is set in the ACL of the resource |
|
216 | + * |
|
217 | + * @param int $resourceId |
|
218 | + * @param array $acl |
|
219 | + * @return array |
|
220 | + */ |
|
221 | + public function applyShareAcl($resourceId, $acl) { |
|
222 | + $shares = $this->getShares($resourceId); |
|
223 | + foreach ($shares as $share) { |
|
224 | + $acl[] = [ |
|
225 | + 'privilege' => '{DAV:}read', |
|
226 | + 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
227 | + 'protected' => true, |
|
228 | + ]; |
|
229 | + if (!$share['readOnly']) { |
|
230 | + $acl[] = [ |
|
231 | + 'privilege' => '{DAV:}write', |
|
232 | + 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
233 | + 'protected' => true, |
|
234 | + ]; |
|
235 | + } elseif ($this->resourceType === 'calendar') { |
|
236 | + // Allow changing the properties of read only calendars, |
|
237 | + // so users can change the visibility. |
|
238 | + $acl[] = [ |
|
239 | + 'privilege' => '{DAV:}write-properties', |
|
240 | + 'principal' => $share['{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}principal'], |
|
241 | + 'protected' => true, |
|
242 | + ]; |
|
243 | + } |
|
244 | + } |
|
245 | + return $acl; |
|
246 | + } |
|
247 | 247 | } |
@@ -108,7 +108,7 @@ |
||
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
111 | - throw new NotFound('Node with name \'' . $name . '\' could not be found'); |
|
111 | + throw new NotFound('Node with name \''.$name.'\' could not be found'); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -42,154 +42,154 @@ |
||
42 | 42 | |
43 | 43 | class CalendarHome extends \Sabre\CalDAV\CalendarHome { |
44 | 44 | |
45 | - /** @var \OCP\IL10N */ |
|
46 | - private $l10n; |
|
47 | - |
|
48 | - /** @var \OCP\IConfig */ |
|
49 | - private $config; |
|
50 | - |
|
51 | - /** @var PluginManager */ |
|
52 | - private $pluginManager; |
|
53 | - |
|
54 | - /** @var bool */ |
|
55 | - private $returnCachedSubscriptions = false; |
|
56 | - |
|
57 | - public function __construct(BackendInterface $caldavBackend, $principalInfo) { |
|
58 | - parent::__construct($caldavBackend, $principalInfo); |
|
59 | - $this->l10n = \OC::$server->getL10N('dav'); |
|
60 | - $this->config = \OC::$server->getConfig(); |
|
61 | - $this->pluginManager = new PluginManager( |
|
62 | - \OC::$server, |
|
63 | - \OC::$server->getAppManager() |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * @return BackendInterface |
|
69 | - */ |
|
70 | - public function getCalDAVBackend() { |
|
71 | - return $this->caldavBackend; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @inheritdoc |
|
76 | - */ |
|
77 | - public function createExtendedCollection($name, MkCol $mkCol) { |
|
78 | - $reservedNames = [BirthdayService::BIRTHDAY_CALENDAR_URI]; |
|
79 | - |
|
80 | - if (\in_array($name, $reservedNames, true) || ExternalCalendar::doesViolateReservedName($name)) { |
|
81 | - throw new MethodNotAllowed('The resource you tried to create has a reserved name'); |
|
82 | - } |
|
83 | - |
|
84 | - parent::createExtendedCollection($name, $mkCol); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @inheritdoc |
|
89 | - */ |
|
90 | - public function getChildren() { |
|
91 | - $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']); |
|
92 | - $objects = []; |
|
93 | - foreach ($calendars as $calendar) { |
|
94 | - $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config); |
|
95 | - } |
|
96 | - |
|
97 | - if ($this->caldavBackend instanceof SchedulingSupport) { |
|
98 | - $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']); |
|
99 | - $objects[] = new Outbox($this->config, $this->principalInfo['uri']); |
|
100 | - } |
|
101 | - |
|
102 | - // We're adding a notifications node, if it's supported by the backend. |
|
103 | - if ($this->caldavBackend instanceof NotificationSupport) { |
|
104 | - $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); |
|
105 | - } |
|
106 | - |
|
107 | - // If the backend supports subscriptions, we'll add those as well, |
|
108 | - if ($this->caldavBackend instanceof SubscriptionSupport) { |
|
109 | - foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { |
|
110 | - if ($this->returnCachedSubscriptions) { |
|
111 | - $objects[] = new CachedSubscription($this->caldavBackend, $subscription); |
|
112 | - } else { |
|
113 | - $objects[] = new Subscription($this->caldavBackend, $subscription); |
|
114 | - } |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) { |
|
119 | - /** @var ICalendarProvider $calendarPlugin */ |
|
120 | - $calendars = $calendarPlugin->fetchAllForCalendarHome($this->principalInfo['uri']); |
|
121 | - foreach ($calendars as $calendar) { |
|
122 | - $objects[] = $calendar; |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - return $objects; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @inheritdoc |
|
131 | - */ |
|
132 | - public function getChild($name) { |
|
133 | - // Special nodes |
|
134 | - if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) { |
|
135 | - return new Inbox($this->caldavBackend, $this->principalInfo['uri']); |
|
136 | - } |
|
137 | - if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) { |
|
138 | - return new Outbox($this->config, $this->principalInfo['uri']); |
|
139 | - } |
|
140 | - if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) { |
|
141 | - return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); |
|
142 | - } |
|
143 | - |
|
144 | - // Calendars |
|
145 | - foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) { |
|
146 | - if ($calendar['uri'] === $name) { |
|
147 | - return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config); |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - if ($this->caldavBackend instanceof SubscriptionSupport) { |
|
152 | - foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { |
|
153 | - if ($subscription['uri'] === $name) { |
|
154 | - if ($this->returnCachedSubscriptions) { |
|
155 | - return new CachedSubscription($this->caldavBackend, $subscription); |
|
156 | - } |
|
157 | - |
|
158 | - return new Subscription($this->caldavBackend, $subscription); |
|
159 | - } |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - if (ExternalCalendar::isAppGeneratedCalendar($name)) { |
|
164 | - [$appId, $calendarUri] = ExternalCalendar::splitAppGeneratedCalendarUri($name); |
|
165 | - |
|
166 | - foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) { |
|
167 | - /** @var ICalendarProvider $calendarPlugin */ |
|
168 | - if ($calendarPlugin->getAppId() !== $appId) { |
|
169 | - continue; |
|
170 | - } |
|
171 | - |
|
172 | - if ($calendarPlugin->hasCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri)) { |
|
173 | - return $calendarPlugin->getCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri); |
|
174 | - } |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - throw new NotFound('Node with name \'' . $name . '\' could not be found'); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @param array $filters |
|
183 | - * @param integer|null $limit |
|
184 | - * @param integer|null $offset |
|
185 | - */ |
|
186 | - public function calendarSearch(array $filters, $limit = null, $offset = null) { |
|
187 | - $principalUri = $this->principalInfo['uri']; |
|
188 | - return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset); |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - public function enableCachedSubscriptionsForThisRequest() { |
|
193 | - $this->returnCachedSubscriptions = true; |
|
194 | - } |
|
45 | + /** @var \OCP\IL10N */ |
|
46 | + private $l10n; |
|
47 | + |
|
48 | + /** @var \OCP\IConfig */ |
|
49 | + private $config; |
|
50 | + |
|
51 | + /** @var PluginManager */ |
|
52 | + private $pluginManager; |
|
53 | + |
|
54 | + /** @var bool */ |
|
55 | + private $returnCachedSubscriptions = false; |
|
56 | + |
|
57 | + public function __construct(BackendInterface $caldavBackend, $principalInfo) { |
|
58 | + parent::__construct($caldavBackend, $principalInfo); |
|
59 | + $this->l10n = \OC::$server->getL10N('dav'); |
|
60 | + $this->config = \OC::$server->getConfig(); |
|
61 | + $this->pluginManager = new PluginManager( |
|
62 | + \OC::$server, |
|
63 | + \OC::$server->getAppManager() |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * @return BackendInterface |
|
69 | + */ |
|
70 | + public function getCalDAVBackend() { |
|
71 | + return $this->caldavBackend; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @inheritdoc |
|
76 | + */ |
|
77 | + public function createExtendedCollection($name, MkCol $mkCol) { |
|
78 | + $reservedNames = [BirthdayService::BIRTHDAY_CALENDAR_URI]; |
|
79 | + |
|
80 | + if (\in_array($name, $reservedNames, true) || ExternalCalendar::doesViolateReservedName($name)) { |
|
81 | + throw new MethodNotAllowed('The resource you tried to create has a reserved name'); |
|
82 | + } |
|
83 | + |
|
84 | + parent::createExtendedCollection($name, $mkCol); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @inheritdoc |
|
89 | + */ |
|
90 | + public function getChildren() { |
|
91 | + $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']); |
|
92 | + $objects = []; |
|
93 | + foreach ($calendars as $calendar) { |
|
94 | + $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config); |
|
95 | + } |
|
96 | + |
|
97 | + if ($this->caldavBackend instanceof SchedulingSupport) { |
|
98 | + $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']); |
|
99 | + $objects[] = new Outbox($this->config, $this->principalInfo['uri']); |
|
100 | + } |
|
101 | + |
|
102 | + // We're adding a notifications node, if it's supported by the backend. |
|
103 | + if ($this->caldavBackend instanceof NotificationSupport) { |
|
104 | + $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); |
|
105 | + } |
|
106 | + |
|
107 | + // If the backend supports subscriptions, we'll add those as well, |
|
108 | + if ($this->caldavBackend instanceof SubscriptionSupport) { |
|
109 | + foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { |
|
110 | + if ($this->returnCachedSubscriptions) { |
|
111 | + $objects[] = new CachedSubscription($this->caldavBackend, $subscription); |
|
112 | + } else { |
|
113 | + $objects[] = new Subscription($this->caldavBackend, $subscription); |
|
114 | + } |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) { |
|
119 | + /** @var ICalendarProvider $calendarPlugin */ |
|
120 | + $calendars = $calendarPlugin->fetchAllForCalendarHome($this->principalInfo['uri']); |
|
121 | + foreach ($calendars as $calendar) { |
|
122 | + $objects[] = $calendar; |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + return $objects; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @inheritdoc |
|
131 | + */ |
|
132 | + public function getChild($name) { |
|
133 | + // Special nodes |
|
134 | + if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) { |
|
135 | + return new Inbox($this->caldavBackend, $this->principalInfo['uri']); |
|
136 | + } |
|
137 | + if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) { |
|
138 | + return new Outbox($this->config, $this->principalInfo['uri']); |
|
139 | + } |
|
140 | + if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) { |
|
141 | + return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); |
|
142 | + } |
|
143 | + |
|
144 | + // Calendars |
|
145 | + foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) { |
|
146 | + if ($calendar['uri'] === $name) { |
|
147 | + return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config); |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + if ($this->caldavBackend instanceof SubscriptionSupport) { |
|
152 | + foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { |
|
153 | + if ($subscription['uri'] === $name) { |
|
154 | + if ($this->returnCachedSubscriptions) { |
|
155 | + return new CachedSubscription($this->caldavBackend, $subscription); |
|
156 | + } |
|
157 | + |
|
158 | + return new Subscription($this->caldavBackend, $subscription); |
|
159 | + } |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + if (ExternalCalendar::isAppGeneratedCalendar($name)) { |
|
164 | + [$appId, $calendarUri] = ExternalCalendar::splitAppGeneratedCalendarUri($name); |
|
165 | + |
|
166 | + foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) { |
|
167 | + /** @var ICalendarProvider $calendarPlugin */ |
|
168 | + if ($calendarPlugin->getAppId() !== $appId) { |
|
169 | + continue; |
|
170 | + } |
|
171 | + |
|
172 | + if ($calendarPlugin->hasCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri)) { |
|
173 | + return $calendarPlugin->getCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri); |
|
174 | + } |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + throw new NotFound('Node with name \'' . $name . '\' could not be found'); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @param array $filters |
|
183 | + * @param integer|null $limit |
|
184 | + * @param integer|null $offset |
|
185 | + */ |
|
186 | + public function calendarSearch(array $filters, $limit = null, $offset = null) { |
|
187 | + $principalUri = $this->principalInfo['uri']; |
|
188 | + return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset); |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + public function enableCachedSubscriptionsForThisRequest() { |
|
193 | + $this->returnCachedSubscriptions = true; |
|
194 | + } |
|
195 | 195 | } |
@@ -35,133 +35,133 @@ |
||
35 | 35 | */ |
36 | 36 | class CalendarSearchReport implements XmlDeserializable { |
37 | 37 | |
38 | - /** |
|
39 | - * An array with requested properties. |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - public $properties; |
|
44 | - |
|
45 | - /** |
|
46 | - * List of property/component filters. |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - public $filters; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var int |
|
54 | - */ |
|
55 | - public $limit; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var int |
|
59 | - */ |
|
60 | - public $offset; |
|
61 | - |
|
62 | - /** |
|
63 | - * The deserialize method is called during xml parsing. |
|
64 | - * |
|
65 | - * This method is called statically, this is because in theory this method |
|
66 | - * may be used as a type of constructor, or factory method. |
|
67 | - * |
|
68 | - * Often you want to return an instance of the current class, but you are |
|
69 | - * free to return other data as well. |
|
70 | - * |
|
71 | - * You are responsible for advancing the reader to the next element. Not |
|
72 | - * doing anything will result in a never-ending loop. |
|
73 | - * |
|
74 | - * If you just want to skip parsing for this element altogether, you can |
|
75 | - * just call $reader->next(); |
|
76 | - * |
|
77 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
78 | - * the next element. |
|
79 | - * |
|
80 | - * @param Reader $reader |
|
81 | - * @return mixed |
|
82 | - */ |
|
83 | - public static function xmlDeserialize(Reader $reader) { |
|
84 | - $elems = $reader->parseInnerTree([ |
|
85 | - '{http://nextcloud.com/ns}comp-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\CompFilter', |
|
86 | - '{http://nextcloud.com/ns}prop-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\PropFilter', |
|
87 | - '{http://nextcloud.com/ns}param-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\ParamFilter', |
|
88 | - '{http://nextcloud.com/ns}search-term' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\SearchTermFilter', |
|
89 | - '{http://nextcloud.com/ns}limit' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\LimitFilter', |
|
90 | - '{http://nextcloud.com/ns}offset' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\OffsetFilter', |
|
91 | - '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', |
|
92 | - ]); |
|
93 | - |
|
94 | - $newProps = [ |
|
95 | - 'filters' => [], |
|
96 | - 'properties' => [], |
|
97 | - 'limit' => null, |
|
98 | - 'offset' => null |
|
99 | - ]; |
|
100 | - |
|
101 | - if (!is_array($elems)) { |
|
102 | - $elems = []; |
|
103 | - } |
|
104 | - |
|
105 | - foreach ($elems as $elem) { |
|
106 | - switch ($elem['name']) { |
|
107 | - case '{DAV:}prop': |
|
108 | - $newProps['properties'] = array_keys($elem['value']); |
|
109 | - break; |
|
110 | - case '{' . SearchPlugin::NS_Nextcloud . '}filter': |
|
111 | - foreach ($elem['value'] as $subElem) { |
|
112 | - if ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}comp-filter') { |
|
113 | - if (!isset($newProps['filters']['comps']) || !is_array($newProps['filters']['comps'])) { |
|
114 | - $newProps['filters']['comps'] = []; |
|
115 | - } |
|
116 | - $newProps['filters']['comps'][] = $subElem['value']; |
|
117 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}prop-filter') { |
|
118 | - if (!isset($newProps['filters']['props']) || !is_array($newProps['filters']['props'])) { |
|
119 | - $newProps['filters']['props'] = []; |
|
120 | - } |
|
121 | - $newProps['filters']['props'][] = $subElem['value']; |
|
122 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}param-filter') { |
|
123 | - if (!isset($newProps['filters']['params']) || !is_array($newProps['filters']['params'])) { |
|
124 | - $newProps['filters']['params'] = []; |
|
125 | - } |
|
126 | - $newProps['filters']['params'][] = $subElem['value']; |
|
127 | - } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}search-term') { |
|
128 | - $newProps['filters']['search-term'] = $subElem['value']; |
|
129 | - } |
|
130 | - } |
|
131 | - break; |
|
132 | - case '{' . SearchPlugin::NS_Nextcloud . '}limit': |
|
133 | - $newProps['limit'] = $elem['value']; |
|
134 | - break; |
|
135 | - case '{' . SearchPlugin::NS_Nextcloud . '}offset': |
|
136 | - $newProps['offset'] = $elem['value']; |
|
137 | - break; |
|
138 | - |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - if (empty($newProps['filters'])) { |
|
143 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}filter element is required for this request'); |
|
144 | - } |
|
145 | - |
|
146 | - $propsOrParamsDefined = (!empty($newProps['filters']['props']) || !empty($newProps['filters']['params'])); |
|
147 | - $noCompsDefined = empty($newProps['filters']['comps']); |
|
148 | - if ($propsOrParamsDefined && $noCompsDefined) { |
|
149 | - throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter given without any {' . SearchPlugin::NS_Nextcloud . '}comp-filter'); |
|
150 | - } |
|
151 | - |
|
152 | - if (!isset($newProps['filters']['search-term'])) { |
|
153 | - throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}search-term is required for this request'); |
|
154 | - } |
|
155 | - |
|
156 | - if (empty($newProps['filters']['props']) && empty($newProps['filters']['params'])) { |
|
157 | - throw new BadRequest('At least one{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter is required for this request'); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - $obj = new self(); |
|
162 | - foreach ($newProps as $key => $value) { |
|
163 | - $obj->$key = $value; |
|
164 | - } |
|
165 | - return $obj; |
|
166 | - } |
|
38 | + /** |
|
39 | + * An array with requested properties. |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + public $properties; |
|
44 | + |
|
45 | + /** |
|
46 | + * List of property/component filters. |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + public $filters; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var int |
|
54 | + */ |
|
55 | + public $limit; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var int |
|
59 | + */ |
|
60 | + public $offset; |
|
61 | + |
|
62 | + /** |
|
63 | + * The deserialize method is called during xml parsing. |
|
64 | + * |
|
65 | + * This method is called statically, this is because in theory this method |
|
66 | + * may be used as a type of constructor, or factory method. |
|
67 | + * |
|
68 | + * Often you want to return an instance of the current class, but you are |
|
69 | + * free to return other data as well. |
|
70 | + * |
|
71 | + * You are responsible for advancing the reader to the next element. Not |
|
72 | + * doing anything will result in a never-ending loop. |
|
73 | + * |
|
74 | + * If you just want to skip parsing for this element altogether, you can |
|
75 | + * just call $reader->next(); |
|
76 | + * |
|
77 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
78 | + * the next element. |
|
79 | + * |
|
80 | + * @param Reader $reader |
|
81 | + * @return mixed |
|
82 | + */ |
|
83 | + public static function xmlDeserialize(Reader $reader) { |
|
84 | + $elems = $reader->parseInnerTree([ |
|
85 | + '{http://nextcloud.com/ns}comp-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\CompFilter', |
|
86 | + '{http://nextcloud.com/ns}prop-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\PropFilter', |
|
87 | + '{http://nextcloud.com/ns}param-filter' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\ParamFilter', |
|
88 | + '{http://nextcloud.com/ns}search-term' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\SearchTermFilter', |
|
89 | + '{http://nextcloud.com/ns}limit' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\LimitFilter', |
|
90 | + '{http://nextcloud.com/ns}offset' => 'OCA\\DAV\\CalDAV\\Search\\Xml\\Filter\\OffsetFilter', |
|
91 | + '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue', |
|
92 | + ]); |
|
93 | + |
|
94 | + $newProps = [ |
|
95 | + 'filters' => [], |
|
96 | + 'properties' => [], |
|
97 | + 'limit' => null, |
|
98 | + 'offset' => null |
|
99 | + ]; |
|
100 | + |
|
101 | + if (!is_array($elems)) { |
|
102 | + $elems = []; |
|
103 | + } |
|
104 | + |
|
105 | + foreach ($elems as $elem) { |
|
106 | + switch ($elem['name']) { |
|
107 | + case '{DAV:}prop': |
|
108 | + $newProps['properties'] = array_keys($elem['value']); |
|
109 | + break; |
|
110 | + case '{' . SearchPlugin::NS_Nextcloud . '}filter': |
|
111 | + foreach ($elem['value'] as $subElem) { |
|
112 | + if ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}comp-filter') { |
|
113 | + if (!isset($newProps['filters']['comps']) || !is_array($newProps['filters']['comps'])) { |
|
114 | + $newProps['filters']['comps'] = []; |
|
115 | + } |
|
116 | + $newProps['filters']['comps'][] = $subElem['value']; |
|
117 | + } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}prop-filter') { |
|
118 | + if (!isset($newProps['filters']['props']) || !is_array($newProps['filters']['props'])) { |
|
119 | + $newProps['filters']['props'] = []; |
|
120 | + } |
|
121 | + $newProps['filters']['props'][] = $subElem['value']; |
|
122 | + } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}param-filter') { |
|
123 | + if (!isset($newProps['filters']['params']) || !is_array($newProps['filters']['params'])) { |
|
124 | + $newProps['filters']['params'] = []; |
|
125 | + } |
|
126 | + $newProps['filters']['params'][] = $subElem['value']; |
|
127 | + } elseif ($subElem['name'] === '{' . SearchPlugin::NS_Nextcloud . '}search-term') { |
|
128 | + $newProps['filters']['search-term'] = $subElem['value']; |
|
129 | + } |
|
130 | + } |
|
131 | + break; |
|
132 | + case '{' . SearchPlugin::NS_Nextcloud . '}limit': |
|
133 | + $newProps['limit'] = $elem['value']; |
|
134 | + break; |
|
135 | + case '{' . SearchPlugin::NS_Nextcloud . '}offset': |
|
136 | + $newProps['offset'] = $elem['value']; |
|
137 | + break; |
|
138 | + |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + if (empty($newProps['filters'])) { |
|
143 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}filter element is required for this request'); |
|
144 | + } |
|
145 | + |
|
146 | + $propsOrParamsDefined = (!empty($newProps['filters']['props']) || !empty($newProps['filters']['params'])); |
|
147 | + $noCompsDefined = empty($newProps['filters']['comps']); |
|
148 | + if ($propsOrParamsDefined && $noCompsDefined) { |
|
149 | + throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter given without any {' . SearchPlugin::NS_Nextcloud . '}comp-filter'); |
|
150 | + } |
|
151 | + |
|
152 | + if (!isset($newProps['filters']['search-term'])) { |
|
153 | + throw new BadRequest('{' . SearchPlugin::NS_Nextcloud . '}search-term is required for this request'); |
|
154 | + } |
|
155 | + |
|
156 | + if (empty($newProps['filters']['props']) && empty($newProps['filters']['params'])) { |
|
157 | + throw new BadRequest('At least one{' . SearchPlugin::NS_Nextcloud . '}prop-filter or {' . SearchPlugin::NS_Nextcloud . '}param-filter is required for this request'); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + $obj = new self(); |
|
162 | + foreach ($newProps as $key => $value) { |
|
163 | + $obj->$key = $value; |
|
164 | + } |
|
165 | + return $obj; |
|
166 | + } |
|
167 | 167 | } |
@@ -21,62 +21,62 @@ |
||
21 | 21 | */ |
22 | 22 | |
23 | 23 | return [ |
24 | - 'routes' => [ |
|
25 | - [ |
|
26 | - 'name' => 'RateLimitTest#userAndAnonProtected', |
|
27 | - 'url' => '/userAndAnonProtected', |
|
28 | - 'verb' => 'GET', |
|
29 | - ], |
|
30 | - [ |
|
31 | - 'name' => 'RateLimitTest#onlyAnonProtected', |
|
32 | - 'url' => '/anonProtected', |
|
33 | - 'verb' => 'GET', |
|
34 | - ], |
|
35 | - ], |
|
24 | + 'routes' => [ |
|
25 | + [ |
|
26 | + 'name' => 'RateLimitTest#userAndAnonProtected', |
|
27 | + 'url' => '/userAndAnonProtected', |
|
28 | + 'verb' => 'GET', |
|
29 | + ], |
|
30 | + [ |
|
31 | + 'name' => 'RateLimitTest#onlyAnonProtected', |
|
32 | + 'url' => '/anonProtected', |
|
33 | + 'verb' => 'GET', |
|
34 | + ], |
|
35 | + ], |
|
36 | 36 | |
37 | - 'ocs' => [ |
|
38 | - [ |
|
39 | - 'name' => 'Config#setAppValue', |
|
40 | - 'url' => '/api/v1/app/{appid}/{configkey}', |
|
41 | - 'verb' => 'POST', |
|
42 | - ], |
|
43 | - [ |
|
44 | - 'name' => 'Config#deleteAppValue', |
|
45 | - 'url' => '/api/v1/app/{appid}/{configkey}', |
|
46 | - 'verb' => 'DELETE', |
|
47 | - ], |
|
48 | - [ |
|
49 | - 'name' => 'Locking#isLockingEnabled', |
|
50 | - 'url' => '/api/v1/lockprovisioning', |
|
51 | - 'verb' => 'GET', |
|
52 | - ], |
|
53 | - [ |
|
54 | - 'name' => 'Locking#isLocked', |
|
55 | - 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
56 | - 'verb' => 'GET', |
|
57 | - ], |
|
58 | - [ |
|
59 | - 'name' => 'Locking#acquireLock', |
|
60 | - 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
61 | - 'verb' => 'POST', |
|
62 | - ], |
|
63 | - [ |
|
64 | - 'name' => 'Locking#changeLock', |
|
65 | - 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
66 | - 'verb' => 'PUT', |
|
67 | - ], |
|
68 | - [ |
|
69 | - 'name' => 'Locking#releaseLock', |
|
70 | - 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
71 | - 'verb' => 'DELETE', |
|
72 | - ], |
|
73 | - [ |
|
74 | - 'name' => 'Locking#releaseAll', |
|
75 | - 'url' => '/api/v1/lockprovisioning/{type}', |
|
76 | - 'verb' => 'DELETE', |
|
77 | - 'defaults' => [ |
|
78 | - 'type' => null |
|
79 | - ] |
|
80 | - ], |
|
81 | - ], |
|
37 | + 'ocs' => [ |
|
38 | + [ |
|
39 | + 'name' => 'Config#setAppValue', |
|
40 | + 'url' => '/api/v1/app/{appid}/{configkey}', |
|
41 | + 'verb' => 'POST', |
|
42 | + ], |
|
43 | + [ |
|
44 | + 'name' => 'Config#deleteAppValue', |
|
45 | + 'url' => '/api/v1/app/{appid}/{configkey}', |
|
46 | + 'verb' => 'DELETE', |
|
47 | + ], |
|
48 | + [ |
|
49 | + 'name' => 'Locking#isLockingEnabled', |
|
50 | + 'url' => '/api/v1/lockprovisioning', |
|
51 | + 'verb' => 'GET', |
|
52 | + ], |
|
53 | + [ |
|
54 | + 'name' => 'Locking#isLocked', |
|
55 | + 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
56 | + 'verb' => 'GET', |
|
57 | + ], |
|
58 | + [ |
|
59 | + 'name' => 'Locking#acquireLock', |
|
60 | + 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
61 | + 'verb' => 'POST', |
|
62 | + ], |
|
63 | + [ |
|
64 | + 'name' => 'Locking#changeLock', |
|
65 | + 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
66 | + 'verb' => 'PUT', |
|
67 | + ], |
|
68 | + [ |
|
69 | + 'name' => 'Locking#releaseLock', |
|
70 | + 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
71 | + 'verb' => 'DELETE', |
|
72 | + ], |
|
73 | + [ |
|
74 | + 'name' => 'Locking#releaseAll', |
|
75 | + 'url' => '/api/v1/lockprovisioning/{type}', |
|
76 | + 'verb' => 'DELETE', |
|
77 | + 'defaults' => [ |
|
78 | + 'type' => null |
|
79 | + ] |
|
80 | + ], |
|
81 | + ], |
|
82 | 82 | ]; |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | if (isset($parameters[$key])) { |
221 | 221 | switch ($parameters[$key]->getType()) { |
222 | 222 | case \OCA\Files_External\Lib\DefinitionParameter::VALUE_BOOLEAN: |
223 | - $value = (bool)$value; |
|
223 | + $value = (bool) $value; |
|
224 | 224 | break; |
225 | 225 | } |
226 | 226 | $backendOptions[$key] = $value; |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | $result['statusMessage'] = $this->statusMessage; |
427 | 427 | } |
428 | 428 | $result['userProvided'] = $this->authMechanism instanceof IUserProvided; |
429 | - $result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system'; |
|
429 | + $result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal' : 'system'; |
|
430 | 430 | return $result; |
431 | 431 | } |
432 | 432 | } |
@@ -37,398 +37,398 @@ |
||
37 | 37 | * External storage configuration |
38 | 38 | */ |
39 | 39 | class StorageConfig implements \JsonSerializable { |
40 | - public const MOUNT_TYPE_ADMIN = 1; |
|
41 | - public const MOUNT_TYPE_PERSONAl = 2; |
|
42 | - |
|
43 | - /** |
|
44 | - * Storage config id |
|
45 | - * |
|
46 | - * @var int |
|
47 | - */ |
|
48 | - private $id; |
|
49 | - |
|
50 | - /** |
|
51 | - * Backend |
|
52 | - * |
|
53 | - * @var Backend |
|
54 | - */ |
|
55 | - private $backend; |
|
56 | - |
|
57 | - /** |
|
58 | - * Authentication mechanism |
|
59 | - * |
|
60 | - * @var AuthMechanism |
|
61 | - */ |
|
62 | - private $authMechanism; |
|
63 | - |
|
64 | - /** |
|
65 | - * Backend options |
|
66 | - * |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - private $backendOptions = []; |
|
70 | - |
|
71 | - /** |
|
72 | - * Mount point path, relative to the user's "files" folder |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - private $mountPoint; |
|
77 | - |
|
78 | - /** |
|
79 | - * Storage status |
|
80 | - * |
|
81 | - * @var int |
|
82 | - */ |
|
83 | - private $status; |
|
84 | - |
|
85 | - /** |
|
86 | - * Status message |
|
87 | - * |
|
88 | - * @var string |
|
89 | - */ |
|
90 | - private $statusMessage; |
|
91 | - |
|
92 | - /** |
|
93 | - * Priority |
|
94 | - * |
|
95 | - * @var int |
|
96 | - */ |
|
97 | - private $priority; |
|
98 | - |
|
99 | - /** |
|
100 | - * List of users who have access to this storage |
|
101 | - * |
|
102 | - * @var array |
|
103 | - */ |
|
104 | - private $applicableUsers = []; |
|
105 | - |
|
106 | - /** |
|
107 | - * List of groups that have access to this storage |
|
108 | - * |
|
109 | - * @var array |
|
110 | - */ |
|
111 | - private $applicableGroups = []; |
|
112 | - |
|
113 | - /** |
|
114 | - * Mount-specific options |
|
115 | - * |
|
116 | - * @var array |
|
117 | - */ |
|
118 | - private $mountOptions = []; |
|
119 | - |
|
120 | - /** |
|
121 | - * Whether it's a personal or admin mount |
|
122 | - * |
|
123 | - * @var int |
|
124 | - */ |
|
125 | - private $type; |
|
126 | - |
|
127 | - /** |
|
128 | - * Creates a storage config |
|
129 | - * |
|
130 | - * @param int|null $id config id or null for a new config |
|
131 | - */ |
|
132 | - public function __construct($id = null) { |
|
133 | - $this->id = $id; |
|
134 | - $this->mountOptions['enable_sharing'] = false; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Returns the configuration id |
|
139 | - * |
|
140 | - * @return int |
|
141 | - */ |
|
142 | - public function getId() { |
|
143 | - return $this->id; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Sets the configuration id |
|
148 | - * |
|
149 | - * @param int $id configuration id |
|
150 | - */ |
|
151 | - public function setId($id) { |
|
152 | - $this->id = $id; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Returns mount point path relative to the user's |
|
157 | - * "files" folder. |
|
158 | - * |
|
159 | - * @return string path |
|
160 | - */ |
|
161 | - public function getMountPoint() { |
|
162 | - return $this->mountPoint; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Sets mount point path relative to the user's |
|
167 | - * "files" folder. |
|
168 | - * The path will be normalized. |
|
169 | - * |
|
170 | - * @param string $mountPoint path |
|
171 | - */ |
|
172 | - public function setMountPoint($mountPoint) { |
|
173 | - $this->mountPoint = \OC\Files\Filesystem::normalizePath($mountPoint); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @return Backend |
|
178 | - */ |
|
179 | - public function getBackend() { |
|
180 | - return $this->backend; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @param Backend $backend |
|
185 | - */ |
|
186 | - public function setBackend(Backend $backend) { |
|
187 | - $this->backend = $backend; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * @return AuthMechanism |
|
192 | - */ |
|
193 | - public function getAuthMechanism() { |
|
194 | - return $this->authMechanism; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @param AuthMechanism $authMechanism |
|
199 | - */ |
|
200 | - public function setAuthMechanism(AuthMechanism $authMechanism) { |
|
201 | - $this->authMechanism = $authMechanism; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Returns the external storage backend-specific options |
|
206 | - * |
|
207 | - * @return array backend options |
|
208 | - */ |
|
209 | - public function getBackendOptions() { |
|
210 | - return $this->backendOptions; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Sets the external storage backend-specific options |
|
215 | - * |
|
216 | - * @param array $backendOptions backend options |
|
217 | - */ |
|
218 | - public function setBackendOptions($backendOptions) { |
|
219 | - if ($this->getBackend() instanceof Backend) { |
|
220 | - $parameters = $this->getBackend()->getParameters(); |
|
221 | - foreach ($backendOptions as $key => $value) { |
|
222 | - if (isset($parameters[$key])) { |
|
223 | - switch ($parameters[$key]->getType()) { |
|
224 | - case \OCA\Files_External\Lib\DefinitionParameter::VALUE_BOOLEAN: |
|
225 | - $value = (bool)$value; |
|
226 | - break; |
|
227 | - } |
|
228 | - $backendOptions[$key] = $value; |
|
229 | - } |
|
230 | - } |
|
231 | - } |
|
232 | - |
|
233 | - $this->backendOptions = $backendOptions; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * @param string $key |
|
238 | - * @return mixed |
|
239 | - */ |
|
240 | - public function getBackendOption($key) { |
|
241 | - if (isset($this->backendOptions[$key])) { |
|
242 | - return $this->backendOptions[$key]; |
|
243 | - } |
|
244 | - return null; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * @param string $key |
|
249 | - * @param mixed $value |
|
250 | - */ |
|
251 | - public function setBackendOption($key, $value) { |
|
252 | - $this->backendOptions[$key] = $value; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Returns the mount priority |
|
257 | - * |
|
258 | - * @return int priority |
|
259 | - */ |
|
260 | - public function getPriority() { |
|
261 | - return $this->priority; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Sets the mount priotity |
|
266 | - * |
|
267 | - * @param int $priority priority |
|
268 | - */ |
|
269 | - public function setPriority($priority) { |
|
270 | - $this->priority = $priority; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Returns the users for which to mount this storage |
|
275 | - * |
|
276 | - * @return array applicable users |
|
277 | - */ |
|
278 | - public function getApplicableUsers() { |
|
279 | - return $this->applicableUsers; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Sets the users for which to mount this storage |
|
284 | - * |
|
285 | - * @param array|null $applicableUsers applicable users |
|
286 | - */ |
|
287 | - public function setApplicableUsers($applicableUsers) { |
|
288 | - if (is_null($applicableUsers)) { |
|
289 | - $applicableUsers = []; |
|
290 | - } |
|
291 | - $this->applicableUsers = $applicableUsers; |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * Returns the groups for which to mount this storage |
|
296 | - * |
|
297 | - * @return array applicable groups |
|
298 | - */ |
|
299 | - public function getApplicableGroups() { |
|
300 | - return $this->applicableGroups; |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Sets the groups for which to mount this storage |
|
305 | - * |
|
306 | - * @param array|null $applicableGroups applicable groups |
|
307 | - */ |
|
308 | - public function setApplicableGroups($applicableGroups) { |
|
309 | - if (is_null($applicableGroups)) { |
|
310 | - $applicableGroups = []; |
|
311 | - } |
|
312 | - $this->applicableGroups = $applicableGroups; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Returns the mount-specific options |
|
317 | - * |
|
318 | - * @return array mount specific options |
|
319 | - */ |
|
320 | - public function getMountOptions() { |
|
321 | - return $this->mountOptions; |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Sets the mount-specific options |
|
326 | - * |
|
327 | - * @param array $mountOptions applicable groups |
|
328 | - */ |
|
329 | - public function setMountOptions($mountOptions) { |
|
330 | - if (is_null($mountOptions)) { |
|
331 | - $mountOptions = []; |
|
332 | - } |
|
333 | - $this->mountOptions = $mountOptions; |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * @param string $key |
|
338 | - * @return mixed |
|
339 | - */ |
|
340 | - public function getMountOption($key) { |
|
341 | - if (isset($this->mountOptions[$key])) { |
|
342 | - return $this->mountOptions[$key]; |
|
343 | - } |
|
344 | - return null; |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * @param string $key |
|
349 | - * @param mixed $value |
|
350 | - */ |
|
351 | - public function setMountOption($key, $value) { |
|
352 | - $this->mountOptions[$key] = $value; |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * Gets the storage status, whether the config worked last time |
|
357 | - * |
|
358 | - * @return int $status status |
|
359 | - */ |
|
360 | - public function getStatus() { |
|
361 | - return $this->status; |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * Gets the message describing the storage status |
|
366 | - * |
|
367 | - * @return string|null |
|
368 | - */ |
|
369 | - public function getStatusMessage() { |
|
370 | - return $this->statusMessage; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Sets the storage status, whether the config worked last time |
|
375 | - * |
|
376 | - * @param int $status status |
|
377 | - * @param string|null $message optional message |
|
378 | - */ |
|
379 | - public function setStatus($status, $message = null) { |
|
380 | - $this->status = $status; |
|
381 | - $this->statusMessage = $message; |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * @return int self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl |
|
386 | - */ |
|
387 | - public function getType() { |
|
388 | - return $this->type; |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl |
|
393 | - */ |
|
394 | - public function setType($type) { |
|
395 | - $this->type = $type; |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Serialize config to JSON |
|
400 | - * |
|
401 | - * @return array |
|
402 | - */ |
|
403 | - public function jsonSerialize() { |
|
404 | - $result = []; |
|
405 | - if (!is_null($this->id)) { |
|
406 | - $result['id'] = $this->id; |
|
407 | - } |
|
408 | - $result['mountPoint'] = $this->mountPoint; |
|
409 | - $result['backend'] = $this->backend->getIdentifier(); |
|
410 | - $result['authMechanism'] = $this->authMechanism->getIdentifier(); |
|
411 | - $result['backendOptions'] = $this->backendOptions; |
|
412 | - if (!is_null($this->priority)) { |
|
413 | - $result['priority'] = $this->priority; |
|
414 | - } |
|
415 | - if (!empty($this->applicableUsers)) { |
|
416 | - $result['applicableUsers'] = $this->applicableUsers; |
|
417 | - } |
|
418 | - if (!empty($this->applicableGroups)) { |
|
419 | - $result['applicableGroups'] = $this->applicableGroups; |
|
420 | - } |
|
421 | - if (!empty($this->mountOptions)) { |
|
422 | - $result['mountOptions'] = $this->mountOptions; |
|
423 | - } |
|
424 | - if (!is_null($this->status)) { |
|
425 | - $result['status'] = $this->status; |
|
426 | - } |
|
427 | - if (!is_null($this->statusMessage)) { |
|
428 | - $result['statusMessage'] = $this->statusMessage; |
|
429 | - } |
|
430 | - $result['userProvided'] = $this->authMechanism instanceof IUserProvided; |
|
431 | - $result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system'; |
|
432 | - return $result; |
|
433 | - } |
|
40 | + public const MOUNT_TYPE_ADMIN = 1; |
|
41 | + public const MOUNT_TYPE_PERSONAl = 2; |
|
42 | + |
|
43 | + /** |
|
44 | + * Storage config id |
|
45 | + * |
|
46 | + * @var int |
|
47 | + */ |
|
48 | + private $id; |
|
49 | + |
|
50 | + /** |
|
51 | + * Backend |
|
52 | + * |
|
53 | + * @var Backend |
|
54 | + */ |
|
55 | + private $backend; |
|
56 | + |
|
57 | + /** |
|
58 | + * Authentication mechanism |
|
59 | + * |
|
60 | + * @var AuthMechanism |
|
61 | + */ |
|
62 | + private $authMechanism; |
|
63 | + |
|
64 | + /** |
|
65 | + * Backend options |
|
66 | + * |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + private $backendOptions = []; |
|
70 | + |
|
71 | + /** |
|
72 | + * Mount point path, relative to the user's "files" folder |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + private $mountPoint; |
|
77 | + |
|
78 | + /** |
|
79 | + * Storage status |
|
80 | + * |
|
81 | + * @var int |
|
82 | + */ |
|
83 | + private $status; |
|
84 | + |
|
85 | + /** |
|
86 | + * Status message |
|
87 | + * |
|
88 | + * @var string |
|
89 | + */ |
|
90 | + private $statusMessage; |
|
91 | + |
|
92 | + /** |
|
93 | + * Priority |
|
94 | + * |
|
95 | + * @var int |
|
96 | + */ |
|
97 | + private $priority; |
|
98 | + |
|
99 | + /** |
|
100 | + * List of users who have access to this storage |
|
101 | + * |
|
102 | + * @var array |
|
103 | + */ |
|
104 | + private $applicableUsers = []; |
|
105 | + |
|
106 | + /** |
|
107 | + * List of groups that have access to this storage |
|
108 | + * |
|
109 | + * @var array |
|
110 | + */ |
|
111 | + private $applicableGroups = []; |
|
112 | + |
|
113 | + /** |
|
114 | + * Mount-specific options |
|
115 | + * |
|
116 | + * @var array |
|
117 | + */ |
|
118 | + private $mountOptions = []; |
|
119 | + |
|
120 | + /** |
|
121 | + * Whether it's a personal or admin mount |
|
122 | + * |
|
123 | + * @var int |
|
124 | + */ |
|
125 | + private $type; |
|
126 | + |
|
127 | + /** |
|
128 | + * Creates a storage config |
|
129 | + * |
|
130 | + * @param int|null $id config id or null for a new config |
|
131 | + */ |
|
132 | + public function __construct($id = null) { |
|
133 | + $this->id = $id; |
|
134 | + $this->mountOptions['enable_sharing'] = false; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Returns the configuration id |
|
139 | + * |
|
140 | + * @return int |
|
141 | + */ |
|
142 | + public function getId() { |
|
143 | + return $this->id; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Sets the configuration id |
|
148 | + * |
|
149 | + * @param int $id configuration id |
|
150 | + */ |
|
151 | + public function setId($id) { |
|
152 | + $this->id = $id; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Returns mount point path relative to the user's |
|
157 | + * "files" folder. |
|
158 | + * |
|
159 | + * @return string path |
|
160 | + */ |
|
161 | + public function getMountPoint() { |
|
162 | + return $this->mountPoint; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Sets mount point path relative to the user's |
|
167 | + * "files" folder. |
|
168 | + * The path will be normalized. |
|
169 | + * |
|
170 | + * @param string $mountPoint path |
|
171 | + */ |
|
172 | + public function setMountPoint($mountPoint) { |
|
173 | + $this->mountPoint = \OC\Files\Filesystem::normalizePath($mountPoint); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @return Backend |
|
178 | + */ |
|
179 | + public function getBackend() { |
|
180 | + return $this->backend; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @param Backend $backend |
|
185 | + */ |
|
186 | + public function setBackend(Backend $backend) { |
|
187 | + $this->backend = $backend; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * @return AuthMechanism |
|
192 | + */ |
|
193 | + public function getAuthMechanism() { |
|
194 | + return $this->authMechanism; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @param AuthMechanism $authMechanism |
|
199 | + */ |
|
200 | + public function setAuthMechanism(AuthMechanism $authMechanism) { |
|
201 | + $this->authMechanism = $authMechanism; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Returns the external storage backend-specific options |
|
206 | + * |
|
207 | + * @return array backend options |
|
208 | + */ |
|
209 | + public function getBackendOptions() { |
|
210 | + return $this->backendOptions; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Sets the external storage backend-specific options |
|
215 | + * |
|
216 | + * @param array $backendOptions backend options |
|
217 | + */ |
|
218 | + public function setBackendOptions($backendOptions) { |
|
219 | + if ($this->getBackend() instanceof Backend) { |
|
220 | + $parameters = $this->getBackend()->getParameters(); |
|
221 | + foreach ($backendOptions as $key => $value) { |
|
222 | + if (isset($parameters[$key])) { |
|
223 | + switch ($parameters[$key]->getType()) { |
|
224 | + case \OCA\Files_External\Lib\DefinitionParameter::VALUE_BOOLEAN: |
|
225 | + $value = (bool)$value; |
|
226 | + break; |
|
227 | + } |
|
228 | + $backendOptions[$key] = $value; |
|
229 | + } |
|
230 | + } |
|
231 | + } |
|
232 | + |
|
233 | + $this->backendOptions = $backendOptions; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * @param string $key |
|
238 | + * @return mixed |
|
239 | + */ |
|
240 | + public function getBackendOption($key) { |
|
241 | + if (isset($this->backendOptions[$key])) { |
|
242 | + return $this->backendOptions[$key]; |
|
243 | + } |
|
244 | + return null; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * @param string $key |
|
249 | + * @param mixed $value |
|
250 | + */ |
|
251 | + public function setBackendOption($key, $value) { |
|
252 | + $this->backendOptions[$key] = $value; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Returns the mount priority |
|
257 | + * |
|
258 | + * @return int priority |
|
259 | + */ |
|
260 | + public function getPriority() { |
|
261 | + return $this->priority; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Sets the mount priotity |
|
266 | + * |
|
267 | + * @param int $priority priority |
|
268 | + */ |
|
269 | + public function setPriority($priority) { |
|
270 | + $this->priority = $priority; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Returns the users for which to mount this storage |
|
275 | + * |
|
276 | + * @return array applicable users |
|
277 | + */ |
|
278 | + public function getApplicableUsers() { |
|
279 | + return $this->applicableUsers; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Sets the users for which to mount this storage |
|
284 | + * |
|
285 | + * @param array|null $applicableUsers applicable users |
|
286 | + */ |
|
287 | + public function setApplicableUsers($applicableUsers) { |
|
288 | + if (is_null($applicableUsers)) { |
|
289 | + $applicableUsers = []; |
|
290 | + } |
|
291 | + $this->applicableUsers = $applicableUsers; |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * Returns the groups for which to mount this storage |
|
296 | + * |
|
297 | + * @return array applicable groups |
|
298 | + */ |
|
299 | + public function getApplicableGroups() { |
|
300 | + return $this->applicableGroups; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Sets the groups for which to mount this storage |
|
305 | + * |
|
306 | + * @param array|null $applicableGroups applicable groups |
|
307 | + */ |
|
308 | + public function setApplicableGroups($applicableGroups) { |
|
309 | + if (is_null($applicableGroups)) { |
|
310 | + $applicableGroups = []; |
|
311 | + } |
|
312 | + $this->applicableGroups = $applicableGroups; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Returns the mount-specific options |
|
317 | + * |
|
318 | + * @return array mount specific options |
|
319 | + */ |
|
320 | + public function getMountOptions() { |
|
321 | + return $this->mountOptions; |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Sets the mount-specific options |
|
326 | + * |
|
327 | + * @param array $mountOptions applicable groups |
|
328 | + */ |
|
329 | + public function setMountOptions($mountOptions) { |
|
330 | + if (is_null($mountOptions)) { |
|
331 | + $mountOptions = []; |
|
332 | + } |
|
333 | + $this->mountOptions = $mountOptions; |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * @param string $key |
|
338 | + * @return mixed |
|
339 | + */ |
|
340 | + public function getMountOption($key) { |
|
341 | + if (isset($this->mountOptions[$key])) { |
|
342 | + return $this->mountOptions[$key]; |
|
343 | + } |
|
344 | + return null; |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * @param string $key |
|
349 | + * @param mixed $value |
|
350 | + */ |
|
351 | + public function setMountOption($key, $value) { |
|
352 | + $this->mountOptions[$key] = $value; |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * Gets the storage status, whether the config worked last time |
|
357 | + * |
|
358 | + * @return int $status status |
|
359 | + */ |
|
360 | + public function getStatus() { |
|
361 | + return $this->status; |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * Gets the message describing the storage status |
|
366 | + * |
|
367 | + * @return string|null |
|
368 | + */ |
|
369 | + public function getStatusMessage() { |
|
370 | + return $this->statusMessage; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Sets the storage status, whether the config worked last time |
|
375 | + * |
|
376 | + * @param int $status status |
|
377 | + * @param string|null $message optional message |
|
378 | + */ |
|
379 | + public function setStatus($status, $message = null) { |
|
380 | + $this->status = $status; |
|
381 | + $this->statusMessage = $message; |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * @return int self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl |
|
386 | + */ |
|
387 | + public function getType() { |
|
388 | + return $this->type; |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl |
|
393 | + */ |
|
394 | + public function setType($type) { |
|
395 | + $this->type = $type; |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Serialize config to JSON |
|
400 | + * |
|
401 | + * @return array |
|
402 | + */ |
|
403 | + public function jsonSerialize() { |
|
404 | + $result = []; |
|
405 | + if (!is_null($this->id)) { |
|
406 | + $result['id'] = $this->id; |
|
407 | + } |
|
408 | + $result['mountPoint'] = $this->mountPoint; |
|
409 | + $result['backend'] = $this->backend->getIdentifier(); |
|
410 | + $result['authMechanism'] = $this->authMechanism->getIdentifier(); |
|
411 | + $result['backendOptions'] = $this->backendOptions; |
|
412 | + if (!is_null($this->priority)) { |
|
413 | + $result['priority'] = $this->priority; |
|
414 | + } |
|
415 | + if (!empty($this->applicableUsers)) { |
|
416 | + $result['applicableUsers'] = $this->applicableUsers; |
|
417 | + } |
|
418 | + if (!empty($this->applicableGroups)) { |
|
419 | + $result['applicableGroups'] = $this->applicableGroups; |
|
420 | + } |
|
421 | + if (!empty($this->mountOptions)) { |
|
422 | + $result['mountOptions'] = $this->mountOptions; |
|
423 | + } |
|
424 | + if (!is_null($this->status)) { |
|
425 | + $result['status'] = $this->status; |
|
426 | + } |
|
427 | + if (!is_null($this->statusMessage)) { |
|
428 | + $result['statusMessage'] = $this->statusMessage; |
|
429 | + } |
|
430 | + $result['userProvided'] = $this->authMechanism instanceof IUserProvided; |
|
431 | + $result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system'; |
|
432 | + return $result; |
|
433 | + } |
|
434 | 434 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $result = []; |
45 | 45 | $timestamp = null; |
46 | 46 | |
47 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
47 | + $view = new \OC\Files\View('/'.$user.'/files_trashbin/files'); |
|
48 | 48 | |
49 | 49 | if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
50 | 50 | throw new \Exception('Directory does not exists'); |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | ]; |
92 | 92 | if ($originalPath) { |
93 | 93 | if ($originalPath !== '.') { |
94 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
94 | + $i['extraData'] = $originalPath.'/'.$originalName; |
|
95 | 95 | } else { |
96 | 96 | $i['extraData'] = $originalName; |
97 | 97 | } |
98 | 98 | } |
99 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
99 | + $result[] = new FileInfo($absoluteDir.'/'.$i['name'], $storage, $internalPath.'/'.$i['name'], $i, $mount); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | if ($sortAttribute !== '') { |
@@ -36,95 +36,95 @@ |
||
36 | 36 | use OCP\Files\Cache\ICacheEntry; |
37 | 37 | |
38 | 38 | class Helper { |
39 | - /** |
|
40 | - * Retrieves the contents of a trash bin directory. |
|
41 | - * |
|
42 | - * @param string $dir path to the directory inside the trashbin |
|
43 | - * or empty to retrieve the root of the trashbin |
|
44 | - * @param string $user |
|
45 | - * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
46 | - * @param bool $sortDescending true for descending sort, false otherwise |
|
47 | - * @return \OCP\Files\FileInfo[] |
|
48 | - */ |
|
49 | - public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
50 | - $result = []; |
|
51 | - $timestamp = null; |
|
39 | + /** |
|
40 | + * Retrieves the contents of a trash bin directory. |
|
41 | + * |
|
42 | + * @param string $dir path to the directory inside the trashbin |
|
43 | + * or empty to retrieve the root of the trashbin |
|
44 | + * @param string $user |
|
45 | + * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
46 | + * @param bool $sortDescending true for descending sort, false otherwise |
|
47 | + * @return \OCP\Files\FileInfo[] |
|
48 | + */ |
|
49 | + public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
50 | + $result = []; |
|
51 | + $timestamp = null; |
|
52 | 52 | |
53 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
53 | + $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
54 | 54 | |
55 | - if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
56 | - throw new \Exception('Directory does not exists'); |
|
57 | - } |
|
55 | + if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
56 | + throw new \Exception('Directory does not exists'); |
|
57 | + } |
|
58 | 58 | |
59 | - $mount = $view->getMount($dir); |
|
60 | - $storage = $mount->getStorage(); |
|
61 | - $absoluteDir = $view->getAbsolutePath($dir); |
|
62 | - $internalPath = $mount->getInternalPath($absoluteDir); |
|
59 | + $mount = $view->getMount($dir); |
|
60 | + $storage = $mount->getStorage(); |
|
61 | + $absoluteDir = $view->getAbsolutePath($dir); |
|
62 | + $internalPath = $mount->getInternalPath($absoluteDir); |
|
63 | 63 | |
64 | - $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
65 | - $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
66 | - foreach ($dirContent as $entry) { |
|
67 | - $entryName = $entry->getName(); |
|
68 | - $name = $entryName; |
|
69 | - if ($dir === '' || $dir === '/') { |
|
70 | - $pathparts = pathinfo($entryName); |
|
71 | - $timestamp = substr($pathparts['extension'], 1); |
|
72 | - $name = $pathparts['filename']; |
|
73 | - } elseif ($timestamp === null) { |
|
74 | - // for subfolders we need to calculate the timestamp only once |
|
75 | - $parts = explode('/', ltrim($dir, '/')); |
|
76 | - $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
77 | - } |
|
78 | - $originalPath = ''; |
|
79 | - $originalName = substr($entryName, 0, -strlen($timestamp) - 2); |
|
80 | - if (isset($originalLocations[$originalName][$timestamp])) { |
|
81 | - $originalPath = $originalLocations[$originalName][$timestamp]; |
|
82 | - if (substr($originalPath, -1) === '/') { |
|
83 | - $originalPath = substr($originalPath, 0, -1); |
|
84 | - } |
|
85 | - } |
|
86 | - $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
87 | - $i = [ |
|
88 | - 'name' => $name, |
|
89 | - 'mtime' => $timestamp, |
|
90 | - 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
91 | - 'type' => $type, |
|
92 | - 'directory' => ($dir === '/') ? '' : $dir, |
|
93 | - 'size' => $entry->getSize(), |
|
94 | - 'etag' => '', |
|
95 | - 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
96 | - 'fileid' => $entry->getId(), |
|
97 | - ]; |
|
98 | - if ($originalPath) { |
|
99 | - if ($originalPath !== '.') { |
|
100 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
101 | - } else { |
|
102 | - $i['extraData'] = $originalName; |
|
103 | - } |
|
104 | - } |
|
105 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
106 | - } |
|
64 | + $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
65 | + $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
66 | + foreach ($dirContent as $entry) { |
|
67 | + $entryName = $entry->getName(); |
|
68 | + $name = $entryName; |
|
69 | + if ($dir === '' || $dir === '/') { |
|
70 | + $pathparts = pathinfo($entryName); |
|
71 | + $timestamp = substr($pathparts['extension'], 1); |
|
72 | + $name = $pathparts['filename']; |
|
73 | + } elseif ($timestamp === null) { |
|
74 | + // for subfolders we need to calculate the timestamp only once |
|
75 | + $parts = explode('/', ltrim($dir, '/')); |
|
76 | + $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
77 | + } |
|
78 | + $originalPath = ''; |
|
79 | + $originalName = substr($entryName, 0, -strlen($timestamp) - 2); |
|
80 | + if (isset($originalLocations[$originalName][$timestamp])) { |
|
81 | + $originalPath = $originalLocations[$originalName][$timestamp]; |
|
82 | + if (substr($originalPath, -1) === '/') { |
|
83 | + $originalPath = substr($originalPath, 0, -1); |
|
84 | + } |
|
85 | + } |
|
86 | + $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
87 | + $i = [ |
|
88 | + 'name' => $name, |
|
89 | + 'mtime' => $timestamp, |
|
90 | + 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
91 | + 'type' => $type, |
|
92 | + 'directory' => ($dir === '/') ? '' : $dir, |
|
93 | + 'size' => $entry->getSize(), |
|
94 | + 'etag' => '', |
|
95 | + 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
96 | + 'fileid' => $entry->getId(), |
|
97 | + ]; |
|
98 | + if ($originalPath) { |
|
99 | + if ($originalPath !== '.') { |
|
100 | + $i['extraData'] = $originalPath . '/' . $originalName; |
|
101 | + } else { |
|
102 | + $i['extraData'] = $originalName; |
|
103 | + } |
|
104 | + } |
|
105 | + $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
106 | + } |
|
107 | 107 | |
108 | - if ($sortAttribute !== '') { |
|
109 | - return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
110 | - } |
|
111 | - return $result; |
|
112 | - } |
|
108 | + if ($sortAttribute !== '') { |
|
109 | + return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
110 | + } |
|
111 | + return $result; |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Format file infos for JSON |
|
116 | - * |
|
117 | - * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
118 | - */ |
|
119 | - public static function formatFileInfos($fileInfos) { |
|
120 | - $files = []; |
|
121 | - foreach ($fileInfos as $i) { |
|
122 | - $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
123 | - $entry['id'] = $i->getId(); |
|
124 | - $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
125 | - $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
126 | - $files[] = $entry; |
|
127 | - } |
|
128 | - return $files; |
|
129 | - } |
|
114 | + /** |
|
115 | + * Format file infos for JSON |
|
116 | + * |
|
117 | + * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
118 | + */ |
|
119 | + public static function formatFileInfos($fileInfos) { |
|
120 | + $files = []; |
|
121 | + foreach ($fileInfos as $i) { |
|
122 | + $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
123 | + $entry['id'] = $i->getId(); |
|
124 | + $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
125 | + $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
126 | + $files[] = $entry; |
|
127 | + } |
|
128 | + return $files; |
|
129 | + } |
|
130 | 130 | } |
@@ -36,56 +36,56 @@ |
||
36 | 36 | * @package OCA\Comments |
37 | 37 | */ |
38 | 38 | class EventHandler implements ICommentsEventHandler { |
39 | - /** @var ActivityListener */ |
|
40 | - private $activityListener; |
|
39 | + /** @var ActivityListener */ |
|
40 | + private $activityListener; |
|
41 | 41 | |
42 | - /** @var NotificationListener */ |
|
43 | - private $notificationListener; |
|
42 | + /** @var NotificationListener */ |
|
43 | + private $notificationListener; |
|
44 | 44 | |
45 | - public function __construct(ActivityListener $activityListener, NotificationListener $notificationListener) { |
|
46 | - $this->activityListener = $activityListener; |
|
47 | - $this->notificationListener = $notificationListener; |
|
48 | - } |
|
45 | + public function __construct(ActivityListener $activityListener, NotificationListener $notificationListener) { |
|
46 | + $this->activityListener = $activityListener; |
|
47 | + $this->notificationListener = $notificationListener; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param CommentsEvent $event |
|
52 | - */ |
|
53 | - public function handle(CommentsEvent $event) { |
|
54 | - if ($event->getComment()->getObjectType() !== 'files') { |
|
55 | - // this is a 'files'-specific Handler |
|
56 | - return; |
|
57 | - } |
|
50 | + /** |
|
51 | + * @param CommentsEvent $event |
|
52 | + */ |
|
53 | + public function handle(CommentsEvent $event) { |
|
54 | + if ($event->getComment()->getObjectType() !== 'files') { |
|
55 | + // this is a 'files'-specific Handler |
|
56 | + return; |
|
57 | + } |
|
58 | 58 | |
59 | - $eventType = $event->getEvent(); |
|
60 | - if ($eventType === CommentsEvent::EVENT_ADD |
|
61 | - ) { |
|
62 | - $this->notificationHandler($event); |
|
63 | - $this->activityHandler($event); |
|
64 | - return; |
|
65 | - } |
|
59 | + $eventType = $event->getEvent(); |
|
60 | + if ($eventType === CommentsEvent::EVENT_ADD |
|
61 | + ) { |
|
62 | + $this->notificationHandler($event); |
|
63 | + $this->activityHandler($event); |
|
64 | + return; |
|
65 | + } |
|
66 | 66 | |
67 | - $applicableEvents = [ |
|
68 | - CommentsEvent::EVENT_PRE_UPDATE, |
|
69 | - CommentsEvent::EVENT_UPDATE, |
|
70 | - CommentsEvent::EVENT_DELETE, |
|
71 | - ]; |
|
72 | - if (in_array($eventType, $applicableEvents)) { |
|
73 | - $this->notificationHandler($event); |
|
74 | - return; |
|
75 | - } |
|
76 | - } |
|
67 | + $applicableEvents = [ |
|
68 | + CommentsEvent::EVENT_PRE_UPDATE, |
|
69 | + CommentsEvent::EVENT_UPDATE, |
|
70 | + CommentsEvent::EVENT_DELETE, |
|
71 | + ]; |
|
72 | + if (in_array($eventType, $applicableEvents)) { |
|
73 | + $this->notificationHandler($event); |
|
74 | + return; |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param CommentsEvent $event |
|
80 | - */ |
|
81 | - private function activityHandler(CommentsEvent $event) { |
|
82 | - $this->activityListener->commentEvent($event); |
|
83 | - } |
|
78 | + /** |
|
79 | + * @param CommentsEvent $event |
|
80 | + */ |
|
81 | + private function activityHandler(CommentsEvent $event) { |
|
82 | + $this->activityListener->commentEvent($event); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param CommentsEvent $event |
|
87 | - */ |
|
88 | - private function notificationHandler(CommentsEvent $event) { |
|
89 | - $this->notificationListener->evaluate($event); |
|
90 | - } |
|
85 | + /** |
|
86 | + * @param CommentsEvent $event |
|
87 | + */ |
|
88 | + private function notificationHandler(CommentsEvent $event) { |
|
89 | + $this->notificationListener->evaluate($event); |
|
90 | + } |
|
91 | 91 | } |
@@ -34,126 +34,126 @@ |
||
34 | 34 | |
35 | 35 | class DecryptAll { |
36 | 36 | |
37 | - /** @var Util */ |
|
38 | - protected $util; |
|
39 | - |
|
40 | - /** @var QuestionHelper */ |
|
41 | - protected $questionHelper; |
|
42 | - |
|
43 | - /** @var Crypt */ |
|
44 | - protected $crypt; |
|
45 | - |
|
46 | - /** @var KeyManager */ |
|
47 | - protected $keyManager; |
|
48 | - |
|
49 | - /** @var Session */ |
|
50 | - protected $session; |
|
51 | - |
|
52 | - /** |
|
53 | - * @param Util $util |
|
54 | - * @param KeyManager $keyManager |
|
55 | - * @param Crypt $crypt |
|
56 | - * @param Session $session |
|
57 | - * @param QuestionHelper $questionHelper |
|
58 | - */ |
|
59 | - public function __construct( |
|
60 | - Util $util, |
|
61 | - KeyManager $keyManager, |
|
62 | - Crypt $crypt, |
|
63 | - Session $session, |
|
64 | - QuestionHelper $questionHelper |
|
65 | - ) { |
|
66 | - $this->util = $util; |
|
67 | - $this->keyManager = $keyManager; |
|
68 | - $this->crypt = $crypt; |
|
69 | - $this->session = $session; |
|
70 | - $this->questionHelper = $questionHelper; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * prepare encryption module to decrypt all files |
|
75 | - * |
|
76 | - * @param InputInterface $input |
|
77 | - * @param OutputInterface $output |
|
78 | - * @param $user |
|
79 | - * @return bool |
|
80 | - */ |
|
81 | - public function prepare(InputInterface $input, OutputInterface $output, $user) { |
|
82 | - $question = new Question('Please enter the recovery key password: '); |
|
83 | - |
|
84 | - if ($this->util->isMasterKeyEnabled()) { |
|
85 | - $output->writeln('Use master key to decrypt all files'); |
|
86 | - $user = $this->keyManager->getMasterKeyId(); |
|
87 | - $password = $this->keyManager->getMasterKeyPassword(); |
|
88 | - } else { |
|
89 | - $recoveryKeyId = $this->keyManager->getRecoveryKeyId(); |
|
90 | - if (!empty($user)) { |
|
91 | - $output->writeln('You can only decrypt the users files if you know'); |
|
92 | - $output->writeln('the users password or if he activated the recovery key.'); |
|
93 | - $output->writeln(''); |
|
94 | - $questionUseLoginPassword = new ConfirmationQuestion( |
|
95 | - 'Do you want to use the users login password to decrypt all files? (y/n) ', |
|
96 | - false |
|
97 | - ); |
|
98 | - $useLoginPassword = $this->questionHelper->ask($input, $output, $questionUseLoginPassword); |
|
99 | - if ($useLoginPassword) { |
|
100 | - $question = new Question('Please enter the user\'s login password: '); |
|
101 | - } elseif ($this->util->isRecoveryEnabledForUser($user) === false) { |
|
102 | - $output->writeln('No recovery key available for user ' . $user); |
|
103 | - return false; |
|
104 | - } else { |
|
105 | - $user = $recoveryKeyId; |
|
106 | - } |
|
107 | - } else { |
|
108 | - $output->writeln('You can only decrypt the files of all users if the'); |
|
109 | - $output->writeln('recovery key is enabled by the admin and activated by the users.'); |
|
110 | - $output->writeln(''); |
|
111 | - $user = $recoveryKeyId; |
|
112 | - } |
|
113 | - |
|
114 | - $question->setHidden(true); |
|
115 | - $question->setHiddenFallback(false); |
|
116 | - $password = $this->questionHelper->ask($input, $output, $question); |
|
117 | - } |
|
118 | - |
|
119 | - $privateKey = $this->getPrivateKey($user, $password); |
|
120 | - if ($privateKey !== false) { |
|
121 | - $this->updateSession($user, $privateKey); |
|
122 | - return true; |
|
123 | - } else { |
|
124 | - $output->writeln('Could not decrypt private key, maybe you entered the wrong password?'); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - return false; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * get the private key which will be used to decrypt all files |
|
133 | - * |
|
134 | - * @param string $user |
|
135 | - * @param string $password |
|
136 | - * @return bool|string |
|
137 | - * @throws \OCA\Encryption\Exceptions\PrivateKeyMissingException |
|
138 | - */ |
|
139 | - protected function getPrivateKey($user, $password) { |
|
140 | - $recoveryKeyId = $this->keyManager->getRecoveryKeyId(); |
|
141 | - $masterKeyId = $this->keyManager->getMasterKeyId(); |
|
142 | - if ($user === $recoveryKeyId) { |
|
143 | - $recoveryKey = $this->keyManager->getSystemPrivateKey($recoveryKeyId); |
|
144 | - $privateKey = $this->crypt->decryptPrivateKey($recoveryKey, $password); |
|
145 | - } elseif ($user === $masterKeyId) { |
|
146 | - $masterKey = $this->keyManager->getSystemPrivateKey($masterKeyId); |
|
147 | - $privateKey = $this->crypt->decryptPrivateKey($masterKey, $password, $masterKeyId); |
|
148 | - } else { |
|
149 | - $userKey = $this->keyManager->getPrivateKey($user); |
|
150 | - $privateKey = $this->crypt->decryptPrivateKey($userKey, $password, $user); |
|
151 | - } |
|
152 | - |
|
153 | - return $privateKey; |
|
154 | - } |
|
155 | - |
|
156 | - protected function updateSession($user, $privateKey) { |
|
157 | - $this->session->prepareDecryptAll($user, $privateKey); |
|
158 | - } |
|
37 | + /** @var Util */ |
|
38 | + protected $util; |
|
39 | + |
|
40 | + /** @var QuestionHelper */ |
|
41 | + protected $questionHelper; |
|
42 | + |
|
43 | + /** @var Crypt */ |
|
44 | + protected $crypt; |
|
45 | + |
|
46 | + /** @var KeyManager */ |
|
47 | + protected $keyManager; |
|
48 | + |
|
49 | + /** @var Session */ |
|
50 | + protected $session; |
|
51 | + |
|
52 | + /** |
|
53 | + * @param Util $util |
|
54 | + * @param KeyManager $keyManager |
|
55 | + * @param Crypt $crypt |
|
56 | + * @param Session $session |
|
57 | + * @param QuestionHelper $questionHelper |
|
58 | + */ |
|
59 | + public function __construct( |
|
60 | + Util $util, |
|
61 | + KeyManager $keyManager, |
|
62 | + Crypt $crypt, |
|
63 | + Session $session, |
|
64 | + QuestionHelper $questionHelper |
|
65 | + ) { |
|
66 | + $this->util = $util; |
|
67 | + $this->keyManager = $keyManager; |
|
68 | + $this->crypt = $crypt; |
|
69 | + $this->session = $session; |
|
70 | + $this->questionHelper = $questionHelper; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * prepare encryption module to decrypt all files |
|
75 | + * |
|
76 | + * @param InputInterface $input |
|
77 | + * @param OutputInterface $output |
|
78 | + * @param $user |
|
79 | + * @return bool |
|
80 | + */ |
|
81 | + public function prepare(InputInterface $input, OutputInterface $output, $user) { |
|
82 | + $question = new Question('Please enter the recovery key password: '); |
|
83 | + |
|
84 | + if ($this->util->isMasterKeyEnabled()) { |
|
85 | + $output->writeln('Use master key to decrypt all files'); |
|
86 | + $user = $this->keyManager->getMasterKeyId(); |
|
87 | + $password = $this->keyManager->getMasterKeyPassword(); |
|
88 | + } else { |
|
89 | + $recoveryKeyId = $this->keyManager->getRecoveryKeyId(); |
|
90 | + if (!empty($user)) { |
|
91 | + $output->writeln('You can only decrypt the users files if you know'); |
|
92 | + $output->writeln('the users password or if he activated the recovery key.'); |
|
93 | + $output->writeln(''); |
|
94 | + $questionUseLoginPassword = new ConfirmationQuestion( |
|
95 | + 'Do you want to use the users login password to decrypt all files? (y/n) ', |
|
96 | + false |
|
97 | + ); |
|
98 | + $useLoginPassword = $this->questionHelper->ask($input, $output, $questionUseLoginPassword); |
|
99 | + if ($useLoginPassword) { |
|
100 | + $question = new Question('Please enter the user\'s login password: '); |
|
101 | + } elseif ($this->util->isRecoveryEnabledForUser($user) === false) { |
|
102 | + $output->writeln('No recovery key available for user ' . $user); |
|
103 | + return false; |
|
104 | + } else { |
|
105 | + $user = $recoveryKeyId; |
|
106 | + } |
|
107 | + } else { |
|
108 | + $output->writeln('You can only decrypt the files of all users if the'); |
|
109 | + $output->writeln('recovery key is enabled by the admin and activated by the users.'); |
|
110 | + $output->writeln(''); |
|
111 | + $user = $recoveryKeyId; |
|
112 | + } |
|
113 | + |
|
114 | + $question->setHidden(true); |
|
115 | + $question->setHiddenFallback(false); |
|
116 | + $password = $this->questionHelper->ask($input, $output, $question); |
|
117 | + } |
|
118 | + |
|
119 | + $privateKey = $this->getPrivateKey($user, $password); |
|
120 | + if ($privateKey !== false) { |
|
121 | + $this->updateSession($user, $privateKey); |
|
122 | + return true; |
|
123 | + } else { |
|
124 | + $output->writeln('Could not decrypt private key, maybe you entered the wrong password?'); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + return false; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * get the private key which will be used to decrypt all files |
|
133 | + * |
|
134 | + * @param string $user |
|
135 | + * @param string $password |
|
136 | + * @return bool|string |
|
137 | + * @throws \OCA\Encryption\Exceptions\PrivateKeyMissingException |
|
138 | + */ |
|
139 | + protected function getPrivateKey($user, $password) { |
|
140 | + $recoveryKeyId = $this->keyManager->getRecoveryKeyId(); |
|
141 | + $masterKeyId = $this->keyManager->getMasterKeyId(); |
|
142 | + if ($user === $recoveryKeyId) { |
|
143 | + $recoveryKey = $this->keyManager->getSystemPrivateKey($recoveryKeyId); |
|
144 | + $privateKey = $this->crypt->decryptPrivateKey($recoveryKey, $password); |
|
145 | + } elseif ($user === $masterKeyId) { |
|
146 | + $masterKey = $this->keyManager->getSystemPrivateKey($masterKeyId); |
|
147 | + $privateKey = $this->crypt->decryptPrivateKey($masterKey, $password, $masterKeyId); |
|
148 | + } else { |
|
149 | + $userKey = $this->keyManager->getPrivateKey($user); |
|
150 | + $privateKey = $this->crypt->decryptPrivateKey($userKey, $password, $user); |
|
151 | + } |
|
152 | + |
|
153 | + return $privateKey; |
|
154 | + } |
|
155 | + |
|
156 | + protected function updateSession($user, $privateKey) { |
|
157 | + $this->session->prepareDecryptAll($user, $privateKey); |
|
158 | + } |
|
159 | 159 | } |
@@ -99,7 +99,7 @@ |
||
99 | 99 | if ($useLoginPassword) { |
100 | 100 | $question = new Question('Please enter the user\'s login password: '); |
101 | 101 | } elseif ($this->util->isRecoveryEnabledForUser($user) === false) { |
102 | - $output->writeln('No recovery key available for user ' . $user); |
|
102 | + $output->writeln('No recovery key available for user '.$user); |
|
103 | 103 | return false; |
104 | 104 | } else { |
105 | 105 | $user = $recoveryKeyId; |