@@ -10,10 +10,10 @@ discard block |
||
10 | 10 | |
11 | 11 | <div id="app-navigation"> |
12 | 12 | <ul class="with-icon"> |
13 | - <?php foreach($_['forms'] as $form) { |
|
13 | + <?php foreach ($_['forms'] as $form) { |
|
14 | 14 | if (isset($form['anchor'])) { |
15 | - $anchor = '#' . $form['anchor']; |
|
16 | - $class = 'nav-icon-' . $form['anchor']; |
|
15 | + $anchor = '#'.$form['anchor']; |
|
16 | + $class = 'nav-icon-'.$form['anchor']; |
|
17 | 17 | $sectionName = $form['section-name']; |
18 | 18 | print_unescaped(sprintf("<li><a href='%s' class='%s'>%s</a></li>", \OCP\Util::sanitizeHTML($anchor), |
19 | 19 | \OCP\Util::sanitizeHTML($class), \OCP\Util::sanitizeHTML($sectionName))); |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | <div id="app-content"> |
26 | 26 | |
27 | 27 | <div id="quota" class="section"> |
28 | - <div style="width:<?php p($_['usage_relative']);?>%" |
|
29 | - <?php if($_['usage_relative'] > 80): ?> class="quota-warning" <?php endif; ?>> |
|
28 | + <div style="width:<?php p($_['usage_relative']); ?>%" |
|
29 | + <?php if ($_['usage_relative'] > 80): ?> class="quota-warning" <?php endif; ?>> |
|
30 | 30 | <p id="quotatext"> |
31 | 31 | <?php if ($_['quota'] === \OCP\Files\FileInfo::SPACE_UNLIMITED): ?> |
32 | 32 | <?php print_unescaped($l->t('You are using <strong>%s</strong> of <strong>%s</strong>', |
33 | - [$_['usage'], $_['total_space']]));?> |
|
33 | + [$_['usage'], $_['total_space']])); ?> |
|
34 | 34 | <?php else: ?> |
35 | 35 | <?php print_unescaped($l->t('You are using <strong>%s</strong> of <strong>%s</strong> (<strong>%s %%</strong>)', |
36 | - [$_['usage'], $_['total_space'], $_['usage_relative']]));?> |
|
36 | + [$_['usage'], $_['total_space'], $_['usage_relative']])); ?> |
|
37 | 37 | <?php endif ?> |
38 | 38 | </p> |
39 | 39 | </div> |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | </div> |
68 | 68 | </div> |
69 | 69 | <span class="icon-checkmark hidden"/> |
70 | - <?php if($_['lookupServerUploadEnabled']) { ?> |
|
70 | + <?php if ($_['lookupServerUploadEnabled']) { ?> |
|
71 | 71 | <input type="hidden" id="avatarscope" value="<?php p($_['avatarScope']) ?>"> |
72 | 72 | <?php } ?> |
73 | 73 | </form> |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | <span class="icon-password"/> |
82 | 82 | </h2> |
83 | 83 | <input type="text" id="displayname" name="displayname" |
84 | - <?php if(!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?> |
|
84 | + <?php if (!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?> |
|
85 | 85 | value="<?php p($_['displayName']) ?>" |
86 | 86 | autocomplete="on" autocapitalize="none" autocorrect="off" /> |
87 | - <?php if(!$_['displayNameChangeSupported']) { ?> |
|
88 | - <span><?php if(isset($_['displayName']) && !empty($_['displayName'])) { p($_['displayName']); } else { p($l->t('No display name set')); } ?></span> |
|
87 | + <?php if (!$_['displayNameChangeSupported']) { ?> |
|
88 | + <span><?php if (isset($_['displayName']) && !empty($_['displayName'])) { p($_['displayName']); } else { p($l->t('No display name set')); } ?></span> |
|
89 | 89 | <?php } ?> |
90 | 90 | <span class="icon-checkmark hidden"/> |
91 | - <?php if($_['lookupServerUploadEnabled']) { ?> |
|
91 | + <?php if ($_['lookupServerUploadEnabled']) { ?> |
|
92 | 92 | <input type="hidden" id="displaynamescope" value="<?php p($_['displayNameScope']) ?>"> |
93 | 93 | <?php } ?> |
94 | 94 | </form> |
@@ -100,23 +100,23 @@ discard block |
||
100 | 100 | <span class="icon-password"/> |
101 | 101 | </h2> |
102 | 102 | <input type="email" name="email" id="email" value="<?php p($_['email']); ?>" |
103 | - <?php if(!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?> |
|
103 | + <?php if (!$_['displayNameChangeSupported']) { print_unescaped('class="hidden"'); } ?> |
|
104 | 104 | placeholder="<?php p($l->t('Your email address')); ?>" |
105 | 105 | autocomplete="on" autocapitalize="none" autocorrect="off" /> |
106 | - <?php if(!$_['displayNameChangeSupported']) { ?> |
|
107 | - <span><?php if(isset($_['email']) && !empty($_['email'])) { p($_['email']); } else { p($l->t('No email address set')); }?></span> |
|
106 | + <?php if (!$_['displayNameChangeSupported']) { ?> |
|
107 | + <span><?php if (isset($_['email']) && !empty($_['email'])) { p($_['email']); } else { p($l->t('No email address set')); }?></span> |
|
108 | 108 | <?php } ?> |
109 | - <?php if($_['displayNameChangeSupported']) { ?> |
|
109 | + <?php if ($_['displayNameChangeSupported']) { ?> |
|
110 | 110 | <br /> |
111 | 111 | <em><?php p($l->t('For password reset and notifications')); ?></em> |
112 | 112 | <?php } ?> |
113 | 113 | <span class="icon-checkmark hidden"/> |
114 | - <?php if($_['lookupServerUploadEnabled']) { ?> |
|
114 | + <?php if ($_['lookupServerUploadEnabled']) { ?> |
|
115 | 115 | <input type="hidden" id="emailscope" value="<?php p($_['emailScope']) ?>"> |
116 | 116 | <?php } ?> |
117 | 117 | </form> |
118 | 118 | </div> |
119 | - <?php if($_['lookupServerUploadEnabled']) { ?> |
|
119 | + <?php if ($_['lookupServerUploadEnabled']) { ?> |
|
120 | 120 | <div class="personal-settings-setting-box"> |
121 | 121 | <form id="phoneform" class="section"> |
122 | 122 | <h2> |
@@ -185,19 +185,19 @@ discard block |
||
185 | 185 | </div> |
186 | 186 | |
187 | 187 | <?php |
188 | -if($_['passwordChangeSupported']) { |
|
188 | +if ($_['passwordChangeSupported']) { |
|
189 | 189 | script('jquery-showpassword'); |
190 | 190 | ?> |
191 | 191 | <form id="passwordform" class="section"> |
192 | - <h2 class="inlineblock"><?php p($l->t('Password'));?></h2> |
|
192 | + <h2 class="inlineblock"><?php p($l->t('Password')); ?></h2> |
|
193 | 193 | <div id="password-error-msg" class="msg success inlineblock" style="display: none;">Saved</div> |
194 | 194 | <br> |
195 | 195 | <label for="pass1" class="hidden-visually"><?php p($l->t('Current password')); ?>: </label> |
196 | 196 | <input type="password" id="pass1" name="oldpassword" |
197 | - placeholder="<?php p($l->t('Current password'));?>" |
|
197 | + placeholder="<?php p($l->t('Current password')); ?>" |
|
198 | 198 | autocomplete="off" autocapitalize="none" autocorrect="off" /> |
199 | 199 | <div class="personal-show-container"> |
200 | - <label for="pass2" class="hidden-visually"><?php p($l->t('New password'));?>: </label> |
|
200 | + <label for="pass2" class="hidden-visually"><?php p($l->t('New password')); ?>: </label> |
|
201 | 201 | <input type="password" id="pass2" name="newpassword" |
202 | 202 | placeholder="<?php p($l->t('New password')); ?>" |
203 | 203 | data-typetoggle="#personal-show" |
@@ -213,44 +213,44 @@ discard block |
||
213 | 213 | |
214 | 214 | <form id="language" class="section"> |
215 | 215 | <h2> |
216 | - <label for="languageinput"><?php p($l->t('Language'));?></label> |
|
216 | + <label for="languageinput"><?php p($l->t('Language')); ?></label> |
|
217 | 217 | </h2> |
218 | - <select id="languageinput" name="lang" data-placeholder="<?php p($l->t('Language'));?>"> |
|
219 | - <option value="<?php p($_['activelanguage']['code']);?>"> |
|
220 | - <?php p($_['activelanguage']['name']);?> |
|
218 | + <select id="languageinput" name="lang" data-placeholder="<?php p($l->t('Language')); ?>"> |
|
219 | + <option value="<?php p($_['activelanguage']['code']); ?>"> |
|
220 | + <?php p($_['activelanguage']['name']); ?> |
|
221 | 221 | </option> |
222 | - <?php foreach($_['commonlanguages'] as $language):?> |
|
223 | - <option value="<?php p($language['code']);?>"> |
|
224 | - <?php p($language['name']);?> |
|
222 | + <?php foreach ($_['commonlanguages'] as $language):?> |
|
223 | + <option value="<?php p($language['code']); ?>"> |
|
224 | + <?php p($language['name']); ?> |
|
225 | 225 | </option> |
226 | - <?php endforeach;?> |
|
226 | + <?php endforeach; ?> |
|
227 | 227 | <optgroup label="––––––––––"></optgroup> |
228 | - <?php foreach($_['languages'] as $language):?> |
|
229 | - <option value="<?php p($language['code']);?>"> |
|
230 | - <?php p($language['name']);?> |
|
228 | + <?php foreach ($_['languages'] as $language):?> |
|
229 | + <option value="<?php p($language['code']); ?>"> |
|
230 | + <?php p($language['name']); ?> |
|
231 | 231 | </option> |
232 | - <?php endforeach;?> |
|
232 | + <?php endforeach; ?> |
|
233 | 233 | </select> |
234 | 234 | <a href="https://www.transifex.com/nextcloud/nextcloud/" |
235 | 235 | target="_blank" rel="noreferrer"> |
236 | - <em><?php p($l->t('Help translate'));?></em> |
|
236 | + <em><?php p($l->t('Help translate')); ?></em> |
|
237 | 237 | </a> |
238 | 238 | </form> |
239 | 239 | |
240 | 240 | |
241 | 241 | <div id="clientsbox" class="section clientsbox"> |
242 | - <h2><?php p($l->t('Get the apps to sync your files'));?></h2> |
|
242 | + <h2><?php p($l->t('Get the apps to sync your files')); ?></h2> |
|
243 | 243 | <a href="<?php p($_['clients']['desktop']); ?>" rel="noreferrer" target="_blank"> |
244 | 244 | <img src="<?php print_unescaped(image_path('core', 'desktopapp.svg')); ?>" |
245 | - alt="<?php p($l->t('Desktop client'));?>" /> |
|
245 | + alt="<?php p($l->t('Desktop client')); ?>" /> |
|
246 | 246 | </a> |
247 | 247 | <a href="<?php p($_['clients']['android']); ?>" rel="noreferrer" target="_blank"> |
248 | 248 | <img src="<?php print_unescaped(image_path('core', 'googleplay.png')); ?>" |
249 | - alt="<?php p($l->t('Android app'));?>" /> |
|
249 | + alt="<?php p($l->t('Android app')); ?>" /> |
|
250 | 250 | </a> |
251 | 251 | <a href="<?php p($_['clients']['ios']); ?>" rel="noreferrer" target="_blank"> |
252 | 252 | <img src="<?php print_unescaped(image_path('core', 'appstore.svg')); ?>" |
253 | - alt="<?php p($l->t('iOS app'));?>" /> |
|
253 | + alt="<?php p($l->t('iOS app')); ?>" /> |
|
254 | 254 | </a> |
255 | 255 | |
256 | 256 | <p> |
@@ -266,19 +266,19 @@ discard block |
||
266 | 266 | $l->t('If you want to support the project {contributeopen}join development{linkclose} or {contributeopen}spread the word{linkclose}!'))); ?> |
267 | 267 | </p> |
268 | 268 | |
269 | - <?php if(OC_APP::isEnabled('firstrunwizard')) {?> |
|
270 | - <p><a class="button" href="#" id="showWizard"><?php p($l->t('Show First Run Wizard again'));?></a></p> |
|
269 | + <?php if (OC_APP::isEnabled('firstrunwizard')) {?> |
|
270 | + <p><a class="button" href="#" id="showWizard"><?php p($l->t('Show First Run Wizard again')); ?></a></p> |
|
271 | 271 | <?php }?> |
272 | 272 | </div> |
273 | 273 | |
274 | 274 | <div id="sessions" class="section"> |
275 | - <h2><?php p($l->t('Sessions'));?></h2> |
|
276 | - <span class="hidden-when-empty"><?php p($l->t('Web, desktop and mobile clients currently logged in to your account.'));?></span> |
|
275 | + <h2><?php p($l->t('Sessions')); ?></h2> |
|
276 | + <span class="hidden-when-empty"><?php p($l->t('Web, desktop and mobile clients currently logged in to your account.')); ?></span> |
|
277 | 277 | <table class="icon-loading"> |
278 | 278 | <thead class="token-list-header"> |
279 | 279 | <tr> |
280 | - <th><?php p($l->t('Device'));?></th> |
|
281 | - <th><?php p($l->t('Last activity'));?></th> |
|
280 | + <th><?php p($l->t('Device')); ?></th> |
|
281 | + <th><?php p($l->t('Last activity')); ?></th> |
|
282 | 282 | <th></th> |
283 | 283 | </tr> |
284 | 284 | </thead> |
@@ -288,13 +288,13 @@ discard block |
||
288 | 288 | </div> |
289 | 289 | |
290 | 290 | <div id="apppasswords" class="section"> |
291 | - <h2><?php p($l->t('App passwords'));?></h2> |
|
292 | - <p><?php p($l->t('Passcodes that give an app or device permissions to access your account.'));?></p> |
|
291 | + <h2><?php p($l->t('App passwords')); ?></h2> |
|
292 | + <p><?php p($l->t('Passcodes that give an app or device permissions to access your account.')); ?></p> |
|
293 | 293 | <table class="icon-loading"> |
294 | 294 | <thead class="hidden-when-empty"> |
295 | 295 | <tr> |
296 | - <th><?php p($l->t('Name'));?></th> |
|
297 | - <th><?php p($l->t('Last activity'));?></th> |
|
296 | + <th><?php p($l->t('Name')); ?></th> |
|
297 | + <th><?php p($l->t('Last activity')); ?></th> |
|
298 | 298 | <th></th> |
299 | 299 | </tr> |
300 | 300 | </thead> |
@@ -323,14 +323,14 @@ discard block |
||
323 | 323 | </div> |
324 | 324 | </div> |
325 | 325 | |
326 | -<?php foreach($_['forms'] as $form) { |
|
326 | +<?php foreach ($_['forms'] as $form) { |
|
327 | 327 | if (isset($form['form'])) {?> |
328 | - <div id="<?php isset($form['anchor']) ? p($form['anchor']) : p('');?>"><?php print_unescaped($form['form']);?></div> |
|
328 | + <div id="<?php isset($form['anchor']) ? p($form['anchor']) : p(''); ?>"><?php print_unescaped($form['form']); ?></div> |
|
329 | 329 | <?php } |
330 | 330 | };?> |
331 | 331 | |
332 | 332 | <div class="section"> |
333 | - <h2><?php p($l->t('Version'));?></h2> |
|
333 | + <h2><?php p($l->t('Version')); ?></h2> |
|
334 | 334 | <p><a href="<?php print_unescaped($theme->getBaseUrl()); ?>" target="_blank"><?php p($theme->getTitle()); ?></a> <?php p(OC_Util::getHumanVersion()) ?></p> |
335 | 335 | <p><?php include('settings.development.notice.php'); ?></p> |
336 | 336 | </div> |
@@ -29,43 +29,43 @@ |
||
29 | 29 | |
30 | 30 | class Admin implements ISettings { |
31 | 31 | |
32 | - /** @var FederatedShareProvider */ |
|
33 | - private $fedShareProvider; |
|
32 | + /** @var FederatedShareProvider */ |
|
33 | + private $fedShareProvider; |
|
34 | 34 | |
35 | - public function __construct(FederatedShareProvider $fedShareProvider) { |
|
36 | - $this->fedShareProvider = $fedShareProvider; |
|
37 | - } |
|
35 | + public function __construct(FederatedShareProvider $fedShareProvider) { |
|
36 | + $this->fedShareProvider = $fedShareProvider; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return TemplateResponse |
|
41 | - */ |
|
42 | - public function getForm() { |
|
43 | - $parameters = [ |
|
44 | - 'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(), |
|
45 | - 'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(), |
|
46 | - 'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(), |
|
47 | - 'lookupServerUploadEnabled' => $this->fedShareProvider->isLookupServerUploadEnabled(), |
|
48 | - ]; |
|
39 | + /** |
|
40 | + * @return TemplateResponse |
|
41 | + */ |
|
42 | + public function getForm() { |
|
43 | + $parameters = [ |
|
44 | + 'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(), |
|
45 | + 'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(), |
|
46 | + 'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(), |
|
47 | + 'lookupServerUploadEnabled' => $this->fedShareProvider->isLookupServerUploadEnabled(), |
|
48 | + ]; |
|
49 | 49 | |
50 | - return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, ''); |
|
51 | - } |
|
50 | + return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, ''); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return string the section ID, e.g. 'sharing' |
|
55 | - */ |
|
56 | - public function getSection() { |
|
57 | - return 'sharing'; |
|
58 | - } |
|
53 | + /** |
|
54 | + * @return string the section ID, e.g. 'sharing' |
|
55 | + */ |
|
56 | + public function getSection() { |
|
57 | + return 'sharing'; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return int whether the form should be rather on the top or bottom of |
|
62 | - * the admin section. The forms are arranged in ascending order of the |
|
63 | - * priority values. It is required to return a value between 0 and 100. |
|
64 | - * |
|
65 | - * E.g.: 70 |
|
66 | - */ |
|
67 | - public function getPriority() { |
|
68 | - return 20; |
|
69 | - } |
|
60 | + /** |
|
61 | + * @return int whether the form should be rather on the top or bottom of |
|
62 | + * the admin section. The forms are arranged in ascending order of the |
|
63 | + * priority values. It is required to return a value between 0 and 100. |
|
64 | + * |
|
65 | + * E.g.: 70 |
|
66 | + */ |
|
67 | + public function getPriority() { |
|
68 | + return 20; |
|
69 | + } |
|
70 | 70 | |
71 | 71 | } |
@@ -49,929 +49,929 @@ |
||
49 | 49 | */ |
50 | 50 | class FederatedShareProvider implements IShareProvider { |
51 | 51 | |
52 | - const SHARE_TYPE_REMOTE = 6; |
|
53 | - |
|
54 | - /** @var IDBConnection */ |
|
55 | - private $dbConnection; |
|
56 | - |
|
57 | - /** @var AddressHandler */ |
|
58 | - private $addressHandler; |
|
59 | - |
|
60 | - /** @var Notifications */ |
|
61 | - private $notifications; |
|
62 | - |
|
63 | - /** @var TokenHandler */ |
|
64 | - private $tokenHandler; |
|
65 | - |
|
66 | - /** @var IL10N */ |
|
67 | - private $l; |
|
68 | - |
|
69 | - /** @var ILogger */ |
|
70 | - private $logger; |
|
71 | - |
|
72 | - /** @var IRootFolder */ |
|
73 | - private $rootFolder; |
|
74 | - |
|
75 | - /** @var IConfig */ |
|
76 | - private $config; |
|
77 | - |
|
78 | - /** @var string */ |
|
79 | - private $externalShareTable = 'share_external'; |
|
80 | - |
|
81 | - /** @var IUserManager */ |
|
82 | - private $userManager; |
|
83 | - |
|
84 | - /** @var ICloudIdManager */ |
|
85 | - private $cloudIdManager; |
|
86 | - |
|
87 | - /** |
|
88 | - * DefaultShareProvider constructor. |
|
89 | - * |
|
90 | - * @param IDBConnection $connection |
|
91 | - * @param AddressHandler $addressHandler |
|
92 | - * @param Notifications $notifications |
|
93 | - * @param TokenHandler $tokenHandler |
|
94 | - * @param IL10N $l10n |
|
95 | - * @param ILogger $logger |
|
96 | - * @param IRootFolder $rootFolder |
|
97 | - * @param IConfig $config |
|
98 | - * @param IUserManager $userManager |
|
99 | - * @param ICloudIdManager $cloudIdManager |
|
100 | - */ |
|
101 | - public function __construct( |
|
102 | - IDBConnection $connection, |
|
103 | - AddressHandler $addressHandler, |
|
104 | - Notifications $notifications, |
|
105 | - TokenHandler $tokenHandler, |
|
106 | - IL10N $l10n, |
|
107 | - ILogger $logger, |
|
108 | - IRootFolder $rootFolder, |
|
109 | - IConfig $config, |
|
110 | - IUserManager $userManager, |
|
111 | - ICloudIdManager $cloudIdManager |
|
112 | - ) { |
|
113 | - $this->dbConnection = $connection; |
|
114 | - $this->addressHandler = $addressHandler; |
|
115 | - $this->notifications = $notifications; |
|
116 | - $this->tokenHandler = $tokenHandler; |
|
117 | - $this->l = $l10n; |
|
118 | - $this->logger = $logger; |
|
119 | - $this->rootFolder = $rootFolder; |
|
120 | - $this->config = $config; |
|
121 | - $this->userManager = $userManager; |
|
122 | - $this->cloudIdManager = $cloudIdManager; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Return the identifier of this provider. |
|
127 | - * |
|
128 | - * @return string Containing only [a-zA-Z0-9] |
|
129 | - */ |
|
130 | - public function identifier() { |
|
131 | - return 'ocFederatedSharing'; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Share a path |
|
136 | - * |
|
137 | - * @param IShare $share |
|
138 | - * @return IShare The share object |
|
139 | - * @throws ShareNotFound |
|
140 | - * @throws \Exception |
|
141 | - */ |
|
142 | - public function create(IShare $share) { |
|
143 | - |
|
144 | - $shareWith = $share->getSharedWith(); |
|
145 | - $itemSource = $share->getNodeId(); |
|
146 | - $itemType = $share->getNodeType(); |
|
147 | - $permissions = $share->getPermissions(); |
|
148 | - $sharedBy = $share->getSharedBy(); |
|
149 | - |
|
150 | - /* |
|
52 | + const SHARE_TYPE_REMOTE = 6; |
|
53 | + |
|
54 | + /** @var IDBConnection */ |
|
55 | + private $dbConnection; |
|
56 | + |
|
57 | + /** @var AddressHandler */ |
|
58 | + private $addressHandler; |
|
59 | + |
|
60 | + /** @var Notifications */ |
|
61 | + private $notifications; |
|
62 | + |
|
63 | + /** @var TokenHandler */ |
|
64 | + private $tokenHandler; |
|
65 | + |
|
66 | + /** @var IL10N */ |
|
67 | + private $l; |
|
68 | + |
|
69 | + /** @var ILogger */ |
|
70 | + private $logger; |
|
71 | + |
|
72 | + /** @var IRootFolder */ |
|
73 | + private $rootFolder; |
|
74 | + |
|
75 | + /** @var IConfig */ |
|
76 | + private $config; |
|
77 | + |
|
78 | + /** @var string */ |
|
79 | + private $externalShareTable = 'share_external'; |
|
80 | + |
|
81 | + /** @var IUserManager */ |
|
82 | + private $userManager; |
|
83 | + |
|
84 | + /** @var ICloudIdManager */ |
|
85 | + private $cloudIdManager; |
|
86 | + |
|
87 | + /** |
|
88 | + * DefaultShareProvider constructor. |
|
89 | + * |
|
90 | + * @param IDBConnection $connection |
|
91 | + * @param AddressHandler $addressHandler |
|
92 | + * @param Notifications $notifications |
|
93 | + * @param TokenHandler $tokenHandler |
|
94 | + * @param IL10N $l10n |
|
95 | + * @param ILogger $logger |
|
96 | + * @param IRootFolder $rootFolder |
|
97 | + * @param IConfig $config |
|
98 | + * @param IUserManager $userManager |
|
99 | + * @param ICloudIdManager $cloudIdManager |
|
100 | + */ |
|
101 | + public function __construct( |
|
102 | + IDBConnection $connection, |
|
103 | + AddressHandler $addressHandler, |
|
104 | + Notifications $notifications, |
|
105 | + TokenHandler $tokenHandler, |
|
106 | + IL10N $l10n, |
|
107 | + ILogger $logger, |
|
108 | + IRootFolder $rootFolder, |
|
109 | + IConfig $config, |
|
110 | + IUserManager $userManager, |
|
111 | + ICloudIdManager $cloudIdManager |
|
112 | + ) { |
|
113 | + $this->dbConnection = $connection; |
|
114 | + $this->addressHandler = $addressHandler; |
|
115 | + $this->notifications = $notifications; |
|
116 | + $this->tokenHandler = $tokenHandler; |
|
117 | + $this->l = $l10n; |
|
118 | + $this->logger = $logger; |
|
119 | + $this->rootFolder = $rootFolder; |
|
120 | + $this->config = $config; |
|
121 | + $this->userManager = $userManager; |
|
122 | + $this->cloudIdManager = $cloudIdManager; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Return the identifier of this provider. |
|
127 | + * |
|
128 | + * @return string Containing only [a-zA-Z0-9] |
|
129 | + */ |
|
130 | + public function identifier() { |
|
131 | + return 'ocFederatedSharing'; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Share a path |
|
136 | + * |
|
137 | + * @param IShare $share |
|
138 | + * @return IShare The share object |
|
139 | + * @throws ShareNotFound |
|
140 | + * @throws \Exception |
|
141 | + */ |
|
142 | + public function create(IShare $share) { |
|
143 | + |
|
144 | + $shareWith = $share->getSharedWith(); |
|
145 | + $itemSource = $share->getNodeId(); |
|
146 | + $itemType = $share->getNodeType(); |
|
147 | + $permissions = $share->getPermissions(); |
|
148 | + $sharedBy = $share->getSharedBy(); |
|
149 | + |
|
150 | + /* |
|
151 | 151 | * Check if file is not already shared with the remote user |
152 | 152 | */ |
153 | - $alreadyShared = $this->getSharedWith($shareWith, self::SHARE_TYPE_REMOTE, $share->getNode(), 1, 0); |
|
154 | - if (!empty($alreadyShared)) { |
|
155 | - $message = 'Sharing %s failed, because this item is already shared with %s'; |
|
156 | - $message_t = $this->l->t('Sharing %s failed, because this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
157 | - $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
158 | - throw new \Exception($message_t); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - // don't allow federated shares if source and target server are the same |
|
163 | - $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
164 | - $currentServer = $this->addressHandler->generateRemoteURL(); |
|
165 | - $currentUser = $sharedBy; |
|
166 | - if ($this->addressHandler->compareAddresses($cloudId->getUser(), $cloudId->getRemote(), $currentUser, $currentServer)) { |
|
167 | - $message = 'Not allowed to create a federated share with the same user.'; |
|
168 | - $message_t = $this->l->t('Not allowed to create a federated share with the same user'); |
|
169 | - $this->logger->debug($message, ['app' => 'Federated File Sharing']); |
|
170 | - throw new \Exception($message_t); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - $share->setSharedWith($cloudId->getId()); |
|
175 | - |
|
176 | - try { |
|
177 | - $remoteShare = $this->getShareFromExternalShareTable($share); |
|
178 | - } catch (ShareNotFound $e) { |
|
179 | - $remoteShare = null; |
|
180 | - } |
|
181 | - |
|
182 | - if ($remoteShare) { |
|
183 | - try { |
|
184 | - $ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']); |
|
185 | - $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time()); |
|
186 | - $share->setId($shareId); |
|
187 | - list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId); |
|
188 | - // remote share was create successfully if we get a valid token as return |
|
189 | - $send = is_string($token) && $token !== ''; |
|
190 | - } catch (\Exception $e) { |
|
191 | - // fall back to old re-share behavior if the remote server |
|
192 | - // doesn't support flat re-shares (was introduced with Nextcloud 9.1) |
|
193 | - $this->removeShareFromTable($share); |
|
194 | - $shareId = $this->createFederatedShare($share); |
|
195 | - } |
|
196 | - if ($send) { |
|
197 | - $this->updateSuccessfulReshare($shareId, $token); |
|
198 | - $this->storeRemoteId($shareId, $remoteId); |
|
199 | - } else { |
|
200 | - $this->removeShareFromTable($share); |
|
201 | - $message_t = $this->l->t('File is already shared with %s', [$shareWith]); |
|
202 | - throw new \Exception($message_t); |
|
203 | - } |
|
204 | - |
|
205 | - } else { |
|
206 | - $shareId = $this->createFederatedShare($share); |
|
207 | - } |
|
208 | - |
|
209 | - $data = $this->getRawShare($shareId); |
|
210 | - return $this->createShareObject($data); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * create federated share and inform the recipient |
|
215 | - * |
|
216 | - * @param IShare $share |
|
217 | - * @return int |
|
218 | - * @throws ShareNotFound |
|
219 | - * @throws \Exception |
|
220 | - */ |
|
221 | - protected function createFederatedShare(IShare $share) { |
|
222 | - $token = $this->tokenHandler->generateToken(); |
|
223 | - $shareId = $this->addShareToDB( |
|
224 | - $share->getNodeId(), |
|
225 | - $share->getNodeType(), |
|
226 | - $share->getSharedWith(), |
|
227 | - $share->getSharedBy(), |
|
228 | - $share->getShareOwner(), |
|
229 | - $share->getPermissions(), |
|
230 | - $token |
|
231 | - ); |
|
232 | - |
|
233 | - $failure = false; |
|
234 | - |
|
235 | - try { |
|
236 | - $sharedByFederatedId = $share->getSharedBy(); |
|
237 | - if ($this->userManager->userExists($sharedByFederatedId)) { |
|
238 | - $cloudId = $this->cloudIdManager->getCloudId($sharedByFederatedId, $this->addressHandler->generateRemoteURL()); |
|
239 | - $sharedByFederatedId = $cloudId->getId(); |
|
240 | - } |
|
241 | - $ownerCloudId = $this->cloudIdManager->getCloudId($share->getShareOwner(), $this->addressHandler->generateRemoteURL()); |
|
242 | - $send = $this->notifications->sendRemoteShare( |
|
243 | - $token, |
|
244 | - $share->getSharedWith(), |
|
245 | - $share->getNode()->getName(), |
|
246 | - $shareId, |
|
247 | - $share->getShareOwner(), |
|
248 | - $ownerCloudId->getId(), |
|
249 | - $share->getSharedBy(), |
|
250 | - $sharedByFederatedId |
|
251 | - ); |
|
252 | - |
|
253 | - if ($send === false) { |
|
254 | - $failure = true; |
|
255 | - } |
|
256 | - } catch (\Exception $e) { |
|
257 | - $this->logger->error('Failed to notify remote server of federated share, removing share (' . $e->getMessage() . ')'); |
|
258 | - $failure = true; |
|
259 | - } |
|
260 | - |
|
261 | - if($failure) { |
|
262 | - $this->removeShareFromTableById($shareId); |
|
263 | - $message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable or uses a self-signed certificate.', |
|
264 | - [$share->getNode()->getName(), $share->getSharedWith()]); |
|
265 | - throw new \Exception($message_t); |
|
266 | - } |
|
267 | - |
|
268 | - return $shareId; |
|
269 | - |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * @param string $shareWith |
|
274 | - * @param IShare $share |
|
275 | - * @param string $shareId internal share Id |
|
276 | - * @return array |
|
277 | - * @throws \Exception |
|
278 | - */ |
|
279 | - protected function askOwnerToReShare($shareWith, IShare $share, $shareId) { |
|
280 | - |
|
281 | - $remoteShare = $this->getShareFromExternalShareTable($share); |
|
282 | - $token = $remoteShare['share_token']; |
|
283 | - $remoteId = $remoteShare['remote_id']; |
|
284 | - $remote = $remoteShare['remote']; |
|
285 | - |
|
286 | - list($token, $remoteId) = $this->notifications->requestReShare( |
|
287 | - $token, |
|
288 | - $remoteId, |
|
289 | - $shareId, |
|
290 | - $remote, |
|
291 | - $shareWith, |
|
292 | - $share->getPermissions() |
|
293 | - ); |
|
294 | - |
|
295 | - return [$token, $remoteId]; |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * get federated share from the share_external table but exclude mounted link shares |
|
300 | - * |
|
301 | - * @param IShare $share |
|
302 | - * @return array |
|
303 | - * @throws ShareNotFound |
|
304 | - */ |
|
305 | - protected function getShareFromExternalShareTable(IShare $share) { |
|
306 | - $query = $this->dbConnection->getQueryBuilder(); |
|
307 | - $query->select('*')->from($this->externalShareTable) |
|
308 | - ->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner()))) |
|
309 | - ->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget()))); |
|
310 | - $result = $query->execute()->fetchAll(); |
|
311 | - |
|
312 | - if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) { |
|
313 | - return $result[0]; |
|
314 | - } |
|
315 | - |
|
316 | - throw new ShareNotFound('share not found in share_external table'); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * add share to the database and return the ID |
|
321 | - * |
|
322 | - * @param int $itemSource |
|
323 | - * @param string $itemType |
|
324 | - * @param string $shareWith |
|
325 | - * @param string $sharedBy |
|
326 | - * @param string $uidOwner |
|
327 | - * @param int $permissions |
|
328 | - * @param string $token |
|
329 | - * @return int |
|
330 | - */ |
|
331 | - private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
332 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
333 | - $qb->insert('share') |
|
334 | - ->setValue('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)) |
|
335 | - ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
336 | - ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
337 | - ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
338 | - ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
339 | - ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
340 | - ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
341 | - ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
342 | - ->setValue('token', $qb->createNamedParameter($token)) |
|
343 | - ->setValue('stime', $qb->createNamedParameter(time())); |
|
344 | - |
|
345 | - /* |
|
153 | + $alreadyShared = $this->getSharedWith($shareWith, self::SHARE_TYPE_REMOTE, $share->getNode(), 1, 0); |
|
154 | + if (!empty($alreadyShared)) { |
|
155 | + $message = 'Sharing %s failed, because this item is already shared with %s'; |
|
156 | + $message_t = $this->l->t('Sharing %s failed, because this item is already shared with %s', array($share->getNode()->getName(), $shareWith)); |
|
157 | + $this->logger->debug(sprintf($message, $share->getNode()->getName(), $shareWith), ['app' => 'Federated File Sharing']); |
|
158 | + throw new \Exception($message_t); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + // don't allow federated shares if source and target server are the same |
|
163 | + $cloudId = $this->cloudIdManager->resolveCloudId($shareWith); |
|
164 | + $currentServer = $this->addressHandler->generateRemoteURL(); |
|
165 | + $currentUser = $sharedBy; |
|
166 | + if ($this->addressHandler->compareAddresses($cloudId->getUser(), $cloudId->getRemote(), $currentUser, $currentServer)) { |
|
167 | + $message = 'Not allowed to create a federated share with the same user.'; |
|
168 | + $message_t = $this->l->t('Not allowed to create a federated share with the same user'); |
|
169 | + $this->logger->debug($message, ['app' => 'Federated File Sharing']); |
|
170 | + throw new \Exception($message_t); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + $share->setSharedWith($cloudId->getId()); |
|
175 | + |
|
176 | + try { |
|
177 | + $remoteShare = $this->getShareFromExternalShareTable($share); |
|
178 | + } catch (ShareNotFound $e) { |
|
179 | + $remoteShare = null; |
|
180 | + } |
|
181 | + |
|
182 | + if ($remoteShare) { |
|
183 | + try { |
|
184 | + $ownerCloudId = $this->cloudIdManager->getCloudId($remoteShare['owner'], $remoteShare['remote']); |
|
185 | + $shareId = $this->addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $ownerCloudId->getId(), $permissions, 'tmp_token_' . time()); |
|
186 | + $share->setId($shareId); |
|
187 | + list($token, $remoteId) = $this->askOwnerToReShare($shareWith, $share, $shareId); |
|
188 | + // remote share was create successfully if we get a valid token as return |
|
189 | + $send = is_string($token) && $token !== ''; |
|
190 | + } catch (\Exception $e) { |
|
191 | + // fall back to old re-share behavior if the remote server |
|
192 | + // doesn't support flat re-shares (was introduced with Nextcloud 9.1) |
|
193 | + $this->removeShareFromTable($share); |
|
194 | + $shareId = $this->createFederatedShare($share); |
|
195 | + } |
|
196 | + if ($send) { |
|
197 | + $this->updateSuccessfulReshare($shareId, $token); |
|
198 | + $this->storeRemoteId($shareId, $remoteId); |
|
199 | + } else { |
|
200 | + $this->removeShareFromTable($share); |
|
201 | + $message_t = $this->l->t('File is already shared with %s', [$shareWith]); |
|
202 | + throw new \Exception($message_t); |
|
203 | + } |
|
204 | + |
|
205 | + } else { |
|
206 | + $shareId = $this->createFederatedShare($share); |
|
207 | + } |
|
208 | + |
|
209 | + $data = $this->getRawShare($shareId); |
|
210 | + return $this->createShareObject($data); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * create federated share and inform the recipient |
|
215 | + * |
|
216 | + * @param IShare $share |
|
217 | + * @return int |
|
218 | + * @throws ShareNotFound |
|
219 | + * @throws \Exception |
|
220 | + */ |
|
221 | + protected function createFederatedShare(IShare $share) { |
|
222 | + $token = $this->tokenHandler->generateToken(); |
|
223 | + $shareId = $this->addShareToDB( |
|
224 | + $share->getNodeId(), |
|
225 | + $share->getNodeType(), |
|
226 | + $share->getSharedWith(), |
|
227 | + $share->getSharedBy(), |
|
228 | + $share->getShareOwner(), |
|
229 | + $share->getPermissions(), |
|
230 | + $token |
|
231 | + ); |
|
232 | + |
|
233 | + $failure = false; |
|
234 | + |
|
235 | + try { |
|
236 | + $sharedByFederatedId = $share->getSharedBy(); |
|
237 | + if ($this->userManager->userExists($sharedByFederatedId)) { |
|
238 | + $cloudId = $this->cloudIdManager->getCloudId($sharedByFederatedId, $this->addressHandler->generateRemoteURL()); |
|
239 | + $sharedByFederatedId = $cloudId->getId(); |
|
240 | + } |
|
241 | + $ownerCloudId = $this->cloudIdManager->getCloudId($share->getShareOwner(), $this->addressHandler->generateRemoteURL()); |
|
242 | + $send = $this->notifications->sendRemoteShare( |
|
243 | + $token, |
|
244 | + $share->getSharedWith(), |
|
245 | + $share->getNode()->getName(), |
|
246 | + $shareId, |
|
247 | + $share->getShareOwner(), |
|
248 | + $ownerCloudId->getId(), |
|
249 | + $share->getSharedBy(), |
|
250 | + $sharedByFederatedId |
|
251 | + ); |
|
252 | + |
|
253 | + if ($send === false) { |
|
254 | + $failure = true; |
|
255 | + } |
|
256 | + } catch (\Exception $e) { |
|
257 | + $this->logger->error('Failed to notify remote server of federated share, removing share (' . $e->getMessage() . ')'); |
|
258 | + $failure = true; |
|
259 | + } |
|
260 | + |
|
261 | + if($failure) { |
|
262 | + $this->removeShareFromTableById($shareId); |
|
263 | + $message_t = $this->l->t('Sharing %s failed, could not find %s, maybe the server is currently unreachable or uses a self-signed certificate.', |
|
264 | + [$share->getNode()->getName(), $share->getSharedWith()]); |
|
265 | + throw new \Exception($message_t); |
|
266 | + } |
|
267 | + |
|
268 | + return $shareId; |
|
269 | + |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * @param string $shareWith |
|
274 | + * @param IShare $share |
|
275 | + * @param string $shareId internal share Id |
|
276 | + * @return array |
|
277 | + * @throws \Exception |
|
278 | + */ |
|
279 | + protected function askOwnerToReShare($shareWith, IShare $share, $shareId) { |
|
280 | + |
|
281 | + $remoteShare = $this->getShareFromExternalShareTable($share); |
|
282 | + $token = $remoteShare['share_token']; |
|
283 | + $remoteId = $remoteShare['remote_id']; |
|
284 | + $remote = $remoteShare['remote']; |
|
285 | + |
|
286 | + list($token, $remoteId) = $this->notifications->requestReShare( |
|
287 | + $token, |
|
288 | + $remoteId, |
|
289 | + $shareId, |
|
290 | + $remote, |
|
291 | + $shareWith, |
|
292 | + $share->getPermissions() |
|
293 | + ); |
|
294 | + |
|
295 | + return [$token, $remoteId]; |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * get federated share from the share_external table but exclude mounted link shares |
|
300 | + * |
|
301 | + * @param IShare $share |
|
302 | + * @return array |
|
303 | + * @throws ShareNotFound |
|
304 | + */ |
|
305 | + protected function getShareFromExternalShareTable(IShare $share) { |
|
306 | + $query = $this->dbConnection->getQueryBuilder(); |
|
307 | + $query->select('*')->from($this->externalShareTable) |
|
308 | + ->where($query->expr()->eq('user', $query->createNamedParameter($share->getShareOwner()))) |
|
309 | + ->andWhere($query->expr()->eq('mountpoint', $query->createNamedParameter($share->getTarget()))); |
|
310 | + $result = $query->execute()->fetchAll(); |
|
311 | + |
|
312 | + if (isset($result[0]) && (int)$result[0]['remote_id'] > 0) { |
|
313 | + return $result[0]; |
|
314 | + } |
|
315 | + |
|
316 | + throw new ShareNotFound('share not found in share_external table'); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * add share to the database and return the ID |
|
321 | + * |
|
322 | + * @param int $itemSource |
|
323 | + * @param string $itemType |
|
324 | + * @param string $shareWith |
|
325 | + * @param string $sharedBy |
|
326 | + * @param string $uidOwner |
|
327 | + * @param int $permissions |
|
328 | + * @param string $token |
|
329 | + * @return int |
|
330 | + */ |
|
331 | + private function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token) { |
|
332 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
333 | + $qb->insert('share') |
|
334 | + ->setValue('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE)) |
|
335 | + ->setValue('item_type', $qb->createNamedParameter($itemType)) |
|
336 | + ->setValue('item_source', $qb->createNamedParameter($itemSource)) |
|
337 | + ->setValue('file_source', $qb->createNamedParameter($itemSource)) |
|
338 | + ->setValue('share_with', $qb->createNamedParameter($shareWith)) |
|
339 | + ->setValue('uid_owner', $qb->createNamedParameter($uidOwner)) |
|
340 | + ->setValue('uid_initiator', $qb->createNamedParameter($sharedBy)) |
|
341 | + ->setValue('permissions', $qb->createNamedParameter($permissions)) |
|
342 | + ->setValue('token', $qb->createNamedParameter($token)) |
|
343 | + ->setValue('stime', $qb->createNamedParameter(time())); |
|
344 | + |
|
345 | + /* |
|
346 | 346 | * Added to fix https://github.com/owncloud/core/issues/22215 |
347 | 347 | * Can be removed once we get rid of ajax/share.php |
348 | 348 | */ |
349 | - $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
350 | - |
|
351 | - $qb->execute(); |
|
352 | - $id = $qb->getLastInsertId(); |
|
353 | - |
|
354 | - return (int)$id; |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Update a share |
|
359 | - * |
|
360 | - * @param IShare $share |
|
361 | - * @return IShare The share object |
|
362 | - */ |
|
363 | - public function update(IShare $share) { |
|
364 | - /* |
|
349 | + $qb->setValue('file_target', $qb->createNamedParameter('')); |
|
350 | + |
|
351 | + $qb->execute(); |
|
352 | + $id = $qb->getLastInsertId(); |
|
353 | + |
|
354 | + return (int)$id; |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Update a share |
|
359 | + * |
|
360 | + * @param IShare $share |
|
361 | + * @return IShare The share object |
|
362 | + */ |
|
363 | + public function update(IShare $share) { |
|
364 | + /* |
|
365 | 365 | * We allow updating the permissions of federated shares |
366 | 366 | */ |
367 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
368 | - $qb->update('share') |
|
369 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
370 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
371 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
372 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
373 | - ->execute(); |
|
374 | - |
|
375 | - // send the updated permission to the owner/initiator, if they are not the same |
|
376 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
377 | - $this->sendPermissionUpdate($share); |
|
378 | - } |
|
379 | - |
|
380 | - return $share; |
|
381 | - } |
|
382 | - |
|
383 | - /** |
|
384 | - * send the updated permission to the owner/initiator, if they are not the same |
|
385 | - * |
|
386 | - * @param IShare $share |
|
387 | - * @throws ShareNotFound |
|
388 | - * @throws \OC\HintException |
|
389 | - */ |
|
390 | - protected function sendPermissionUpdate(IShare $share) { |
|
391 | - $remoteId = $this->getRemoteId($share); |
|
392 | - // if the local user is the owner we send the permission change to the initiator |
|
393 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
394 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
395 | - } else { // ... if not we send the permission change to the owner |
|
396 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
397 | - } |
|
398 | - $this->notifications->sendPermissionChange($remote, $remoteId, $share->getToken(), $share->getPermissions()); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * update successful reShare with the correct token |
|
404 | - * |
|
405 | - * @param int $shareId |
|
406 | - * @param string $token |
|
407 | - */ |
|
408 | - protected function updateSuccessfulReShare($shareId, $token) { |
|
409 | - $query = $this->dbConnection->getQueryBuilder(); |
|
410 | - $query->update('share') |
|
411 | - ->where($query->expr()->eq('id', $query->createNamedParameter($shareId))) |
|
412 | - ->set('token', $query->createNamedParameter($token)) |
|
413 | - ->execute(); |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * store remote ID in federated reShare table |
|
418 | - * |
|
419 | - * @param $shareId |
|
420 | - * @param $remoteId |
|
421 | - */ |
|
422 | - public function storeRemoteId($shareId, $remoteId) { |
|
423 | - $query = $this->dbConnection->getQueryBuilder(); |
|
424 | - $query->insert('federated_reshares') |
|
425 | - ->values( |
|
426 | - [ |
|
427 | - 'share_id' => $query->createNamedParameter($shareId), |
|
428 | - 'remote_id' => $query->createNamedParameter($remoteId), |
|
429 | - ] |
|
430 | - ); |
|
431 | - $query->execute(); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * get share ID on remote server for federated re-shares |
|
436 | - * |
|
437 | - * @param IShare $share |
|
438 | - * @return int |
|
439 | - * @throws ShareNotFound |
|
440 | - */ |
|
441 | - public function getRemoteId(IShare $share) { |
|
442 | - $query = $this->dbConnection->getQueryBuilder(); |
|
443 | - $query->select('remote_id')->from('federated_reshares') |
|
444 | - ->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId()))); |
|
445 | - $data = $query->execute()->fetch(); |
|
446 | - |
|
447 | - if (!is_array($data) || !isset($data['remote_id'])) { |
|
448 | - throw new ShareNotFound(); |
|
449 | - } |
|
450 | - |
|
451 | - return (int)$data['remote_id']; |
|
452 | - } |
|
453 | - |
|
454 | - /** |
|
455 | - * @inheritdoc |
|
456 | - */ |
|
457 | - public function move(IShare $share, $recipient) { |
|
458 | - /* |
|
367 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
368 | + $qb->update('share') |
|
369 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
370 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
371 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
372 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
373 | + ->execute(); |
|
374 | + |
|
375 | + // send the updated permission to the owner/initiator, if they are not the same |
|
376 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
377 | + $this->sendPermissionUpdate($share); |
|
378 | + } |
|
379 | + |
|
380 | + return $share; |
|
381 | + } |
|
382 | + |
|
383 | + /** |
|
384 | + * send the updated permission to the owner/initiator, if they are not the same |
|
385 | + * |
|
386 | + * @param IShare $share |
|
387 | + * @throws ShareNotFound |
|
388 | + * @throws \OC\HintException |
|
389 | + */ |
|
390 | + protected function sendPermissionUpdate(IShare $share) { |
|
391 | + $remoteId = $this->getRemoteId($share); |
|
392 | + // if the local user is the owner we send the permission change to the initiator |
|
393 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
394 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
395 | + } else { // ... if not we send the permission change to the owner |
|
396 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
397 | + } |
|
398 | + $this->notifications->sendPermissionChange($remote, $remoteId, $share->getToken(), $share->getPermissions()); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * update successful reShare with the correct token |
|
404 | + * |
|
405 | + * @param int $shareId |
|
406 | + * @param string $token |
|
407 | + */ |
|
408 | + protected function updateSuccessfulReShare($shareId, $token) { |
|
409 | + $query = $this->dbConnection->getQueryBuilder(); |
|
410 | + $query->update('share') |
|
411 | + ->where($query->expr()->eq('id', $query->createNamedParameter($shareId))) |
|
412 | + ->set('token', $query->createNamedParameter($token)) |
|
413 | + ->execute(); |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * store remote ID in federated reShare table |
|
418 | + * |
|
419 | + * @param $shareId |
|
420 | + * @param $remoteId |
|
421 | + */ |
|
422 | + public function storeRemoteId($shareId, $remoteId) { |
|
423 | + $query = $this->dbConnection->getQueryBuilder(); |
|
424 | + $query->insert('federated_reshares') |
|
425 | + ->values( |
|
426 | + [ |
|
427 | + 'share_id' => $query->createNamedParameter($shareId), |
|
428 | + 'remote_id' => $query->createNamedParameter($remoteId), |
|
429 | + ] |
|
430 | + ); |
|
431 | + $query->execute(); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * get share ID on remote server for federated re-shares |
|
436 | + * |
|
437 | + * @param IShare $share |
|
438 | + * @return int |
|
439 | + * @throws ShareNotFound |
|
440 | + */ |
|
441 | + public function getRemoteId(IShare $share) { |
|
442 | + $query = $this->dbConnection->getQueryBuilder(); |
|
443 | + $query->select('remote_id')->from('federated_reshares') |
|
444 | + ->where($query->expr()->eq('share_id', $query->createNamedParameter((int)$share->getId()))); |
|
445 | + $data = $query->execute()->fetch(); |
|
446 | + |
|
447 | + if (!is_array($data) || !isset($data['remote_id'])) { |
|
448 | + throw new ShareNotFound(); |
|
449 | + } |
|
450 | + |
|
451 | + return (int)$data['remote_id']; |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * @inheritdoc |
|
456 | + */ |
|
457 | + public function move(IShare $share, $recipient) { |
|
458 | + /* |
|
459 | 459 | * This function does nothing yet as it is just for outgoing |
460 | 460 | * federated shares. |
461 | 461 | */ |
462 | - return $share; |
|
463 | - } |
|
464 | - |
|
465 | - /** |
|
466 | - * Get all children of this share |
|
467 | - * |
|
468 | - * @param IShare $parent |
|
469 | - * @return IShare[] |
|
470 | - */ |
|
471 | - public function getChildren(IShare $parent) { |
|
472 | - $children = []; |
|
473 | - |
|
474 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
475 | - $qb->select('*') |
|
476 | - ->from('share') |
|
477 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
478 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
479 | - ->orderBy('id'); |
|
480 | - |
|
481 | - $cursor = $qb->execute(); |
|
482 | - while($data = $cursor->fetch()) { |
|
483 | - $children[] = $this->createShareObject($data); |
|
484 | - } |
|
485 | - $cursor->closeCursor(); |
|
486 | - |
|
487 | - return $children; |
|
488 | - } |
|
489 | - |
|
490 | - /** |
|
491 | - * Delete a share (owner unShares the file) |
|
492 | - * |
|
493 | - * @param IShare $share |
|
494 | - */ |
|
495 | - public function delete(IShare $share) { |
|
496 | - |
|
497 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith()); |
|
498 | - |
|
499 | - $isOwner = false; |
|
500 | - |
|
501 | - $this->removeShareFromTable($share); |
|
502 | - |
|
503 | - // if the local user is the owner we can send the unShare request directly... |
|
504 | - if ($this->userManager->userExists($share->getShareOwner())) { |
|
505 | - $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken()); |
|
506 | - $this->revokeShare($share, true); |
|
507 | - $isOwner = true; |
|
508 | - } else { // ... if not we need to correct ID for the unShare request |
|
509 | - $remoteId = $this->getRemoteId($share); |
|
510 | - $this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken()); |
|
511 | - $this->revokeShare($share, false); |
|
512 | - } |
|
513 | - |
|
514 | - // send revoke notification to the other user, if initiator and owner are not the same user |
|
515 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
516 | - $remoteId = $this->getRemoteId($share); |
|
517 | - if ($isOwner) { |
|
518 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
519 | - } else { |
|
520 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
521 | - } |
|
522 | - $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
523 | - } |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * in case of a re-share we need to send the other use (initiator or owner) |
|
528 | - * a message that the file was unshared |
|
529 | - * |
|
530 | - * @param IShare $share |
|
531 | - * @param bool $isOwner the user can either be the owner or the user who re-sahred it |
|
532 | - * @throws ShareNotFound |
|
533 | - * @throws \OC\HintException |
|
534 | - */ |
|
535 | - protected function revokeShare($share, $isOwner) { |
|
536 | - // also send a unShare request to the initiator, if this is a different user than the owner |
|
537 | - if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
538 | - if ($isOwner) { |
|
539 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
540 | - } else { |
|
541 | - list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
542 | - } |
|
543 | - $remoteId = $this->getRemoteId($share); |
|
544 | - $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
545 | - } |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * remove share from table |
|
550 | - * |
|
551 | - * @param IShare $share |
|
552 | - */ |
|
553 | - public function removeShareFromTable(IShare $share) { |
|
554 | - $this->removeShareFromTableById($share->getId()); |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * remove share from table |
|
559 | - * |
|
560 | - * @param string $shareId |
|
561 | - */ |
|
562 | - private function removeShareFromTableById($shareId) { |
|
563 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
564 | - $qb->delete('share') |
|
565 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
566 | - $qb->execute(); |
|
567 | - |
|
568 | - $qb->delete('federated_reshares') |
|
569 | - ->where($qb->expr()->eq('share_id', $qb->createNamedParameter($shareId))); |
|
570 | - $qb->execute(); |
|
571 | - } |
|
572 | - |
|
573 | - /** |
|
574 | - * @inheritdoc |
|
575 | - */ |
|
576 | - public function deleteFromSelf(IShare $share, $recipient) { |
|
577 | - // nothing to do here. Technically deleteFromSelf in the context of federated |
|
578 | - // shares is a umount of a external storage. This is handled here |
|
579 | - // apps/files_sharing/lib/external/manager.php |
|
580 | - // TODO move this code over to this app |
|
581 | - return; |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
586 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
587 | - $qb->select('*') |
|
588 | - ->from('share', 's') |
|
589 | - ->andWhere($qb->expr()->orX( |
|
590 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
591 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
592 | - )) |
|
593 | - ->andWhere( |
|
594 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)) |
|
595 | - ); |
|
596 | - |
|
597 | - /** |
|
598 | - * Reshares for this user are shares where they are the owner. |
|
599 | - */ |
|
600 | - if ($reshares === false) { |
|
601 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
602 | - } else { |
|
603 | - $qb->andWhere( |
|
604 | - $qb->expr()->orX( |
|
605 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
606 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
607 | - ) |
|
608 | - ); |
|
609 | - } |
|
610 | - |
|
611 | - $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); |
|
612 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
613 | - |
|
614 | - $qb->orderBy('id'); |
|
615 | - |
|
616 | - $cursor = $qb->execute(); |
|
617 | - $shares = []; |
|
618 | - while ($data = $cursor->fetch()) { |
|
619 | - $shares[$data['fileid']][] = $this->createShareObject($data); |
|
620 | - } |
|
621 | - $cursor->closeCursor(); |
|
622 | - |
|
623 | - return $shares; |
|
624 | - } |
|
625 | - |
|
626 | - /** |
|
627 | - * @inheritdoc |
|
628 | - */ |
|
629 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
630 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
631 | - $qb->select('*') |
|
632 | - ->from('share'); |
|
633 | - |
|
634 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
635 | - |
|
636 | - /** |
|
637 | - * Reshares for this user are shares where they are the owner. |
|
638 | - */ |
|
639 | - if ($reshares === false) { |
|
640 | - //Special case for old shares created via the web UI |
|
641 | - $or1 = $qb->expr()->andX( |
|
642 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
643 | - $qb->expr()->isNull('uid_initiator') |
|
644 | - ); |
|
645 | - |
|
646 | - $qb->andWhere( |
|
647 | - $qb->expr()->orX( |
|
648 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
649 | - $or1 |
|
650 | - ) |
|
651 | - ); |
|
652 | - } else { |
|
653 | - $qb->andWhere( |
|
654 | - $qb->expr()->orX( |
|
655 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
656 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
657 | - ) |
|
658 | - ); |
|
659 | - } |
|
660 | - |
|
661 | - if ($node !== null) { |
|
662 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
663 | - } |
|
664 | - |
|
665 | - if ($limit !== -1) { |
|
666 | - $qb->setMaxResults($limit); |
|
667 | - } |
|
668 | - |
|
669 | - $qb->setFirstResult($offset); |
|
670 | - $qb->orderBy('id'); |
|
671 | - |
|
672 | - $cursor = $qb->execute(); |
|
673 | - $shares = []; |
|
674 | - while($data = $cursor->fetch()) { |
|
675 | - $shares[] = $this->createShareObject($data); |
|
676 | - } |
|
677 | - $cursor->closeCursor(); |
|
678 | - |
|
679 | - return $shares; |
|
680 | - } |
|
681 | - |
|
682 | - /** |
|
683 | - * @inheritdoc |
|
684 | - */ |
|
685 | - public function getShareById($id, $recipientId = null) { |
|
686 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
687 | - |
|
688 | - $qb->select('*') |
|
689 | - ->from('share') |
|
690 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
691 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
692 | - |
|
693 | - $cursor = $qb->execute(); |
|
694 | - $data = $cursor->fetch(); |
|
695 | - $cursor->closeCursor(); |
|
696 | - |
|
697 | - if ($data === false) { |
|
698 | - throw new ShareNotFound(); |
|
699 | - } |
|
700 | - |
|
701 | - try { |
|
702 | - $share = $this->createShareObject($data); |
|
703 | - } catch (InvalidShare $e) { |
|
704 | - throw new ShareNotFound(); |
|
705 | - } |
|
706 | - |
|
707 | - return $share; |
|
708 | - } |
|
709 | - |
|
710 | - /** |
|
711 | - * Get shares for a given path |
|
712 | - * |
|
713 | - * @param \OCP\Files\Node $path |
|
714 | - * @return IShare[] |
|
715 | - */ |
|
716 | - public function getSharesByPath(Node $path) { |
|
717 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
718 | - |
|
719 | - $cursor = $qb->select('*') |
|
720 | - ->from('share') |
|
721 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
722 | - ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
723 | - ->execute(); |
|
724 | - |
|
725 | - $shares = []; |
|
726 | - while($data = $cursor->fetch()) { |
|
727 | - $shares[] = $this->createShareObject($data); |
|
728 | - } |
|
729 | - $cursor->closeCursor(); |
|
730 | - |
|
731 | - return $shares; |
|
732 | - } |
|
733 | - |
|
734 | - /** |
|
735 | - * @inheritdoc |
|
736 | - */ |
|
737 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
738 | - /** @var IShare[] $shares */ |
|
739 | - $shares = []; |
|
740 | - |
|
741 | - //Get shares directly with this user |
|
742 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
743 | - $qb->select('*') |
|
744 | - ->from('share'); |
|
745 | - |
|
746 | - // Order by id |
|
747 | - $qb->orderBy('id'); |
|
748 | - |
|
749 | - // Set limit and offset |
|
750 | - if ($limit !== -1) { |
|
751 | - $qb->setMaxResults($limit); |
|
752 | - } |
|
753 | - $qb->setFirstResult($offset); |
|
754 | - |
|
755 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
756 | - $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
757 | - |
|
758 | - // Filter by node if provided |
|
759 | - if ($node !== null) { |
|
760 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
761 | - } |
|
762 | - |
|
763 | - $cursor = $qb->execute(); |
|
764 | - |
|
765 | - while($data = $cursor->fetch()) { |
|
766 | - $shares[] = $this->createShareObject($data); |
|
767 | - } |
|
768 | - $cursor->closeCursor(); |
|
769 | - |
|
770 | - |
|
771 | - return $shares; |
|
772 | - } |
|
773 | - |
|
774 | - /** |
|
775 | - * Get a share by token |
|
776 | - * |
|
777 | - * @param string $token |
|
778 | - * @return IShare |
|
779 | - * @throws ShareNotFound |
|
780 | - */ |
|
781 | - public function getShareByToken($token) { |
|
782 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
783 | - |
|
784 | - $cursor = $qb->select('*') |
|
785 | - ->from('share') |
|
786 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
787 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
788 | - ->execute(); |
|
789 | - |
|
790 | - $data = $cursor->fetch(); |
|
791 | - |
|
792 | - if ($data === false) { |
|
793 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
794 | - } |
|
795 | - |
|
796 | - try { |
|
797 | - $share = $this->createShareObject($data); |
|
798 | - } catch (InvalidShare $e) { |
|
799 | - throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
800 | - } |
|
801 | - |
|
802 | - return $share; |
|
803 | - } |
|
804 | - |
|
805 | - /** |
|
806 | - * get database row of a give share |
|
807 | - * |
|
808 | - * @param $id |
|
809 | - * @return array |
|
810 | - * @throws ShareNotFound |
|
811 | - */ |
|
812 | - private function getRawShare($id) { |
|
813 | - |
|
814 | - // Now fetch the inserted share and create a complete share object |
|
815 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
816 | - $qb->select('*') |
|
817 | - ->from('share') |
|
818 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
819 | - |
|
820 | - $cursor = $qb->execute(); |
|
821 | - $data = $cursor->fetch(); |
|
822 | - $cursor->closeCursor(); |
|
823 | - |
|
824 | - if ($data === false) { |
|
825 | - throw new ShareNotFound; |
|
826 | - } |
|
827 | - |
|
828 | - return $data; |
|
829 | - } |
|
830 | - |
|
831 | - /** |
|
832 | - * Create a share object from an database row |
|
833 | - * |
|
834 | - * @param array $data |
|
835 | - * @return IShare |
|
836 | - * @throws InvalidShare |
|
837 | - * @throws ShareNotFound |
|
838 | - */ |
|
839 | - private function createShareObject($data) { |
|
840 | - |
|
841 | - $share = new Share($this->rootFolder, $this->userManager); |
|
842 | - $share->setId((int)$data['id']) |
|
843 | - ->setShareType((int)$data['share_type']) |
|
844 | - ->setPermissions((int)$data['permissions']) |
|
845 | - ->setTarget($data['file_target']) |
|
846 | - ->setMailSend((bool)$data['mail_send']) |
|
847 | - ->setToken($data['token']); |
|
848 | - |
|
849 | - $shareTime = new \DateTime(); |
|
850 | - $shareTime->setTimestamp((int)$data['stime']); |
|
851 | - $share->setShareTime($shareTime); |
|
852 | - $share->setSharedWith($data['share_with']); |
|
853 | - |
|
854 | - if ($data['uid_initiator'] !== null) { |
|
855 | - $share->setShareOwner($data['uid_owner']); |
|
856 | - $share->setSharedBy($data['uid_initiator']); |
|
857 | - } else { |
|
858 | - //OLD SHARE |
|
859 | - $share->setSharedBy($data['uid_owner']); |
|
860 | - $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
861 | - |
|
862 | - $owner = $path->getOwner(); |
|
863 | - $share->setShareOwner($owner->getUID()); |
|
864 | - } |
|
865 | - |
|
866 | - $share->setNodeId((int)$data['file_source']); |
|
867 | - $share->setNodeType($data['item_type']); |
|
868 | - |
|
869 | - $share->setProviderId($this->identifier()); |
|
870 | - |
|
871 | - return $share; |
|
872 | - } |
|
873 | - |
|
874 | - /** |
|
875 | - * Get the node with file $id for $user |
|
876 | - * |
|
877 | - * @param string $userId |
|
878 | - * @param int $id |
|
879 | - * @return \OCP\Files\File|\OCP\Files\Folder |
|
880 | - * @throws InvalidShare |
|
881 | - */ |
|
882 | - private function getNode($userId, $id) { |
|
883 | - try { |
|
884 | - $userFolder = $this->rootFolder->getUserFolder($userId); |
|
885 | - } catch (NotFoundException $e) { |
|
886 | - throw new InvalidShare(); |
|
887 | - } |
|
888 | - |
|
889 | - $nodes = $userFolder->getById($id); |
|
890 | - |
|
891 | - if (empty($nodes)) { |
|
892 | - throw new InvalidShare(); |
|
893 | - } |
|
894 | - |
|
895 | - return $nodes[0]; |
|
896 | - } |
|
897 | - |
|
898 | - /** |
|
899 | - * A user is deleted from the system |
|
900 | - * So clean up the relevant shares. |
|
901 | - * |
|
902 | - * @param string $uid |
|
903 | - * @param int $shareType |
|
904 | - */ |
|
905 | - public function userDeleted($uid, $shareType) { |
|
906 | - //TODO: probabaly a good idea to send unshare info to remote servers |
|
907 | - |
|
908 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
909 | - |
|
910 | - $qb->delete('share') |
|
911 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
912 | - ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
913 | - ->execute(); |
|
914 | - } |
|
915 | - |
|
916 | - /** |
|
917 | - * This provider does not handle groups |
|
918 | - * |
|
919 | - * @param string $gid |
|
920 | - */ |
|
921 | - public function groupDeleted($gid) { |
|
922 | - // We don't handle groups here |
|
923 | - return; |
|
924 | - } |
|
925 | - |
|
926 | - /** |
|
927 | - * This provider does not handle groups |
|
928 | - * |
|
929 | - * @param string $uid |
|
930 | - * @param string $gid |
|
931 | - */ |
|
932 | - public function userDeletedFromGroup($uid, $gid) { |
|
933 | - // We don't handle groups here |
|
934 | - return; |
|
935 | - } |
|
936 | - |
|
937 | - /** |
|
938 | - * check if users from other Nextcloud instances are allowed to mount public links share by this instance |
|
939 | - * |
|
940 | - * @return bool |
|
941 | - */ |
|
942 | - public function isOutgoingServer2serverShareEnabled() { |
|
943 | - $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); |
|
944 | - return ($result === 'yes') ? true : false; |
|
945 | - } |
|
946 | - |
|
947 | - /** |
|
948 | - * check if users are allowed to mount public links from other ownClouds |
|
949 | - * |
|
950 | - * @return bool |
|
951 | - */ |
|
952 | - public function isIncomingServer2serverShareEnabled() { |
|
953 | - $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); |
|
954 | - return ($result === 'yes') ? true : false; |
|
955 | - } |
|
956 | - |
|
957 | - /** |
|
958 | - * Check if querying sharees on the lookup server is enabled |
|
959 | - * |
|
960 | - * @return bool |
|
961 | - */ |
|
962 | - public function isLookupServerQueriesEnabled() { |
|
963 | - $result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no'); |
|
964 | - return ($result === 'yes') ? true : false; |
|
965 | - } |
|
966 | - |
|
967 | - |
|
968 | - /** |
|
969 | - * Check if it is allowed to publish user specific data to the lookup server |
|
970 | - * |
|
971 | - * @return bool |
|
972 | - */ |
|
973 | - public function isLookupServerUploadEnabled() { |
|
974 | - $result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes'); |
|
975 | - return ($result === 'yes') ? true : false; |
|
976 | - } |
|
462 | + return $share; |
|
463 | + } |
|
464 | + |
|
465 | + /** |
|
466 | + * Get all children of this share |
|
467 | + * |
|
468 | + * @param IShare $parent |
|
469 | + * @return IShare[] |
|
470 | + */ |
|
471 | + public function getChildren(IShare $parent) { |
|
472 | + $children = []; |
|
473 | + |
|
474 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
475 | + $qb->select('*') |
|
476 | + ->from('share') |
|
477 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
478 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
479 | + ->orderBy('id'); |
|
480 | + |
|
481 | + $cursor = $qb->execute(); |
|
482 | + while($data = $cursor->fetch()) { |
|
483 | + $children[] = $this->createShareObject($data); |
|
484 | + } |
|
485 | + $cursor->closeCursor(); |
|
486 | + |
|
487 | + return $children; |
|
488 | + } |
|
489 | + |
|
490 | + /** |
|
491 | + * Delete a share (owner unShares the file) |
|
492 | + * |
|
493 | + * @param IShare $share |
|
494 | + */ |
|
495 | + public function delete(IShare $share) { |
|
496 | + |
|
497 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedWith()); |
|
498 | + |
|
499 | + $isOwner = false; |
|
500 | + |
|
501 | + $this->removeShareFromTable($share); |
|
502 | + |
|
503 | + // if the local user is the owner we can send the unShare request directly... |
|
504 | + if ($this->userManager->userExists($share->getShareOwner())) { |
|
505 | + $this->notifications->sendRemoteUnShare($remote, $share->getId(), $share->getToken()); |
|
506 | + $this->revokeShare($share, true); |
|
507 | + $isOwner = true; |
|
508 | + } else { // ... if not we need to correct ID for the unShare request |
|
509 | + $remoteId = $this->getRemoteId($share); |
|
510 | + $this->notifications->sendRemoteUnShare($remote, $remoteId, $share->getToken()); |
|
511 | + $this->revokeShare($share, false); |
|
512 | + } |
|
513 | + |
|
514 | + // send revoke notification to the other user, if initiator and owner are not the same user |
|
515 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
516 | + $remoteId = $this->getRemoteId($share); |
|
517 | + if ($isOwner) { |
|
518 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
519 | + } else { |
|
520 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
521 | + } |
|
522 | + $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
523 | + } |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * in case of a re-share we need to send the other use (initiator or owner) |
|
528 | + * a message that the file was unshared |
|
529 | + * |
|
530 | + * @param IShare $share |
|
531 | + * @param bool $isOwner the user can either be the owner or the user who re-sahred it |
|
532 | + * @throws ShareNotFound |
|
533 | + * @throws \OC\HintException |
|
534 | + */ |
|
535 | + protected function revokeShare($share, $isOwner) { |
|
536 | + // also send a unShare request to the initiator, if this is a different user than the owner |
|
537 | + if ($share->getShareOwner() !== $share->getSharedBy()) { |
|
538 | + if ($isOwner) { |
|
539 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy()); |
|
540 | + } else { |
|
541 | + list(, $remote) = $this->addressHandler->splitUserRemote($share->getShareOwner()); |
|
542 | + } |
|
543 | + $remoteId = $this->getRemoteId($share); |
|
544 | + $this->notifications->sendRevokeShare($remote, $remoteId, $share->getToken()); |
|
545 | + } |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * remove share from table |
|
550 | + * |
|
551 | + * @param IShare $share |
|
552 | + */ |
|
553 | + public function removeShareFromTable(IShare $share) { |
|
554 | + $this->removeShareFromTableById($share->getId()); |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * remove share from table |
|
559 | + * |
|
560 | + * @param string $shareId |
|
561 | + */ |
|
562 | + private function removeShareFromTableById($shareId) { |
|
563 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
564 | + $qb->delete('share') |
|
565 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); |
|
566 | + $qb->execute(); |
|
567 | + |
|
568 | + $qb->delete('federated_reshares') |
|
569 | + ->where($qb->expr()->eq('share_id', $qb->createNamedParameter($shareId))); |
|
570 | + $qb->execute(); |
|
571 | + } |
|
572 | + |
|
573 | + /** |
|
574 | + * @inheritdoc |
|
575 | + */ |
|
576 | + public function deleteFromSelf(IShare $share, $recipient) { |
|
577 | + // nothing to do here. Technically deleteFromSelf in the context of federated |
|
578 | + // shares is a umount of a external storage. This is handled here |
|
579 | + // apps/files_sharing/lib/external/manager.php |
|
580 | + // TODO move this code over to this app |
|
581 | + return; |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
586 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
587 | + $qb->select('*') |
|
588 | + ->from('share', 's') |
|
589 | + ->andWhere($qb->expr()->orX( |
|
590 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
591 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
592 | + )) |
|
593 | + ->andWhere( |
|
594 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE)) |
|
595 | + ); |
|
596 | + |
|
597 | + /** |
|
598 | + * Reshares for this user are shares where they are the owner. |
|
599 | + */ |
|
600 | + if ($reshares === false) { |
|
601 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
602 | + } else { |
|
603 | + $qb->andWhere( |
|
604 | + $qb->expr()->orX( |
|
605 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
606 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
607 | + ) |
|
608 | + ); |
|
609 | + } |
|
610 | + |
|
611 | + $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); |
|
612 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
613 | + |
|
614 | + $qb->orderBy('id'); |
|
615 | + |
|
616 | + $cursor = $qb->execute(); |
|
617 | + $shares = []; |
|
618 | + while ($data = $cursor->fetch()) { |
|
619 | + $shares[$data['fileid']][] = $this->createShareObject($data); |
|
620 | + } |
|
621 | + $cursor->closeCursor(); |
|
622 | + |
|
623 | + return $shares; |
|
624 | + } |
|
625 | + |
|
626 | + /** |
|
627 | + * @inheritdoc |
|
628 | + */ |
|
629 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
630 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
631 | + $qb->select('*') |
|
632 | + ->from('share'); |
|
633 | + |
|
634 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
635 | + |
|
636 | + /** |
|
637 | + * Reshares for this user are shares where they are the owner. |
|
638 | + */ |
|
639 | + if ($reshares === false) { |
|
640 | + //Special case for old shares created via the web UI |
|
641 | + $or1 = $qb->expr()->andX( |
|
642 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
643 | + $qb->expr()->isNull('uid_initiator') |
|
644 | + ); |
|
645 | + |
|
646 | + $qb->andWhere( |
|
647 | + $qb->expr()->orX( |
|
648 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)), |
|
649 | + $or1 |
|
650 | + ) |
|
651 | + ); |
|
652 | + } else { |
|
653 | + $qb->andWhere( |
|
654 | + $qb->expr()->orX( |
|
655 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
656 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
657 | + ) |
|
658 | + ); |
|
659 | + } |
|
660 | + |
|
661 | + if ($node !== null) { |
|
662 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
663 | + } |
|
664 | + |
|
665 | + if ($limit !== -1) { |
|
666 | + $qb->setMaxResults($limit); |
|
667 | + } |
|
668 | + |
|
669 | + $qb->setFirstResult($offset); |
|
670 | + $qb->orderBy('id'); |
|
671 | + |
|
672 | + $cursor = $qb->execute(); |
|
673 | + $shares = []; |
|
674 | + while($data = $cursor->fetch()) { |
|
675 | + $shares[] = $this->createShareObject($data); |
|
676 | + } |
|
677 | + $cursor->closeCursor(); |
|
678 | + |
|
679 | + return $shares; |
|
680 | + } |
|
681 | + |
|
682 | + /** |
|
683 | + * @inheritdoc |
|
684 | + */ |
|
685 | + public function getShareById($id, $recipientId = null) { |
|
686 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
687 | + |
|
688 | + $qb->select('*') |
|
689 | + ->from('share') |
|
690 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
691 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
692 | + |
|
693 | + $cursor = $qb->execute(); |
|
694 | + $data = $cursor->fetch(); |
|
695 | + $cursor->closeCursor(); |
|
696 | + |
|
697 | + if ($data === false) { |
|
698 | + throw new ShareNotFound(); |
|
699 | + } |
|
700 | + |
|
701 | + try { |
|
702 | + $share = $this->createShareObject($data); |
|
703 | + } catch (InvalidShare $e) { |
|
704 | + throw new ShareNotFound(); |
|
705 | + } |
|
706 | + |
|
707 | + return $share; |
|
708 | + } |
|
709 | + |
|
710 | + /** |
|
711 | + * Get shares for a given path |
|
712 | + * |
|
713 | + * @param \OCP\Files\Node $path |
|
714 | + * @return IShare[] |
|
715 | + */ |
|
716 | + public function getSharesByPath(Node $path) { |
|
717 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
718 | + |
|
719 | + $cursor = $qb->select('*') |
|
720 | + ->from('share') |
|
721 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
722 | + ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
723 | + ->execute(); |
|
724 | + |
|
725 | + $shares = []; |
|
726 | + while($data = $cursor->fetch()) { |
|
727 | + $shares[] = $this->createShareObject($data); |
|
728 | + } |
|
729 | + $cursor->closeCursor(); |
|
730 | + |
|
731 | + return $shares; |
|
732 | + } |
|
733 | + |
|
734 | + /** |
|
735 | + * @inheritdoc |
|
736 | + */ |
|
737 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
738 | + /** @var IShare[] $shares */ |
|
739 | + $shares = []; |
|
740 | + |
|
741 | + //Get shares directly with this user |
|
742 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
743 | + $qb->select('*') |
|
744 | + ->from('share'); |
|
745 | + |
|
746 | + // Order by id |
|
747 | + $qb->orderBy('id'); |
|
748 | + |
|
749 | + // Set limit and offset |
|
750 | + if ($limit !== -1) { |
|
751 | + $qb->setMaxResults($limit); |
|
752 | + } |
|
753 | + $qb->setFirstResult($offset); |
|
754 | + |
|
755 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))); |
|
756 | + $qb->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))); |
|
757 | + |
|
758 | + // Filter by node if provided |
|
759 | + if ($node !== null) { |
|
760 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
761 | + } |
|
762 | + |
|
763 | + $cursor = $qb->execute(); |
|
764 | + |
|
765 | + while($data = $cursor->fetch()) { |
|
766 | + $shares[] = $this->createShareObject($data); |
|
767 | + } |
|
768 | + $cursor->closeCursor(); |
|
769 | + |
|
770 | + |
|
771 | + return $shares; |
|
772 | + } |
|
773 | + |
|
774 | + /** |
|
775 | + * Get a share by token |
|
776 | + * |
|
777 | + * @param string $token |
|
778 | + * @return IShare |
|
779 | + * @throws ShareNotFound |
|
780 | + */ |
|
781 | + public function getShareByToken($token) { |
|
782 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
783 | + |
|
784 | + $cursor = $qb->select('*') |
|
785 | + ->from('share') |
|
786 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_REMOTE))) |
|
787 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
788 | + ->execute(); |
|
789 | + |
|
790 | + $data = $cursor->fetch(); |
|
791 | + |
|
792 | + if ($data === false) { |
|
793 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
794 | + } |
|
795 | + |
|
796 | + try { |
|
797 | + $share = $this->createShareObject($data); |
|
798 | + } catch (InvalidShare $e) { |
|
799 | + throw new ShareNotFound('Share not found', $this->l->t('Could not find share')); |
|
800 | + } |
|
801 | + |
|
802 | + return $share; |
|
803 | + } |
|
804 | + |
|
805 | + /** |
|
806 | + * get database row of a give share |
|
807 | + * |
|
808 | + * @param $id |
|
809 | + * @return array |
|
810 | + * @throws ShareNotFound |
|
811 | + */ |
|
812 | + private function getRawShare($id) { |
|
813 | + |
|
814 | + // Now fetch the inserted share and create a complete share object |
|
815 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
816 | + $qb->select('*') |
|
817 | + ->from('share') |
|
818 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
819 | + |
|
820 | + $cursor = $qb->execute(); |
|
821 | + $data = $cursor->fetch(); |
|
822 | + $cursor->closeCursor(); |
|
823 | + |
|
824 | + if ($data === false) { |
|
825 | + throw new ShareNotFound; |
|
826 | + } |
|
827 | + |
|
828 | + return $data; |
|
829 | + } |
|
830 | + |
|
831 | + /** |
|
832 | + * Create a share object from an database row |
|
833 | + * |
|
834 | + * @param array $data |
|
835 | + * @return IShare |
|
836 | + * @throws InvalidShare |
|
837 | + * @throws ShareNotFound |
|
838 | + */ |
|
839 | + private function createShareObject($data) { |
|
840 | + |
|
841 | + $share = new Share($this->rootFolder, $this->userManager); |
|
842 | + $share->setId((int)$data['id']) |
|
843 | + ->setShareType((int)$data['share_type']) |
|
844 | + ->setPermissions((int)$data['permissions']) |
|
845 | + ->setTarget($data['file_target']) |
|
846 | + ->setMailSend((bool)$data['mail_send']) |
|
847 | + ->setToken($data['token']); |
|
848 | + |
|
849 | + $shareTime = new \DateTime(); |
|
850 | + $shareTime->setTimestamp((int)$data['stime']); |
|
851 | + $share->setShareTime($shareTime); |
|
852 | + $share->setSharedWith($data['share_with']); |
|
853 | + |
|
854 | + if ($data['uid_initiator'] !== null) { |
|
855 | + $share->setShareOwner($data['uid_owner']); |
|
856 | + $share->setSharedBy($data['uid_initiator']); |
|
857 | + } else { |
|
858 | + //OLD SHARE |
|
859 | + $share->setSharedBy($data['uid_owner']); |
|
860 | + $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']); |
|
861 | + |
|
862 | + $owner = $path->getOwner(); |
|
863 | + $share->setShareOwner($owner->getUID()); |
|
864 | + } |
|
865 | + |
|
866 | + $share->setNodeId((int)$data['file_source']); |
|
867 | + $share->setNodeType($data['item_type']); |
|
868 | + |
|
869 | + $share->setProviderId($this->identifier()); |
|
870 | + |
|
871 | + return $share; |
|
872 | + } |
|
873 | + |
|
874 | + /** |
|
875 | + * Get the node with file $id for $user |
|
876 | + * |
|
877 | + * @param string $userId |
|
878 | + * @param int $id |
|
879 | + * @return \OCP\Files\File|\OCP\Files\Folder |
|
880 | + * @throws InvalidShare |
|
881 | + */ |
|
882 | + private function getNode($userId, $id) { |
|
883 | + try { |
|
884 | + $userFolder = $this->rootFolder->getUserFolder($userId); |
|
885 | + } catch (NotFoundException $e) { |
|
886 | + throw new InvalidShare(); |
|
887 | + } |
|
888 | + |
|
889 | + $nodes = $userFolder->getById($id); |
|
890 | + |
|
891 | + if (empty($nodes)) { |
|
892 | + throw new InvalidShare(); |
|
893 | + } |
|
894 | + |
|
895 | + return $nodes[0]; |
|
896 | + } |
|
897 | + |
|
898 | + /** |
|
899 | + * A user is deleted from the system |
|
900 | + * So clean up the relevant shares. |
|
901 | + * |
|
902 | + * @param string $uid |
|
903 | + * @param int $shareType |
|
904 | + */ |
|
905 | + public function userDeleted($uid, $shareType) { |
|
906 | + //TODO: probabaly a good idea to send unshare info to remote servers |
|
907 | + |
|
908 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
909 | + |
|
910 | + $qb->delete('share') |
|
911 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_REMOTE))) |
|
912 | + ->andWhere($qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid))) |
|
913 | + ->execute(); |
|
914 | + } |
|
915 | + |
|
916 | + /** |
|
917 | + * This provider does not handle groups |
|
918 | + * |
|
919 | + * @param string $gid |
|
920 | + */ |
|
921 | + public function groupDeleted($gid) { |
|
922 | + // We don't handle groups here |
|
923 | + return; |
|
924 | + } |
|
925 | + |
|
926 | + /** |
|
927 | + * This provider does not handle groups |
|
928 | + * |
|
929 | + * @param string $uid |
|
930 | + * @param string $gid |
|
931 | + */ |
|
932 | + public function userDeletedFromGroup($uid, $gid) { |
|
933 | + // We don't handle groups here |
|
934 | + return; |
|
935 | + } |
|
936 | + |
|
937 | + /** |
|
938 | + * check if users from other Nextcloud instances are allowed to mount public links share by this instance |
|
939 | + * |
|
940 | + * @return bool |
|
941 | + */ |
|
942 | + public function isOutgoingServer2serverShareEnabled() { |
|
943 | + $result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes'); |
|
944 | + return ($result === 'yes') ? true : false; |
|
945 | + } |
|
946 | + |
|
947 | + /** |
|
948 | + * check if users are allowed to mount public links from other ownClouds |
|
949 | + * |
|
950 | + * @return bool |
|
951 | + */ |
|
952 | + public function isIncomingServer2serverShareEnabled() { |
|
953 | + $result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes'); |
|
954 | + return ($result === 'yes') ? true : false; |
|
955 | + } |
|
956 | + |
|
957 | + /** |
|
958 | + * Check if querying sharees on the lookup server is enabled |
|
959 | + * |
|
960 | + * @return bool |
|
961 | + */ |
|
962 | + public function isLookupServerQueriesEnabled() { |
|
963 | + $result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no'); |
|
964 | + return ($result === 'yes') ? true : false; |
|
965 | + } |
|
966 | + |
|
967 | + |
|
968 | + /** |
|
969 | + * Check if it is allowed to publish user specific data to the lookup server |
|
970 | + * |
|
971 | + * @return bool |
|
972 | + */ |
|
973 | + public function isLookupServerUploadEnabled() { |
|
974 | + $result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes'); |
|
975 | + return ($result === 'yes') ? true : false; |
|
976 | + } |
|
977 | 977 | } |
@@ -5,16 +5,16 @@ discard block |
||
5 | 5 | ?> |
6 | 6 | |
7 | 7 | <div id="fileSharingSettings" class="followupsection"> |
8 | - <h3><?php p($l->t('Federated Cloud Sharing'));?></h3> |
|
8 | + <h3><?php p($l->t('Federated Cloud Sharing')); ?></h3> |
|
9 | 9 | <a target="_blank" rel="noreferrer" class="icon-info svg" |
10 | - title="<?php p($l->t('Open documentation'));?>" |
|
10 | + title="<?php p($l->t('Open documentation')); ?>" |
|
11 | 11 | href="<?php p(link_to_docs('admin-sharing-federated')); ?>"></a> |
12 | 12 | |
13 | 13 | <p> |
14 | 14 | <input type="checkbox" name="outgoing_server2server_share_enabled" id="outgoingServer2serverShareEnabled" class="checkbox" |
15 | 15 | value="1" <?php if ($_['outgoingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
16 | 16 | <label for="outgoingServer2serverShareEnabled"> |
17 | - <?php p($l->t('Allow users on this server to send shares to other servers'));?> |
|
17 | + <?php p($l->t('Allow users on this server to send shares to other servers')); ?> |
|
18 | 18 | </label> |
19 | 19 | </p> |
20 | 20 | |
@@ -22,21 +22,21 @@ discard block |
||
22 | 22 | <input type="checkbox" name="incoming_server2server_share_enabled" id="incomingServer2serverShareEnabled" class="checkbox" |
23 | 23 | value="1" <?php if ($_['incomingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
24 | 24 | <label for="incomingServer2serverShareEnabled"> |
25 | - <?php p($l->t('Allow users on this server to receive shares from other servers'));?> |
|
25 | + <?php p($l->t('Allow users on this server to receive shares from other servers')); ?> |
|
26 | 26 | </label><br/> |
27 | 27 | </p> |
28 | 28 | <p> |
29 | 29 | <input type="checkbox" name="lookupServerEnabled" id="lookupServerEnabled" class="checkbox" |
30 | 30 | value="1" <?php if ($_['lookupServerEnabled']) print_unescaped('checked="checked"'); ?> /> |
31 | 31 | <label for="lookupServerEnabled"> |
32 | - <?php p($l->t('Search global and public address book for users and let local users publish their data'));?> |
|
32 | + <?php p($l->t('Search global and public address book for users and let local users publish their data')); ?> |
|
33 | 33 | </label><br/> |
34 | 34 | </p> |
35 | 35 | <p> |
36 | 36 | <input type="checkbox" name="lookupServerUploadEnabled" id="lookupServerUploadEnabled" class="checkbox" |
37 | 37 | value="1" <?php if ($_['lookupServerUploadEnabled']) print_unescaped('checked="checked"'); ?> /> |
38 | 38 | <label for="lookupServerUploadEnabled"> |
39 | - <?php p($l->t('Allow users to publish their data to a global and public address book'));?> |
|
39 | + <?php p($l->t('Allow users to publish their data to a global and public address book')); ?> |
|
40 | 40 | </label><br/> |
41 | 41 | </p> |
42 | 42 |
@@ -12,7 +12,10 @@ discard block |
||
12 | 12 | |
13 | 13 | <p> |
14 | 14 | <input type="checkbox" name="outgoing_server2server_share_enabled" id="outgoingServer2serverShareEnabled" class="checkbox" |
15 | - value="1" <?php if ($_['outgoingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
15 | + value="1" <?php if ($_['outgoingServer2serverShareEnabled']) { |
|
16 | + print_unescaped('checked="checked"'); |
|
17 | +} |
|
18 | +?> /> |
|
16 | 19 | <label for="outgoingServer2serverShareEnabled"> |
17 | 20 | <?php p($l->t('Allow users on this server to send shares to other servers'));?> |
18 | 21 | </label> |
@@ -20,21 +23,30 @@ discard block |
||
20 | 23 | |
21 | 24 | <p> |
22 | 25 | <input type="checkbox" name="incoming_server2server_share_enabled" id="incomingServer2serverShareEnabled" class="checkbox" |
23 | - value="1" <?php if ($_['incomingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
26 | + value="1" <?php if ($_['incomingServer2serverShareEnabled']) { |
|
27 | + print_unescaped('checked="checked"'); |
|
28 | +} |
|
29 | +?> /> |
|
24 | 30 | <label for="incomingServer2serverShareEnabled"> |
25 | 31 | <?php p($l->t('Allow users on this server to receive shares from other servers'));?> |
26 | 32 | </label><br/> |
27 | 33 | </p> |
28 | 34 | <p> |
29 | 35 | <input type="checkbox" name="lookupServerEnabled" id="lookupServerEnabled" class="checkbox" |
30 | - value="1" <?php if ($_['lookupServerEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
36 | + value="1" <?php if ($_['lookupServerEnabled']) { |
|
37 | + print_unescaped('checked="checked"'); |
|
38 | +} |
|
39 | +?> /> |
|
31 | 40 | <label for="lookupServerEnabled"> |
32 | 41 | <?php p($l->t('Search global and public address book for users and let local users publish their data'));?> |
33 | 42 | </label><br/> |
34 | 43 | </p> |
35 | 44 | <p> |
36 | 45 | <input type="checkbox" name="lookupServerUploadEnabled" id="lookupServerUploadEnabled" class="checkbox" |
37 | - value="1" <?php if ($_['lookupServerUploadEnabled']) print_unescaped('checked="checked"'); ?> /> |
|
46 | + value="1" <?php if ($_['lookupServerUploadEnabled']) { |
|
47 | + print_unescaped('checked="checked"'); |
|
48 | +} |
|
49 | +?> /> |
|
38 | 50 | <label for="lookupServerUploadEnabled"> |
39 | 51 | <?php p($l->t('Allow users to publish their data to a global and public address book'));?> |
40 | 52 | </label><br/> |