@@ -33,72 +33,72 @@ |
||
33 | 33 | */ |
34 | 34 | class Capabilities implements ICapability { |
35 | 35 | |
36 | - /** @var IConfig */ |
|
37 | - private $config; |
|
36 | + /** @var IConfig */ |
|
37 | + private $config; |
|
38 | 38 | |
39 | - public function __construct(IConfig $config) { |
|
40 | - $this->config = $config; |
|
41 | - } |
|
39 | + public function __construct(IConfig $config) { |
|
40 | + $this->config = $config; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Return this classes capabilities |
|
45 | - * |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - public function getCapabilities() { |
|
49 | - $res = []; |
|
43 | + /** |
|
44 | + * Return this classes capabilities |
|
45 | + * |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + public function getCapabilities() { |
|
49 | + $res = []; |
|
50 | 50 | |
51 | - if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { |
|
52 | - $res['api_enabled'] = false; |
|
53 | - $res['public'] = ['enabled' => false]; |
|
54 | - $res['user'] = ['send_mail' => false]; |
|
55 | - $res['resharing'] = false; |
|
56 | - } else { |
|
57 | - $res['api_enabled'] = true; |
|
51 | + if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { |
|
52 | + $res['api_enabled'] = false; |
|
53 | + $res['public'] = ['enabled' => false]; |
|
54 | + $res['user'] = ['send_mail' => false]; |
|
55 | + $res['resharing'] = false; |
|
56 | + } else { |
|
57 | + $res['api_enabled'] = true; |
|
58 | 58 | |
59 | - $public = []; |
|
60 | - $public['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
61 | - if ($public['enabled']) { |
|
62 | - $public['password'] = []; |
|
63 | - $public['password']['enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'); |
|
59 | + $public = []; |
|
60 | + $public['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
61 | + if ($public['enabled']) { |
|
62 | + $public['password'] = []; |
|
63 | + $public['password']['enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'); |
|
64 | 64 | |
65 | - $public['expire_date'] = []; |
|
66 | - $public['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
67 | - if ($public['expire_date']['enabled']) { |
|
68 | - $public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
69 | - $public['expire_date']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
70 | - } |
|
65 | + $public['expire_date'] = []; |
|
66 | + $public['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
67 | + if ($public['expire_date']['enabled']) { |
|
68 | + $public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
69 | + $public['expire_date']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
70 | + } |
|
71 | 71 | |
72 | - $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes'; |
|
73 | - $public['upload'] = $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
74 | - $public['upload_files_drop'] = $public['upload']; |
|
75 | - } |
|
76 | - $res['public'] = $public; |
|
72 | + $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes'; |
|
73 | + $public['upload'] = $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
74 | + $public['upload_files_drop'] = $public['upload']; |
|
75 | + } |
|
76 | + $res['public'] = $public; |
|
77 | 77 | |
78 | - $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes'; |
|
78 | + $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes'; |
|
79 | 79 | |
80 | - $res['user']['send_mail'] = false; |
|
81 | - $res['user']['expire_date']['enabled'] = true; |
|
80 | + $res['user']['send_mail'] = false; |
|
81 | + $res['user']['expire_date']['enabled'] = true; |
|
82 | 82 | |
83 | - // deprecated in favour of 'group', but we need to keep it for now |
|
84 | - // in order to stay compatible with older clients |
|
85 | - $res['group_sharing'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
83 | + // deprecated in favour of 'group', but we need to keep it for now |
|
84 | + // in order to stay compatible with older clients |
|
85 | + $res['group_sharing'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
86 | 86 | |
87 | - $res['group'] = []; |
|
88 | - $res['group']['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
89 | - $res['group']['expire_date']['enabled'] = true; |
|
90 | - $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
91 | - } |
|
87 | + $res['group'] = []; |
|
88 | + $res['group']['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
89 | + $res['group']['expire_date']['enabled'] = true; |
|
90 | + $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
91 | + } |
|
92 | 92 | |
93 | - //Federated sharing |
|
94 | - $res['federation'] = [ |
|
95 | - 'outgoing' => $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes', |
|
96 | - 'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes', |
|
97 | - 'expire_date' => ['enabled' => true] |
|
98 | - ]; |
|
93 | + //Federated sharing |
|
94 | + $res['federation'] = [ |
|
95 | + 'outgoing' => $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes', |
|
96 | + 'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes', |
|
97 | + 'expire_date' => ['enabled' => true] |
|
98 | + ]; |
|
99 | 99 | |
100 | - return [ |
|
101 | - 'files_sharing' => $res, |
|
102 | - ]; |
|
103 | - } |
|
100 | + return [ |
|
101 | + 'files_sharing' => $res, |
|
102 | + ]; |
|
103 | + } |
|
104 | 104 | } |
@@ -87,7 +87,7 @@ |
||
87 | 87 | $res['group'] = []; |
88 | 88 | $res['group']['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
89 | 89 | $res['group']['expire_date']['enabled'] = true; |
90 | - $res['default_permissions'] = (int)$this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
90 | + $res['default_permissions'] = (int) $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | //Federated sharing |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered |
230 | 230 | $result = \OC::$server->getContactsManager()->search($query, [$property]); |
231 | 231 | foreach ($result as $r) { |
232 | - foreach($r[$property] as $value) { |
|
232 | + foreach ($r[$property] as $value) { |
|
233 | 233 | if ($value === $query) { |
234 | 234 | return $r['FN']; |
235 | 235 | } |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | |
511 | 511 | $shares = array_merge($userShares, $groupShares, $circleShares); |
512 | 512 | |
513 | - $shares = array_filter($shares, function (IShare $share) { |
|
513 | + $shares = array_filter($shares, function(IShare $share) { |
|
514 | 514 | return $share->getShareOwner() !== $this->currentUser; |
515 | 515 | }); |
516 | 516 | |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); |
550 | 550 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); |
551 | 551 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); |
552 | - if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
552 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
553 | 553 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0)); |
554 | 554 | } |
555 | 555 | if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | } |
712 | 712 | |
713 | 713 | if ($permissions !== null) { |
714 | - $newPermissions = (int)$permissions; |
|
714 | + $newPermissions = (int) $permissions; |
|
715 | 715 | $newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE; |
716 | 716 | } |
717 | 717 | |
@@ -769,7 +769,7 @@ discard block |
||
769 | 769 | |
770 | 770 | } else { |
771 | 771 | if ($permissions !== null) { |
772 | - $permissions = (int)$permissions; |
|
772 | + $permissions = (int) $permissions; |
|
773 | 773 | $share->setPermissions($permissions); |
774 | 774 | } |
775 | 775 | |
@@ -901,7 +901,7 @@ discard block |
||
901 | 901 | |
902 | 902 | // First check if it is an internal share. |
903 | 903 | try { |
904 | - $share = $this->shareManager->getShareById('ocinternal:' . $id); |
|
904 | + $share = $this->shareManager->getShareById('ocinternal:'.$id); |
|
905 | 905 | return $share; |
906 | 906 | } catch (ShareNotFound $e) { |
907 | 907 | // Do nothing, just try the other share type |
@@ -910,7 +910,7 @@ discard block |
||
910 | 910 | |
911 | 911 | try { |
912 | 912 | if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
913 | - $share = $this->shareManager->getShareById('ocCircleShare:' . $id); |
|
913 | + $share = $this->shareManager->getShareById('ocCircleShare:'.$id); |
|
914 | 914 | return $share; |
915 | 915 | } |
916 | 916 | } catch (ShareNotFound $e) { |
@@ -919,7 +919,7 @@ discard block |
||
919 | 919 | |
920 | 920 | try { |
921 | 921 | if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
922 | - $share = $this->shareManager->getShareById('ocMailShare:' . $id); |
|
922 | + $share = $this->shareManager->getShareById('ocMailShare:'.$id); |
|
923 | 923 | return $share; |
924 | 924 | } |
925 | 925 | } catch (ShareNotFound $e) { |
@@ -929,7 +929,7 @@ discard block |
||
929 | 929 | if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
930 | 930 | throw new ShareNotFound(); |
931 | 931 | } |
932 | - $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id); |
|
932 | + $share = $this->shareManager->getShareById('ocFederatedSharing:'.$id); |
|
933 | 933 | |
934 | 934 | return $share; |
935 | 935 | } |
@@ -59,897 +59,897 @@ |
||
59 | 59 | */ |
60 | 60 | class ShareAPIController extends OCSController { |
61 | 61 | |
62 | - /** @var IManager */ |
|
63 | - private $shareManager; |
|
64 | - /** @var IGroupManager */ |
|
65 | - private $groupManager; |
|
66 | - /** @var IUserManager */ |
|
67 | - private $userManager; |
|
68 | - /** @var IRequest */ |
|
69 | - protected $request; |
|
70 | - /** @var IRootFolder */ |
|
71 | - private $rootFolder; |
|
72 | - /** @var IURLGenerator */ |
|
73 | - private $urlGenerator; |
|
74 | - /** @var string */ |
|
75 | - private $currentUser; |
|
76 | - /** @var IL10N */ |
|
77 | - private $l; |
|
78 | - /** @var \OCP\Files\Node */ |
|
79 | - private $lockedNode; |
|
80 | - /** @var IConfig */ |
|
81 | - private $config; |
|
82 | - |
|
83 | - /** |
|
84 | - * Share20OCS constructor. |
|
85 | - * |
|
86 | - * @param string $appName |
|
87 | - * @param IRequest $request |
|
88 | - * @param IManager $shareManager |
|
89 | - * @param IGroupManager $groupManager |
|
90 | - * @param IUserManager $userManager |
|
91 | - * @param IRootFolder $rootFolder |
|
92 | - * @param IURLGenerator $urlGenerator |
|
93 | - * @param string $userId |
|
94 | - * @param IL10N $l10n |
|
95 | - * @param IConfig $config |
|
96 | - */ |
|
97 | - public function __construct( |
|
98 | - $appName, |
|
99 | - IRequest $request, |
|
100 | - IManager $shareManager, |
|
101 | - IGroupManager $groupManager, |
|
102 | - IUserManager $userManager, |
|
103 | - IRootFolder $rootFolder, |
|
104 | - IURLGenerator $urlGenerator, |
|
105 | - $userId, |
|
106 | - IL10N $l10n, |
|
107 | - IConfig $config |
|
108 | - ) { |
|
109 | - parent::__construct($appName, $request); |
|
110 | - |
|
111 | - $this->shareManager = $shareManager; |
|
112 | - $this->userManager = $userManager; |
|
113 | - $this->groupManager = $groupManager; |
|
114 | - $this->request = $request; |
|
115 | - $this->rootFolder = $rootFolder; |
|
116 | - $this->urlGenerator = $urlGenerator; |
|
117 | - $this->currentUser = $userId; |
|
118 | - $this->l = $l10n; |
|
119 | - $this->config = $config; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Convert an IShare to an array for OCS output |
|
124 | - * |
|
125 | - * @param \OCP\Share\IShare $share |
|
126 | - * @param Node|null $recipientNode |
|
127 | - * @return array |
|
128 | - * @throws NotFoundException In case the node can't be resolved. |
|
129 | - */ |
|
130 | - protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null) { |
|
131 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
132 | - $shareOwner = $this->userManager->get($share->getShareOwner()); |
|
133 | - |
|
134 | - $result = [ |
|
135 | - 'id' => $share->getId(), |
|
136 | - 'share_type' => $share->getShareType(), |
|
137 | - 'uid_owner' => $share->getSharedBy(), |
|
138 | - 'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(), |
|
139 | - 'permissions' => $share->getPermissions(), |
|
140 | - 'stime' => $share->getShareTime()->getTimestamp(), |
|
141 | - 'parent' => null, |
|
142 | - 'expiration' => null, |
|
143 | - 'token' => null, |
|
144 | - 'uid_file_owner' => $share->getShareOwner(), |
|
145 | - 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(), |
|
146 | - ]; |
|
147 | - |
|
148 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
149 | - if ($recipientNode) { |
|
150 | - $node = $recipientNode; |
|
151 | - } else { |
|
152 | - $nodes = $userFolder->getById($share->getNodeId()); |
|
153 | - |
|
154 | - if (empty($nodes)) { |
|
155 | - // fallback to guessing the path |
|
156 | - $node = $userFolder->get($share->getTarget()); |
|
157 | - if ($node === null) { |
|
158 | - throw new NotFoundException(); |
|
159 | - } |
|
160 | - } else { |
|
161 | - $node = $nodes[0]; |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - $result['path'] = $userFolder->getRelativePath($node->getPath()); |
|
166 | - if ($node instanceOf \OCP\Files\Folder) { |
|
167 | - $result['item_type'] = 'folder'; |
|
168 | - } else { |
|
169 | - $result['item_type'] = 'file'; |
|
170 | - } |
|
171 | - $result['mimetype'] = $node->getMimetype(); |
|
172 | - $result['storage_id'] = $node->getStorage()->getId(); |
|
173 | - $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId(); |
|
174 | - $result['item_source'] = $node->getId(); |
|
175 | - $result['file_source'] = $node->getId(); |
|
176 | - $result['file_parent'] = $node->getParent()->getId(); |
|
177 | - $result['file_target'] = $share->getTarget(); |
|
178 | - |
|
179 | - $expiration = $share->getExpirationDate(); |
|
180 | - if ($expiration !== null) { |
|
181 | - $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); |
|
182 | - } |
|
183 | - |
|
184 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
185 | - $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
186 | - $result['share_with'] = $share->getSharedWith(); |
|
187 | - $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith(); |
|
188 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
189 | - $group = $this->groupManager->get($share->getSharedWith()); |
|
190 | - $result['share_with'] = $share->getSharedWith(); |
|
191 | - $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); |
|
192 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
193 | - |
|
194 | - $result['share_with'] = $share->getPassword(); |
|
195 | - $result['share_with_displayname'] = $share->getPassword(); |
|
196 | - |
|
197 | - $result['token'] = $share->getToken(); |
|
198 | - $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]); |
|
199 | - |
|
200 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
201 | - $result['share_with'] = $share->getSharedWith(); |
|
202 | - $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD'); |
|
203 | - $result['token'] = $share->getToken(); |
|
204 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
205 | - $result['share_with'] = $share->getSharedWith(); |
|
206 | - $result['password'] = $share->getPassword(); |
|
207 | - $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL'); |
|
208 | - $result['token'] = $share->getToken(); |
|
209 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
210 | - $result['share_with_displayname'] = $share->getSharedWith(); |
|
211 | - $result['share_with'] = explode(' ', $share->getSharedWith(), 2)[0]; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - $result['mail_send'] = $share->getMailSend() ? 1 : 0; |
|
216 | - |
|
217 | - return $result; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Check if one of the users address books knows the exact property, if |
|
222 | - * yes we return the full name. |
|
223 | - * |
|
224 | - * @param string $query |
|
225 | - * @param string $property |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - private function getDisplayNameFromAddressBook($query, $property) { |
|
229 | - // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered |
|
230 | - $result = \OC::$server->getContactsManager()->search($query, [$property]); |
|
231 | - foreach ($result as $r) { |
|
232 | - foreach($r[$property] as $value) { |
|
233 | - if ($value === $query) { |
|
234 | - return $r['FN']; |
|
235 | - } |
|
236 | - } |
|
237 | - } |
|
238 | - |
|
239 | - return $query; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Get a specific share by id |
|
244 | - * |
|
245 | - * @NoAdminRequired |
|
246 | - * |
|
247 | - * @param string $id |
|
248 | - * @return DataResponse |
|
249 | - * @throws OCSNotFoundException |
|
250 | - */ |
|
251 | - public function getShare($id) { |
|
252 | - try { |
|
253 | - $share = $this->getShareById($id); |
|
254 | - } catch (ShareNotFound $e) { |
|
255 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
256 | - } |
|
257 | - |
|
258 | - if ($this->canAccessShare($share)) { |
|
259 | - try { |
|
260 | - $share = $this->formatShare($share); |
|
261 | - return new DataResponse([$share]); |
|
262 | - } catch (NotFoundException $e) { |
|
263 | - //Fall trough |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Delete a share |
|
272 | - * |
|
273 | - * @NoAdminRequired |
|
274 | - * |
|
275 | - * @param string $id |
|
276 | - * @return DataResponse |
|
277 | - * @throws OCSNotFoundException |
|
278 | - */ |
|
279 | - public function deleteShare($id) { |
|
280 | - try { |
|
281 | - $share = $this->getShareById($id); |
|
282 | - } catch (ShareNotFound $e) { |
|
283 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
284 | - } |
|
285 | - |
|
286 | - try { |
|
287 | - $this->lock($share->getNode()); |
|
288 | - } catch (LockedException $e) { |
|
289 | - throw new OCSNotFoundException($this->l->t('could not delete share')); |
|
290 | - } |
|
291 | - |
|
292 | - if (!$this->canAccessShare($share)) { |
|
293 | - throw new OCSNotFoundException($this->l->t('Could not delete share')); |
|
294 | - } |
|
295 | - |
|
296 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && |
|
297 | - $share->getShareOwner() !== $this->currentUser && |
|
298 | - $share->getSharedBy() !== $this->currentUser) { |
|
299 | - $this->shareManager->deleteFromSelf($share, $this->currentUser); |
|
300 | - } else { |
|
301 | - $this->shareManager->deleteShare($share); |
|
302 | - } |
|
303 | - |
|
304 | - return new DataResponse(); |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * @NoAdminRequired |
|
309 | - * |
|
310 | - * @param string $path |
|
311 | - * @param int $permissions |
|
312 | - * @param int $shareType |
|
313 | - * @param string $shareWith |
|
314 | - * @param string $publicUpload |
|
315 | - * @param string $password |
|
316 | - * @param string $expireDate |
|
317 | - * |
|
318 | - * @return DataResponse |
|
319 | - * @throws OCSNotFoundException |
|
320 | - * @throws OCSForbiddenException |
|
321 | - * @throws OCSBadRequestException |
|
322 | - * @throws OCSException |
|
323 | - * |
|
324 | - * @suppress PhanUndeclaredClassMethod |
|
325 | - */ |
|
326 | - public function createShare( |
|
327 | - $path = null, |
|
328 | - $permissions = null, |
|
329 | - $shareType = -1, |
|
330 | - $shareWith = null, |
|
331 | - $publicUpload = 'false', |
|
332 | - $password = '', |
|
333 | - $expireDate = '' |
|
334 | - ) { |
|
335 | - $share = $this->shareManager->newShare(); |
|
336 | - |
|
337 | - if ($permissions === null) { |
|
338 | - $permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
339 | - } |
|
340 | - |
|
341 | - // Verify path |
|
342 | - if ($path === null) { |
|
343 | - throw new OCSNotFoundException($this->l->t('Please specify a file or folder path')); |
|
344 | - } |
|
345 | - |
|
346 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
347 | - try { |
|
348 | - $path = $userFolder->get($path); |
|
349 | - } catch (NotFoundException $e) { |
|
350 | - throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
351 | - } |
|
352 | - |
|
353 | - $share->setNode($path); |
|
354 | - |
|
355 | - try { |
|
356 | - $this->lock($share->getNode()); |
|
357 | - } catch (LockedException $e) { |
|
358 | - throw new OCSNotFoundException($this->l->t('Could not create share')); |
|
359 | - } |
|
360 | - |
|
361 | - if ($permissions < 0 || $permissions > Constants::PERMISSION_ALL) { |
|
362 | - throw new OCSNotFoundException($this->l->t('invalid permissions')); |
|
363 | - } |
|
364 | - |
|
365 | - // Shares always require read permissions |
|
366 | - $permissions |= Constants::PERMISSION_READ; |
|
367 | - |
|
368 | - if ($path instanceof \OCP\Files\File) { |
|
369 | - // Single file shares should never have delete or create permissions |
|
370 | - $permissions &= ~Constants::PERMISSION_DELETE; |
|
371 | - $permissions &= ~Constants::PERMISSION_CREATE; |
|
372 | - } |
|
373 | - |
|
374 | - /* |
|
62 | + /** @var IManager */ |
|
63 | + private $shareManager; |
|
64 | + /** @var IGroupManager */ |
|
65 | + private $groupManager; |
|
66 | + /** @var IUserManager */ |
|
67 | + private $userManager; |
|
68 | + /** @var IRequest */ |
|
69 | + protected $request; |
|
70 | + /** @var IRootFolder */ |
|
71 | + private $rootFolder; |
|
72 | + /** @var IURLGenerator */ |
|
73 | + private $urlGenerator; |
|
74 | + /** @var string */ |
|
75 | + private $currentUser; |
|
76 | + /** @var IL10N */ |
|
77 | + private $l; |
|
78 | + /** @var \OCP\Files\Node */ |
|
79 | + private $lockedNode; |
|
80 | + /** @var IConfig */ |
|
81 | + private $config; |
|
82 | + |
|
83 | + /** |
|
84 | + * Share20OCS constructor. |
|
85 | + * |
|
86 | + * @param string $appName |
|
87 | + * @param IRequest $request |
|
88 | + * @param IManager $shareManager |
|
89 | + * @param IGroupManager $groupManager |
|
90 | + * @param IUserManager $userManager |
|
91 | + * @param IRootFolder $rootFolder |
|
92 | + * @param IURLGenerator $urlGenerator |
|
93 | + * @param string $userId |
|
94 | + * @param IL10N $l10n |
|
95 | + * @param IConfig $config |
|
96 | + */ |
|
97 | + public function __construct( |
|
98 | + $appName, |
|
99 | + IRequest $request, |
|
100 | + IManager $shareManager, |
|
101 | + IGroupManager $groupManager, |
|
102 | + IUserManager $userManager, |
|
103 | + IRootFolder $rootFolder, |
|
104 | + IURLGenerator $urlGenerator, |
|
105 | + $userId, |
|
106 | + IL10N $l10n, |
|
107 | + IConfig $config |
|
108 | + ) { |
|
109 | + parent::__construct($appName, $request); |
|
110 | + |
|
111 | + $this->shareManager = $shareManager; |
|
112 | + $this->userManager = $userManager; |
|
113 | + $this->groupManager = $groupManager; |
|
114 | + $this->request = $request; |
|
115 | + $this->rootFolder = $rootFolder; |
|
116 | + $this->urlGenerator = $urlGenerator; |
|
117 | + $this->currentUser = $userId; |
|
118 | + $this->l = $l10n; |
|
119 | + $this->config = $config; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Convert an IShare to an array for OCS output |
|
124 | + * |
|
125 | + * @param \OCP\Share\IShare $share |
|
126 | + * @param Node|null $recipientNode |
|
127 | + * @return array |
|
128 | + * @throws NotFoundException In case the node can't be resolved. |
|
129 | + */ |
|
130 | + protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null) { |
|
131 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
132 | + $shareOwner = $this->userManager->get($share->getShareOwner()); |
|
133 | + |
|
134 | + $result = [ |
|
135 | + 'id' => $share->getId(), |
|
136 | + 'share_type' => $share->getShareType(), |
|
137 | + 'uid_owner' => $share->getSharedBy(), |
|
138 | + 'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(), |
|
139 | + 'permissions' => $share->getPermissions(), |
|
140 | + 'stime' => $share->getShareTime()->getTimestamp(), |
|
141 | + 'parent' => null, |
|
142 | + 'expiration' => null, |
|
143 | + 'token' => null, |
|
144 | + 'uid_file_owner' => $share->getShareOwner(), |
|
145 | + 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(), |
|
146 | + ]; |
|
147 | + |
|
148 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
149 | + if ($recipientNode) { |
|
150 | + $node = $recipientNode; |
|
151 | + } else { |
|
152 | + $nodes = $userFolder->getById($share->getNodeId()); |
|
153 | + |
|
154 | + if (empty($nodes)) { |
|
155 | + // fallback to guessing the path |
|
156 | + $node = $userFolder->get($share->getTarget()); |
|
157 | + if ($node === null) { |
|
158 | + throw new NotFoundException(); |
|
159 | + } |
|
160 | + } else { |
|
161 | + $node = $nodes[0]; |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + $result['path'] = $userFolder->getRelativePath($node->getPath()); |
|
166 | + if ($node instanceOf \OCP\Files\Folder) { |
|
167 | + $result['item_type'] = 'folder'; |
|
168 | + } else { |
|
169 | + $result['item_type'] = 'file'; |
|
170 | + } |
|
171 | + $result['mimetype'] = $node->getMimetype(); |
|
172 | + $result['storage_id'] = $node->getStorage()->getId(); |
|
173 | + $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId(); |
|
174 | + $result['item_source'] = $node->getId(); |
|
175 | + $result['file_source'] = $node->getId(); |
|
176 | + $result['file_parent'] = $node->getParent()->getId(); |
|
177 | + $result['file_target'] = $share->getTarget(); |
|
178 | + |
|
179 | + $expiration = $share->getExpirationDate(); |
|
180 | + if ($expiration !== null) { |
|
181 | + $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); |
|
182 | + } |
|
183 | + |
|
184 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
185 | + $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
186 | + $result['share_with'] = $share->getSharedWith(); |
|
187 | + $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith(); |
|
188 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
189 | + $group = $this->groupManager->get($share->getSharedWith()); |
|
190 | + $result['share_with'] = $share->getSharedWith(); |
|
191 | + $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); |
|
192 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
193 | + |
|
194 | + $result['share_with'] = $share->getPassword(); |
|
195 | + $result['share_with_displayname'] = $share->getPassword(); |
|
196 | + |
|
197 | + $result['token'] = $share->getToken(); |
|
198 | + $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]); |
|
199 | + |
|
200 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
201 | + $result['share_with'] = $share->getSharedWith(); |
|
202 | + $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD'); |
|
203 | + $result['token'] = $share->getToken(); |
|
204 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
205 | + $result['share_with'] = $share->getSharedWith(); |
|
206 | + $result['password'] = $share->getPassword(); |
|
207 | + $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL'); |
|
208 | + $result['token'] = $share->getToken(); |
|
209 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
210 | + $result['share_with_displayname'] = $share->getSharedWith(); |
|
211 | + $result['share_with'] = explode(' ', $share->getSharedWith(), 2)[0]; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + $result['mail_send'] = $share->getMailSend() ? 1 : 0; |
|
216 | + |
|
217 | + return $result; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Check if one of the users address books knows the exact property, if |
|
222 | + * yes we return the full name. |
|
223 | + * |
|
224 | + * @param string $query |
|
225 | + * @param string $property |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + private function getDisplayNameFromAddressBook($query, $property) { |
|
229 | + // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered |
|
230 | + $result = \OC::$server->getContactsManager()->search($query, [$property]); |
|
231 | + foreach ($result as $r) { |
|
232 | + foreach($r[$property] as $value) { |
|
233 | + if ($value === $query) { |
|
234 | + return $r['FN']; |
|
235 | + } |
|
236 | + } |
|
237 | + } |
|
238 | + |
|
239 | + return $query; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Get a specific share by id |
|
244 | + * |
|
245 | + * @NoAdminRequired |
|
246 | + * |
|
247 | + * @param string $id |
|
248 | + * @return DataResponse |
|
249 | + * @throws OCSNotFoundException |
|
250 | + */ |
|
251 | + public function getShare($id) { |
|
252 | + try { |
|
253 | + $share = $this->getShareById($id); |
|
254 | + } catch (ShareNotFound $e) { |
|
255 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
256 | + } |
|
257 | + |
|
258 | + if ($this->canAccessShare($share)) { |
|
259 | + try { |
|
260 | + $share = $this->formatShare($share); |
|
261 | + return new DataResponse([$share]); |
|
262 | + } catch (NotFoundException $e) { |
|
263 | + //Fall trough |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Delete a share |
|
272 | + * |
|
273 | + * @NoAdminRequired |
|
274 | + * |
|
275 | + * @param string $id |
|
276 | + * @return DataResponse |
|
277 | + * @throws OCSNotFoundException |
|
278 | + */ |
|
279 | + public function deleteShare($id) { |
|
280 | + try { |
|
281 | + $share = $this->getShareById($id); |
|
282 | + } catch (ShareNotFound $e) { |
|
283 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
284 | + } |
|
285 | + |
|
286 | + try { |
|
287 | + $this->lock($share->getNode()); |
|
288 | + } catch (LockedException $e) { |
|
289 | + throw new OCSNotFoundException($this->l->t('could not delete share')); |
|
290 | + } |
|
291 | + |
|
292 | + if (!$this->canAccessShare($share)) { |
|
293 | + throw new OCSNotFoundException($this->l->t('Could not delete share')); |
|
294 | + } |
|
295 | + |
|
296 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && |
|
297 | + $share->getShareOwner() !== $this->currentUser && |
|
298 | + $share->getSharedBy() !== $this->currentUser) { |
|
299 | + $this->shareManager->deleteFromSelf($share, $this->currentUser); |
|
300 | + } else { |
|
301 | + $this->shareManager->deleteShare($share); |
|
302 | + } |
|
303 | + |
|
304 | + return new DataResponse(); |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * @NoAdminRequired |
|
309 | + * |
|
310 | + * @param string $path |
|
311 | + * @param int $permissions |
|
312 | + * @param int $shareType |
|
313 | + * @param string $shareWith |
|
314 | + * @param string $publicUpload |
|
315 | + * @param string $password |
|
316 | + * @param string $expireDate |
|
317 | + * |
|
318 | + * @return DataResponse |
|
319 | + * @throws OCSNotFoundException |
|
320 | + * @throws OCSForbiddenException |
|
321 | + * @throws OCSBadRequestException |
|
322 | + * @throws OCSException |
|
323 | + * |
|
324 | + * @suppress PhanUndeclaredClassMethod |
|
325 | + */ |
|
326 | + public function createShare( |
|
327 | + $path = null, |
|
328 | + $permissions = null, |
|
329 | + $shareType = -1, |
|
330 | + $shareWith = null, |
|
331 | + $publicUpload = 'false', |
|
332 | + $password = '', |
|
333 | + $expireDate = '' |
|
334 | + ) { |
|
335 | + $share = $this->shareManager->newShare(); |
|
336 | + |
|
337 | + if ($permissions === null) { |
|
338 | + $permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
339 | + } |
|
340 | + |
|
341 | + // Verify path |
|
342 | + if ($path === null) { |
|
343 | + throw new OCSNotFoundException($this->l->t('Please specify a file or folder path')); |
|
344 | + } |
|
345 | + |
|
346 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
347 | + try { |
|
348 | + $path = $userFolder->get($path); |
|
349 | + } catch (NotFoundException $e) { |
|
350 | + throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
351 | + } |
|
352 | + |
|
353 | + $share->setNode($path); |
|
354 | + |
|
355 | + try { |
|
356 | + $this->lock($share->getNode()); |
|
357 | + } catch (LockedException $e) { |
|
358 | + throw new OCSNotFoundException($this->l->t('Could not create share')); |
|
359 | + } |
|
360 | + |
|
361 | + if ($permissions < 0 || $permissions > Constants::PERMISSION_ALL) { |
|
362 | + throw new OCSNotFoundException($this->l->t('invalid permissions')); |
|
363 | + } |
|
364 | + |
|
365 | + // Shares always require read permissions |
|
366 | + $permissions |= Constants::PERMISSION_READ; |
|
367 | + |
|
368 | + if ($path instanceof \OCP\Files\File) { |
|
369 | + // Single file shares should never have delete or create permissions |
|
370 | + $permissions &= ~Constants::PERMISSION_DELETE; |
|
371 | + $permissions &= ~Constants::PERMISSION_CREATE; |
|
372 | + } |
|
373 | + |
|
374 | + /* |
|
375 | 375 | * Hack for https://github.com/owncloud/core/issues/22587 |
376 | 376 | * We check the permissions via webdav. But the permissions of the mount point |
377 | 377 | * do not equal the share permissions. Here we fix that for federated mounts. |
378 | 378 | */ |
379 | - if ($path->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
380 | - $permissions &= ~($permissions & ~$path->getPermissions()); |
|
381 | - } |
|
382 | - |
|
383 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
384 | - // Valid user is required to share |
|
385 | - if ($shareWith === null || !$this->userManager->userExists($shareWith)) { |
|
386 | - throw new OCSNotFoundException($this->l->t('Please specify a valid user')); |
|
387 | - } |
|
388 | - $share->setSharedWith($shareWith); |
|
389 | - $share->setPermissions($permissions); |
|
390 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
391 | - if (!$this->shareManager->allowGroupSharing()) { |
|
392 | - throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator')); |
|
393 | - } |
|
394 | - |
|
395 | - // Valid group is required to share |
|
396 | - if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { |
|
397 | - throw new OCSNotFoundException($this->l->t('Please specify a valid group')); |
|
398 | - } |
|
399 | - $share->setSharedWith($shareWith); |
|
400 | - $share->setPermissions($permissions); |
|
401 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
402 | - //Can we even share links? |
|
403 | - if (!$this->shareManager->shareApiAllowLinks()) { |
|
404 | - throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator')); |
|
405 | - } |
|
406 | - |
|
407 | - /* |
|
379 | + if ($path->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
380 | + $permissions &= ~($permissions & ~$path->getPermissions()); |
|
381 | + } |
|
382 | + |
|
383 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
384 | + // Valid user is required to share |
|
385 | + if ($shareWith === null || !$this->userManager->userExists($shareWith)) { |
|
386 | + throw new OCSNotFoundException($this->l->t('Please specify a valid user')); |
|
387 | + } |
|
388 | + $share->setSharedWith($shareWith); |
|
389 | + $share->setPermissions($permissions); |
|
390 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
391 | + if (!$this->shareManager->allowGroupSharing()) { |
|
392 | + throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator')); |
|
393 | + } |
|
394 | + |
|
395 | + // Valid group is required to share |
|
396 | + if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { |
|
397 | + throw new OCSNotFoundException($this->l->t('Please specify a valid group')); |
|
398 | + } |
|
399 | + $share->setSharedWith($shareWith); |
|
400 | + $share->setPermissions($permissions); |
|
401 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
402 | + //Can we even share links? |
|
403 | + if (!$this->shareManager->shareApiAllowLinks()) { |
|
404 | + throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator')); |
|
405 | + } |
|
406 | + |
|
407 | + /* |
|
408 | 408 | * For now we only allow 1 link share. |
409 | 409 | * Return the existing link share if this is a duplicate |
410 | 410 | */ |
411 | - $existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); |
|
412 | - if (!empty($existingShares)) { |
|
413 | - return new DataResponse($this->formatShare($existingShares[0])); |
|
414 | - } |
|
415 | - |
|
416 | - if ($publicUpload === 'true') { |
|
417 | - // Check if public upload is allowed |
|
418 | - if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
419 | - throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
420 | - } |
|
421 | - |
|
422 | - // Public upload can only be set for folders |
|
423 | - if ($path instanceof \OCP\Files\File) { |
|
424 | - throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
425 | - } |
|
426 | - |
|
427 | - $share->setPermissions( |
|
428 | - Constants::PERMISSION_READ | |
|
429 | - Constants::PERMISSION_CREATE | |
|
430 | - Constants::PERMISSION_UPDATE | |
|
431 | - Constants::PERMISSION_DELETE |
|
432 | - ); |
|
433 | - } else { |
|
434 | - $share->setPermissions(Constants::PERMISSION_READ); |
|
435 | - } |
|
436 | - |
|
437 | - // Set password |
|
438 | - if ($password !== '') { |
|
439 | - $share->setPassword($password); |
|
440 | - } |
|
441 | - |
|
442 | - //Expire date |
|
443 | - if ($expireDate !== '') { |
|
444 | - try { |
|
445 | - $expireDate = $this->parseDate($expireDate); |
|
446 | - $share->setExpirationDate($expireDate); |
|
447 | - } catch (\Exception $e) { |
|
448 | - throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); |
|
449 | - } |
|
450 | - } |
|
451 | - |
|
452 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
453 | - if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
454 | - throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType])); |
|
455 | - } |
|
456 | - |
|
457 | - $share->setSharedWith($shareWith); |
|
458 | - $share->setPermissions($permissions); |
|
459 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
460 | - if ($share->getNodeType() === 'file') { |
|
461 | - $share->setPermissions(Constants::PERMISSION_READ); |
|
462 | - } else { |
|
463 | - $share->setPermissions($permissions); |
|
464 | - } |
|
465 | - $share->setSharedWith($shareWith); |
|
466 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
467 | - if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { |
|
468 | - throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); |
|
469 | - } |
|
470 | - |
|
471 | - $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($shareWith); |
|
472 | - |
|
473 | - // Valid circle is required to share |
|
474 | - if ($circle === null) { |
|
475 | - throw new OCSNotFoundException($this->l->t('Please specify a valid circle')); |
|
476 | - } |
|
477 | - $share->setSharedWith($shareWith); |
|
478 | - $share->setPermissions($permissions); |
|
479 | - } else { |
|
480 | - throw new OCSBadRequestException($this->l->t('Unknown share type')); |
|
481 | - } |
|
482 | - |
|
483 | - $share->setShareType($shareType); |
|
484 | - $share->setSharedBy($this->currentUser); |
|
485 | - |
|
486 | - try { |
|
487 | - $share = $this->shareManager->createShare($share); |
|
488 | - } catch (GenericShareException $e) { |
|
489 | - $code = $e->getCode() === 0 ? 403 : $e->getCode(); |
|
490 | - throw new OCSException($e->getHint(), $code); |
|
491 | - } catch (\Exception $e) { |
|
492 | - throw new OCSForbiddenException($e->getMessage(), $e); |
|
493 | - } |
|
494 | - |
|
495 | - $output = $this->formatShare($share); |
|
496 | - |
|
497 | - return new DataResponse($output); |
|
498 | - } |
|
499 | - |
|
500 | - /** |
|
501 | - * @param \OCP\Files\File|\OCP\Files\Folder $node |
|
502 | - * @param boolean $includeTags |
|
503 | - * @return DataResponse |
|
504 | - */ |
|
505 | - private function getSharedWithMe($node = null, $includeTags) { |
|
506 | - |
|
507 | - $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0); |
|
508 | - $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0); |
|
509 | - $circleShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $node, -1, 0); |
|
510 | - |
|
511 | - $shares = array_merge($userShares, $groupShares, $circleShares); |
|
512 | - |
|
513 | - $shares = array_filter($shares, function (IShare $share) { |
|
514 | - return $share->getShareOwner() !== $this->currentUser; |
|
515 | - }); |
|
516 | - |
|
517 | - $formatted = []; |
|
518 | - foreach ($shares as $share) { |
|
519 | - if ($this->canAccessShare($share)) { |
|
520 | - try { |
|
521 | - $formatted[] = $this->formatShare($share); |
|
522 | - } catch (NotFoundException $e) { |
|
523 | - // Ignore this share |
|
524 | - } |
|
525 | - } |
|
526 | - } |
|
527 | - |
|
528 | - if ($includeTags) { |
|
529 | - $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager()); |
|
530 | - } |
|
531 | - |
|
532 | - return new DataResponse($formatted); |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * @param \OCP\Files\Folder $folder |
|
537 | - * @return DataResponse |
|
538 | - * @throws OCSBadRequestException |
|
539 | - */ |
|
540 | - private function getSharesInDir($folder) { |
|
541 | - if (!($folder instanceof \OCP\Files\Folder)) { |
|
542 | - throw new OCSBadRequestException($this->l->t('Not a directory')); |
|
543 | - } |
|
544 | - |
|
545 | - $nodes = $folder->getDirectoryListing(); |
|
546 | - /** @var \OCP\Share\IShare[] $shares */ |
|
547 | - $shares = []; |
|
548 | - foreach ($nodes as $node) { |
|
549 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); |
|
550 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); |
|
551 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); |
|
552 | - if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
553 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0)); |
|
554 | - } |
|
555 | - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
556 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0)); |
|
557 | - } |
|
558 | - } |
|
559 | - |
|
560 | - $formatted = []; |
|
561 | - foreach ($shares as $share) { |
|
562 | - try { |
|
563 | - $formatted[] = $this->formatShare($share); |
|
564 | - } catch (NotFoundException $e) { |
|
565 | - //Ignore this share |
|
566 | - } |
|
567 | - } |
|
568 | - |
|
569 | - return new DataResponse($formatted); |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * The getShares function. |
|
574 | - * |
|
575 | - * @NoAdminRequired |
|
576 | - * |
|
577 | - * @param string $shared_with_me |
|
578 | - * @param string $reshares |
|
579 | - * @param string $subfiles |
|
580 | - * @param string $path |
|
581 | - * |
|
582 | - * - Get shares by the current user |
|
583 | - * - Get shares by the current user and reshares (?reshares=true) |
|
584 | - * - Get shares with the current user (?shared_with_me=true) |
|
585 | - * - Get shares for a specific path (?path=...) |
|
586 | - * - Get all shares in a folder (?subfiles=true&path=..) |
|
587 | - * |
|
588 | - * @return DataResponse |
|
589 | - * @throws OCSNotFoundException |
|
590 | - */ |
|
591 | - public function getShares( |
|
592 | - $shared_with_me = 'false', |
|
593 | - $reshares = 'false', |
|
594 | - $subfiles = 'false', |
|
595 | - $path = null, |
|
596 | - $include_tags = 'false' |
|
597 | - ) { |
|
598 | - |
|
599 | - if ($path !== null) { |
|
600 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
601 | - try { |
|
602 | - $path = $userFolder->get($path); |
|
603 | - $this->lock($path); |
|
604 | - } catch (\OCP\Files\NotFoundException $e) { |
|
605 | - throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
606 | - } catch (LockedException $e) { |
|
607 | - throw new OCSNotFoundException($this->l->t('Could not lock path')); |
|
608 | - } |
|
609 | - } |
|
610 | - |
|
611 | - if ($shared_with_me === 'true') { |
|
612 | - $result = $this->getSharedWithMe($path, $include_tags); |
|
613 | - return $result; |
|
614 | - } |
|
615 | - |
|
616 | - if ($subfiles === 'true') { |
|
617 | - $result = $this->getSharesInDir($path); |
|
618 | - return $result; |
|
619 | - } |
|
620 | - |
|
621 | - if ($reshares === 'true') { |
|
622 | - $reshares = true; |
|
623 | - } else { |
|
624 | - $reshares = false; |
|
625 | - } |
|
626 | - |
|
627 | - // Get all shares |
|
628 | - $userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); |
|
629 | - $groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); |
|
630 | - $linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); |
|
631 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
632 | - $mailShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0); |
|
633 | - } else { |
|
634 | - $mailShares = []; |
|
635 | - } |
|
636 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
637 | - $circleShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0); |
|
638 | - } else { |
|
639 | - $circleShares = []; |
|
640 | - } |
|
641 | - |
|
642 | - $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares); |
|
643 | - |
|
644 | - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
645 | - $federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); |
|
646 | - $shares = array_merge($shares, $federatedShares); |
|
647 | - } |
|
648 | - |
|
649 | - $formatted = []; |
|
650 | - foreach ($shares as $share) { |
|
651 | - try { |
|
652 | - $formatted[] = $this->formatShare($share, $path); |
|
653 | - } catch (NotFoundException $e) { |
|
654 | - //Ignore share |
|
655 | - } |
|
656 | - } |
|
657 | - |
|
658 | - if ($include_tags) { |
|
659 | - $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager()); |
|
660 | - } |
|
661 | - |
|
662 | - return new DataResponse($formatted); |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * @NoAdminRequired |
|
667 | - * |
|
668 | - * @param int $id |
|
669 | - * @param int $permissions |
|
670 | - * @param string $password |
|
671 | - * @param string $publicUpload |
|
672 | - * @param string $expireDate |
|
673 | - * @return DataResponse |
|
674 | - * @throws OCSNotFoundException |
|
675 | - * @throws OCSBadRequestException |
|
676 | - * @throws OCSForbiddenException |
|
677 | - */ |
|
678 | - public function updateShare( |
|
679 | - $id, |
|
680 | - $permissions = null, |
|
681 | - $password = null, |
|
682 | - $publicUpload = null, |
|
683 | - $expireDate = null |
|
684 | - ) { |
|
685 | - try { |
|
686 | - $share = $this->getShareById($id); |
|
687 | - } catch (ShareNotFound $e) { |
|
688 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
689 | - } |
|
690 | - |
|
691 | - $this->lock($share->getNode()); |
|
692 | - |
|
693 | - if (!$this->canAccessShare($share, false)) { |
|
694 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
695 | - } |
|
696 | - |
|
697 | - if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { |
|
698 | - throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given')); |
|
699 | - } |
|
700 | - |
|
701 | - /* |
|
411 | + $existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); |
|
412 | + if (!empty($existingShares)) { |
|
413 | + return new DataResponse($this->formatShare($existingShares[0])); |
|
414 | + } |
|
415 | + |
|
416 | + if ($publicUpload === 'true') { |
|
417 | + // Check if public upload is allowed |
|
418 | + if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
419 | + throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
420 | + } |
|
421 | + |
|
422 | + // Public upload can only be set for folders |
|
423 | + if ($path instanceof \OCP\Files\File) { |
|
424 | + throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
425 | + } |
|
426 | + |
|
427 | + $share->setPermissions( |
|
428 | + Constants::PERMISSION_READ | |
|
429 | + Constants::PERMISSION_CREATE | |
|
430 | + Constants::PERMISSION_UPDATE | |
|
431 | + Constants::PERMISSION_DELETE |
|
432 | + ); |
|
433 | + } else { |
|
434 | + $share->setPermissions(Constants::PERMISSION_READ); |
|
435 | + } |
|
436 | + |
|
437 | + // Set password |
|
438 | + if ($password !== '') { |
|
439 | + $share->setPassword($password); |
|
440 | + } |
|
441 | + |
|
442 | + //Expire date |
|
443 | + if ($expireDate !== '') { |
|
444 | + try { |
|
445 | + $expireDate = $this->parseDate($expireDate); |
|
446 | + $share->setExpirationDate($expireDate); |
|
447 | + } catch (\Exception $e) { |
|
448 | + throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); |
|
449 | + } |
|
450 | + } |
|
451 | + |
|
452 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
453 | + if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
454 | + throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType])); |
|
455 | + } |
|
456 | + |
|
457 | + $share->setSharedWith($shareWith); |
|
458 | + $share->setPermissions($permissions); |
|
459 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
460 | + if ($share->getNodeType() === 'file') { |
|
461 | + $share->setPermissions(Constants::PERMISSION_READ); |
|
462 | + } else { |
|
463 | + $share->setPermissions($permissions); |
|
464 | + } |
|
465 | + $share->setSharedWith($shareWith); |
|
466 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
467 | + if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { |
|
468 | + throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); |
|
469 | + } |
|
470 | + |
|
471 | + $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($shareWith); |
|
472 | + |
|
473 | + // Valid circle is required to share |
|
474 | + if ($circle === null) { |
|
475 | + throw new OCSNotFoundException($this->l->t('Please specify a valid circle')); |
|
476 | + } |
|
477 | + $share->setSharedWith($shareWith); |
|
478 | + $share->setPermissions($permissions); |
|
479 | + } else { |
|
480 | + throw new OCSBadRequestException($this->l->t('Unknown share type')); |
|
481 | + } |
|
482 | + |
|
483 | + $share->setShareType($shareType); |
|
484 | + $share->setSharedBy($this->currentUser); |
|
485 | + |
|
486 | + try { |
|
487 | + $share = $this->shareManager->createShare($share); |
|
488 | + } catch (GenericShareException $e) { |
|
489 | + $code = $e->getCode() === 0 ? 403 : $e->getCode(); |
|
490 | + throw new OCSException($e->getHint(), $code); |
|
491 | + } catch (\Exception $e) { |
|
492 | + throw new OCSForbiddenException($e->getMessage(), $e); |
|
493 | + } |
|
494 | + |
|
495 | + $output = $this->formatShare($share); |
|
496 | + |
|
497 | + return new DataResponse($output); |
|
498 | + } |
|
499 | + |
|
500 | + /** |
|
501 | + * @param \OCP\Files\File|\OCP\Files\Folder $node |
|
502 | + * @param boolean $includeTags |
|
503 | + * @return DataResponse |
|
504 | + */ |
|
505 | + private function getSharedWithMe($node = null, $includeTags) { |
|
506 | + |
|
507 | + $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0); |
|
508 | + $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0); |
|
509 | + $circleShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $node, -1, 0); |
|
510 | + |
|
511 | + $shares = array_merge($userShares, $groupShares, $circleShares); |
|
512 | + |
|
513 | + $shares = array_filter($shares, function (IShare $share) { |
|
514 | + return $share->getShareOwner() !== $this->currentUser; |
|
515 | + }); |
|
516 | + |
|
517 | + $formatted = []; |
|
518 | + foreach ($shares as $share) { |
|
519 | + if ($this->canAccessShare($share)) { |
|
520 | + try { |
|
521 | + $formatted[] = $this->formatShare($share); |
|
522 | + } catch (NotFoundException $e) { |
|
523 | + // Ignore this share |
|
524 | + } |
|
525 | + } |
|
526 | + } |
|
527 | + |
|
528 | + if ($includeTags) { |
|
529 | + $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager()); |
|
530 | + } |
|
531 | + |
|
532 | + return new DataResponse($formatted); |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * @param \OCP\Files\Folder $folder |
|
537 | + * @return DataResponse |
|
538 | + * @throws OCSBadRequestException |
|
539 | + */ |
|
540 | + private function getSharesInDir($folder) { |
|
541 | + if (!($folder instanceof \OCP\Files\Folder)) { |
|
542 | + throw new OCSBadRequestException($this->l->t('Not a directory')); |
|
543 | + } |
|
544 | + |
|
545 | + $nodes = $folder->getDirectoryListing(); |
|
546 | + /** @var \OCP\Share\IShare[] $shares */ |
|
547 | + $shares = []; |
|
548 | + foreach ($nodes as $node) { |
|
549 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); |
|
550 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); |
|
551 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); |
|
552 | + if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
553 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0)); |
|
554 | + } |
|
555 | + if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
556 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0)); |
|
557 | + } |
|
558 | + } |
|
559 | + |
|
560 | + $formatted = []; |
|
561 | + foreach ($shares as $share) { |
|
562 | + try { |
|
563 | + $formatted[] = $this->formatShare($share); |
|
564 | + } catch (NotFoundException $e) { |
|
565 | + //Ignore this share |
|
566 | + } |
|
567 | + } |
|
568 | + |
|
569 | + return new DataResponse($formatted); |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * The getShares function. |
|
574 | + * |
|
575 | + * @NoAdminRequired |
|
576 | + * |
|
577 | + * @param string $shared_with_me |
|
578 | + * @param string $reshares |
|
579 | + * @param string $subfiles |
|
580 | + * @param string $path |
|
581 | + * |
|
582 | + * - Get shares by the current user |
|
583 | + * - Get shares by the current user and reshares (?reshares=true) |
|
584 | + * - Get shares with the current user (?shared_with_me=true) |
|
585 | + * - Get shares for a specific path (?path=...) |
|
586 | + * - Get all shares in a folder (?subfiles=true&path=..) |
|
587 | + * |
|
588 | + * @return DataResponse |
|
589 | + * @throws OCSNotFoundException |
|
590 | + */ |
|
591 | + public function getShares( |
|
592 | + $shared_with_me = 'false', |
|
593 | + $reshares = 'false', |
|
594 | + $subfiles = 'false', |
|
595 | + $path = null, |
|
596 | + $include_tags = 'false' |
|
597 | + ) { |
|
598 | + |
|
599 | + if ($path !== null) { |
|
600 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
601 | + try { |
|
602 | + $path = $userFolder->get($path); |
|
603 | + $this->lock($path); |
|
604 | + } catch (\OCP\Files\NotFoundException $e) { |
|
605 | + throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
606 | + } catch (LockedException $e) { |
|
607 | + throw new OCSNotFoundException($this->l->t('Could not lock path')); |
|
608 | + } |
|
609 | + } |
|
610 | + |
|
611 | + if ($shared_with_me === 'true') { |
|
612 | + $result = $this->getSharedWithMe($path, $include_tags); |
|
613 | + return $result; |
|
614 | + } |
|
615 | + |
|
616 | + if ($subfiles === 'true') { |
|
617 | + $result = $this->getSharesInDir($path); |
|
618 | + return $result; |
|
619 | + } |
|
620 | + |
|
621 | + if ($reshares === 'true') { |
|
622 | + $reshares = true; |
|
623 | + } else { |
|
624 | + $reshares = false; |
|
625 | + } |
|
626 | + |
|
627 | + // Get all shares |
|
628 | + $userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); |
|
629 | + $groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); |
|
630 | + $linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); |
|
631 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
632 | + $mailShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0); |
|
633 | + } else { |
|
634 | + $mailShares = []; |
|
635 | + } |
|
636 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
637 | + $circleShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0); |
|
638 | + } else { |
|
639 | + $circleShares = []; |
|
640 | + } |
|
641 | + |
|
642 | + $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares); |
|
643 | + |
|
644 | + if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
645 | + $federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); |
|
646 | + $shares = array_merge($shares, $federatedShares); |
|
647 | + } |
|
648 | + |
|
649 | + $formatted = []; |
|
650 | + foreach ($shares as $share) { |
|
651 | + try { |
|
652 | + $formatted[] = $this->formatShare($share, $path); |
|
653 | + } catch (NotFoundException $e) { |
|
654 | + //Ignore share |
|
655 | + } |
|
656 | + } |
|
657 | + |
|
658 | + if ($include_tags) { |
|
659 | + $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager()); |
|
660 | + } |
|
661 | + |
|
662 | + return new DataResponse($formatted); |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * @NoAdminRequired |
|
667 | + * |
|
668 | + * @param int $id |
|
669 | + * @param int $permissions |
|
670 | + * @param string $password |
|
671 | + * @param string $publicUpload |
|
672 | + * @param string $expireDate |
|
673 | + * @return DataResponse |
|
674 | + * @throws OCSNotFoundException |
|
675 | + * @throws OCSBadRequestException |
|
676 | + * @throws OCSForbiddenException |
|
677 | + */ |
|
678 | + public function updateShare( |
|
679 | + $id, |
|
680 | + $permissions = null, |
|
681 | + $password = null, |
|
682 | + $publicUpload = null, |
|
683 | + $expireDate = null |
|
684 | + ) { |
|
685 | + try { |
|
686 | + $share = $this->getShareById($id); |
|
687 | + } catch (ShareNotFound $e) { |
|
688 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
689 | + } |
|
690 | + |
|
691 | + $this->lock($share->getNode()); |
|
692 | + |
|
693 | + if (!$this->canAccessShare($share, false)) { |
|
694 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
695 | + } |
|
696 | + |
|
697 | + if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { |
|
698 | + throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given')); |
|
699 | + } |
|
700 | + |
|
701 | + /* |
|
702 | 702 | * expirationdate, password and publicUpload only make sense for link shares |
703 | 703 | */ |
704 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
705 | - |
|
706 | - $newPermissions = null; |
|
707 | - if ($publicUpload === 'true') { |
|
708 | - $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; |
|
709 | - } else if ($publicUpload === 'false') { |
|
710 | - $newPermissions = Constants::PERMISSION_READ; |
|
711 | - } |
|
712 | - |
|
713 | - if ($permissions !== null) { |
|
714 | - $newPermissions = (int)$permissions; |
|
715 | - $newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE; |
|
716 | - } |
|
717 | - |
|
718 | - if ($newPermissions !== null && |
|
719 | - !in_array($newPermissions, [ |
|
720 | - Constants::PERMISSION_READ, |
|
721 | - Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, // legacy |
|
722 | - Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, // correct |
|
723 | - Constants::PERMISSION_CREATE, // hidden file list |
|
724 | - Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE, // allow to edit single files |
|
725 | - ]) |
|
726 | - ) { |
|
727 | - throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links')); |
|
728 | - } |
|
729 | - |
|
730 | - if ( |
|
731 | - // legacy |
|
732 | - $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE) || |
|
733 | - // correct |
|
734 | - $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
735 | - ) { |
|
736 | - if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
737 | - throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
738 | - } |
|
739 | - |
|
740 | - if (!($share->getNode() instanceof \OCP\Files\Folder)) { |
|
741 | - throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
742 | - } |
|
743 | - |
|
744 | - // normalize to correct public upload permissions |
|
745 | - $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; |
|
746 | - } |
|
747 | - |
|
748 | - if ($newPermissions !== null) { |
|
749 | - $share->setPermissions($newPermissions); |
|
750 | - $permissions = $newPermissions; |
|
751 | - } |
|
752 | - |
|
753 | - if ($expireDate === '') { |
|
754 | - $share->setExpirationDate(null); |
|
755 | - } else if ($expireDate !== null) { |
|
756 | - try { |
|
757 | - $expireDate = $this->parseDate($expireDate); |
|
758 | - } catch (\Exception $e) { |
|
759 | - throw new OCSBadRequestException($e->getMessage(), $e); |
|
760 | - } |
|
761 | - $share->setExpirationDate($expireDate); |
|
762 | - } |
|
763 | - |
|
764 | - if ($password === '') { |
|
765 | - $share->setPassword(null); |
|
766 | - } else if ($password !== null) { |
|
767 | - $share->setPassword($password); |
|
768 | - } |
|
769 | - |
|
770 | - } else { |
|
771 | - if ($permissions !== null) { |
|
772 | - $permissions = (int)$permissions; |
|
773 | - $share->setPermissions($permissions); |
|
774 | - } |
|
775 | - |
|
776 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
777 | - if ($password === '') { |
|
778 | - $share->setPassword(null); |
|
779 | - } else if ($password !== null) { |
|
780 | - $share->setPassword($password); |
|
781 | - } |
|
782 | - } |
|
783 | - |
|
784 | - if ($expireDate === '') { |
|
785 | - $share->setExpirationDate(null); |
|
786 | - } else if ($expireDate !== null) { |
|
787 | - try { |
|
788 | - $expireDate = $this->parseDate($expireDate); |
|
789 | - } catch (\Exception $e) { |
|
790 | - throw new OCSBadRequestException($e->getMessage(), $e); |
|
791 | - } |
|
792 | - $share->setExpirationDate($expireDate); |
|
793 | - } |
|
794 | - |
|
795 | - } |
|
796 | - |
|
797 | - if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) { |
|
798 | - /* Check if this is an incomming share */ |
|
799 | - $incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0); |
|
800 | - $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0)); |
|
801 | - |
|
802 | - /** @var \OCP\Share\IShare[] $incomingShares */ |
|
803 | - if (!empty($incomingShares)) { |
|
804 | - $maxPermissions = 0; |
|
805 | - foreach ($incomingShares as $incomingShare) { |
|
806 | - $maxPermissions |= $incomingShare->getPermissions(); |
|
807 | - } |
|
808 | - |
|
809 | - if ($share->getPermissions() & ~$maxPermissions) { |
|
810 | - throw new OCSNotFoundException($this->l->t('Cannot increase permissions')); |
|
811 | - } |
|
812 | - } |
|
813 | - } |
|
814 | - |
|
815 | - |
|
816 | - try { |
|
817 | - $share = $this->shareManager->updateShare($share); |
|
818 | - } catch (\Exception $e) { |
|
819 | - throw new OCSBadRequestException($e->getMessage(), $e); |
|
820 | - } |
|
821 | - |
|
822 | - return new DataResponse($this->formatShare($share)); |
|
823 | - } |
|
824 | - |
|
825 | - /** |
|
826 | - * @param \OCP\Share\IShare $share |
|
827 | - * @return bool |
|
828 | - */ |
|
829 | - protected function canAccessShare(\OCP\Share\IShare $share, $checkGroups = true) { |
|
830 | - // A file with permissions 0 can't be accessed by us. So Don't show it |
|
831 | - if ($share->getPermissions() === 0) { |
|
832 | - return false; |
|
833 | - } |
|
834 | - |
|
835 | - // Owner of the file and the sharer of the file can always get share |
|
836 | - if ($share->getShareOwner() === $this->currentUser || |
|
837 | - $share->getSharedBy() === $this->currentUser |
|
838 | - ) { |
|
839 | - return true; |
|
840 | - } |
|
841 | - |
|
842 | - // If the share is shared with you (or a group you are a member of) |
|
843 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
844 | - $share->getSharedWith() === $this->currentUser |
|
845 | - ) { |
|
846 | - return true; |
|
847 | - } |
|
848 | - |
|
849 | - if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
850 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
851 | - $user = $this->userManager->get($this->currentUser); |
|
852 | - if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) { |
|
853 | - return true; |
|
854 | - } |
|
855 | - } |
|
856 | - |
|
857 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
858 | - // TODO: have a sanity check like above? |
|
859 | - return true; |
|
860 | - } |
|
861 | - |
|
862 | - return false; |
|
863 | - } |
|
864 | - |
|
865 | - /** |
|
866 | - * Make sure that the passed date is valid ISO 8601 |
|
867 | - * So YYYY-MM-DD |
|
868 | - * If not throw an exception |
|
869 | - * |
|
870 | - * @param string $expireDate |
|
871 | - * |
|
872 | - * @throws \Exception |
|
873 | - * @return \DateTime |
|
874 | - */ |
|
875 | - private function parseDate($expireDate) { |
|
876 | - try { |
|
877 | - $date = new \DateTime($expireDate); |
|
878 | - } catch (\Exception $e) { |
|
879 | - throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
880 | - } |
|
881 | - |
|
882 | - if ($date === false) { |
|
883 | - throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
884 | - } |
|
885 | - |
|
886 | - $date->setTime(0, 0, 0); |
|
887 | - |
|
888 | - return $date; |
|
889 | - } |
|
890 | - |
|
891 | - /** |
|
892 | - * Since we have multiple providers but the OCS Share API v1 does |
|
893 | - * not support this we need to check all backends. |
|
894 | - * |
|
895 | - * @param string $id |
|
896 | - * @return \OCP\Share\IShare |
|
897 | - * @throws ShareNotFound |
|
898 | - */ |
|
899 | - private function getShareById($id) { |
|
900 | - $share = null; |
|
901 | - |
|
902 | - // First check if it is an internal share. |
|
903 | - try { |
|
904 | - $share = $this->shareManager->getShareById('ocinternal:' . $id); |
|
905 | - return $share; |
|
906 | - } catch (ShareNotFound $e) { |
|
907 | - // Do nothing, just try the other share type |
|
908 | - } |
|
909 | - |
|
910 | - |
|
911 | - try { |
|
912 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
913 | - $share = $this->shareManager->getShareById('ocCircleShare:' . $id); |
|
914 | - return $share; |
|
915 | - } |
|
916 | - } catch (ShareNotFound $e) { |
|
917 | - // Do nothing, just try the other share type |
|
918 | - } |
|
919 | - |
|
920 | - try { |
|
921 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
922 | - $share = $this->shareManager->getShareById('ocMailShare:' . $id); |
|
923 | - return $share; |
|
924 | - } |
|
925 | - } catch (ShareNotFound $e) { |
|
926 | - // Do nothing, just try the other share type |
|
927 | - } |
|
928 | - |
|
929 | - if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
930 | - throw new ShareNotFound(); |
|
931 | - } |
|
932 | - $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id); |
|
933 | - |
|
934 | - return $share; |
|
935 | - } |
|
936 | - |
|
937 | - /** |
|
938 | - * Lock a Node |
|
939 | - * |
|
940 | - * @param \OCP\Files\Node $node |
|
941 | - */ |
|
942 | - private function lock(\OCP\Files\Node $node) { |
|
943 | - $node->lock(ILockingProvider::LOCK_SHARED); |
|
944 | - $this->lockedNode = $node; |
|
945 | - } |
|
946 | - |
|
947 | - /** |
|
948 | - * Cleanup the remaining locks |
|
949 | - */ |
|
950 | - public function cleanup() { |
|
951 | - if ($this->lockedNode !== null) { |
|
952 | - $this->lockedNode->unlock(ILockingProvider::LOCK_SHARED); |
|
953 | - } |
|
954 | - } |
|
704 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
705 | + |
|
706 | + $newPermissions = null; |
|
707 | + if ($publicUpload === 'true') { |
|
708 | + $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; |
|
709 | + } else if ($publicUpload === 'false') { |
|
710 | + $newPermissions = Constants::PERMISSION_READ; |
|
711 | + } |
|
712 | + |
|
713 | + if ($permissions !== null) { |
|
714 | + $newPermissions = (int)$permissions; |
|
715 | + $newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE; |
|
716 | + } |
|
717 | + |
|
718 | + if ($newPermissions !== null && |
|
719 | + !in_array($newPermissions, [ |
|
720 | + Constants::PERMISSION_READ, |
|
721 | + Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, // legacy |
|
722 | + Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, // correct |
|
723 | + Constants::PERMISSION_CREATE, // hidden file list |
|
724 | + Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE, // allow to edit single files |
|
725 | + ]) |
|
726 | + ) { |
|
727 | + throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links')); |
|
728 | + } |
|
729 | + |
|
730 | + if ( |
|
731 | + // legacy |
|
732 | + $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE) || |
|
733 | + // correct |
|
734 | + $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
735 | + ) { |
|
736 | + if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
737 | + throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
738 | + } |
|
739 | + |
|
740 | + if (!($share->getNode() instanceof \OCP\Files\Folder)) { |
|
741 | + throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
742 | + } |
|
743 | + |
|
744 | + // normalize to correct public upload permissions |
|
745 | + $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; |
|
746 | + } |
|
747 | + |
|
748 | + if ($newPermissions !== null) { |
|
749 | + $share->setPermissions($newPermissions); |
|
750 | + $permissions = $newPermissions; |
|
751 | + } |
|
752 | + |
|
753 | + if ($expireDate === '') { |
|
754 | + $share->setExpirationDate(null); |
|
755 | + } else if ($expireDate !== null) { |
|
756 | + try { |
|
757 | + $expireDate = $this->parseDate($expireDate); |
|
758 | + } catch (\Exception $e) { |
|
759 | + throw new OCSBadRequestException($e->getMessage(), $e); |
|
760 | + } |
|
761 | + $share->setExpirationDate($expireDate); |
|
762 | + } |
|
763 | + |
|
764 | + if ($password === '') { |
|
765 | + $share->setPassword(null); |
|
766 | + } else if ($password !== null) { |
|
767 | + $share->setPassword($password); |
|
768 | + } |
|
769 | + |
|
770 | + } else { |
|
771 | + if ($permissions !== null) { |
|
772 | + $permissions = (int)$permissions; |
|
773 | + $share->setPermissions($permissions); |
|
774 | + } |
|
775 | + |
|
776 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
777 | + if ($password === '') { |
|
778 | + $share->setPassword(null); |
|
779 | + } else if ($password !== null) { |
|
780 | + $share->setPassword($password); |
|
781 | + } |
|
782 | + } |
|
783 | + |
|
784 | + if ($expireDate === '') { |
|
785 | + $share->setExpirationDate(null); |
|
786 | + } else if ($expireDate !== null) { |
|
787 | + try { |
|
788 | + $expireDate = $this->parseDate($expireDate); |
|
789 | + } catch (\Exception $e) { |
|
790 | + throw new OCSBadRequestException($e->getMessage(), $e); |
|
791 | + } |
|
792 | + $share->setExpirationDate($expireDate); |
|
793 | + } |
|
794 | + |
|
795 | + } |
|
796 | + |
|
797 | + if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) { |
|
798 | + /* Check if this is an incomming share */ |
|
799 | + $incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0); |
|
800 | + $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0)); |
|
801 | + |
|
802 | + /** @var \OCP\Share\IShare[] $incomingShares */ |
|
803 | + if (!empty($incomingShares)) { |
|
804 | + $maxPermissions = 0; |
|
805 | + foreach ($incomingShares as $incomingShare) { |
|
806 | + $maxPermissions |= $incomingShare->getPermissions(); |
|
807 | + } |
|
808 | + |
|
809 | + if ($share->getPermissions() & ~$maxPermissions) { |
|
810 | + throw new OCSNotFoundException($this->l->t('Cannot increase permissions')); |
|
811 | + } |
|
812 | + } |
|
813 | + } |
|
814 | + |
|
815 | + |
|
816 | + try { |
|
817 | + $share = $this->shareManager->updateShare($share); |
|
818 | + } catch (\Exception $e) { |
|
819 | + throw new OCSBadRequestException($e->getMessage(), $e); |
|
820 | + } |
|
821 | + |
|
822 | + return new DataResponse($this->formatShare($share)); |
|
823 | + } |
|
824 | + |
|
825 | + /** |
|
826 | + * @param \OCP\Share\IShare $share |
|
827 | + * @return bool |
|
828 | + */ |
|
829 | + protected function canAccessShare(\OCP\Share\IShare $share, $checkGroups = true) { |
|
830 | + // A file with permissions 0 can't be accessed by us. So Don't show it |
|
831 | + if ($share->getPermissions() === 0) { |
|
832 | + return false; |
|
833 | + } |
|
834 | + |
|
835 | + // Owner of the file and the sharer of the file can always get share |
|
836 | + if ($share->getShareOwner() === $this->currentUser || |
|
837 | + $share->getSharedBy() === $this->currentUser |
|
838 | + ) { |
|
839 | + return true; |
|
840 | + } |
|
841 | + |
|
842 | + // If the share is shared with you (or a group you are a member of) |
|
843 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
844 | + $share->getSharedWith() === $this->currentUser |
|
845 | + ) { |
|
846 | + return true; |
|
847 | + } |
|
848 | + |
|
849 | + if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
850 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
851 | + $user = $this->userManager->get($this->currentUser); |
|
852 | + if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) { |
|
853 | + return true; |
|
854 | + } |
|
855 | + } |
|
856 | + |
|
857 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
858 | + // TODO: have a sanity check like above? |
|
859 | + return true; |
|
860 | + } |
|
861 | + |
|
862 | + return false; |
|
863 | + } |
|
864 | + |
|
865 | + /** |
|
866 | + * Make sure that the passed date is valid ISO 8601 |
|
867 | + * So YYYY-MM-DD |
|
868 | + * If not throw an exception |
|
869 | + * |
|
870 | + * @param string $expireDate |
|
871 | + * |
|
872 | + * @throws \Exception |
|
873 | + * @return \DateTime |
|
874 | + */ |
|
875 | + private function parseDate($expireDate) { |
|
876 | + try { |
|
877 | + $date = new \DateTime($expireDate); |
|
878 | + } catch (\Exception $e) { |
|
879 | + throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
880 | + } |
|
881 | + |
|
882 | + if ($date === false) { |
|
883 | + throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
884 | + } |
|
885 | + |
|
886 | + $date->setTime(0, 0, 0); |
|
887 | + |
|
888 | + return $date; |
|
889 | + } |
|
890 | + |
|
891 | + /** |
|
892 | + * Since we have multiple providers but the OCS Share API v1 does |
|
893 | + * not support this we need to check all backends. |
|
894 | + * |
|
895 | + * @param string $id |
|
896 | + * @return \OCP\Share\IShare |
|
897 | + * @throws ShareNotFound |
|
898 | + */ |
|
899 | + private function getShareById($id) { |
|
900 | + $share = null; |
|
901 | + |
|
902 | + // First check if it is an internal share. |
|
903 | + try { |
|
904 | + $share = $this->shareManager->getShareById('ocinternal:' . $id); |
|
905 | + return $share; |
|
906 | + } catch (ShareNotFound $e) { |
|
907 | + // Do nothing, just try the other share type |
|
908 | + } |
|
909 | + |
|
910 | + |
|
911 | + try { |
|
912 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
913 | + $share = $this->shareManager->getShareById('ocCircleShare:' . $id); |
|
914 | + return $share; |
|
915 | + } |
|
916 | + } catch (ShareNotFound $e) { |
|
917 | + // Do nothing, just try the other share type |
|
918 | + } |
|
919 | + |
|
920 | + try { |
|
921 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
922 | + $share = $this->shareManager->getShareById('ocMailShare:' . $id); |
|
923 | + return $share; |
|
924 | + } |
|
925 | + } catch (ShareNotFound $e) { |
|
926 | + // Do nothing, just try the other share type |
|
927 | + } |
|
928 | + |
|
929 | + if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
930 | + throw new ShareNotFound(); |
|
931 | + } |
|
932 | + $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id); |
|
933 | + |
|
934 | + return $share; |
|
935 | + } |
|
936 | + |
|
937 | + /** |
|
938 | + * Lock a Node |
|
939 | + * |
|
940 | + * @param \OCP\Files\Node $node |
|
941 | + */ |
|
942 | + private function lock(\OCP\Files\Node $node) { |
|
943 | + $node->lock(ILockingProvider::LOCK_SHARED); |
|
944 | + $this->lockedNode = $node; |
|
945 | + } |
|
946 | + |
|
947 | + /** |
|
948 | + * Cleanup the remaining locks |
|
949 | + */ |
|
950 | + public function cleanup() { |
|
951 | + if ($this->lockedNode !== null) { |
|
952 | + $this->lockedNode->unlock(ILockingProvider::LOCK_SHARED); |
|
953 | + } |
|
954 | + } |
|
955 | 955 | } |
@@ -27,94 +27,94 @@ |
||
27 | 27 | ?> |
28 | 28 | |
29 | 29 | <div class="section" id="shareAPI"> |
30 | - <h2><?php p($l->t('Sharing'));?></h2> |
|
30 | + <h2><?php p($l->t('Sharing')); ?></h2> |
|
31 | 31 | <a target="_blank" rel="noreferrer noopener" class="icon-info" |
32 | - title="<?php p($l->t('Open documentation'));?>" |
|
32 | + title="<?php p($l->t('Open documentation')); ?>" |
|
33 | 33 | href="<?php p(link_to_docs('admin-sharing')); ?>"></a> |
34 | - <p class="settings-hint"><?php p($l->t('As admin you can fine-tune the sharing behavior. Please see the documentation for more information.'));?></p> |
|
34 | + <p class="settings-hint"><?php p($l->t('As admin you can fine-tune the sharing behavior. Please see the documentation for more information.')); ?></p> |
|
35 | 35 | <p id="enable"> |
36 | 36 | <input type="checkbox" name="shareapi_enabled" id="shareAPIEnabled" class="checkbox" |
37 | 37 | value="1" <?php if ($_['shareAPIEnabled'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
38 | - <label for="shareAPIEnabled"><?php p($l->t('Allow apps to use the Share API'));?></label><br/> |
|
38 | + <label for="shareAPIEnabled"><?php p($l->t('Allow apps to use the Share API')); ?></label><br/> |
|
39 | 39 | </p> |
40 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
40 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
41 | 41 | <input type="checkbox" name="shareapi_allow_links" id="allowLinks" class="checkbox" |
42 | 42 | value="1" <?php if ($_['allowLinks'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
43 | - <label for="allowLinks"><?php p($l->t('Allow users to share via link'));?></label><br/> |
|
43 | + <label for="allowLinks"><?php p($l->t('Allow users to share via link')); ?></label><br/> |
|
44 | 44 | </p> |
45 | 45 | |
46 | 46 | <p id="publicLinkSettings" class="indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
47 | 47 | <input type="checkbox" name="shareapi_allow_public_upload" id="allowPublicUpload" class="checkbox" |
48 | 48 | value="1" <?php if ($_['allowPublicUpload'] == 'yes') print_unescaped('checked="checked"'); ?> /> |
49 | - <label for="allowPublicUpload"><?php p($l->t('Allow public uploads'));?></label><br/> |
|
49 | + <label for="allowPublicUpload"><?php p($l->t('Allow public uploads')); ?></label><br/> |
|
50 | 50 | <input type="checkbox" name="shareapi_enable_link_password_by_default" id="enableLinkPasswordByDefault" class="checkbox" |
51 | 51 | value="1" <?php if ($_['enableLinkPasswordByDefault'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
52 | - <label for="enableLinkPasswordByDefault"><?php p($l->t('Always ask for a password'));?></label><br/> |
|
52 | + <label for="enableLinkPasswordByDefault"><?php p($l->t('Always ask for a password')); ?></label><br/> |
|
53 | 53 | <input type="checkbox" name="shareapi_enforce_links_password" id="enforceLinkPassword" class="checkbox" |
54 | 54 | value="1" <?php if ($_['enforceLinkPassword']) print_unescaped('checked="checked"'); ?> /> |
55 | - <label for="enforceLinkPassword"><?php p($l->t('Enforce password protection'));?></label><br/> |
|
55 | + <label for="enforceLinkPassword"><?php p($l->t('Enforce password protection')); ?></label><br/> |
|
56 | 56 | |
57 | 57 | <input type="checkbox" name="shareapi_default_expire_date" id="shareapiDefaultExpireDate" class="checkbox" |
58 | 58 | value="1" <?php if ($_['shareDefaultExpireDateSet'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
59 | - <label for="shareapiDefaultExpireDate"><?php p($l->t('Set default expiration date'));?></label><br/> |
|
59 | + <label for="shareapiDefaultExpireDate"><?php p($l->t('Set default expiration date')); ?></label><br/> |
|
60 | 60 | |
61 | 61 | </p> |
62 | - <p id="setDefaultExpireDate" class="double-indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareDefaultExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
63 | - <?php p($l->t( 'Expire after ' )); ?> |
|
62 | + <p id="setDefaultExpireDate" class="double-indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareDefaultExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
63 | + <?php p($l->t('Expire after ')); ?> |
|
64 | 64 | <input type="text" name='shareapi_expire_after_n_days' id="shareapiExpireAfterNDays" placeholder="<?php p('7')?>" |
65 | 65 | value='<?php p($_['shareExpireAfterNDays']) ?>' /> |
66 | - <?php p($l->t( 'days' )); ?> |
|
66 | + <?php p($l->t('days')); ?> |
|
67 | 67 | <input type="checkbox" name="shareapi_enforce_expire_date" id="shareapiEnforceExpireDate" class="checkbox" |
68 | 68 | value="1" <?php if ($_['shareEnforceExpireDate'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
69 | - <label for="shareapiEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/> |
|
69 | + <label for="shareapiEnforceExpireDate"><?php p($l->t('Enforce expiration date')); ?></label><br/> |
|
70 | 70 | </p> |
71 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
71 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
72 | 72 | <input type="checkbox" name="shareapi_allow_resharing" id="allowResharing" class="checkbox" |
73 | 73 | value="1" <?php if ($_['allowResharing'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
74 | - <label for="allowResharing"><?php p($l->t('Allow resharing'));?></label><br/> |
|
74 | + <label for="allowResharing"><?php p($l->t('Allow resharing')); ?></label><br/> |
|
75 | 75 | </p> |
76 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
76 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
77 | 77 | <input type="checkbox" name="shareapi_allow_group_sharing" id="allowGroupSharing" class="checkbox" |
78 | 78 | value="1" <?php if ($_['allowGroupSharing'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
79 | - <label for="allowGroupSharing"><?php p($l->t('Allow sharing with groups'));?></label><br /> |
|
79 | + <label for="allowGroupSharing"><?php p($l->t('Allow sharing with groups')); ?></label><br /> |
|
80 | 80 | </p> |
81 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
81 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
82 | 82 | <input type="checkbox" name="shareapi_only_share_with_group_members" id="onlyShareWithGroupMembers" class="checkbox" |
83 | 83 | value="1" <?php if ($_['onlyShareWithGroupMembers']) print_unescaped('checked="checked"'); ?> /> |
84 | - <label for="onlyShareWithGroupMembers"><?php p($l->t('Restrict users to only share with users in their groups'));?></label><br/> |
|
84 | + <label for="onlyShareWithGroupMembers"><?php p($l->t('Restrict users to only share with users in their groups')); ?></label><br/> |
|
85 | 85 | </p> |
86 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
86 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
87 | 87 | <input type="checkbox" name="shareapi_exclude_groups" id="shareapiExcludeGroups" class="checkbox" |
88 | 88 | value="1" <?php if ($_['shareExcludeGroups']) print_unescaped('checked="checked"'); ?> /> |
89 | - <label for="shareapiExcludeGroups"><?php p($l->t('Exclude groups from sharing'));?></label><br/> |
|
89 | + <label for="shareapiExcludeGroups"><?php p($l->t('Exclude groups from sharing')); ?></label><br/> |
|
90 | 90 | </p> |
91 | 91 | <p id="selectExcludedGroups" class="indent <?php if (!$_['shareExcludeGroups'] || $_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
92 | 92 | <input name="shareapi_exclude_groups_list" type="hidden" id="excludedGroups" value="<?php p($_['shareExcludedGroupsList']) ?>" style="width: 400px" class="noJSAutoUpdate"/> |
93 | 93 | <br /> |
94 | 94 | <em><?php p($l->t('These groups will still be able to receive shares, but not to initiate them.')); ?></em> |
95 | 95 | </p> |
96 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
96 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
97 | 97 | <input type="checkbox" name="shareapi_allow_share_dialog_user_enumeration" value="1" id="shareapi_allow_share_dialog_user_enumeration" class="checkbox" |
98 | 98 | <?php if ($_['allowShareDialogUserEnumeration'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
99 | - <label for="shareapi_allow_share_dialog_user_enumeration"><?php p($l->t('Allow username autocompletion in share dialog. If this is disabled the full username or email address needs to be entered.'));?></label><br /> |
|
99 | + <label for="shareapi_allow_share_dialog_user_enumeration"><?php p($l->t('Allow username autocompletion in share dialog. If this is disabled the full username or email address needs to be entered.')); ?></label><br /> |
|
100 | 100 | </p> |
101 | 101 | <p> |
102 | 102 | <input type="checkbox" id="publicShareDisclaimer" class="checkbox noJSAutoUpdate" |
103 | 103 | <?php if ($_['publicShareDisclaimerText'] !== null) print_unescaped('checked="checked"'); ?> /> |
104 | - <label for="publicShareDisclaimer"><?php p($l->t('Show disclaimer text on the public link upload page. (Only shown when the file list is hidden.)'));?></label> |
|
104 | + <label for="publicShareDisclaimer"><?php p($l->t('Show disclaimer text on the public link upload page. (Only shown when the file list is hidden.)')); ?></label> |
|
105 | 105 | <span id="publicShareDisclaimerStatus" class="msg" style="display:none"></span> |
106 | 106 | <br/> |
107 | 107 | <textarea placeholder="<?php p($l->t('This text will be shown on the public link upload page when the file list is hidden.')) ?>" id="publicShareDisclaimerText" <?php if ($_['publicShareDisclaimerText'] === null) { print_unescaped('class="hidden"'); } ?>><?php p($_['publicShareDisclaimerText']) ?></textarea> |
108 | 108 | </p> |
109 | 109 | |
110 | - <h3><?php p($l->t('Default share permissions'));?></h3> |
|
110 | + <h3><?php p($l->t('Default share permissions')); ?></h3> |
|
111 | 111 | <input type="hidden" name="shareapi_default_permissions" id="shareApiDefaultPermissions" class="checkbox" |
112 | 112 | value="<?php p($_['shareApiDefaultPermissions']) ?>" /> |
113 | 113 | <p id="shareApiDefaultPermissionsSection" class="indent <?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
114 | 114 | <?php foreach ($_['shareApiDefaultPermissionsCheckboxes'] as $perm): ?> |
115 | 115 | <input type="checkbox" name="shareapi_default_permission_<?php p($perm['id']) ?>" id="shareapi_default_permission_<?php p($perm['id']) ?>" |
116 | 116 | class="noautosave checkbox" value="<?php p($perm['value']) ?>" <?php if (($_['shareApiDefaultPermissions'] & $perm['value']) !== 0) print_unescaped('checked="checked"'); ?> /> |
117 | - <label for="shareapi_default_permission_<?php p($perm['id']) ?>"><?php p($perm['label']);?></label> |
|
117 | + <label for="shareapi_default_permission_<?php p($perm['id']) ?>"><?php p($perm['label']); ?></label> |
|
118 | 118 | <?php endforeach ?> |
119 | 119 | </p> |
120 | 120 | </div> |
@@ -34,73 +34,139 @@ discard block |
||
34 | 34 | <p class="settings-hint"><?php p($l->t('As admin you can fine-tune the sharing behavior. Please see the documentation for more information.'));?></p> |
35 | 35 | <p id="enable"> |
36 | 36 | <input type="checkbox" name="shareapi_enabled" id="shareAPIEnabled" class="checkbox" |
37 | - value="1" <?php if ($_['shareAPIEnabled'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
37 | + value="1" <?php if ($_['shareAPIEnabled'] === 'yes') { |
|
38 | + print_unescaped('checked="checked"'); |
|
39 | +} |
|
40 | +?> /> |
|
38 | 41 | <label for="shareAPIEnabled"><?php p($l->t('Allow apps to use the Share API'));?></label><br/> |
39 | 42 | </p> |
40 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
43 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
|
44 | + p('hidden'); |
|
45 | +} |
|
46 | +?>"> |
|
41 | 47 | <input type="checkbox" name="shareapi_allow_links" id="allowLinks" class="checkbox" |
42 | - value="1" <?php if ($_['allowLinks'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
48 | + value="1" <?php if ($_['allowLinks'] === 'yes') { |
|
49 | + print_unescaped('checked="checked"'); |
|
50 | +} |
|
51 | +?> /> |
|
43 | 52 | <label for="allowLinks"><?php p($l->t('Allow users to share via link'));?></label><br/> |
44 | 53 | </p> |
45 | 54 | |
46 | - <p id="publicLinkSettings" class="indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
55 | + <p id="publicLinkSettings" class="indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareAPIEnabled'] === 'no') { |
|
56 | + p('hidden'); |
|
57 | +} |
|
58 | +?>"> |
|
47 | 59 | <input type="checkbox" name="shareapi_allow_public_upload" id="allowPublicUpload" class="checkbox" |
48 | - value="1" <?php if ($_['allowPublicUpload'] == 'yes') print_unescaped('checked="checked"'); ?> /> |
|
60 | + value="1" <?php if ($_['allowPublicUpload'] == 'yes') { |
|
61 | + print_unescaped('checked="checked"'); |
|
62 | +} |
|
63 | +?> /> |
|
49 | 64 | <label for="allowPublicUpload"><?php p($l->t('Allow public uploads'));?></label><br/> |
50 | 65 | <input type="checkbox" name="shareapi_enable_link_password_by_default" id="enableLinkPasswordByDefault" class="checkbox" |
51 | - value="1" <?php if ($_['enableLinkPasswordByDefault'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
66 | + value="1" <?php if ($_['enableLinkPasswordByDefault'] === 'yes') { |
|
67 | + print_unescaped('checked="checked"'); |
|
68 | +} |
|
69 | +?> /> |
|
52 | 70 | <label for="enableLinkPasswordByDefault"><?php p($l->t('Always ask for a password'));?></label><br/> |
53 | 71 | <input type="checkbox" name="shareapi_enforce_links_password" id="enforceLinkPassword" class="checkbox" |
54 | - value="1" <?php if ($_['enforceLinkPassword']) print_unescaped('checked="checked"'); ?> /> |
|
72 | + value="1" <?php if ($_['enforceLinkPassword']) { |
|
73 | + print_unescaped('checked="checked"'); |
|
74 | +} |
|
75 | +?> /> |
|
55 | 76 | <label for="enforceLinkPassword"><?php p($l->t('Enforce password protection'));?></label><br/> |
56 | 77 | |
57 | 78 | <input type="checkbox" name="shareapi_default_expire_date" id="shareapiDefaultExpireDate" class="checkbox" |
58 | - value="1" <?php if ($_['shareDefaultExpireDateSet'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
79 | + value="1" <?php if ($_['shareDefaultExpireDateSet'] === 'yes') { |
|
80 | + print_unescaped('checked="checked"'); |
|
81 | +} |
|
82 | +?> /> |
|
59 | 83 | <label for="shareapiDefaultExpireDate"><?php p($l->t('Set default expiration date'));?></label><br/> |
60 | 84 | |
61 | 85 | </p> |
62 | - <p id="setDefaultExpireDate" class="double-indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareDefaultExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
86 | + <p id="setDefaultExpireDate" class="double-indent <?php if ($_['allowLinks'] !== 'yes' || $_['shareDefaultExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') { |
|
87 | + p('hidden'); |
|
88 | +} |
|
89 | +?>"> |
|
63 | 90 | <?php p($l->t( 'Expire after ' )); ?> |
64 | 91 | <input type="text" name='shareapi_expire_after_n_days' id="shareapiExpireAfterNDays" placeholder="<?php p('7')?>" |
65 | 92 | value='<?php p($_['shareExpireAfterNDays']) ?>' /> |
66 | 93 | <?php p($l->t( 'days' )); ?> |
67 | 94 | <input type="checkbox" name="shareapi_enforce_expire_date" id="shareapiEnforceExpireDate" class="checkbox" |
68 | - value="1" <?php if ($_['shareEnforceExpireDate'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
95 | + value="1" <?php if ($_['shareEnforceExpireDate'] === 'yes') { |
|
96 | + print_unescaped('checked="checked"'); |
|
97 | +} |
|
98 | +?> /> |
|
69 | 99 | <label for="shareapiEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/> |
70 | 100 | </p> |
71 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
101 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
|
102 | + p('hidden'); |
|
103 | +} |
|
104 | +?>"> |
|
72 | 105 | <input type="checkbox" name="shareapi_allow_resharing" id="allowResharing" class="checkbox" |
73 | - value="1" <?php if ($_['allowResharing'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
106 | + value="1" <?php if ($_['allowResharing'] === 'yes') { |
|
107 | + print_unescaped('checked="checked"'); |
|
108 | +} |
|
109 | +?> /> |
|
74 | 110 | <label for="allowResharing"><?php p($l->t('Allow resharing'));?></label><br/> |
75 | 111 | </p> |
76 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
112 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
|
113 | + p('hidden'); |
|
114 | +} |
|
115 | +?>"> |
|
77 | 116 | <input type="checkbox" name="shareapi_allow_group_sharing" id="allowGroupSharing" class="checkbox" |
78 | - value="1" <?php if ($_['allowGroupSharing'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
117 | + value="1" <?php if ($_['allowGroupSharing'] === 'yes') { |
|
118 | + print_unescaped('checked="checked"'); |
|
119 | +} |
|
120 | +?> /> |
|
79 | 121 | <label for="allowGroupSharing"><?php p($l->t('Allow sharing with groups'));?></label><br /> |
80 | 122 | </p> |
81 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
123 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
|
124 | + p('hidden'); |
|
125 | +} |
|
126 | +?>"> |
|
82 | 127 | <input type="checkbox" name="shareapi_only_share_with_group_members" id="onlyShareWithGroupMembers" class="checkbox" |
83 | - value="1" <?php if ($_['onlyShareWithGroupMembers']) print_unescaped('checked="checked"'); ?> /> |
|
128 | + value="1" <?php if ($_['onlyShareWithGroupMembers']) { |
|
129 | + print_unescaped('checked="checked"'); |
|
130 | +} |
|
131 | +?> /> |
|
84 | 132 | <label for="onlyShareWithGroupMembers"><?php p($l->t('Restrict users to only share with users in their groups'));?></label><br/> |
85 | 133 | </p> |
86 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
134 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
|
135 | + p('hidden'); |
|
136 | +} |
|
137 | +?>"> |
|
87 | 138 | <input type="checkbox" name="shareapi_exclude_groups" id="shareapiExcludeGroups" class="checkbox" |
88 | - value="1" <?php if ($_['shareExcludeGroups']) print_unescaped('checked="checked"'); ?> /> |
|
139 | + value="1" <?php if ($_['shareExcludeGroups']) { |
|
140 | + print_unescaped('checked="checked"'); |
|
141 | +} |
|
142 | +?> /> |
|
89 | 143 | <label for="shareapiExcludeGroups"><?php p($l->t('Exclude groups from sharing'));?></label><br/> |
90 | 144 | </p> |
91 | - <p id="selectExcludedGroups" class="indent <?php if (!$_['shareExcludeGroups'] || $_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
145 | + <p id="selectExcludedGroups" class="indent <?php if (!$_['shareExcludeGroups'] || $_['shareAPIEnabled'] === 'no') { |
|
146 | + p('hidden'); |
|
147 | +} |
|
148 | +?>"> |
|
92 | 149 | <input name="shareapi_exclude_groups_list" type="hidden" id="excludedGroups" value="<?php p($_['shareExcludedGroupsList']) ?>" style="width: 400px" class="noJSAutoUpdate"/> |
93 | 150 | <br /> |
94 | 151 | <em><?php p($l->t('These groups will still be able to receive shares, but not to initiate them.')); ?></em> |
95 | 152 | </p> |
96 | - <p class="<?php if ($_['shareAPIEnabled'] === 'no') p('hidden');?>"> |
|
153 | + <p class="<?php if ($_['shareAPIEnabled'] === 'no') { |
|
154 | + p('hidden'); |
|
155 | +} |
|
156 | +?>"> |
|
97 | 157 | <input type="checkbox" name="shareapi_allow_share_dialog_user_enumeration" value="1" id="shareapi_allow_share_dialog_user_enumeration" class="checkbox" |
98 | - <?php if ($_['allowShareDialogUserEnumeration'] === 'yes') print_unescaped('checked="checked"'); ?> /> |
|
158 | + <?php if ($_['allowShareDialogUserEnumeration'] === 'yes') { |
|
159 | + print_unescaped('checked="checked"'); |
|
160 | +} |
|
161 | +?> /> |
|
99 | 162 | <label for="shareapi_allow_share_dialog_user_enumeration"><?php p($l->t('Allow username autocompletion in share dialog. If this is disabled the full username or email address needs to be entered.'));?></label><br /> |
100 | 163 | </p> |
101 | 164 | <p> |
102 | 165 | <input type="checkbox" id="publicShareDisclaimer" class="checkbox noJSAutoUpdate" |
103 | - <?php if ($_['publicShareDisclaimerText'] !== null) print_unescaped('checked="checked"'); ?> /> |
|
166 | + <?php if ($_['publicShareDisclaimerText'] !== null) { |
|
167 | + print_unescaped('checked="checked"'); |
|
168 | +} |
|
169 | +?> /> |
|
104 | 170 | <label for="publicShareDisclaimer"><?php p($l->t('Show disclaimer text on the public link upload page. (Only shown when the file list is hidden.)'));?></label> |
105 | 171 | <span id="publicShareDisclaimerStatus" class="msg" style="display:none"></span> |
106 | 172 | <br/> |
@@ -110,10 +176,16 @@ discard block |
||
110 | 176 | <h3><?php p($l->t('Default share permissions'));?></h3> |
111 | 177 | <input type="hidden" name="shareapi_default_permissions" id="shareApiDefaultPermissions" class="checkbox" |
112 | 178 | value="<?php p($_['shareApiDefaultPermissions']) ?>" /> |
113 | - <p id="shareApiDefaultPermissionsSection" class="indent <?php if ($_['shareAPIEnabled'] === 'no') p('hidden'); ?>"> |
|
179 | + <p id="shareApiDefaultPermissionsSection" class="indent <?php if ($_['shareAPIEnabled'] === 'no') { |
|
180 | + p('hidden'); |
|
181 | +} |
|
182 | +?>"> |
|
114 | 183 | <?php foreach ($_['shareApiDefaultPermissionsCheckboxes'] as $perm): ?> |
115 | 184 | <input type="checkbox" name="shareapi_default_permission_<?php p($perm['id']) ?>" id="shareapi_default_permission_<?php p($perm['id']) ?>" |
116 | - class="noautosave checkbox" value="<?php p($perm['value']) ?>" <?php if (($_['shareApiDefaultPermissions'] & $perm['value']) !== 0) print_unescaped('checked="checked"'); ?> /> |
|
185 | + class="noautosave checkbox" value="<?php p($perm['value']) ?>" <?php if (($_['shareApiDefaultPermissions'] & $perm['value']) !== 0) { |
|
186 | + print_unescaped('checked="checked"'); |
|
187 | +} |
|
188 | +?> /> |
|
117 | 189 | <label for="shareapi_default_permission_<?php p($perm['id']) ?>"><?php p($perm['label']);?></label> |
118 | 190 | <?php endforeach ?> |
119 | 191 | </p> |
@@ -43,62 +43,62 @@ |
||
43 | 43 | |
44 | 44 | class OCJSController extends Controller { |
45 | 45 | |
46 | - /** @var JSConfigHelper */ |
|
47 | - private $helper; |
|
46 | + /** @var JSConfigHelper */ |
|
47 | + private $helper; |
|
48 | 48 | |
49 | - /** |
|
50 | - * OCJSController constructor. |
|
51 | - * |
|
52 | - * @param string $appName |
|
53 | - * @param IRequest $request |
|
54 | - * @param IFactory $l10nFactory |
|
55 | - * @param Defaults $defaults |
|
56 | - * @param IAppManager $appManager |
|
57 | - * @param ISession $session |
|
58 | - * @param IUserSession $userSession |
|
59 | - * @param IConfig $config |
|
60 | - * @param IGroupManager $groupManager |
|
61 | - * @param IniGetWrapper $iniWrapper |
|
62 | - * @param IURLGenerator $urlGenerator |
|
63 | - * @param CapabilitiesManager $capabilitiesManager |
|
64 | - */ |
|
65 | - public function __construct($appName, |
|
66 | - IRequest $request, |
|
67 | - IFactory $l10nFactory, |
|
68 | - Defaults $defaults, |
|
69 | - IAppManager $appManager, |
|
70 | - ISession $session, |
|
71 | - IUserSession $userSession, |
|
72 | - IConfig $config, |
|
73 | - IGroupManager $groupManager, |
|
74 | - IniGetWrapper $iniWrapper, |
|
75 | - IURLGenerator $urlGenerator, |
|
76 | - CapabilitiesManager $capabilitiesManager) { |
|
77 | - parent::__construct($appName, $request); |
|
49 | + /** |
|
50 | + * OCJSController constructor. |
|
51 | + * |
|
52 | + * @param string $appName |
|
53 | + * @param IRequest $request |
|
54 | + * @param IFactory $l10nFactory |
|
55 | + * @param Defaults $defaults |
|
56 | + * @param IAppManager $appManager |
|
57 | + * @param ISession $session |
|
58 | + * @param IUserSession $userSession |
|
59 | + * @param IConfig $config |
|
60 | + * @param IGroupManager $groupManager |
|
61 | + * @param IniGetWrapper $iniWrapper |
|
62 | + * @param IURLGenerator $urlGenerator |
|
63 | + * @param CapabilitiesManager $capabilitiesManager |
|
64 | + */ |
|
65 | + public function __construct($appName, |
|
66 | + IRequest $request, |
|
67 | + IFactory $l10nFactory, |
|
68 | + Defaults $defaults, |
|
69 | + IAppManager $appManager, |
|
70 | + ISession $session, |
|
71 | + IUserSession $userSession, |
|
72 | + IConfig $config, |
|
73 | + IGroupManager $groupManager, |
|
74 | + IniGetWrapper $iniWrapper, |
|
75 | + IURLGenerator $urlGenerator, |
|
76 | + CapabilitiesManager $capabilitiesManager) { |
|
77 | + parent::__construct($appName, $request); |
|
78 | 78 | |
79 | - $this->helper = new JSConfigHelper( |
|
80 | - $l10nFactory->get('lib'), |
|
81 | - $defaults, |
|
82 | - $appManager, |
|
83 | - $session, |
|
84 | - $userSession->getUser(), |
|
85 | - $config, |
|
86 | - $groupManager, |
|
87 | - $iniWrapper, |
|
88 | - $urlGenerator, |
|
89 | - $capabilitiesManager |
|
90 | - ); |
|
91 | - } |
|
79 | + $this->helper = new JSConfigHelper( |
|
80 | + $l10nFactory->get('lib'), |
|
81 | + $defaults, |
|
82 | + $appManager, |
|
83 | + $session, |
|
84 | + $userSession->getUser(), |
|
85 | + $config, |
|
86 | + $groupManager, |
|
87 | + $iniWrapper, |
|
88 | + $urlGenerator, |
|
89 | + $capabilitiesManager |
|
90 | + ); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @NoCSRFRequired |
|
95 | - * @PublicPage |
|
96 | - * |
|
97 | - * @return DataDisplayResponse |
|
98 | - */ |
|
99 | - public function getConfig() { |
|
100 | - $data = $this->helper->getConfig(); |
|
93 | + /** |
|
94 | + * @NoCSRFRequired |
|
95 | + * @PublicPage |
|
96 | + * |
|
97 | + * @return DataDisplayResponse |
|
98 | + */ |
|
99 | + public function getConfig() { |
|
100 | + $data = $this->helper->getConfig(); |
|
101 | 101 | |
102 | - return new DataDisplayResponse($data, Http::STATUS_OK, ['Content-type' => 'text/javascript']); |
|
103 | - } |
|
102 | + return new DataDisplayResponse($data, Http::STATUS_OK, ['Content-type' => 'text/javascript']); |
|
103 | + } |
|
104 | 104 | } |
@@ -40,249 +40,249 @@ |
||
40 | 40 | |
41 | 41 | class JSConfigHelper { |
42 | 42 | |
43 | - /** @var IL10N */ |
|
44 | - private $l; |
|
43 | + /** @var IL10N */ |
|
44 | + private $l; |
|
45 | 45 | |
46 | - /** @var Defaults */ |
|
47 | - private $defaults; |
|
46 | + /** @var Defaults */ |
|
47 | + private $defaults; |
|
48 | 48 | |
49 | - /** @var IAppManager */ |
|
50 | - private $appManager; |
|
49 | + /** @var IAppManager */ |
|
50 | + private $appManager; |
|
51 | 51 | |
52 | - /** @var ISession */ |
|
53 | - private $session; |
|
52 | + /** @var ISession */ |
|
53 | + private $session; |
|
54 | 54 | |
55 | - /** @var IUser|null */ |
|
56 | - private $currentUser; |
|
55 | + /** @var IUser|null */ |
|
56 | + private $currentUser; |
|
57 | 57 | |
58 | - /** @var IConfig */ |
|
59 | - private $config; |
|
58 | + /** @var IConfig */ |
|
59 | + private $config; |
|
60 | 60 | |
61 | - /** @var IGroupManager */ |
|
62 | - private $groupManager; |
|
61 | + /** @var IGroupManager */ |
|
62 | + private $groupManager; |
|
63 | 63 | |
64 | - /** @var IniGetWrapper */ |
|
65 | - private $iniWrapper; |
|
64 | + /** @var IniGetWrapper */ |
|
65 | + private $iniWrapper; |
|
66 | 66 | |
67 | - /** @var IURLGenerator */ |
|
68 | - private $urlGenerator; |
|
67 | + /** @var IURLGenerator */ |
|
68 | + private $urlGenerator; |
|
69 | 69 | |
70 | - /** @var CapabilitiesManager */ |
|
71 | - private $capabilitiesManager; |
|
70 | + /** @var CapabilitiesManager */ |
|
71 | + private $capabilitiesManager; |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param IL10N $l |
|
75 | - * @param Defaults $defaults |
|
76 | - * @param IAppManager $appManager |
|
77 | - * @param ISession $session |
|
78 | - * @param IUser|null $currentUser |
|
79 | - * @param IConfig $config |
|
80 | - * @param IGroupManager $groupManager |
|
81 | - * @param IniGetWrapper $iniWrapper |
|
82 | - * @param IURLGenerator $urlGenerator |
|
83 | - * @param CapabilitiesManager $capabilitiesManager |
|
84 | - */ |
|
85 | - public function __construct(IL10N $l, |
|
86 | - Defaults $defaults, |
|
87 | - IAppManager $appManager, |
|
88 | - ISession $session, |
|
89 | - $currentUser, |
|
90 | - IConfig $config, |
|
91 | - IGroupManager $groupManager, |
|
92 | - IniGetWrapper $iniWrapper, |
|
93 | - IURLGenerator $urlGenerator, |
|
94 | - CapabilitiesManager $capabilitiesManager) { |
|
95 | - $this->l = $l; |
|
96 | - $this->defaults = $defaults; |
|
97 | - $this->appManager = $appManager; |
|
98 | - $this->session = $session; |
|
99 | - $this->currentUser = $currentUser; |
|
100 | - $this->config = $config; |
|
101 | - $this->groupManager = $groupManager; |
|
102 | - $this->iniWrapper = $iniWrapper; |
|
103 | - $this->urlGenerator = $urlGenerator; |
|
104 | - $this->capabilitiesManager = $capabilitiesManager; |
|
105 | - } |
|
73 | + /** |
|
74 | + * @param IL10N $l |
|
75 | + * @param Defaults $defaults |
|
76 | + * @param IAppManager $appManager |
|
77 | + * @param ISession $session |
|
78 | + * @param IUser|null $currentUser |
|
79 | + * @param IConfig $config |
|
80 | + * @param IGroupManager $groupManager |
|
81 | + * @param IniGetWrapper $iniWrapper |
|
82 | + * @param IURLGenerator $urlGenerator |
|
83 | + * @param CapabilitiesManager $capabilitiesManager |
|
84 | + */ |
|
85 | + public function __construct(IL10N $l, |
|
86 | + Defaults $defaults, |
|
87 | + IAppManager $appManager, |
|
88 | + ISession $session, |
|
89 | + $currentUser, |
|
90 | + IConfig $config, |
|
91 | + IGroupManager $groupManager, |
|
92 | + IniGetWrapper $iniWrapper, |
|
93 | + IURLGenerator $urlGenerator, |
|
94 | + CapabilitiesManager $capabilitiesManager) { |
|
95 | + $this->l = $l; |
|
96 | + $this->defaults = $defaults; |
|
97 | + $this->appManager = $appManager; |
|
98 | + $this->session = $session; |
|
99 | + $this->currentUser = $currentUser; |
|
100 | + $this->config = $config; |
|
101 | + $this->groupManager = $groupManager; |
|
102 | + $this->iniWrapper = $iniWrapper; |
|
103 | + $this->urlGenerator = $urlGenerator; |
|
104 | + $this->capabilitiesManager = $capabilitiesManager; |
|
105 | + } |
|
106 | 106 | |
107 | - public function getConfig() { |
|
107 | + public function getConfig() { |
|
108 | 108 | |
109 | - if ($this->currentUser !== null) { |
|
110 | - $uid = $this->currentUser->getUID(); |
|
111 | - $userBackend = $this->currentUser->getBackendClassName(); |
|
112 | - } else { |
|
113 | - $uid = null; |
|
114 | - $userBackend = ''; |
|
115 | - } |
|
109 | + if ($this->currentUser !== null) { |
|
110 | + $uid = $this->currentUser->getUID(); |
|
111 | + $userBackend = $this->currentUser->getBackendClassName(); |
|
112 | + } else { |
|
113 | + $uid = null; |
|
114 | + $userBackend = ''; |
|
115 | + } |
|
116 | 116 | |
117 | - // Get the config |
|
118 | - $apps_paths = []; |
|
117 | + // Get the config |
|
118 | + $apps_paths = []; |
|
119 | 119 | |
120 | - if ($this->currentUser === null) { |
|
121 | - $apps = $this->appManager->getInstalledApps(); |
|
122 | - } else { |
|
123 | - $apps = $this->appManager->getEnabledAppsForUser($this->currentUser); |
|
124 | - } |
|
120 | + if ($this->currentUser === null) { |
|
121 | + $apps = $this->appManager->getInstalledApps(); |
|
122 | + } else { |
|
123 | + $apps = $this->appManager->getEnabledAppsForUser($this->currentUser); |
|
124 | + } |
|
125 | 125 | |
126 | - foreach($apps as $app) { |
|
127 | - $apps_paths[$app] = \OC_App::getAppWebPath($app); |
|
128 | - } |
|
126 | + foreach($apps as $app) { |
|
127 | + $apps_paths[$app] = \OC_App::getAppWebPath($app); |
|
128 | + } |
|
129 | 129 | |
130 | 130 | |
131 | - $enableLinkPasswordByDefault = $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'); |
|
132 | - $enableLinkPasswordByDefault = $enableLinkPasswordByDefault === 'yes'; |
|
133 | - $defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
134 | - $defaultExpireDate = $enforceDefaultExpireDate = null; |
|
135 | - if ($defaultExpireDateEnabled) { |
|
136 | - $defaultExpireDate = (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
137 | - $enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
138 | - } |
|
139 | - $outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
131 | + $enableLinkPasswordByDefault = $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'); |
|
132 | + $enableLinkPasswordByDefault = $enableLinkPasswordByDefault === 'yes'; |
|
133 | + $defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
134 | + $defaultExpireDate = $enforceDefaultExpireDate = null; |
|
135 | + if ($defaultExpireDateEnabled) { |
|
136 | + $defaultExpireDate = (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
137 | + $enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
138 | + } |
|
139 | + $outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
140 | 140 | |
141 | - $countOfDataLocation = 0; |
|
142 | - $dataLocation = str_replace(\OC::$SERVERROOT .'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); |
|
143 | - if($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) { |
|
144 | - $dataLocation = false; |
|
145 | - } |
|
141 | + $countOfDataLocation = 0; |
|
142 | + $dataLocation = str_replace(\OC::$SERVERROOT .'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); |
|
143 | + if($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) { |
|
144 | + $dataLocation = false; |
|
145 | + } |
|
146 | 146 | |
147 | - if ($this->currentUser instanceof IUser) { |
|
148 | - $lastConfirmTimestamp = $this->session->get('last-password-confirm'); |
|
149 | - if (!is_int($lastConfirmTimestamp)) { |
|
150 | - $lastConfirmTimestamp = 0; |
|
151 | - } |
|
152 | - } else { |
|
153 | - $lastConfirmTimestamp = 0; |
|
154 | - } |
|
147 | + if ($this->currentUser instanceof IUser) { |
|
148 | + $lastConfirmTimestamp = $this->session->get('last-password-confirm'); |
|
149 | + if (!is_int($lastConfirmTimestamp)) { |
|
150 | + $lastConfirmTimestamp = 0; |
|
151 | + } |
|
152 | + } else { |
|
153 | + $lastConfirmTimestamp = 0; |
|
154 | + } |
|
155 | 155 | |
156 | - $capabilities = $this->capabilitiesManager->getCapabilities(); |
|
156 | + $capabilities = $this->capabilitiesManager->getCapabilities(); |
|
157 | 157 | |
158 | - $array = [ |
|
159 | - "oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false', |
|
160 | - "oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', |
|
161 | - "backendAllowsPasswordConfirmation" => $userBackend === 'user_saml'? 'false' : 'true', |
|
162 | - "oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false', |
|
163 | - "oc_webroot" => "\"".\OC::$WEBROOT."\"", |
|
164 | - "oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution |
|
165 | - "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), |
|
166 | - 'nc_lastLogin' => $lastConfirmTimestamp, |
|
167 | - 'nc_pageLoad' => time(), |
|
168 | - "dayNames" => json_encode([ |
|
169 | - (string)$this->l->t('Sunday'), |
|
170 | - (string)$this->l->t('Monday'), |
|
171 | - (string)$this->l->t('Tuesday'), |
|
172 | - (string)$this->l->t('Wednesday'), |
|
173 | - (string)$this->l->t('Thursday'), |
|
174 | - (string)$this->l->t('Friday'), |
|
175 | - (string)$this->l->t('Saturday') |
|
176 | - ]), |
|
177 | - "dayNamesShort" => json_encode([ |
|
178 | - (string)$this->l->t('Sun.'), |
|
179 | - (string)$this->l->t('Mon.'), |
|
180 | - (string)$this->l->t('Tue.'), |
|
181 | - (string)$this->l->t('Wed.'), |
|
182 | - (string)$this->l->t('Thu.'), |
|
183 | - (string)$this->l->t('Fri.'), |
|
184 | - (string)$this->l->t('Sat.') |
|
185 | - ]), |
|
186 | - "dayNamesMin" => json_encode([ |
|
187 | - (string)$this->l->t('Su'), |
|
188 | - (string)$this->l->t('Mo'), |
|
189 | - (string)$this->l->t('Tu'), |
|
190 | - (string)$this->l->t('We'), |
|
191 | - (string)$this->l->t('Th'), |
|
192 | - (string)$this->l->t('Fr'), |
|
193 | - (string)$this->l->t('Sa') |
|
194 | - ]), |
|
195 | - "monthNames" => json_encode([ |
|
196 | - (string)$this->l->t('January'), |
|
197 | - (string)$this->l->t('February'), |
|
198 | - (string)$this->l->t('March'), |
|
199 | - (string)$this->l->t('April'), |
|
200 | - (string)$this->l->t('May'), |
|
201 | - (string)$this->l->t('June'), |
|
202 | - (string)$this->l->t('July'), |
|
203 | - (string)$this->l->t('August'), |
|
204 | - (string)$this->l->t('September'), |
|
205 | - (string)$this->l->t('October'), |
|
206 | - (string)$this->l->t('November'), |
|
207 | - (string)$this->l->t('December') |
|
208 | - ]), |
|
209 | - "monthNamesShort" => json_encode([ |
|
210 | - (string)$this->l->t('Jan.'), |
|
211 | - (string)$this->l->t('Feb.'), |
|
212 | - (string)$this->l->t('Mar.'), |
|
213 | - (string)$this->l->t('Apr.'), |
|
214 | - (string)$this->l->t('May.'), |
|
215 | - (string)$this->l->t('Jun.'), |
|
216 | - (string)$this->l->t('Jul.'), |
|
217 | - (string)$this->l->t('Aug.'), |
|
218 | - (string)$this->l->t('Sep.'), |
|
219 | - (string)$this->l->t('Oct.'), |
|
220 | - (string)$this->l->t('Nov.'), |
|
221 | - (string)$this->l->t('Dec.') |
|
222 | - ]), |
|
223 | - "firstDay" => json_encode($this->l->l('firstday', null)) , |
|
224 | - "oc_config" => json_encode([ |
|
225 | - 'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')), |
|
226 | - 'session_keepalive' => $this->config->getSystemValue('session_keepalive', true), |
|
227 | - 'version' => implode('.', \OCP\Util::getVersion()), |
|
228 | - 'versionstring' => \OC_Util::getVersionString(), |
|
229 | - 'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value |
|
230 | - 'lost_password_link'=> $this->config->getSystemValue('lost_password_link', null), |
|
231 | - 'modRewriteWorking' => $this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true', |
|
232 | - 'sharing.maxAutocompleteResults' => (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0), |
|
233 | - 'sharing.minSearchStringLength' => (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0), |
|
234 | - 'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX, |
|
235 | - ]), |
|
236 | - "oc_appconfig" => json_encode([ |
|
237 | - 'core' => [ |
|
238 | - 'defaultExpireDateEnabled' => $defaultExpireDateEnabled, |
|
239 | - 'defaultExpireDate' => $defaultExpireDate, |
|
240 | - 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, |
|
241 | - 'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(), |
|
242 | - 'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault, |
|
243 | - 'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(), |
|
244 | - 'resharingAllowed' => \OC\Share\Share::isResharingAllowed(), |
|
245 | - 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, |
|
246 | - 'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'), |
|
247 | - 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing() |
|
248 | - ] |
|
249 | - ]), |
|
250 | - "oc_defaults" => json_encode([ |
|
251 | - 'entity' => $this->defaults->getEntity(), |
|
252 | - 'name' => $this->defaults->getName(), |
|
253 | - 'title' => $this->defaults->getTitle(), |
|
254 | - 'baseUrl' => $this->defaults->getBaseUrl(), |
|
255 | - 'syncClientUrl' => $this->defaults->getSyncClientUrl(), |
|
256 | - 'docBaseUrl' => $this->defaults->getDocBaseUrl(), |
|
257 | - 'docPlaceholderUrl' => $this->defaults->buildDocLinkToKey('PLACEHOLDER'), |
|
258 | - 'slogan' => $this->defaults->getSlogan(), |
|
259 | - 'logoClaim' => '', |
|
260 | - 'shortFooter' => $this->defaults->getShortFooter(), |
|
261 | - 'longFooter' => $this->defaults->getLongFooter(), |
|
262 | - 'folder' => \OC_Util::getTheme(), |
|
263 | - ]), |
|
264 | - "oc_capabilities" => json_encode($capabilities), |
|
265 | - ]; |
|
158 | + $array = [ |
|
159 | + "oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false', |
|
160 | + "oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', |
|
161 | + "backendAllowsPasswordConfirmation" => $userBackend === 'user_saml'? 'false' : 'true', |
|
162 | + "oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false', |
|
163 | + "oc_webroot" => "\"".\OC::$WEBROOT."\"", |
|
164 | + "oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution |
|
165 | + "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), |
|
166 | + 'nc_lastLogin' => $lastConfirmTimestamp, |
|
167 | + 'nc_pageLoad' => time(), |
|
168 | + "dayNames" => json_encode([ |
|
169 | + (string)$this->l->t('Sunday'), |
|
170 | + (string)$this->l->t('Monday'), |
|
171 | + (string)$this->l->t('Tuesday'), |
|
172 | + (string)$this->l->t('Wednesday'), |
|
173 | + (string)$this->l->t('Thursday'), |
|
174 | + (string)$this->l->t('Friday'), |
|
175 | + (string)$this->l->t('Saturday') |
|
176 | + ]), |
|
177 | + "dayNamesShort" => json_encode([ |
|
178 | + (string)$this->l->t('Sun.'), |
|
179 | + (string)$this->l->t('Mon.'), |
|
180 | + (string)$this->l->t('Tue.'), |
|
181 | + (string)$this->l->t('Wed.'), |
|
182 | + (string)$this->l->t('Thu.'), |
|
183 | + (string)$this->l->t('Fri.'), |
|
184 | + (string)$this->l->t('Sat.') |
|
185 | + ]), |
|
186 | + "dayNamesMin" => json_encode([ |
|
187 | + (string)$this->l->t('Su'), |
|
188 | + (string)$this->l->t('Mo'), |
|
189 | + (string)$this->l->t('Tu'), |
|
190 | + (string)$this->l->t('We'), |
|
191 | + (string)$this->l->t('Th'), |
|
192 | + (string)$this->l->t('Fr'), |
|
193 | + (string)$this->l->t('Sa') |
|
194 | + ]), |
|
195 | + "monthNames" => json_encode([ |
|
196 | + (string)$this->l->t('January'), |
|
197 | + (string)$this->l->t('February'), |
|
198 | + (string)$this->l->t('March'), |
|
199 | + (string)$this->l->t('April'), |
|
200 | + (string)$this->l->t('May'), |
|
201 | + (string)$this->l->t('June'), |
|
202 | + (string)$this->l->t('July'), |
|
203 | + (string)$this->l->t('August'), |
|
204 | + (string)$this->l->t('September'), |
|
205 | + (string)$this->l->t('October'), |
|
206 | + (string)$this->l->t('November'), |
|
207 | + (string)$this->l->t('December') |
|
208 | + ]), |
|
209 | + "monthNamesShort" => json_encode([ |
|
210 | + (string)$this->l->t('Jan.'), |
|
211 | + (string)$this->l->t('Feb.'), |
|
212 | + (string)$this->l->t('Mar.'), |
|
213 | + (string)$this->l->t('Apr.'), |
|
214 | + (string)$this->l->t('May.'), |
|
215 | + (string)$this->l->t('Jun.'), |
|
216 | + (string)$this->l->t('Jul.'), |
|
217 | + (string)$this->l->t('Aug.'), |
|
218 | + (string)$this->l->t('Sep.'), |
|
219 | + (string)$this->l->t('Oct.'), |
|
220 | + (string)$this->l->t('Nov.'), |
|
221 | + (string)$this->l->t('Dec.') |
|
222 | + ]), |
|
223 | + "firstDay" => json_encode($this->l->l('firstday', null)) , |
|
224 | + "oc_config" => json_encode([ |
|
225 | + 'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')), |
|
226 | + 'session_keepalive' => $this->config->getSystemValue('session_keepalive', true), |
|
227 | + 'version' => implode('.', \OCP\Util::getVersion()), |
|
228 | + 'versionstring' => \OC_Util::getVersionString(), |
|
229 | + 'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value |
|
230 | + 'lost_password_link'=> $this->config->getSystemValue('lost_password_link', null), |
|
231 | + 'modRewriteWorking' => $this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true', |
|
232 | + 'sharing.maxAutocompleteResults' => (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0), |
|
233 | + 'sharing.minSearchStringLength' => (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0), |
|
234 | + 'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX, |
|
235 | + ]), |
|
236 | + "oc_appconfig" => json_encode([ |
|
237 | + 'core' => [ |
|
238 | + 'defaultExpireDateEnabled' => $defaultExpireDateEnabled, |
|
239 | + 'defaultExpireDate' => $defaultExpireDate, |
|
240 | + 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, |
|
241 | + 'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(), |
|
242 | + 'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault, |
|
243 | + 'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(), |
|
244 | + 'resharingAllowed' => \OC\Share\Share::isResharingAllowed(), |
|
245 | + 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, |
|
246 | + 'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'), |
|
247 | + 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing() |
|
248 | + ] |
|
249 | + ]), |
|
250 | + "oc_defaults" => json_encode([ |
|
251 | + 'entity' => $this->defaults->getEntity(), |
|
252 | + 'name' => $this->defaults->getName(), |
|
253 | + 'title' => $this->defaults->getTitle(), |
|
254 | + 'baseUrl' => $this->defaults->getBaseUrl(), |
|
255 | + 'syncClientUrl' => $this->defaults->getSyncClientUrl(), |
|
256 | + 'docBaseUrl' => $this->defaults->getDocBaseUrl(), |
|
257 | + 'docPlaceholderUrl' => $this->defaults->buildDocLinkToKey('PLACEHOLDER'), |
|
258 | + 'slogan' => $this->defaults->getSlogan(), |
|
259 | + 'logoClaim' => '', |
|
260 | + 'shortFooter' => $this->defaults->getShortFooter(), |
|
261 | + 'longFooter' => $this->defaults->getLongFooter(), |
|
262 | + 'folder' => \OC_Util::getTheme(), |
|
263 | + ]), |
|
264 | + "oc_capabilities" => json_encode($capabilities), |
|
265 | + ]; |
|
266 | 266 | |
267 | - if ($this->currentUser !== null) { |
|
268 | - $array['oc_userconfig'] = json_encode([ |
|
269 | - 'avatar' => [ |
|
270 | - 'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0), |
|
271 | - 'generated' => $this->config->getUserValue($uid, 'avatar', 'generated', 'true') === 'true', |
|
272 | - ] |
|
273 | - ]); |
|
274 | - } |
|
267 | + if ($this->currentUser !== null) { |
|
268 | + $array['oc_userconfig'] = json_encode([ |
|
269 | + 'avatar' => [ |
|
270 | + 'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0), |
|
271 | + 'generated' => $this->config->getUserValue($uid, 'avatar', 'generated', 'true') === 'true', |
|
272 | + ] |
|
273 | + ]); |
|
274 | + } |
|
275 | 275 | |
276 | - // Allow hooks to modify the output values |
|
277 | - \OC_Hook::emit('\OCP\Config', 'js', array('array' => &$array)); |
|
276 | + // Allow hooks to modify the output values |
|
277 | + \OC_Hook::emit('\OCP\Config', 'js', array('array' => &$array)); |
|
278 | 278 | |
279 | - $result = ''; |
|
279 | + $result = ''; |
|
280 | 280 | |
281 | - // Echo it |
|
282 | - foreach ($array as $setting => $value) { |
|
283 | - $result .= 'var '. $setting . '='. $value . ';' . PHP_EOL; |
|
284 | - } |
|
281 | + // Echo it |
|
282 | + foreach ($array as $setting => $value) { |
|
283 | + $result .= 'var '. $setting . '='. $value . ';' . PHP_EOL; |
|
284 | + } |
|
285 | 285 | |
286 | - return $result; |
|
287 | - } |
|
286 | + return $result; |
|
287 | + } |
|
288 | 288 | } |
@@ -49,356 +49,356 @@ |
||
49 | 49 | use OCP\Util; |
50 | 50 | |
51 | 51 | class Manager implements IManager { |
52 | - /** @var ILogger */ |
|
53 | - private $log; |
|
54 | - /** @var IDBConnection */ |
|
55 | - private $dbc; |
|
56 | - /** @var IL10N */ |
|
57 | - private $l; |
|
58 | - /** @var IConfig */ |
|
59 | - private $config; |
|
60 | - /** @var EncryptionManager */ |
|
61 | - private $encryptionManager; |
|
62 | - /** @var IUserManager */ |
|
63 | - private $userManager; |
|
64 | - /** @var ILockingProvider */ |
|
65 | - private $lockingProvider; |
|
66 | - /** @var IRequest */ |
|
67 | - private $request; |
|
68 | - /** @var IURLGenerator */ |
|
69 | - private $url; |
|
70 | - /** @var AccountManager */ |
|
71 | - private $accountManager; |
|
72 | - /** @var IGroupManager */ |
|
73 | - private $groupManager; |
|
74 | - /** @var IFactory */ |
|
75 | - private $l10nFactory; |
|
76 | - /** @var IAppManager */ |
|
77 | - private $appManager; |
|
78 | - |
|
79 | - /** |
|
80 | - * @param ILogger $log |
|
81 | - * @param IDBConnection $dbc |
|
82 | - * @param IL10N $l |
|
83 | - * @param IConfig $config |
|
84 | - * @param EncryptionManager $encryptionManager |
|
85 | - * @param IUserManager $userManager |
|
86 | - * @param ILockingProvider $lockingProvider |
|
87 | - * @param IRequest $request |
|
88 | - * @param IURLGenerator $url |
|
89 | - * @param AccountManager $accountManager |
|
90 | - * @param IGroupManager $groupManager |
|
91 | - * @param IFactory $l10nFactory |
|
92 | - * @param IAppManager $appManager |
|
93 | - */ |
|
94 | - public function __construct( |
|
95 | - ILogger $log, |
|
96 | - IDBConnection $dbc, |
|
97 | - IL10N $l, |
|
98 | - IConfig $config, |
|
99 | - EncryptionManager $encryptionManager, |
|
100 | - IUserManager $userManager, |
|
101 | - ILockingProvider $lockingProvider, |
|
102 | - IRequest $request, |
|
103 | - IURLGenerator $url, |
|
104 | - AccountManager $accountManager, |
|
105 | - IGroupManager $groupManager, |
|
106 | - IFactory $l10nFactory, |
|
107 | - IAppManager $appManager |
|
108 | - ) { |
|
109 | - $this->log = $log; |
|
110 | - $this->dbc = $dbc; |
|
111 | - $this->l = $l; |
|
112 | - $this->config = $config; |
|
113 | - $this->encryptionManager = $encryptionManager; |
|
114 | - $this->userManager = $userManager; |
|
115 | - $this->lockingProvider = $lockingProvider; |
|
116 | - $this->request = $request; |
|
117 | - $this->url = $url; |
|
118 | - $this->accountManager = $accountManager; |
|
119 | - $this->groupManager = $groupManager; |
|
120 | - $this->l10nFactory = $l10nFactory; |
|
121 | - $this->appManager = $appManager; |
|
122 | - } |
|
123 | - |
|
124 | - /** @var array */ |
|
125 | - protected $sectionClasses = []; |
|
126 | - |
|
127 | - /** @var array */ |
|
128 | - protected $sections = []; |
|
129 | - |
|
130 | - /** |
|
131 | - * @param string $type 'admin' or 'personal' |
|
132 | - * @param string $section Class must implement OCP\Settings\ISection |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - public function registerSection(string $type, string $section) { |
|
136 | - $this->sectionClasses[$section] = $type; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $type 'admin' or 'personal' |
|
141 | - * @return ISection[] |
|
142 | - */ |
|
143 | - protected function getSections(string $type): array { |
|
144 | - if (!isset($this->sections[$type])) { |
|
145 | - $this->sections[$type] = []; |
|
146 | - } |
|
147 | - |
|
148 | - foreach ($this->sectionClasses as $class => $sectionType) { |
|
149 | - try { |
|
150 | - /** @var ISection $section */ |
|
151 | - $section = \OC::$server->query($class); |
|
152 | - } catch (QueryException $e) { |
|
153 | - $this->log->logException($e, ['level' => Util::INFO]); |
|
154 | - continue; |
|
155 | - } |
|
156 | - |
|
157 | - if (!$section instanceof ISection) { |
|
158 | - $this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => Util::INFO]); |
|
159 | - continue; |
|
160 | - } |
|
161 | - |
|
162 | - $this->sections[$sectionType][$section->getID()] = $section; |
|
163 | - |
|
164 | - unset($this->sectionClasses[$class]); |
|
165 | - } |
|
166 | - |
|
167 | - return $this->sections[$type]; |
|
168 | - } |
|
169 | - |
|
170 | - /** @var array */ |
|
171 | - protected $settingClasses = []; |
|
172 | - |
|
173 | - /** @var array */ |
|
174 | - protected $settings = []; |
|
175 | - |
|
176 | - /** |
|
177 | - * @param string $type 'admin' or 'personal' |
|
178 | - * @param string $setting Class must implement OCP\Settings\ISetting |
|
179 | - * @return void |
|
180 | - */ |
|
181 | - public function registerSetting(string $type, string $setting) { |
|
182 | - $this->settingClasses[$setting] = $type; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @param string $type 'admin' or 'personal' |
|
187 | - * @param string $section |
|
188 | - * @return ISettings[] |
|
189 | - */ |
|
190 | - protected function getSettings(string $type, string $section): array { |
|
191 | - if (!isset($this->settings[$type])) { |
|
192 | - $this->settings[$type] = []; |
|
193 | - } |
|
194 | - if (!isset($this->settings[$type][$section])) { |
|
195 | - $this->settings[$type][$section] = []; |
|
196 | - } |
|
197 | - |
|
198 | - foreach ($this->settingClasses as $class => $settingsType) { |
|
199 | - try { |
|
200 | - /** @var ISettings $setting */ |
|
201 | - $setting = \OC::$server->query($class); |
|
202 | - } catch (QueryException $e) { |
|
203 | - $this->log->logException($e, ['level' => Util::INFO]); |
|
204 | - continue; |
|
205 | - } |
|
206 | - |
|
207 | - if (!$setting instanceof ISettings) { |
|
208 | - $this->log->logException(new \InvalidArgumentException('Invalid settings setting registered'), ['level' => Util::INFO]); |
|
209 | - continue; |
|
210 | - } |
|
211 | - |
|
212 | - if (!isset($this->settings[$settingsType][$setting->getSection()])) { |
|
213 | - $this->settings[$settingsType][$setting->getSection()] = []; |
|
214 | - } |
|
215 | - $this->settings[$settingsType][$setting->getSection()][] = $setting; |
|
216 | - |
|
217 | - unset($this->settingClasses[$class]); |
|
218 | - } |
|
219 | - |
|
220 | - return $this->settings[$type][$section]; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @inheritdoc |
|
225 | - */ |
|
226 | - public function getAdminSections(): array { |
|
227 | - // built-in sections |
|
228 | - $sections = [ |
|
229 | - 0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
230 | - 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
231 | - 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
232 | - 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
233 | - 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
234 | - 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))], |
|
235 | - ]; |
|
236 | - |
|
237 | - $appSections = $this->getSections('admin'); |
|
238 | - |
|
239 | - foreach ($appSections as $section) { |
|
240 | - /** @var ISection $section */ |
|
241 | - if (!isset($sections[$section->getPriority()])) { |
|
242 | - $sections[$section->getPriority()] = []; |
|
243 | - } |
|
244 | - |
|
245 | - $sections[$section->getPriority()][] = $section; |
|
246 | - } |
|
247 | - |
|
248 | - ksort($sections); |
|
249 | - |
|
250 | - return $sections; |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * @param string $section |
|
255 | - * @return ISection[] |
|
256 | - */ |
|
257 | - private function getBuiltInAdminSettings($section): array { |
|
258 | - $forms = []; |
|
259 | - |
|
260 | - if ($section === 'server') { |
|
261 | - /** @var ISettings $form */ |
|
262 | - $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
263 | - $forms[$form->getPriority()] = [$form]; |
|
264 | - $form = new Admin\ServerDevNotice(); |
|
265 | - $forms[$form->getPriority()] = [$form]; |
|
266 | - } |
|
267 | - if ($section === 'encryption') { |
|
268 | - /** @var ISettings $form */ |
|
269 | - $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
270 | - $forms[$form->getPriority()] = [$form]; |
|
271 | - } |
|
272 | - if ($section === 'sharing') { |
|
273 | - /** @var ISettings $form */ |
|
274 | - $form = new Admin\Sharing($this->config, $this->l); |
|
275 | - $forms[$form->getPriority()] = [$form]; |
|
276 | - } |
|
277 | - if ($section === 'additional') { |
|
278 | - /** @var ISettings $form */ |
|
279 | - $form = new Admin\Additional($this->config); |
|
280 | - $forms[$form->getPriority()] = [$form]; |
|
281 | - } |
|
282 | - if ($section === 'tips-tricks') { |
|
283 | - /** @var ISettings $form */ |
|
284 | - $form = new Admin\TipsTricks($this->config); |
|
285 | - $forms[$form->getPriority()] = [$form]; |
|
286 | - } |
|
287 | - |
|
288 | - return $forms; |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * @param string $section |
|
293 | - * @return ISection[] |
|
294 | - */ |
|
295 | - private function getBuiltInPersonalSettings($section): array { |
|
296 | - $forms = []; |
|
297 | - |
|
298 | - if ($section === 'personal-info') { |
|
299 | - /** @var ISettings $form */ |
|
300 | - $form = new Personal\PersonalInfo( |
|
301 | - $this->config, |
|
302 | - $this->userManager, |
|
303 | - $this->groupManager, |
|
304 | - $this->accountManager, |
|
305 | - $this->appManager, |
|
306 | - $this->l10nFactory, |
|
307 | - $this->l |
|
308 | - ); |
|
309 | - $forms[$form->getPriority()] = [$form]; |
|
310 | - } |
|
311 | - if($section === 'security') { |
|
312 | - /** @var ISettings $form */ |
|
313 | - $form = new Personal\Security(); |
|
314 | - $forms[$form->getPriority()] = [$form]; |
|
315 | - } |
|
316 | - if ($section === 'additional') { |
|
317 | - /** @var ISettings $form */ |
|
318 | - $form = new Personal\Additional(); |
|
319 | - $forms[$form->getPriority()] = [$form]; |
|
320 | - } |
|
321 | - |
|
322 | - return $forms; |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * @inheritdoc |
|
327 | - */ |
|
328 | - public function getAdminSettings($section): array { |
|
329 | - $settings = $this->getBuiltInAdminSettings($section); |
|
330 | - $appSettings = $this->getSettings('admin', $section); |
|
331 | - |
|
332 | - foreach ($appSettings as $setting) { |
|
333 | - if (!isset($settings[$setting->getPriority()])) { |
|
334 | - $settings[$setting->getPriority()] = []; |
|
335 | - } |
|
336 | - $settings[$setting->getPriority()][] = $setting; |
|
337 | - } |
|
338 | - |
|
339 | - ksort($settings); |
|
340 | - return $settings; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * @inheritdoc |
|
345 | - */ |
|
346 | - public function getPersonalSections(): array { |
|
347 | - $sections = [ |
|
348 | - 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
349 | - 5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
350 | - 15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))], |
|
351 | - ]; |
|
352 | - |
|
353 | - $legacyForms = \OC_App::getForms('personal'); |
|
354 | - if(!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
|
355 | - $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
|
356 | - } |
|
357 | - |
|
358 | - $appSections = $this->getSections('personal'); |
|
359 | - |
|
360 | - foreach ($appSections as $section) { |
|
361 | - /** @var ISection $section */ |
|
362 | - if (!isset($sections[$section->getPriority()])) { |
|
363 | - $sections[$section->getPriority()] = []; |
|
364 | - } |
|
365 | - |
|
366 | - $sections[$section->getPriority()][] = $section; |
|
367 | - } |
|
368 | - |
|
369 | - ksort($sections); |
|
370 | - |
|
371 | - return $sections; |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * @param string[] $forms |
|
376 | - * @return bool |
|
377 | - */ |
|
378 | - private function hasLegacyPersonalSettingsToRender(array $forms): bool { |
|
379 | - foreach ($forms as $form) { |
|
380 | - if(trim($form) !== '') { |
|
381 | - return true; |
|
382 | - } |
|
383 | - } |
|
384 | - return false; |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * @inheritdoc |
|
389 | - */ |
|
390 | - public function getPersonalSettings($section): array { |
|
391 | - $settings = $this->getBuiltInPersonalSettings($section); |
|
392 | - $appSettings = $this->getSettings('personal', $section); |
|
393 | - |
|
394 | - foreach ($appSettings as $setting) { |
|
395 | - if (!isset($settings[$setting->getPriority()])) { |
|
396 | - $settings[$setting->getPriority()] = []; |
|
397 | - } |
|
398 | - $settings[$setting->getPriority()][] = $setting; |
|
399 | - } |
|
400 | - |
|
401 | - ksort($settings); |
|
402 | - return $settings; |
|
403 | - } |
|
52 | + /** @var ILogger */ |
|
53 | + private $log; |
|
54 | + /** @var IDBConnection */ |
|
55 | + private $dbc; |
|
56 | + /** @var IL10N */ |
|
57 | + private $l; |
|
58 | + /** @var IConfig */ |
|
59 | + private $config; |
|
60 | + /** @var EncryptionManager */ |
|
61 | + private $encryptionManager; |
|
62 | + /** @var IUserManager */ |
|
63 | + private $userManager; |
|
64 | + /** @var ILockingProvider */ |
|
65 | + private $lockingProvider; |
|
66 | + /** @var IRequest */ |
|
67 | + private $request; |
|
68 | + /** @var IURLGenerator */ |
|
69 | + private $url; |
|
70 | + /** @var AccountManager */ |
|
71 | + private $accountManager; |
|
72 | + /** @var IGroupManager */ |
|
73 | + private $groupManager; |
|
74 | + /** @var IFactory */ |
|
75 | + private $l10nFactory; |
|
76 | + /** @var IAppManager */ |
|
77 | + private $appManager; |
|
78 | + |
|
79 | + /** |
|
80 | + * @param ILogger $log |
|
81 | + * @param IDBConnection $dbc |
|
82 | + * @param IL10N $l |
|
83 | + * @param IConfig $config |
|
84 | + * @param EncryptionManager $encryptionManager |
|
85 | + * @param IUserManager $userManager |
|
86 | + * @param ILockingProvider $lockingProvider |
|
87 | + * @param IRequest $request |
|
88 | + * @param IURLGenerator $url |
|
89 | + * @param AccountManager $accountManager |
|
90 | + * @param IGroupManager $groupManager |
|
91 | + * @param IFactory $l10nFactory |
|
92 | + * @param IAppManager $appManager |
|
93 | + */ |
|
94 | + public function __construct( |
|
95 | + ILogger $log, |
|
96 | + IDBConnection $dbc, |
|
97 | + IL10N $l, |
|
98 | + IConfig $config, |
|
99 | + EncryptionManager $encryptionManager, |
|
100 | + IUserManager $userManager, |
|
101 | + ILockingProvider $lockingProvider, |
|
102 | + IRequest $request, |
|
103 | + IURLGenerator $url, |
|
104 | + AccountManager $accountManager, |
|
105 | + IGroupManager $groupManager, |
|
106 | + IFactory $l10nFactory, |
|
107 | + IAppManager $appManager |
|
108 | + ) { |
|
109 | + $this->log = $log; |
|
110 | + $this->dbc = $dbc; |
|
111 | + $this->l = $l; |
|
112 | + $this->config = $config; |
|
113 | + $this->encryptionManager = $encryptionManager; |
|
114 | + $this->userManager = $userManager; |
|
115 | + $this->lockingProvider = $lockingProvider; |
|
116 | + $this->request = $request; |
|
117 | + $this->url = $url; |
|
118 | + $this->accountManager = $accountManager; |
|
119 | + $this->groupManager = $groupManager; |
|
120 | + $this->l10nFactory = $l10nFactory; |
|
121 | + $this->appManager = $appManager; |
|
122 | + } |
|
123 | + |
|
124 | + /** @var array */ |
|
125 | + protected $sectionClasses = []; |
|
126 | + |
|
127 | + /** @var array */ |
|
128 | + protected $sections = []; |
|
129 | + |
|
130 | + /** |
|
131 | + * @param string $type 'admin' or 'personal' |
|
132 | + * @param string $section Class must implement OCP\Settings\ISection |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + public function registerSection(string $type, string $section) { |
|
136 | + $this->sectionClasses[$section] = $type; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $type 'admin' or 'personal' |
|
141 | + * @return ISection[] |
|
142 | + */ |
|
143 | + protected function getSections(string $type): array { |
|
144 | + if (!isset($this->sections[$type])) { |
|
145 | + $this->sections[$type] = []; |
|
146 | + } |
|
147 | + |
|
148 | + foreach ($this->sectionClasses as $class => $sectionType) { |
|
149 | + try { |
|
150 | + /** @var ISection $section */ |
|
151 | + $section = \OC::$server->query($class); |
|
152 | + } catch (QueryException $e) { |
|
153 | + $this->log->logException($e, ['level' => Util::INFO]); |
|
154 | + continue; |
|
155 | + } |
|
156 | + |
|
157 | + if (!$section instanceof ISection) { |
|
158 | + $this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => Util::INFO]); |
|
159 | + continue; |
|
160 | + } |
|
161 | + |
|
162 | + $this->sections[$sectionType][$section->getID()] = $section; |
|
163 | + |
|
164 | + unset($this->sectionClasses[$class]); |
|
165 | + } |
|
166 | + |
|
167 | + return $this->sections[$type]; |
|
168 | + } |
|
169 | + |
|
170 | + /** @var array */ |
|
171 | + protected $settingClasses = []; |
|
172 | + |
|
173 | + /** @var array */ |
|
174 | + protected $settings = []; |
|
175 | + |
|
176 | + /** |
|
177 | + * @param string $type 'admin' or 'personal' |
|
178 | + * @param string $setting Class must implement OCP\Settings\ISetting |
|
179 | + * @return void |
|
180 | + */ |
|
181 | + public function registerSetting(string $type, string $setting) { |
|
182 | + $this->settingClasses[$setting] = $type; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @param string $type 'admin' or 'personal' |
|
187 | + * @param string $section |
|
188 | + * @return ISettings[] |
|
189 | + */ |
|
190 | + protected function getSettings(string $type, string $section): array { |
|
191 | + if (!isset($this->settings[$type])) { |
|
192 | + $this->settings[$type] = []; |
|
193 | + } |
|
194 | + if (!isset($this->settings[$type][$section])) { |
|
195 | + $this->settings[$type][$section] = []; |
|
196 | + } |
|
197 | + |
|
198 | + foreach ($this->settingClasses as $class => $settingsType) { |
|
199 | + try { |
|
200 | + /** @var ISettings $setting */ |
|
201 | + $setting = \OC::$server->query($class); |
|
202 | + } catch (QueryException $e) { |
|
203 | + $this->log->logException($e, ['level' => Util::INFO]); |
|
204 | + continue; |
|
205 | + } |
|
206 | + |
|
207 | + if (!$setting instanceof ISettings) { |
|
208 | + $this->log->logException(new \InvalidArgumentException('Invalid settings setting registered'), ['level' => Util::INFO]); |
|
209 | + continue; |
|
210 | + } |
|
211 | + |
|
212 | + if (!isset($this->settings[$settingsType][$setting->getSection()])) { |
|
213 | + $this->settings[$settingsType][$setting->getSection()] = []; |
|
214 | + } |
|
215 | + $this->settings[$settingsType][$setting->getSection()][] = $setting; |
|
216 | + |
|
217 | + unset($this->settingClasses[$class]); |
|
218 | + } |
|
219 | + |
|
220 | + return $this->settings[$type][$section]; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @inheritdoc |
|
225 | + */ |
|
226 | + public function getAdminSections(): array { |
|
227 | + // built-in sections |
|
228 | + $sections = [ |
|
229 | + 0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
230 | + 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
231 | + 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
232 | + 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
233 | + 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
234 | + 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))], |
|
235 | + ]; |
|
236 | + |
|
237 | + $appSections = $this->getSections('admin'); |
|
238 | + |
|
239 | + foreach ($appSections as $section) { |
|
240 | + /** @var ISection $section */ |
|
241 | + if (!isset($sections[$section->getPriority()])) { |
|
242 | + $sections[$section->getPriority()] = []; |
|
243 | + } |
|
244 | + |
|
245 | + $sections[$section->getPriority()][] = $section; |
|
246 | + } |
|
247 | + |
|
248 | + ksort($sections); |
|
249 | + |
|
250 | + return $sections; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * @param string $section |
|
255 | + * @return ISection[] |
|
256 | + */ |
|
257 | + private function getBuiltInAdminSettings($section): array { |
|
258 | + $forms = []; |
|
259 | + |
|
260 | + if ($section === 'server') { |
|
261 | + /** @var ISettings $form */ |
|
262 | + $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
263 | + $forms[$form->getPriority()] = [$form]; |
|
264 | + $form = new Admin\ServerDevNotice(); |
|
265 | + $forms[$form->getPriority()] = [$form]; |
|
266 | + } |
|
267 | + if ($section === 'encryption') { |
|
268 | + /** @var ISettings $form */ |
|
269 | + $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
270 | + $forms[$form->getPriority()] = [$form]; |
|
271 | + } |
|
272 | + if ($section === 'sharing') { |
|
273 | + /** @var ISettings $form */ |
|
274 | + $form = new Admin\Sharing($this->config, $this->l); |
|
275 | + $forms[$form->getPriority()] = [$form]; |
|
276 | + } |
|
277 | + if ($section === 'additional') { |
|
278 | + /** @var ISettings $form */ |
|
279 | + $form = new Admin\Additional($this->config); |
|
280 | + $forms[$form->getPriority()] = [$form]; |
|
281 | + } |
|
282 | + if ($section === 'tips-tricks') { |
|
283 | + /** @var ISettings $form */ |
|
284 | + $form = new Admin\TipsTricks($this->config); |
|
285 | + $forms[$form->getPriority()] = [$form]; |
|
286 | + } |
|
287 | + |
|
288 | + return $forms; |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * @param string $section |
|
293 | + * @return ISection[] |
|
294 | + */ |
|
295 | + private function getBuiltInPersonalSettings($section): array { |
|
296 | + $forms = []; |
|
297 | + |
|
298 | + if ($section === 'personal-info') { |
|
299 | + /** @var ISettings $form */ |
|
300 | + $form = new Personal\PersonalInfo( |
|
301 | + $this->config, |
|
302 | + $this->userManager, |
|
303 | + $this->groupManager, |
|
304 | + $this->accountManager, |
|
305 | + $this->appManager, |
|
306 | + $this->l10nFactory, |
|
307 | + $this->l |
|
308 | + ); |
|
309 | + $forms[$form->getPriority()] = [$form]; |
|
310 | + } |
|
311 | + if($section === 'security') { |
|
312 | + /** @var ISettings $form */ |
|
313 | + $form = new Personal\Security(); |
|
314 | + $forms[$form->getPriority()] = [$form]; |
|
315 | + } |
|
316 | + if ($section === 'additional') { |
|
317 | + /** @var ISettings $form */ |
|
318 | + $form = new Personal\Additional(); |
|
319 | + $forms[$form->getPriority()] = [$form]; |
|
320 | + } |
|
321 | + |
|
322 | + return $forms; |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * @inheritdoc |
|
327 | + */ |
|
328 | + public function getAdminSettings($section): array { |
|
329 | + $settings = $this->getBuiltInAdminSettings($section); |
|
330 | + $appSettings = $this->getSettings('admin', $section); |
|
331 | + |
|
332 | + foreach ($appSettings as $setting) { |
|
333 | + if (!isset($settings[$setting->getPriority()])) { |
|
334 | + $settings[$setting->getPriority()] = []; |
|
335 | + } |
|
336 | + $settings[$setting->getPriority()][] = $setting; |
|
337 | + } |
|
338 | + |
|
339 | + ksort($settings); |
|
340 | + return $settings; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * @inheritdoc |
|
345 | + */ |
|
346 | + public function getPersonalSections(): array { |
|
347 | + $sections = [ |
|
348 | + 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
349 | + 5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
350 | + 15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))], |
|
351 | + ]; |
|
352 | + |
|
353 | + $legacyForms = \OC_App::getForms('personal'); |
|
354 | + if(!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) { |
|
355 | + $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))]; |
|
356 | + } |
|
357 | + |
|
358 | + $appSections = $this->getSections('personal'); |
|
359 | + |
|
360 | + foreach ($appSections as $section) { |
|
361 | + /** @var ISection $section */ |
|
362 | + if (!isset($sections[$section->getPriority()])) { |
|
363 | + $sections[$section->getPriority()] = []; |
|
364 | + } |
|
365 | + |
|
366 | + $sections[$section->getPriority()][] = $section; |
|
367 | + } |
|
368 | + |
|
369 | + ksort($sections); |
|
370 | + |
|
371 | + return $sections; |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * @param string[] $forms |
|
376 | + * @return bool |
|
377 | + */ |
|
378 | + private function hasLegacyPersonalSettingsToRender(array $forms): bool { |
|
379 | + foreach ($forms as $form) { |
|
380 | + if(trim($form) !== '') { |
|
381 | + return true; |
|
382 | + } |
|
383 | + } |
|
384 | + return false; |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * @inheritdoc |
|
389 | + */ |
|
390 | + public function getPersonalSettings($section): array { |
|
391 | + $settings = $this->getBuiltInPersonalSettings($section); |
|
392 | + $appSettings = $this->getSettings('personal', $section); |
|
393 | + |
|
394 | + foreach ($appSettings as $setting) { |
|
395 | + if (!isset($settings[$setting->getPriority()])) { |
|
396 | + $settings[$setting->getPriority()] = []; |
|
397 | + } |
|
398 | + $settings[$setting->getPriority()][] = $setting; |
|
399 | + } |
|
400 | + |
|
401 | + ksort($settings); |
|
402 | + return $settings; |
|
403 | + } |
|
404 | 404 | } |
@@ -35,97 +35,97 @@ |
||
35 | 35 | use OCP\Util; |
36 | 36 | |
37 | 37 | class Sharing implements ISettings { |
38 | - /** @var IConfig */ |
|
39 | - private $config; |
|
38 | + /** @var IConfig */ |
|
39 | + private $config; |
|
40 | 40 | |
41 | - /** @var IL10N */ |
|
42 | - private $l; |
|
41 | + /** @var IL10N */ |
|
42 | + private $l; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param IConfig $config |
|
46 | - */ |
|
47 | - public function __construct(IConfig $config, IL10N $l) { |
|
48 | - $this->config = $config; |
|
49 | - $this->l = $l; |
|
50 | - } |
|
44 | + /** |
|
45 | + * @param IConfig $config |
|
46 | + */ |
|
47 | + public function __construct(IConfig $config, IL10N $l) { |
|
48 | + $this->config = $config; |
|
49 | + $this->l = $l; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return TemplateResponse |
|
54 | - */ |
|
55 | - public function getForm() { |
|
56 | - $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
57 | - $excludeGroupsList = !is_null(json_decode($excludedGroups)) |
|
58 | - ? implode('|', json_decode($excludedGroups, true)) : ''; |
|
52 | + /** |
|
53 | + * @return TemplateResponse |
|
54 | + */ |
|
55 | + public function getForm() { |
|
56 | + $excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', ''); |
|
57 | + $excludeGroupsList = !is_null(json_decode($excludedGroups)) |
|
58 | + ? implode('|', json_decode($excludedGroups, true)) : ''; |
|
59 | 59 | |
60 | - $parameters = [ |
|
61 | - // Built-In Sharing |
|
62 | - 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'), |
|
63 | - 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'), |
|
64 | - 'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'), |
|
65 | - 'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'), |
|
66 | - 'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'), |
|
67 | - 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(), |
|
68 | - 'onlyShareWithGroupMembers' => Share::shareWithGroupMembersOnly(), |
|
69 | - 'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'), |
|
70 | - 'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'), |
|
71 | - 'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'), |
|
72 | - 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'), |
|
73 | - 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes', |
|
74 | - 'shareExcludedGroupsList' => $excludeGroupsList, |
|
75 | - 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null), |
|
76 | - 'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'), |
|
77 | - 'shareApiDefaultPermissions' => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL), |
|
78 | - 'shareApiDefaultPermissionsCheckboxes' => $this->getSharePermissionList(), |
|
79 | - ]; |
|
60 | + $parameters = [ |
|
61 | + // Built-In Sharing |
|
62 | + 'allowGroupSharing' => $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes'), |
|
63 | + 'allowLinks' => $this->config->getAppValue('core', 'shareapi_allow_links', 'yes'), |
|
64 | + 'allowPublicUpload' => $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes'), |
|
65 | + 'allowResharing' => $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes'), |
|
66 | + 'allowShareDialogUserEnumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes'), |
|
67 | + 'enforceLinkPassword' => Util::isPublicLinkPasswordRequired(), |
|
68 | + 'onlyShareWithGroupMembers' => Share::shareWithGroupMembersOnly(), |
|
69 | + 'shareAPIEnabled' => $this->config->getAppValue('core', 'shareapi_enabled', 'yes'), |
|
70 | + 'shareDefaultExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no'), |
|
71 | + 'shareExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'), |
|
72 | + 'shareEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'), |
|
73 | + 'shareExcludeGroups' => $this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes', |
|
74 | + 'shareExcludedGroupsList' => $excludeGroupsList, |
|
75 | + 'publicShareDisclaimerText' => $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null), |
|
76 | + 'enableLinkPasswordByDefault' => $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'), |
|
77 | + 'shareApiDefaultPermissions' => $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL), |
|
78 | + 'shareApiDefaultPermissionsCheckboxes' => $this->getSharePermissionList(), |
|
79 | + ]; |
|
80 | 80 | |
81 | - return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, ''); |
|
82 | - } |
|
81 | + return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, ''); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * get share permission list for template |
|
86 | - * |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - private function getSharePermissionList() { |
|
90 | - return [ |
|
91 | - [ |
|
92 | - 'id' => 'cancreate', |
|
93 | - 'label' => $this->l->t('Create'), |
|
94 | - 'value' => Constants::PERMISSION_CREATE |
|
95 | - ], |
|
96 | - [ |
|
97 | - 'id' => 'canupdate', |
|
98 | - 'label' => $this->l->t('Change'), |
|
99 | - 'value' => Constants::PERMISSION_UPDATE |
|
100 | - ], |
|
101 | - [ |
|
102 | - 'id' => 'candelete', |
|
103 | - 'label' => $this->l->t('Delete'), |
|
104 | - 'value' => Constants::PERMISSION_DELETE |
|
105 | - ], |
|
106 | - [ |
|
107 | - 'id' => 'canshare', |
|
108 | - 'label' => $this->l->t('Share'), |
|
109 | - 'value' => Constants::PERMISSION_SHARE |
|
110 | - ], |
|
111 | - ]; |
|
112 | - } |
|
84 | + /** |
|
85 | + * get share permission list for template |
|
86 | + * |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + private function getSharePermissionList() { |
|
90 | + return [ |
|
91 | + [ |
|
92 | + 'id' => 'cancreate', |
|
93 | + 'label' => $this->l->t('Create'), |
|
94 | + 'value' => Constants::PERMISSION_CREATE |
|
95 | + ], |
|
96 | + [ |
|
97 | + 'id' => 'canupdate', |
|
98 | + 'label' => $this->l->t('Change'), |
|
99 | + 'value' => Constants::PERMISSION_UPDATE |
|
100 | + ], |
|
101 | + [ |
|
102 | + 'id' => 'candelete', |
|
103 | + 'label' => $this->l->t('Delete'), |
|
104 | + 'value' => Constants::PERMISSION_DELETE |
|
105 | + ], |
|
106 | + [ |
|
107 | + 'id' => 'canshare', |
|
108 | + 'label' => $this->l->t('Share'), |
|
109 | + 'value' => Constants::PERMISSION_SHARE |
|
110 | + ], |
|
111 | + ]; |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * @return string the section ID, e.g. 'sharing' |
|
116 | - */ |
|
117 | - public function getSection() { |
|
118 | - return 'sharing'; |
|
119 | - } |
|
114 | + /** |
|
115 | + * @return string the section ID, e.g. 'sharing' |
|
116 | + */ |
|
117 | + public function getSection() { |
|
118 | + return 'sharing'; |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * @return int whether the form should be rather on the top or bottom of |
|
123 | - * the admin section. The forms are arranged in ascending order of the |
|
124 | - * priority values. It is required to return a value between 0 and 100. |
|
125 | - * |
|
126 | - * E.g.: 70 |
|
127 | - */ |
|
128 | - public function getPriority() { |
|
129 | - return 0; |
|
130 | - } |
|
121 | + /** |
|
122 | + * @return int whether the form should be rather on the top or bottom of |
|
123 | + * the admin section. The forms are arranged in ascending order of the |
|
124 | + * priority values. It is required to return a value between 0 and 100. |
|
125 | + * |
|
126 | + * E.g.: 70 |
|
127 | + */ |
|
128 | + public function getPriority() { |
|
129 | + return 0; |
|
130 | + } |
|
131 | 131 | } |
@@ -45,287 +45,287 @@ |
||
45 | 45 | |
46 | 46 | class TemplateLayout extends \OC_Template { |
47 | 47 | |
48 | - private static $versionHash = ''; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var \OCP\IConfig |
|
52 | - */ |
|
53 | - private $config; |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $renderAs |
|
57 | - * @param string $appId application id |
|
58 | - */ |
|
59 | - public function __construct( $renderAs, $appId = '' ) { |
|
60 | - |
|
61 | - // yes - should be injected .... |
|
62 | - $this->config = \OC::$server->getConfig(); |
|
63 | - |
|
64 | - |
|
65 | - // Decide which page we show |
|
66 | - if($renderAs == 'user') { |
|
67 | - parent::__construct( 'core', 'layout.user' ); |
|
68 | - if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
69 | - $this->assign('bodyid', 'body-settings'); |
|
70 | - }else{ |
|
71 | - $this->assign('bodyid', 'body-user'); |
|
72 | - } |
|
73 | - |
|
74 | - // Code integrity notification |
|
75 | - $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
76 | - if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
77 | - \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
78 | - } |
|
79 | - |
|
80 | - // Add navigation entry |
|
81 | - $this->assign( 'application', ''); |
|
82 | - $this->assign( 'appid', $appId ); |
|
83 | - $navigation = \OC_App::getNavigation(); |
|
84 | - $this->assign( 'navigation', $navigation); |
|
85 | - $settingsNavigation = \OC_App::getSettingsNavigation(); |
|
86 | - $this->assign( 'settingsnavigation', $settingsNavigation); |
|
87 | - foreach($navigation as $entry) { |
|
88 | - if ($entry['active']) { |
|
89 | - $this->assign( 'application', $entry['name'] ); |
|
90 | - break; |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - foreach($settingsNavigation as $entry) { |
|
95 | - if ($entry['active']) { |
|
96 | - $this->assign( 'application', $entry['name'] ); |
|
97 | - break; |
|
98 | - } |
|
99 | - } |
|
100 | - $userDisplayName = \OC_User::getDisplayName(); |
|
101 | - $this->assign('user_displayname', $userDisplayName); |
|
102 | - $this->assign('user_uid', \OC_User::getUser()); |
|
103 | - |
|
104 | - if (\OC_User::getUser() === false) { |
|
105 | - $this->assign('userAvatarSet', false); |
|
106 | - } else { |
|
107 | - $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
108 | - $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
109 | - } |
|
110 | - |
|
111 | - // check if app menu icons should be inverted |
|
112 | - try { |
|
113 | - /** @var \OCA\Theming\Util $util */ |
|
114 | - $util = \OC::$server->query(\OCA\Theming\Util::class); |
|
115 | - $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary())); |
|
116 | - } catch (\OCP\AppFramework\QueryException $e) { |
|
117 | - $this->assign('themingInvertMenu', false); |
|
118 | - } |
|
119 | - |
|
120 | - } else if ($renderAs == 'error') { |
|
121 | - parent::__construct('core', 'layout.guest', '', false); |
|
122 | - $this->assign('bodyid', 'body-login'); |
|
123 | - } else if ($renderAs == 'guest') { |
|
124 | - parent::__construct('core', 'layout.guest'); |
|
125 | - $this->assign('bodyid', 'body-login'); |
|
126 | - } else { |
|
127 | - parent::__construct('core', 'layout.base'); |
|
128 | - |
|
129 | - } |
|
130 | - // Send the language to our layouts |
|
131 | - $lang = \OC::$server->getL10NFactory()->findLanguage(); |
|
132 | - $lang = str_replace('_', '-', $lang); |
|
133 | - $this->assign('language', $lang); |
|
134 | - |
|
135 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
136 | - if (empty(self::$versionHash)) { |
|
137 | - $v = \OC_App::getAppVersions(); |
|
138 | - $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
139 | - self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
|
140 | - } |
|
141 | - } else { |
|
142 | - self::$versionHash = md5('not installed'); |
|
143 | - } |
|
144 | - |
|
145 | - // Add the js files |
|
146 | - $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
147 | - $this->assign('jsfiles', array()); |
|
148 | - if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
149 | - if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
150 | - $jsConfigHelper = new JSConfigHelper( |
|
151 | - \OC::$server->getL10N('lib'), |
|
152 | - \OC::$server->query(Defaults::class), |
|
153 | - \OC::$server->getAppManager(), |
|
154 | - \OC::$server->getSession(), |
|
155 | - \OC::$server->getUserSession()->getUser(), |
|
156 | - $this->config, |
|
157 | - \OC::$server->getGroupManager(), |
|
158 | - \OC::$server->getIniWrapper(), |
|
159 | - \OC::$server->getURLGenerator(), |
|
160 | - \OC::$server->getCapabilitiesManager() |
|
161 | - ); |
|
162 | - $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
163 | - } else { |
|
164 | - $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
165 | - } |
|
166 | - } |
|
167 | - foreach($jsFiles as $info) { |
|
168 | - $web = $info[1]; |
|
169 | - $file = $info[2]; |
|
170 | - $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
171 | - } |
|
172 | - |
|
173 | - try { |
|
174 | - $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
175 | - } catch (\Exception $e) { |
|
176 | - $pathInfo = ''; |
|
177 | - } |
|
178 | - |
|
179 | - // Do not initialise scss appdata until we have a fully installed instance |
|
180 | - // Do not load scss for update, errors, installation or login page |
|
181 | - if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
182 | - && !\OCP\Util::needUpgrade() |
|
183 | - && $pathInfo !== '' |
|
184 | - && !preg_match('/^\/login/', $pathInfo) |
|
185 | - && $renderAs !== 'error' && $renderAs !== 'guest' |
|
186 | - ) { |
|
187 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
188 | - } else { |
|
189 | - // If we ignore the scss compiler, |
|
190 | - // we need to load the guest css fallback |
|
191 | - \OC_Util::addStyle('guest'); |
|
192 | - $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
193 | - } |
|
194 | - |
|
195 | - $this->assign('cssfiles', array()); |
|
196 | - $this->assign('printcssfiles', []); |
|
197 | - $this->assign('versionHash', self::$versionHash); |
|
198 | - foreach($cssFiles as $info) { |
|
199 | - $web = $info[1]; |
|
200 | - $file = $info[2]; |
|
201 | - |
|
202 | - if (substr($file, -strlen('print.css')) === 'print.css') { |
|
203 | - $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
204 | - } else { |
|
205 | - $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file) ); |
|
206 | - } |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @param string $path |
|
212 | - * @param string $file |
|
213 | - * @return string |
|
214 | - */ |
|
215 | - protected function getVersionHashSuffix($path = false, $file = false) { |
|
216 | - if ($this->config->getSystemValue('debug', false)) { |
|
217 | - // allows chrome workspace mapping in debug mode |
|
218 | - return ""; |
|
219 | - } |
|
220 | - $themingSuffix = ''; |
|
221 | - $v = []; |
|
222 | - |
|
223 | - if ($this->config->getSystemValue('installed', false)) { |
|
224 | - if (\OC::$server->getAppManager()->isInstalled('theming')) { |
|
225 | - $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
226 | - } |
|
227 | - $v = \OC_App::getAppVersions(); |
|
228 | - } |
|
229 | - |
|
230 | - // Try the webroot path for a match |
|
231 | - if ($path !== false && $path !== '') { |
|
232 | - $appName = $this->getAppNamefromPath($path); |
|
233 | - if(array_key_exists($appName, $v)) { |
|
234 | - $appVersion = $v[$appName]; |
|
235 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
236 | - } |
|
237 | - } |
|
238 | - // fallback to the file path instead |
|
239 | - if ($file !== false && $file !== '') { |
|
240 | - $appName = $this->getAppNamefromPath($file); |
|
241 | - if(array_key_exists($appName, $v)) { |
|
242 | - $appVersion = $v[$appName]; |
|
243 | - return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
244 | - } |
|
245 | - } |
|
246 | - |
|
247 | - return '?v=' . self::$versionHash . $themingSuffix; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * @param array $styles |
|
252 | - * @return array |
|
253 | - */ |
|
254 | - static public function findStylesheetFiles($styles, $compileScss = true) { |
|
255 | - // Read the selected theme from the config file |
|
256 | - $theme = \OC_Util::getTheme(); |
|
257 | - |
|
258 | - if($compileScss) { |
|
259 | - $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
260 | - } else { |
|
261 | - $SCSSCacher = null; |
|
262 | - } |
|
263 | - |
|
264 | - $locator = new \OC\Template\CSSResourceLocator( |
|
265 | - \OC::$server->getLogger(), |
|
266 | - $theme, |
|
267 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
268 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
269 | - $SCSSCacher |
|
270 | - ); |
|
271 | - $locator->find($styles); |
|
272 | - return $locator->getResources(); |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * @param string $path |
|
277 | - * @return string|boolean |
|
278 | - */ |
|
279 | - public function getAppNamefromPath($path) { |
|
280 | - if ($path !== '' && is_string($path)) { |
|
281 | - $pathParts = explode('/', $path); |
|
282 | - if ($pathParts[0] === 'css') { |
|
283 | - // This is a scss request |
|
284 | - return $pathParts[1]; |
|
285 | - } |
|
286 | - return end($pathParts); |
|
287 | - } |
|
288 | - return false; |
|
289 | - |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * @param array $scripts |
|
294 | - * @return array |
|
295 | - */ |
|
296 | - static public function findJavascriptFiles($scripts) { |
|
297 | - // Read the selected theme from the config file |
|
298 | - $theme = \OC_Util::getTheme(); |
|
299 | - |
|
300 | - $locator = new \OC\Template\JSResourceLocator( |
|
301 | - \OC::$server->getLogger(), |
|
302 | - $theme, |
|
303 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
304 | - array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
305 | - new JSCombiner( |
|
306 | - \OC::$server->getAppDataDir('js'), |
|
307 | - \OC::$server->getURLGenerator(), |
|
308 | - \OC::$server->getMemCacheFactory()->createDistributed('JS'), |
|
309 | - \OC::$server->getSystemConfig(), |
|
310 | - \OC::$server->getLogger() |
|
311 | - ) |
|
312 | - ); |
|
313 | - $locator->find($scripts); |
|
314 | - return $locator->getResources(); |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
319 | - * @param string $filePath Absolute path |
|
320 | - * @return string Relative path |
|
321 | - * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
322 | - */ |
|
323 | - public static function convertToRelativePath($filePath) { |
|
324 | - $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
325 | - if(count($relativePath) !== 2) { |
|
326 | - throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
327 | - } |
|
328 | - |
|
329 | - return $relativePath[1]; |
|
330 | - } |
|
48 | + private static $versionHash = ''; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var \OCP\IConfig |
|
52 | + */ |
|
53 | + private $config; |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $renderAs |
|
57 | + * @param string $appId application id |
|
58 | + */ |
|
59 | + public function __construct( $renderAs, $appId = '' ) { |
|
60 | + |
|
61 | + // yes - should be injected .... |
|
62 | + $this->config = \OC::$server->getConfig(); |
|
63 | + |
|
64 | + |
|
65 | + // Decide which page we show |
|
66 | + if($renderAs == 'user') { |
|
67 | + parent::__construct( 'core', 'layout.user' ); |
|
68 | + if(in_array(\OC_App::getCurrentApp(), ['settings','admin', 'help']) !== false) { |
|
69 | + $this->assign('bodyid', 'body-settings'); |
|
70 | + }else{ |
|
71 | + $this->assign('bodyid', 'body-user'); |
|
72 | + } |
|
73 | + |
|
74 | + // Code integrity notification |
|
75 | + $integrityChecker = \OC::$server->getIntegrityCodeChecker(); |
|
76 | + if(\OC_User::isAdminUser(\OC_User::getUser()) && $integrityChecker->isCodeCheckEnforced() && !$integrityChecker->hasPassedCheck()) { |
|
77 | + \OCP\Util::addScript('core', 'integritycheck-failed-notification'); |
|
78 | + } |
|
79 | + |
|
80 | + // Add navigation entry |
|
81 | + $this->assign( 'application', ''); |
|
82 | + $this->assign( 'appid', $appId ); |
|
83 | + $navigation = \OC_App::getNavigation(); |
|
84 | + $this->assign( 'navigation', $navigation); |
|
85 | + $settingsNavigation = \OC_App::getSettingsNavigation(); |
|
86 | + $this->assign( 'settingsnavigation', $settingsNavigation); |
|
87 | + foreach($navigation as $entry) { |
|
88 | + if ($entry['active']) { |
|
89 | + $this->assign( 'application', $entry['name'] ); |
|
90 | + break; |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + foreach($settingsNavigation as $entry) { |
|
95 | + if ($entry['active']) { |
|
96 | + $this->assign( 'application', $entry['name'] ); |
|
97 | + break; |
|
98 | + } |
|
99 | + } |
|
100 | + $userDisplayName = \OC_User::getDisplayName(); |
|
101 | + $this->assign('user_displayname', $userDisplayName); |
|
102 | + $this->assign('user_uid', \OC_User::getUser()); |
|
103 | + |
|
104 | + if (\OC_User::getUser() === false) { |
|
105 | + $this->assign('userAvatarSet', false); |
|
106 | + } else { |
|
107 | + $this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists()); |
|
108 | + $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); |
|
109 | + } |
|
110 | + |
|
111 | + // check if app menu icons should be inverted |
|
112 | + try { |
|
113 | + /** @var \OCA\Theming\Util $util */ |
|
114 | + $util = \OC::$server->query(\OCA\Theming\Util::class); |
|
115 | + $this->assign('themingInvertMenu', $util->invertTextColor(\OC::$server->getThemingDefaults()->getColorPrimary())); |
|
116 | + } catch (\OCP\AppFramework\QueryException $e) { |
|
117 | + $this->assign('themingInvertMenu', false); |
|
118 | + } |
|
119 | + |
|
120 | + } else if ($renderAs == 'error') { |
|
121 | + parent::__construct('core', 'layout.guest', '', false); |
|
122 | + $this->assign('bodyid', 'body-login'); |
|
123 | + } else if ($renderAs == 'guest') { |
|
124 | + parent::__construct('core', 'layout.guest'); |
|
125 | + $this->assign('bodyid', 'body-login'); |
|
126 | + } else { |
|
127 | + parent::__construct('core', 'layout.base'); |
|
128 | + |
|
129 | + } |
|
130 | + // Send the language to our layouts |
|
131 | + $lang = \OC::$server->getL10NFactory()->findLanguage(); |
|
132 | + $lang = str_replace('_', '-', $lang); |
|
133 | + $this->assign('language', $lang); |
|
134 | + |
|
135 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
136 | + if (empty(self::$versionHash)) { |
|
137 | + $v = \OC_App::getAppVersions(); |
|
138 | + $v['core'] = implode('.', \OCP\Util::getVersion()); |
|
139 | + self::$versionHash = substr(md5(implode(',', $v)), 0, 8); |
|
140 | + } |
|
141 | + } else { |
|
142 | + self::$versionHash = md5('not installed'); |
|
143 | + } |
|
144 | + |
|
145 | + // Add the js files |
|
146 | + $jsFiles = self::findJavascriptFiles(\OC_Util::$scripts); |
|
147 | + $this->assign('jsfiles', array()); |
|
148 | + if ($this->config->getSystemValue('installed', false) && $renderAs != 'error') { |
|
149 | + if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) { |
|
150 | + $jsConfigHelper = new JSConfigHelper( |
|
151 | + \OC::$server->getL10N('lib'), |
|
152 | + \OC::$server->query(Defaults::class), |
|
153 | + \OC::$server->getAppManager(), |
|
154 | + \OC::$server->getSession(), |
|
155 | + \OC::$server->getUserSession()->getUser(), |
|
156 | + $this->config, |
|
157 | + \OC::$server->getGroupManager(), |
|
158 | + \OC::$server->getIniWrapper(), |
|
159 | + \OC::$server->getURLGenerator(), |
|
160 | + \OC::$server->getCapabilitiesManager() |
|
161 | + ); |
|
162 | + $this->assign('inline_ocjs', $jsConfigHelper->getConfig()); |
|
163 | + } else { |
|
164 | + $this->append('jsfiles', \OC::$server->getURLGenerator()->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); |
|
165 | + } |
|
166 | + } |
|
167 | + foreach($jsFiles as $info) { |
|
168 | + $web = $info[1]; |
|
169 | + $file = $info[2]; |
|
170 | + $this->append( 'jsfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
171 | + } |
|
172 | + |
|
173 | + try { |
|
174 | + $pathInfo = \OC::$server->getRequest()->getPathInfo(); |
|
175 | + } catch (\Exception $e) { |
|
176 | + $pathInfo = ''; |
|
177 | + } |
|
178 | + |
|
179 | + // Do not initialise scss appdata until we have a fully installed instance |
|
180 | + // Do not load scss for update, errors, installation or login page |
|
181 | + if(\OC::$server->getSystemConfig()->getValue('installed', false) |
|
182 | + && !\OCP\Util::needUpgrade() |
|
183 | + && $pathInfo !== '' |
|
184 | + && !preg_match('/^\/login/', $pathInfo) |
|
185 | + && $renderAs !== 'error' && $renderAs !== 'guest' |
|
186 | + ) { |
|
187 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles); |
|
188 | + } else { |
|
189 | + // If we ignore the scss compiler, |
|
190 | + // we need to load the guest css fallback |
|
191 | + \OC_Util::addStyle('guest'); |
|
192 | + $cssFiles = self::findStylesheetFiles(\OC_Util::$styles, false); |
|
193 | + } |
|
194 | + |
|
195 | + $this->assign('cssfiles', array()); |
|
196 | + $this->assign('printcssfiles', []); |
|
197 | + $this->assign('versionHash', self::$versionHash); |
|
198 | + foreach($cssFiles as $info) { |
|
199 | + $web = $info[1]; |
|
200 | + $file = $info[2]; |
|
201 | + |
|
202 | + if (substr($file, -strlen('print.css')) === 'print.css') { |
|
203 | + $this->append( 'printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix() ); |
|
204 | + } else { |
|
205 | + $this->append( 'cssfiles', $web.'/'.$file . $this->getVersionHashSuffix($web, $file) ); |
|
206 | + } |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @param string $path |
|
212 | + * @param string $file |
|
213 | + * @return string |
|
214 | + */ |
|
215 | + protected function getVersionHashSuffix($path = false, $file = false) { |
|
216 | + if ($this->config->getSystemValue('debug', false)) { |
|
217 | + // allows chrome workspace mapping in debug mode |
|
218 | + return ""; |
|
219 | + } |
|
220 | + $themingSuffix = ''; |
|
221 | + $v = []; |
|
222 | + |
|
223 | + if ($this->config->getSystemValue('installed', false)) { |
|
224 | + if (\OC::$server->getAppManager()->isInstalled('theming')) { |
|
225 | + $themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
226 | + } |
|
227 | + $v = \OC_App::getAppVersions(); |
|
228 | + } |
|
229 | + |
|
230 | + // Try the webroot path for a match |
|
231 | + if ($path !== false && $path !== '') { |
|
232 | + $appName = $this->getAppNamefromPath($path); |
|
233 | + if(array_key_exists($appName, $v)) { |
|
234 | + $appVersion = $v[$appName]; |
|
235 | + return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
236 | + } |
|
237 | + } |
|
238 | + // fallback to the file path instead |
|
239 | + if ($file !== false && $file !== '') { |
|
240 | + $appName = $this->getAppNamefromPath($file); |
|
241 | + if(array_key_exists($appName, $v)) { |
|
242 | + $appVersion = $v[$appName]; |
|
243 | + return '?v=' . substr(md5($appVersion), 0, 8) . $themingSuffix; |
|
244 | + } |
|
245 | + } |
|
246 | + |
|
247 | + return '?v=' . self::$versionHash . $themingSuffix; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * @param array $styles |
|
252 | + * @return array |
|
253 | + */ |
|
254 | + static public function findStylesheetFiles($styles, $compileScss = true) { |
|
255 | + // Read the selected theme from the config file |
|
256 | + $theme = \OC_Util::getTheme(); |
|
257 | + |
|
258 | + if($compileScss) { |
|
259 | + $SCSSCacher = \OC::$server->query(SCSSCacher::class); |
|
260 | + } else { |
|
261 | + $SCSSCacher = null; |
|
262 | + } |
|
263 | + |
|
264 | + $locator = new \OC\Template\CSSResourceLocator( |
|
265 | + \OC::$server->getLogger(), |
|
266 | + $theme, |
|
267 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
268 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
269 | + $SCSSCacher |
|
270 | + ); |
|
271 | + $locator->find($styles); |
|
272 | + return $locator->getResources(); |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * @param string $path |
|
277 | + * @return string|boolean |
|
278 | + */ |
|
279 | + public function getAppNamefromPath($path) { |
|
280 | + if ($path !== '' && is_string($path)) { |
|
281 | + $pathParts = explode('/', $path); |
|
282 | + if ($pathParts[0] === 'css') { |
|
283 | + // This is a scss request |
|
284 | + return $pathParts[1]; |
|
285 | + } |
|
286 | + return end($pathParts); |
|
287 | + } |
|
288 | + return false; |
|
289 | + |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * @param array $scripts |
|
294 | + * @return array |
|
295 | + */ |
|
296 | + static public function findJavascriptFiles($scripts) { |
|
297 | + // Read the selected theme from the config file |
|
298 | + $theme = \OC_Util::getTheme(); |
|
299 | + |
|
300 | + $locator = new \OC\Template\JSResourceLocator( |
|
301 | + \OC::$server->getLogger(), |
|
302 | + $theme, |
|
303 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
304 | + array( \OC::$SERVERROOT => \OC::$WEBROOT ), |
|
305 | + new JSCombiner( |
|
306 | + \OC::$server->getAppDataDir('js'), |
|
307 | + \OC::$server->getURLGenerator(), |
|
308 | + \OC::$server->getMemCacheFactory()->createDistributed('JS'), |
|
309 | + \OC::$server->getSystemConfig(), |
|
310 | + \OC::$server->getLogger() |
|
311 | + ) |
|
312 | + ); |
|
313 | + $locator->find($scripts); |
|
314 | + return $locator->getResources(); |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * Converts the absolute file path to a relative path from \OC::$SERVERROOT |
|
319 | + * @param string $filePath Absolute path |
|
320 | + * @return string Relative path |
|
321 | + * @throws \Exception If $filePath is not under \OC::$SERVERROOT |
|
322 | + */ |
|
323 | + public static function convertToRelativePath($filePath) { |
|
324 | + $relativePath = explode(\OC::$SERVERROOT, $filePath); |
|
325 | + if(count($relativePath) !== 2) { |
|
326 | + throw new \Exception('$filePath is not under the \OC::$SERVERROOT'); |
|
327 | + } |
|
328 | + |
|
329 | + return $relativePath[1]; |
|
330 | + } |
|
331 | 331 | } |