This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | /* global escapeHTML */ |
||
2 | |||
3 | (function(OC) { |
||
4 | // copied and stripped out from the old core |
||
5 | OC.Share = _.extend(OC.Share, { |
||
6 | /** |
||
7 | * @deprecated use OC.Share.currentShares instead |
||
8 | */ |
||
9 | itemShares:[], |
||
10 | /** |
||
11 | * Full list of all share statuses |
||
12 | */ |
||
13 | statuses:{}, |
||
14 | /** |
||
15 | * Shares for the currently selected file. |
||
16 | * (for which the dropdown is open) |
||
17 | * |
||
18 | * Key is item type and value is an array or |
||
19 | * shares of the given item type. |
||
20 | */ |
||
21 | currentShares: {}, |
||
22 | /** |
||
23 | * Whether the share dropdown is opened. |
||
24 | */ |
||
25 | droppedDown:false, |
||
26 | /** |
||
27 | * Loads ALL share statuses from server, stores them in |
||
28 | * OC.Share.statuses then calls OC.Share.updateIcons() to update the |
||
29 | * files "Share" icon to "Shared" according to their share status and |
||
30 | * share type. |
||
31 | * |
||
32 | * If a callback is specified, the update step is skipped. |
||
33 | * |
||
34 | * @param itemType item type |
||
35 | * @param fileList file list instance, defaults to OCA.Files.App.fileList |
||
36 | * @param callback function to call after the shares were loaded |
||
37 | */ |
||
38 | loadIcons:function(itemType, fileList, callback) { |
||
39 | // Load all share icons |
||
40 | $.get( |
||
41 | OC.filePath('core', 'ajax', 'share.php'), |
||
42 | { |
||
43 | fetch: 'getItemsSharedStatuses', |
||
44 | itemType: itemType |
||
45 | }, function(result) { |
||
46 | if (result && result.status === 'success') { |
||
47 | OC.Share.statuses = {}; |
||
48 | $.each(result.data, function(item, data) { |
||
49 | OC.Share.statuses[item] = data; |
||
50 | }); |
||
51 | if (_.isFunction(callback)) { |
||
52 | callback(OC.Share.statuses); |
||
53 | } else { |
||
54 | OC.Share.updateIcons(itemType, fileList); |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 | ); |
||
59 | }, |
||
60 | /** |
||
61 | * Updates the files' "Share" icons according to the known |
||
62 | * sharing states stored in OC.Share.statuses. |
||
63 | * (not reloaded from server) |
||
64 | * |
||
65 | * @param itemType item type |
||
66 | * @param fileList file list instance |
||
67 | * defaults to OCA.Files.App.fileList |
||
68 | */ |
||
69 | updateIcons:function(itemType, fileList){ |
||
70 | var item; |
||
71 | var $fileList; |
||
72 | var currentDir; |
||
73 | if (!fileList && OCA.Files) { |
||
74 | fileList = OCA.Files.App.fileList; |
||
75 | } |
||
76 | // fileList is usually only defined in the files app |
||
77 | if (fileList) { |
||
78 | $fileList = fileList.$fileList; |
||
79 | currentDir = fileList.getCurrentDirectory(); |
||
80 | } |
||
81 | // TODO: iterating over the files might be more efficient |
||
82 | for (item in OC.Share.statuses){ |
||
83 | var image = OC.imagePath('core', 'actions/share'); |
||
84 | var data = OC.Share.statuses[item]; |
||
85 | var hasLink = data.link; |
||
86 | // Links override shared in terms of icon display |
||
87 | if (hasLink) { |
||
88 | image = OC.imagePath('core', 'actions/public'); |
||
89 | } |
||
90 | if (itemType !== 'file' && itemType !== 'folder') { |
||
91 | $('a.share[data-item="'+item+'"]').css('background', 'url('+image+') no-repeat center'); |
||
92 | } else { |
||
93 | // TODO: ultimately this part should be moved to files_sharing app |
||
94 | var file = $fileList.find('tr[data-id="'+item+'"]'); |
||
95 | var shareFolder = OC.imagePath('core', 'filetypes/folder-shared'); |
||
96 | var img; |
||
97 | if (file.length > 0) { |
||
98 | this.markFileAsShared(file, true, hasLink); |
||
99 | } else { |
||
100 | var dir = currentDir; |
||
101 | if (dir.length > 1) { |
||
102 | var last = ''; |
||
103 | var path = dir; |
||
104 | // Search for possible parent folders that are shared |
||
105 | while (path != last) { |
||
106 | if (path === data.path && !data.link) { |
||
107 | var actions = $fileList.find('.fileactions .action[data-action="Share"]'); |
||
108 | var files = $fileList.find('.filename'); |
||
109 | var i; |
||
110 | for (i = 0; i < actions.length; i++) { |
||
111 | // TODO: use this.markFileAsShared() |
||
112 | img = $(actions[i]).find('img'); |
||
113 | if (img.attr('src') !== OC.imagePath('core', 'actions/public')) { |
||
114 | img.attr('src', image); |
||
115 | $(actions[i]).addClass('permanent'); |
||
116 | $(actions[i]).html(' <span>'+t('core', 'Shared')+'</span>').prepend(img); |
||
117 | } |
||
118 | } |
||
119 | for(i = 0; i < files.length; i++) { |
||
120 | if ($(files[i]).closest('tr').data('type') === 'dir') { |
||
121 | $(files[i]).find('.thumbnail').css('background-image', 'url('+shareFolder+')'); |
||
122 | } |
||
123 | } |
||
124 | } |
||
125 | last = path; |
||
126 | path = OC.Share.dirname(path); |
||
127 | } |
||
128 | } |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | }, |
||
133 | updateIcon:function(itemType, itemSource) { |
||
134 | var shares = false; |
||
135 | var link = false; |
||
136 | var image = OC.imagePath('core', 'actions/share'); |
||
137 | $.each(OC.Share.itemShares, function(index) { |
||
138 | if (OC.Share.itemShares[index]) { |
||
139 | if (index == OC.Share.SHARE_TYPE_LINK) { |
||
140 | if (OC.Share.itemShares[index] == true) { |
||
0 ignored issues
–
show
|
|||
141 | shares = true; |
||
142 | image = OC.imagePath('core', 'actions/public'); |
||
143 | link = true; |
||
144 | return; |
||
145 | } |
||
146 | } else if (OC.Share.itemShares[index].length > 0) { |
||
147 | shares = true; |
||
148 | image = OC.imagePath('core', 'actions/share'); |
||
149 | } |
||
150 | } |
||
151 | }); |
||
152 | if (itemType != 'file' && itemType != 'folder') { |
||
153 | $('a.share[data-item="'+itemSource+'"]').css('background', 'url('+image+') no-repeat center'); |
||
154 | } else { |
||
155 | var $tr = $('tr').filterAttr('data-id', String(itemSource)); |
||
156 | if ($tr.length > 0) { |
||
157 | // it might happen that multiple lists exist in the DOM |
||
158 | // with the same id |
||
159 | $tr.each(function() { |
||
160 | OC.Share.markFileAsShared($(this), shares, link); |
||
161 | }); |
||
162 | } |
||
163 | } |
||
164 | if (shares) { |
||
165 | OC.Share.statuses[itemSource] = OC.Share.statuses[itemSource] || {}; |
||
166 | OC.Share.statuses[itemSource]['link'] = link; |
||
167 | } else { |
||
168 | delete OC.Share.statuses[itemSource]; |
||
169 | } |
||
170 | }, |
||
171 | /** |
||
172 | * Format a remote address |
||
173 | * |
||
174 | * @param {String} remoteAddress full remote share |
||
175 | * @return {String} HTML code to display |
||
176 | */ |
||
177 | _formatRemoteShare: function(remoteAddress) { |
||
178 | var parts = this._REMOTE_OWNER_REGEXP.exec(remoteAddress); |
||
179 | if (!parts) { |
||
180 | // display as is, most likely to be a simple owner name |
||
181 | return escapeHTML(remoteAddress); |
||
182 | } |
||
183 | |||
184 | var userName = parts[1]; |
||
185 | var userDomain = parts[3]; |
||
186 | var server = parts[4]; |
||
187 | var dir = parts[6]; |
||
188 | var tooltip = userName; |
||
189 | if (userDomain) { |
||
190 | tooltip += '@' + userDomain; |
||
191 | } |
||
192 | if (server) { |
||
193 | if (!userDomain) { |
||
194 | userDomain = '…'; |
||
195 | } |
||
196 | tooltip += '@' + server; |
||
197 | } |
||
198 | |||
199 | var html = '<span class="remoteAddress" title="' + escapeHTML(tooltip) + '">'; |
||
200 | html += '<span class="username">' + escapeHTML(userName) + '</span>'; |
||
201 | if (userDomain) { |
||
202 | html += '<span class="userDomain">@' + escapeHTML(userDomain) + '</span>'; |
||
203 | } |
||
204 | html += '</span>'; |
||
205 | return html; |
||
206 | }, |
||
207 | /** |
||
208 | * Marks/unmarks a given file as shared by changing its action icon |
||
209 | * and folder icon. |
||
210 | * |
||
211 | * @param $tr file element to mark as shared |
||
212 | * @param hasShares whether shares are available |
||
213 | * @param hasLink whether link share is available |
||
214 | */ |
||
215 | loadItem:function(itemType, itemSource) { |
||
216 | var data = ''; |
||
217 | var checkReshare = true; |
||
218 | if (typeof OC.Share.statuses[itemSource] === 'undefined') { |
||
219 | // NOTE: Check does not always work and misses some shares, fix later |
||
220 | var checkShares = true; |
||
221 | } else { |
||
222 | var checkShares = true; |
||
223 | } |
||
224 | $.ajax({type: 'GET', url: OC.filePath('core', 'ajax', 'share.php'), data: { fetch: 'getItem', itemType: itemType, itemSource: itemSource, checkReshare: checkReshare, checkShares: checkShares }, async: false, success: function(result) { |
||
225 | if (result && result.status === 'success') { |
||
226 | data = result.data; |
||
227 | } else { |
||
228 | data = false; |
||
229 | } |
||
230 | }}); |
||
231 | |||
232 | return data; |
||
233 | }, |
||
234 | share:function(itemType, itemSource, shareType, shareWith, permissions, itemSourceName, expirationDate, callback, errorCallback) { |
||
235 | // Add a fallback for old share() calls without expirationDate. |
||
236 | // We should remove this in a later version, |
||
237 | // after the Apps have been updated. |
||
238 | if (typeof callback === 'undefined' && |
||
239 | typeof expirationDate === 'function') { |
||
240 | callback = expirationDate; |
||
241 | expirationDate = ''; |
||
242 | console.warn( |
||
243 | "Call to 'OC.Share.share()' with too few arguments. " + |
||
244 | "'expirationDate' was assumed to be 'callback'. " + |
||
245 | "Please revisit the call and fix the list of arguments." |
||
246 | ); |
||
247 | } |
||
248 | |||
249 | return $.post(OC.filePath('core', 'ajax', 'share.php'), |
||
250 | { |
||
251 | action: 'share', |
||
252 | itemType: itemType, |
||
253 | itemSource: itemSource, |
||
254 | shareType: shareType, |
||
255 | shareWith: shareWith, |
||
256 | permissions: permissions, |
||
257 | itemSourceName: itemSourceName, |
||
258 | expirationDate: expirationDate |
||
259 | }, function (result) { |
||
260 | if (result && result.status === 'success') { |
||
261 | if (callback) { |
||
262 | callback(result.data); |
||
263 | } |
||
264 | } else { |
||
265 | if (_.isUndefined(errorCallback)) { |
||
266 | var msg = t('core', 'Error'); |
||
267 | if (result.data && result.data.message) { |
||
268 | msg = result.data.message; |
||
269 | } |
||
270 | OC.dialogs.alert(msg, t('core', 'Error while sharing')); |
||
271 | } else { |
||
272 | errorCallback(result); |
||
273 | } |
||
274 | } |
||
275 | } |
||
276 | ); |
||
277 | }, |
||
278 | unshare:function(itemType, itemSource, shareType, shareWith, callback) { |
||
279 | $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'unshare', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith }, function(result) { |
||
280 | if (result && result.status === 'success') { |
||
281 | if (callback) { |
||
282 | callback(); |
||
283 | } |
||
284 | } else { |
||
285 | OC.dialogs.alert(t('core', 'Error while unsharing'), t('core', 'Error')); |
||
286 | } |
||
287 | }); |
||
288 | }, |
||
289 | setPermissions:function(itemType, itemSource, shareType, shareWith, permissions) { |
||
290 | $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setPermissions', itemType: itemType, itemSource: itemSource, shareType: shareType, shareWith: shareWith, permissions: permissions }, function(result) { |
||
291 | if (!result || result.status !== 'success') { |
||
292 | OC.dialogs.alert(t('core', 'Error while changing permissions'), t('core', 'Error')); |
||
293 | } |
||
294 | }); |
||
295 | }, |
||
296 | showDropDown:function(itemType, itemSource, appendTo, link, possiblePermissions, filename) { |
||
297 | var data = OC.Share.loadItem(itemType, itemSource); |
||
298 | var dropDownEl; |
||
299 | var html = '<div id="dropdown" class="drop shareDropDown" data-item-type="'+escapeHTML(itemType)+'" data-item-source="'+escapeHTML(itemSource)+'">'; |
||
300 | if (data !== false && data.reshare !== false && data.reshare.uid_owner !== undefined && data.reshare.uid_owner !== OC.currentUser) { |
||
301 | html += '<span class="reshare">'; |
||
302 | if (oc_config.enable_avatars === true) { |
||
303 | html += '<div class="avatar"></div> '; |
||
304 | } |
||
305 | |||
306 | if (data.reshare.share_type == OC.Share.SHARE_TYPE_GROUP) { |
||
307 | html += t('core', 'Shared with you and the group {group} by {owner}', {group: data.reshare.share_with, owner: data.reshare.displayname_owner}); |
||
308 | } else { |
||
309 | html += t('core', 'Shared with you by {owner}', {owner: data.reshare.displayname_owner}); |
||
310 | } |
||
311 | html += '</span><br />'; |
||
312 | // reduce possible permissions to what the original share allowed |
||
313 | possiblePermissions = possiblePermissions & data.reshare.permissions; |
||
314 | } |
||
315 | |||
316 | if (possiblePermissions & OC.PERMISSION_SHARE) { |
||
317 | // Determine the Allow Public Upload status. |
||
318 | // Used later on to determine if the |
||
319 | // respective checkbox should be checked or |
||
320 | // not. |
||
321 | |||
322 | var publicUploadEnabled = $('#filestable').data('allow-public-upload'); |
||
323 | if (typeof publicUploadEnabled == 'undefined') { |
||
324 | publicUploadEnabled = 'no'; |
||
325 | } |
||
326 | var allowPublicUploadStatus = false; |
||
327 | |||
328 | $.each(data.shares, function(key, value) { |
||
329 | if (value.share_type === OC.Share.SHARE_TYPE_LINK) { |
||
330 | allowPublicUploadStatus = (value.permissions & OC.PERMISSION_CREATE) ? true : false; |
||
331 | return true; |
||
332 | } |
||
333 | }); |
||
334 | |||
335 | var sharePlaceholder = t('core', 'Share with users or groups …'); |
||
336 | if(oc_appconfig.core.remoteShareAllowed) { |
||
337 | sharePlaceholder = t('core', 'Share with users, groups or remote users …'); |
||
338 | } |
||
339 | |||
340 | html += '<label for="shareWith" class="hidden-visually">'+t('core', 'Share')+'</label>'; |
||
341 | html += '<input id="shareWith" type="text" placeholder="' + sharePlaceholder + '" />'; |
||
342 | if(oc_appconfig.core.remoteShareAllowed) { |
||
343 | var federatedCloudSharingDoc = '<a target="_blank" class="icon-info svg shareWithRemoteInfo" href="{docLink}" ' |
||
344 | + 'title="' + t('core', 'Share with people on other ownClouds using the syntax [email protected]/owncloud') + '"></a>'; |
||
0 ignored issues
–
show
|
|||
345 | html += federatedCloudSharingDoc.replace('{docLink}', oc_appconfig.core.federatedCloudShareDoc); |
||
346 | } |
||
347 | html += '<span class="shareWithLoading icon-loading-small hidden"></span>'; |
||
348 | html += '<ul id="shareWithList">'; |
||
349 | html += '</ul>'; |
||
350 | var linksAllowed = $('#allowShareWithLink').val() === 'yes'; |
||
351 | if (link && linksAllowed) { |
||
352 | html += '<div id="link" class="linkShare">'; |
||
353 | html += '<span class="icon-loading-small hidden"></span>'; |
||
354 | html += '<input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" /><label for="linkCheckbox">'+t('core', 'Share link')+'</label>'; |
||
355 | html += '<br />'; |
||
356 | |||
357 | var defaultExpireMessage = ''; |
||
358 | if ((itemType === 'folder' || itemType === 'file') && oc_appconfig.core.defaultExpireDateEnforced) { |
||
359 | defaultExpireMessage = t('core', 'The public link will expire no later than {days} days after it is created', {'days': oc_appconfig.core.defaultExpireDate}) + '<br/>'; |
||
360 | } |
||
361 | |||
362 | html += '<label for="linkText" class="hidden-visually">'+t('core', 'Link')+'</label>'; |
||
363 | html += '<input id="linkText" type="text" readonly="readonly" />'; |
||
364 | html += '<input type="checkbox" name="showPassword" id="showPassword" value="1" style="display:none;" /><label for="showPassword" style="display:none;">'+t('core', 'Password protect')+'</label>'; |
||
365 | html += '<div id="linkPass">'; |
||
366 | html += '<label for="linkPassText" class="hidden-visually">'+t('core', 'Password')+'</label>'; |
||
367 | html += '<input id="linkPassText" type="password" placeholder="'+t('core', 'Choose a password for the public link')+'" />'; |
||
368 | html += '<span class="icon-loading-small hidden"></span>'; |
||
369 | html += '</div>'; |
||
370 | |||
371 | if (itemType === 'folder' && (possiblePermissions & OC.PERMISSION_CREATE) && publicUploadEnabled === 'yes') { |
||
372 | html += '<div id="allowPublicUploadWrapper" style="display:none;">'; |
||
373 | html += '<span class="icon-loading-small hidden"></span>'; |
||
374 | html += '<input type="checkbox" value="1" name="allowPublicUpload" id="sharingDialogAllowPublicUpload"' + ((allowPublicUploadStatus) ? 'checked="checked"' : '') + ' />'; |
||
375 | html += '<label for="sharingDialogAllowPublicUpload">' + t('core', 'Allow editing') + '</label>'; |
||
376 | html += '</div>'; |
||
377 | } |
||
378 | html += '</div>'; |
||
379 | var mailPublicNotificationEnabled = $('input:hidden[name=mailPublicNotificationEnabled]').val(); |
||
380 | if (mailPublicNotificationEnabled === 'yes') { |
||
381 | html += '<form id="emailPrivateLink">'; |
||
382 | html += '<input id="email" style="display:none; width:62%;" value="" placeholder="'+t('core', 'Email link to person')+'" type="text" />'; |
||
383 | html += '<input id="emailButton" style="display:none;" type="submit" value="'+t('core', 'Send')+'" />'; |
||
384 | html += '</form>'; |
||
385 | } |
||
386 | } |
||
387 | |||
388 | html += '<div id="expiration">'; |
||
389 | html += '<input type="checkbox" name="expirationCheckbox" id="expirationCheckbox" value="1" /><label for="expirationCheckbox">'+t('core', 'Set expiration date')+'</label>'; |
||
390 | html += '<label for="expirationDate" class="hidden-visually">'+t('core', 'Expiration')+'</label>'; |
||
391 | html += '<input id="expirationDate" type="text" placeholder="'+t('core', 'Expiration date')+'" style="display:none; width:90%;" />'; |
||
392 | html += '<em id="defaultExpireMessage">'+defaultExpireMessage+'</em>'; |
||
393 | html += '</div>'; |
||
394 | dropDownEl = $(html); |
||
395 | dropDownEl = dropDownEl.appendTo(appendTo); |
||
396 | |||
397 | // trigger remote share info tooltip |
||
398 | if(oc_appconfig.core.remoteShareAllowed) { |
||
399 | $('.shareWithRemoteInfo').tipsy({gravity: 'e'}); |
||
400 | } |
||
401 | |||
402 | //Get owner avatars |
||
403 | if (oc_config.enable_avatars === true && data !== false && data.reshare !== false && data.reshare.uid_owner !== undefined) { |
||
404 | dropDownEl.find(".avatar").avatar(data.reshare.uid_owner, 32); |
||
405 | } |
||
406 | |||
407 | // Reset item shares |
||
408 | OC.Share.itemShares = []; |
||
409 | OC.Share.currentShares = {}; |
||
410 | if (data.shares) { |
||
411 | $.each(data.shares, function(index, share) { |
||
412 | if (share.share_type == OC.Share.SHARE_TYPE_LINK) { |
||
413 | if (itemSource === share.file_source || itemSource === share.item_source) { |
||
414 | OC.Share.showLink(share.token, share.share_with, itemSource); |
||
415 | } |
||
416 | } else { |
||
417 | if (share.collection) { |
||
418 | OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.mail_send, share.collection); |
||
419 | } else { |
||
420 | if (share.share_type === OC.Share.SHARE_TYPE_REMOTE) { |
||
421 | OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, OC.PERMISSION_READ | OC.PERMISSION_UPDATE | OC.PERMISSION_CREATE, share.mail_send, false); |
||
422 | } else { |
||
423 | OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.mail_send, false); |
||
424 | } |
||
425 | } |
||
426 | } |
||
427 | if (share.expiration != null) { |
||
0 ignored issues
–
show
It is recommended to use
!== to compare with null .
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator. ![]() |
|||
428 | OC.Share.showExpirationDate(share.expiration, share.stime); |
||
429 | } |
||
430 | }); |
||
431 | } |
||
432 | $('#shareWith').autocomplete({minLength: 2, delay: 750, source: function(search, response) { |
||
433 | var $loading = $('#dropdown .shareWithLoading'); |
||
434 | $loading.removeClass('hidden'); |
||
435 | $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWith', search: search.term.trim(), limit: 200, itemShares: OC.Share.itemShares, itemType: itemType }, function(result) { |
||
436 | $loading.addClass('hidden'); |
||
437 | if (result.status == 'success' && result.data.length > 0) { |
||
438 | $( "#shareWith" ).autocomplete( "option", "autoFocus", true ); |
||
439 | response(result.data); |
||
440 | } else { |
||
441 | response(); |
||
442 | } |
||
443 | }).fail(function(){ |
||
444 | $('#dropdown').find('.shareWithLoading').addClass('hidden'); |
||
445 | OC.Notification.show(t('core', 'An error occured. Please try again')); |
||
446 | window.setTimeout(OC.Notification.hide, 5000); |
||
447 | }); |
||
448 | }, |
||
449 | focus: function(event, focused) { |
||
450 | event.preventDefault(); |
||
451 | }, |
||
452 | select: function(event, selected) { |
||
453 | event.stopPropagation(); |
||
454 | var $dropDown = $('#dropdown'); |
||
455 | var itemType = $dropDown.data('item-type'); |
||
456 | var itemSource = $dropDown.data('item-source'); |
||
457 | var itemSourceName = $dropDown.data('item-source-name'); |
||
458 | var expirationDate = ''; |
||
459 | if ( $('#expirationCheckbox').is(':checked') === true ) { |
||
460 | expirationDate = $( "#expirationDate" ).val(); |
||
461 | } |
||
462 | var shareType = selected.item.value.shareType; |
||
463 | var shareWith = selected.item.value.shareWith; |
||
464 | $(this).val(shareWith); |
||
465 | // Default permissions are Edit (CRUD) and Share |
||
466 | // Check if these permissions are possible |
||
467 | var permissions = OC.PERMISSION_READ; |
||
468 | if (shareType === OC.Share.SHARE_TYPE_REMOTE) { |
||
469 | permissions = OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_READ; |
||
470 | } else { |
||
471 | if (possiblePermissions & OC.PERMISSION_UPDATE) { |
||
472 | permissions = permissions | OC.PERMISSION_UPDATE; |
||
473 | } |
||
474 | if (possiblePermissions & OC.PERMISSION_CREATE) { |
||
475 | permissions = permissions | OC.PERMISSION_CREATE; |
||
476 | } |
||
477 | if (possiblePermissions & OC.PERMISSION_DELETE) { |
||
478 | permissions = permissions | OC.PERMISSION_DELETE; |
||
479 | } |
||
480 | if (oc_appconfig.core.resharingAllowed && (possiblePermissions & OC.PERMISSION_SHARE)) { |
||
481 | permissions = permissions | OC.PERMISSION_SHARE; |
||
482 | } |
||
483 | } |
||
484 | |||
485 | var $input = $(this); |
||
486 | var $loading = $dropDown.find('.shareWithLoading'); |
||
487 | $loading.removeClass('hidden'); |
||
488 | $input.val(t('core', 'Adding user...')); |
||
489 | $input.prop('disabled', true); |
||
490 | |||
491 | OC.Share.share(itemType, itemSource, shareType, shareWith, permissions, itemSourceName, expirationDate, function() { |
||
492 | $input.prop('disabled', false); |
||
493 | $loading.addClass('hidden'); |
||
494 | var posPermissions = possiblePermissions; |
||
495 | if (shareType === OC.Share.SHARE_TYPE_REMOTE) { |
||
496 | posPermissions = permissions; |
||
497 | } |
||
498 | OC.Share.addShareWith(shareType, shareWith, selected.item.label, permissions, posPermissions); |
||
499 | $('#shareWith').val(''); |
||
500 | $('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares})); |
||
501 | OC.Share.updateIcon(itemType, itemSource); |
||
502 | }); |
||
503 | return false; |
||
504 | } |
||
505 | }) |
||
506 | // customize internal _renderItem function to display groups and users differently |
||
507 | .data("ui-autocomplete")._renderItem = function( ul, item ) { |
||
508 | var insert = $( "<a>" ); |
||
509 | var text = item.label; |
||
510 | if (item.value.shareType === OC.Share.SHARE_TYPE_GROUP) { |
||
511 | text = text + ' ('+t('core', 'group')+')'; |
||
512 | } else if (item.value.shareType === OC.Share.SHARE_TYPE_REMOTE) { |
||
513 | text = text + ' ('+t('core', 'remote')+')'; |
||
514 | } |
||
515 | insert.text( text ); |
||
516 | if(item.value.shareType === OC.Share.SHARE_TYPE_GROUP) { |
||
517 | insert = insert.wrapInner('<strong></strong>'); |
||
518 | } |
||
519 | return $( "<li>" ) |
||
520 | .addClass((item.value.shareType === OC.Share.SHARE_TYPE_GROUP)?'group':'user') |
||
521 | .append( insert ) |
||
522 | .appendTo( ul ); |
||
523 | }; |
||
524 | if (link && linksAllowed && $('#email').length != 0) { |
||
0 ignored issues
–
show
It is recommended to use
!== to compare with 0 .
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator. ![]() |
|||
525 | $('#email').autocomplete({ |
||
526 | minLength: 1, |
||
527 | source: function (search, response) { |
||
528 | $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWithEmail', search: search.term }, function(result) { |
||
529 | if (result.status == 'success' && result.data.length > 0) { |
||
530 | response(result.data); |
||
531 | } |
||
532 | }); |
||
533 | }, |
||
534 | select: function( event, item ) { |
||
535 | $('#email').val(item.item.email); |
||
536 | return false; |
||
537 | } |
||
538 | }) |
||
539 | .data("ui-autocomplete")._renderItem = function( ul, item ) { |
||
540 | return $('<li>') |
||
541 | .append('<a>' + escapeHTML(item.displayname) + "<br>" + escapeHTML(item.email) + '</a>' ) |
||
542 | .appendTo( ul ); |
||
543 | }; |
||
544 | } |
||
545 | |||
546 | } else { |
||
547 | html += '<input id="shareWith" type="text" placeholder="'+t('core', 'Resharing is not allowed')+'" style="width:90%;" disabled="disabled"/>'; |
||
548 | html += '</div>'; |
||
549 | dropDownEl = $(html); |
||
550 | dropDownEl.appendTo(appendTo); |
||
551 | } |
||
552 | dropDownEl.attr('data-item-source-name', filename); |
||
553 | $('#dropdown').slideDown(OC.menuSpeed, function() { |
||
554 | OC.Share.droppedDown = true; |
||
555 | }); |
||
556 | if ($('html').hasClass('lte9')){ |
||
557 | $('#dropdown input[placeholder]').placeholder(); |
||
558 | } |
||
559 | $('#shareWith').focus(); |
||
560 | }, |
||
561 | hideDropDown:function(callback) { |
||
562 | OC.Share.currentShares = null; |
||
563 | $('#dropdown').slideUp(OC.menuSpeed, function() { |
||
564 | OC.Share.droppedDown = false; |
||
565 | $('#dropdown').remove(); |
||
566 | if (typeof FileActions !== 'undefined') { |
||
567 | $('tr').removeClass('mouseOver'); |
||
568 | } |
||
569 | if (callback) { |
||
570 | callback.call(); |
||
571 | } |
||
572 | }); |
||
573 | }, |
||
574 | addShareWith:function(shareType, shareWith, shareWithDisplayName, permissions, possiblePermissions, mailSend, collection) { |
||
575 | var shareItem = { |
||
576 | share_type: shareType, |
||
577 | share_with: shareWith, |
||
578 | share_with_displayname: shareWithDisplayName, |
||
579 | permissions: permissions |
||
580 | }; |
||
581 | if (shareType === OC.Share.SHARE_TYPE_GROUP) { |
||
582 | shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'group') + ')'; |
||
583 | } |
||
584 | if (shareType === OC.Share.SHARE_TYPE_REMOTE) { |
||
585 | shareWithDisplayName = shareWithDisplayName + " (" + t('core', 'remote') + ')'; |
||
586 | } |
||
587 | if (!OC.Share.itemShares[shareType]) { |
||
588 | OC.Share.itemShares[shareType] = []; |
||
589 | } |
||
590 | OC.Share.itemShares[shareType].push(shareWith); |
||
591 | if (collection) { |
||
592 | if (collection.item_type == 'file' || collection.item_type == 'folder') { |
||
593 | var item = collection.path; |
||
594 | } else { |
||
595 | var item = collection.item_source; |
||
596 | } |
||
597 | var collectionList = $('#shareWithList li').filterAttr('data-collection', item); |
||
598 | if (collectionList.length > 0) { |
||
599 | $(collectionList).append(', '+shareWithDisplayName); |
||
600 | } else { |
||
601 | var html = '<li style="clear: both;" data-collection="'+item+'">'+t('core', 'Shared in {item} with {user}', {'item': item, user: shareWithDisplayName})+'</li>'; |
||
602 | $('#shareWithList').prepend(html); |
||
603 | } |
||
604 | } else { |
||
605 | var editChecked = createChecked = updateChecked = deleteChecked = shareChecked = ''; |
||
0 ignored issues
–
show
|
|||
606 | if (permissions & OC.PERMISSION_CREATE) { |
||
607 | createChecked = 'checked="checked"'; |
||
608 | editChecked = 'checked="checked"'; |
||
609 | } |
||
610 | if (permissions & OC.PERMISSION_UPDATE) { |
||
611 | updateChecked = 'checked="checked"'; |
||
612 | editChecked = 'checked="checked"'; |
||
613 | } |
||
614 | if (permissions & OC.PERMISSION_DELETE) { |
||
615 | deleteChecked = 'checked="checked"'; |
||
616 | editChecked = 'checked="checked"'; |
||
617 | } |
||
618 | if (permissions & OC.PERMISSION_SHARE) { |
||
619 | shareChecked = 'checked="checked"'; |
||
620 | } |
||
621 | var html = '<li style="clear: both;" data-share-type="'+escapeHTML(shareType)+'" data-share-with="'+escapeHTML(shareWith)+'" title="' + escapeHTML(shareWith) + '">'; |
||
622 | var showCrudsButton; |
||
623 | html += '<a href="#" class="unshare"><img class="svg" alt="'+t('core', 'Unshare')+'" title="'+t('core', 'Unshare')+'" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>'; |
||
624 | if (oc_config.enable_avatars === true) { |
||
625 | html += '<div class="avatar"></div>'; |
||
626 | } |
||
627 | html += '<span class="username">' + escapeHTML(shareWithDisplayName) + '</span>'; |
||
628 | var mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val(); |
||
629 | if (mailNotificationEnabled === 'yes' && shareType !== OC.Share.SHARE_TYPE_REMOTE) { |
||
630 | var checked = ''; |
||
631 | if (mailSend === '1') { |
||
632 | checked = 'checked'; |
||
633 | } |
||
634 | html += '<input id="mail-'+escapeHTML(shareWith)+'" type="checkbox" name="mailNotification" class="mailNotification" ' + checked + ' /><label for="mail-'+escapeHTML(shareWith)+'">'+t('core', 'notify by email')+'</label> '; |
||
635 | } |
||
636 | if (oc_appconfig.core.resharingAllowed && (possiblePermissions & OC.PERMISSION_SHARE)) { |
||
637 | html += '<input id="canShare-'+escapeHTML(shareWith)+'" type="checkbox" name="share" class="permissions" '+shareChecked+' data-permissions="'+OC.PERMISSION_SHARE+'" />'; |
||
638 | html += '<label for="canShare-'+escapeHTML(shareWith)+'">'+t('core', 'can share')+'</label>'; |
||
639 | } |
||
640 | if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) { |
||
641 | html += '<input id="canEdit-'+escapeHTML(shareWith)+'" type="checkbox" name="edit" class="permissions" '+editChecked+' />'; |
||
642 | html += '<label for="canEdit-'+escapeHTML(shareWith)+'">'+t('core', 'can edit')+'</label>'; |
||
643 | } |
||
644 | if (shareType !== OC.Share.SHARE_TYPE_REMOTE) { |
||
645 | showCrudsButton = '<a href="#" class="showCruds"><img class="svg" alt="'+t('core', 'access control')+'" src="'+OC.imagePath('core', 'actions/triangle-s')+'"/></a>'; |
||
646 | } |
||
647 | html += '<div class="cruds" style="display:none;">'; |
||
648 | if (possiblePermissions & OC.PERMISSION_CREATE) { |
||
649 | html += '<input id="canCreate-' + escapeHTML(shareWith) + '" type="checkbox" name="create" class="permissions" ' + createChecked + ' data-permissions="' + OC.PERMISSION_CREATE + '"/>'; |
||
650 | html += '<label for="canCreate-' + escapeHTML(shareWith) + '">' + t('core', 'create') + '</label>'; |
||
651 | } |
||
652 | if (possiblePermissions & OC.PERMISSION_UPDATE) { |
||
653 | html += '<input id="canUpdate-' + escapeHTML(shareWith) + '" type="checkbox" name="update" class="permissions" ' + updateChecked + ' data-permissions="' + OC.PERMISSION_UPDATE + '"/>'; |
||
654 | html += '<label for="canUpdate-' + escapeHTML(shareWith) + '">' + t('core', 'change') + '</label>'; |
||
655 | } |
||
656 | if (possiblePermissions & OC.PERMISSION_DELETE) { |
||
657 | html += '<input id="canDelete-' + escapeHTML(shareWith) + '" type="checkbox" name="delete" class="permissions" ' + deleteChecked + ' data-permissions="' + OC.PERMISSION_DELETE + '"/>'; |
||
658 | html += '<label for="canDelete-' + escapeHTML(shareWith) + '">' + t('core', 'delete') + '</label>'; |
||
659 | } |
||
660 | html += '</div>'; |
||
661 | html += '</li>'; |
||
662 | html = $(html).appendTo('#shareWithList'); |
||
663 | if (oc_config.enable_avatars === true) { |
||
664 | if (shareType === OC.Share.SHARE_TYPE_USER) { |
||
665 | html.find('.avatar').avatar(escapeHTML(shareWith), 32); |
||
666 | } else { |
||
667 | //Add sharetype to generate different seed if there is a group and use with the same name |
||
668 | html.find('.avatar').imageplaceholder(escapeHTML(shareWith) + ' ' + shareType); |
||
669 | } |
||
670 | } |
||
671 | // insert cruds button into last label element |
||
672 | var lastLabel = html.find('>label:last'); |
||
673 | if (lastLabel.exists()){ |
||
674 | lastLabel.append(showCrudsButton); |
||
675 | } |
||
676 | else{ |
||
677 | html.find('.cruds').before(showCrudsButton); |
||
678 | } |
||
679 | if (!OC.Share.currentShares[shareType]) { |
||
680 | OC.Share.currentShares[shareType] = []; |
||
681 | } |
||
682 | OC.Share.currentShares[shareType].push(shareItem); |
||
683 | } |
||
684 | }, |
||
685 | showLink:function(token, password, itemSource) { |
||
686 | OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = true; |
||
687 | $('#linkCheckbox').attr('checked', true); |
||
688 | |||
689 | //check itemType |
||
690 | var linkSharetype=$('#dropdown').data('item-type'); |
||
691 | |||
692 | if (! token) { |
||
693 | //fallback to pre token link |
||
694 | var filename = $('tr').filterAttr('data-id', String(itemSource)).data('file'); |
||
695 | var type = $('tr').filterAttr('data-id', String(itemSource)).data('type'); |
||
696 | if ($('#dir').val() == '/') { |
||
697 | var file = $('#dir').val() + filename; |
||
698 | } else { |
||
699 | var file = $('#dir').val() + '/' + filename; |
||
700 | } |
||
701 | file = '/'+OC.currentUser+'/files'+file; |
||
702 | // TODO: use oc webroot ? |
||
703 | var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&'+type+'='+encodeURIComponent(file); |
||
704 | } else { |
||
705 | //TODO add path param when showing a link to file in a subfolder of a public link share |
||
706 | var service=''; |
||
707 | if(linkSharetype === 'folder' || linkSharetype === 'file'){ |
||
708 | service='files'; |
||
709 | }else{ |
||
710 | service=linkSharetype; |
||
711 | } |
||
712 | |||
713 | // TODO: use oc webroot ? |
||
714 | if (service !== 'files') { |
||
715 | var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service='+service+'&t='+token; |
||
716 | } else { |
||
717 | var link = parent.location.protocol+'//'+location.host+OC.generateUrl('/s/')+token; |
||
718 | } |
||
719 | } |
||
720 | $('#linkText').val(link); |
||
721 | $('#linkText').slideDown(OC.menuSpeed); |
||
722 | $('#linkText').css('display','block'); |
||
723 | if (oc_appconfig.core.enforcePasswordForPublicLink === false || password === null) { |
||
724 | $('#showPassword').show(); |
||
725 | $('#showPassword+label').show(); |
||
726 | } |
||
727 | if (password != null) { |
||
0 ignored issues
–
show
It is recommended to use
!== to compare with null .
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator. ![]() |
|||
728 | $('#linkPass').slideDown(OC.menuSpeed); |
||
729 | $('#showPassword').attr('checked', true); |
||
730 | $('#linkPassText').attr('placeholder', '**********'); |
||
731 | } |
||
732 | $('#expiration').show(); |
||
733 | $('#emailPrivateLink #email').show(); |
||
734 | $('#emailPrivateLink #emailButton').show(); |
||
735 | $('#allowPublicUploadWrapper').show(); |
||
736 | }, |
||
737 | hideLink:function() { |
||
738 | $('#linkText').slideUp(OC.menuSpeed); |
||
739 | $('#defaultExpireMessage').hide(); |
||
740 | $('#showPassword').hide(); |
||
741 | $('#showPassword+label').hide(); |
||
742 | $('#linkPass').slideUp(OC.menuSpeed); |
||
743 | $('#emailPrivateLink #email').hide(); |
||
744 | $('#emailPrivateLink #emailButton').hide(); |
||
745 | $('#allowPublicUploadWrapper').hide(); |
||
746 | }, |
||
747 | dirname:function(path) { |
||
748 | return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, ''); |
||
749 | }, |
||
750 | /** |
||
751 | * Parses a string to an valid integer (unix timestamp) |
||
752 | * @param time |
||
753 | * @returns {*} |
||
754 | * @internal Only used to work around a bug in the backend |
||
755 | */ |
||
756 | _parseTime: function(time) { |
||
757 | if (_.isString(time)) { |
||
758 | // skip empty strings and hex values |
||
759 | if (time === '' || (time.length > 1 && time[0] === '0' && time[1] === 'x')) { |
||
760 | return null; |
||
761 | } |
||
762 | time = parseInt(time, 10); |
||
763 | if(isNaN(time)) { |
||
764 | time = null; |
||
765 | } |
||
766 | } |
||
767 | return time; |
||
768 | }, |
||
769 | /** |
||
770 | * Displays the expiration date field |
||
771 | * |
||
772 | * @param {Date} date current expiration date |
||
773 | * @param {int} [shareTime] share timestamp in seconds, defaults to now |
||
774 | */ |
||
775 | showExpirationDate:function(date, shareTime) { |
||
776 | var now = new Date(); |
||
777 | // min date should always be the next day |
||
778 | var minDate = new Date(); |
||
779 | minDate.setDate(minDate.getDate()+1); |
||
780 | var datePickerOptions = { |
||
781 | minDate: minDate, |
||
782 | maxDate: null |
||
783 | }; |
||
784 | // TODO: hack: backend returns string instead of integer |
||
785 | shareTime = OC.Share._parseTime(shareTime); |
||
786 | if (_.isNumber(shareTime)) { |
||
787 | shareTime = new Date(shareTime * 1000); |
||
788 | } |
||
789 | if (!shareTime) { |
||
790 | shareTime = now; |
||
791 | } |
||
792 | $('#expirationCheckbox').attr('checked', true); |
||
793 | $('#expirationDate').val(date); |
||
794 | $('#expirationDate').slideDown(OC.menuSpeed); |
||
795 | $('#expirationDate').css('display','block'); |
||
796 | $('#expirationDate').datepicker({ |
||
797 | dateFormat : 'dd-mm-yy' |
||
798 | }); |
||
799 | if (oc_appconfig.core.defaultExpireDateEnforced) { |
||
800 | $('#expirationCheckbox').attr('disabled', true); |
||
801 | shareTime = OC.Util.stripTime(shareTime).getTime(); |
||
802 | // max date is share date + X days |
||
803 | datePickerOptions.maxDate = new Date(shareTime + oc_appconfig.core.defaultExpireDate * 24 * 3600 * 1000); |
||
804 | } |
||
805 | if(oc_appconfig.core.defaultExpireDateEnabled) { |
||
806 | $('#defaultExpireMessage').slideDown(OC.menuSpeed); |
||
807 | } |
||
808 | $.datepicker.setDefaults(datePickerOptions); |
||
809 | }, |
||
810 | /** |
||
811 | * Get the default Expire date |
||
812 | * |
||
813 | * @return {String} The expire date |
||
814 | */ |
||
815 | getDefaultExpirationDate:function() { |
||
816 | var expireDateString = ''; |
||
817 | if (oc_appconfig.core.defaultExpireDateEnabled) { |
||
818 | var date = new Date().getTime(); |
||
819 | var expireAfterMs = oc_appconfig.core.defaultExpireDate * 24 * 60 * 60 * 1000; |
||
820 | var expireDate = new Date(date + expireAfterMs); |
||
821 | var month = expireDate.getMonth() + 1; |
||
822 | var year = expireDate.getFullYear(); |
||
823 | var day = expireDate.getDate(); |
||
824 | expireDateString = year + "-" + month + '-' + day + ' 00:00:00'; |
||
825 | } |
||
826 | return expireDateString; |
||
827 | } |
||
828 | }); |
||
829 | |||
830 | $(document).ready(function() { |
||
831 | |||
832 | if(typeof monthNames != 'undefined'){ |
||
833 | // min date should always be the next day |
||
834 | var minDate = new Date(); |
||
835 | minDate.setDate(minDate.getDate()+1); |
||
836 | $.datepicker.setDefaults({ |
||
837 | monthNames: monthNames, |
||
838 | monthNamesShort: $.map(monthNames, function(v) { return v.slice(0,3)+'.'; }), |
||
839 | dayNames: dayNames, |
||
840 | dayNamesMin: $.map(dayNames, function(v) { return v.slice(0,2); }), |
||
841 | dayNamesShort: $.map(dayNames, function(v) { return v.slice(0,3)+'.'; }), |
||
842 | firstDay: firstDay, |
||
843 | minDate : minDate |
||
844 | }); |
||
845 | } |
||
846 | $(document).on('click', 'a.share', function(event) { |
||
847 | event.stopPropagation(); |
||
848 | if ($(this).data('item-type') !== undefined && $(this).data('item') !== undefined) { |
||
849 | var itemType = $(this).data('item-type'); |
||
850 | var itemSource = $(this).data('item'); |
||
851 | var appendTo = $(this).parent().parent(); |
||
852 | var link = false; |
||
853 | var possiblePermissions = $(this).data('possible-permissions'); |
||
854 | if ($(this).data('link') !== undefined && $(this).data('link') == true) { |
||
0 ignored issues
–
show
It is recommended to use
=== to compare with true .
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator. ![]() |
|||
855 | link = true; |
||
856 | } |
||
857 | if (OC.Share.droppedDown) { |
||
858 | if (itemSource != $('#dropdown').data('item')) { |
||
859 | OC.Share.hideDropDown(function () { |
||
860 | OC.Share.showDropDown(itemType, itemSource, appendTo, link, possiblePermissions); |
||
861 | }); |
||
862 | } else { |
||
863 | OC.Share.hideDropDown(); |
||
864 | } |
||
865 | } else { |
||
866 | OC.Share.showDropDown(itemType, itemSource, appendTo, link, possiblePermissions); |
||
867 | } |
||
868 | } |
||
869 | }); |
||
870 | |||
871 | $(this).click(function(event) { |
||
872 | var target = $(event.target); |
||
873 | var isMatched = !target.is('.drop, .ui-datepicker-next, .ui-datepicker-prev, .ui-icon') |
||
874 | && !target.closest('#ui-datepicker-div').length && !target.closest('.ui-autocomplete').length; |
||
0 ignored issues
–
show
|
|||
875 | if (OC.Share.droppedDown && isMatched && $('#dropdown').has(event.target).length === 0) { |
||
876 | OC.Share.hideDropDown(); |
||
877 | } |
||
878 | }); |
||
879 | |||
880 | $(document).on('click', '#dropdown .showCruds', function() { |
||
881 | $(this).closest('li').find('.cruds').toggle(); |
||
882 | return false; |
||
883 | }); |
||
884 | |||
885 | $(document).on('click', '#dropdown .unshare', function() { |
||
886 | var $li = $(this).closest('li'); |
||
887 | var itemType = $('#dropdown').data('item-type'); |
||
888 | var itemSource = $('#dropdown').data('item-source'); |
||
889 | var shareType = $li.data('share-type'); |
||
890 | var shareWith = $li.attr('data-share-with'); |
||
891 | var $button = $(this); |
||
892 | |||
893 | if (!$button.is('a')) { |
||
894 | $button = $button.closest('a'); |
||
895 | } |
||
896 | |||
897 | if ($button.hasClass('icon-loading-small')) { |
||
898 | // deletion in progress |
||
899 | return false; |
||
900 | } |
||
901 | $button.empty().addClass('icon-loading-small'); |
||
902 | |||
903 | OC.Share.unshare(itemType, itemSource, shareType, shareWith, function() { |
||
904 | $li.remove(); |
||
905 | var index = OC.Share.itemShares[shareType].indexOf(shareWith); |
||
906 | OC.Share.itemShares[shareType].splice(index, 1); |
||
907 | // updated list of shares |
||
908 | OC.Share.currentShares[shareType].splice(index, 1); |
||
909 | $('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares})); |
||
910 | OC.Share.updateIcon(itemType, itemSource); |
||
911 | if (typeof OC.Share.statuses[itemSource] === 'undefined') { |
||
912 | $('#expiration').slideUp(OC.menuSpeed); |
||
913 | } |
||
914 | }); |
||
915 | |||
916 | return false; |
||
917 | }); |
||
918 | |||
919 | $(document).on('change', '#dropdown .permissions', function() { |
||
920 | var li = $(this).closest('li'); |
||
921 | if ($(this).attr('name') == 'edit') { |
||
922 | var checkboxes = $('.permissions', li); |
||
923 | var checked = $(this).is(':checked'); |
||
924 | // Check/uncheck Create, Update, and Delete checkboxes if Edit is checked/unck |
||
925 | $(checkboxes).filter('input[name="create"]').attr('checked', checked); |
||
926 | $(checkboxes).filter('input[name="update"]').attr('checked', checked); |
||
927 | $(checkboxes).filter('input[name="delete"]').attr('checked', checked); |
||
928 | } else { |
||
929 | var checkboxes = $('.permissions', li); |
||
930 | // Uncheck Edit if Create, Update, and Delete are not checked |
||
931 | if (!$(this).is(':checked') |
||
932 | && !$(checkboxes).filter('input[name="create"]').is(':checked') |
||
0 ignored issues
–
show
|
|||
933 | && !$(checkboxes).filter('input[name="update"]').is(':checked') |
||
0 ignored issues
–
show
|
|||
934 | && !$(checkboxes).filter('input[name="delete"]').is(':checked')) |
||
0 ignored issues
–
show
|
|||
935 | { |
||
936 | $(checkboxes).filter('input[name="edit"]').attr('checked', false); |
||
937 | // Check Edit if Create, Update, or Delete is checked |
||
938 | } else if (($(this).attr('name') == 'create' |
||
939 | || $(this).attr('name') == 'update' |
||
0 ignored issues
–
show
|
|||
940 | || $(this).attr('name') == 'delete')) |
||
0 ignored issues
–
show
|
|||
941 | { |
||
942 | $(checkboxes).filter('input[name="edit"]').attr('checked', true); |
||
943 | } |
||
944 | } |
||
945 | var permissions = OC.PERMISSION_READ; |
||
946 | $(checkboxes).filter(':not(input[name="edit"])').filter(':checked').each(function(index, checkbox) { |
||
947 | permissions |= $(checkbox).data('permissions'); |
||
948 | }); |
||
949 | OC.Share.setPermissions($('#dropdown').data('item-type'), |
||
950 | $('#dropdown').data('item-source'), |
||
951 | li.data('share-type'), |
||
952 | li.attr('data-share-with'), |
||
953 | permissions); |
||
954 | }); |
||
955 | |||
956 | $(document).on('change', '#dropdown #linkCheckbox', function() { |
||
957 | var $dropDown = $('#dropdown'); |
||
958 | var itemType = $dropDown.data('item-type'); |
||
959 | var itemSource = $dropDown.data('item-source'); |
||
960 | var itemSourceName = $dropDown.data('item-source-name'); |
||
961 | var $loading = $dropDown.find('#link .icon-loading-small'); |
||
962 | var $button = $(this); |
||
963 | |||
964 | if (!$loading.hasClass('hidden')) { |
||
965 | // already in progress |
||
966 | return false; |
||
967 | } |
||
968 | |||
969 | if (this.checked) { |
||
970 | // Reset password placeholder |
||
971 | $('#linkPassText').attr('placeholder', t('core', 'Choose a password for the public link')); |
||
972 | // Reset link |
||
973 | $('#linkText').val(''); |
||
974 | $('#showPassword').prop('checked', false); |
||
975 | $('#linkPass').hide(); |
||
976 | $('#sharingDialogAllowPublicUpload').prop('checked', false); |
||
977 | $('#expirationCheckbox').prop('checked', false); |
||
978 | $('#expirationDate').hide(); |
||
979 | var expireDateString = ''; |
||
980 | // Create a link |
||
981 | if (oc_appconfig.core.enforcePasswordForPublicLink === false) { |
||
982 | expireDateString = OC.Share.getDefaultExpirationDate(); |
||
983 | $loading.removeClass('hidden'); |
||
984 | $button.addClass('hidden'); |
||
985 | $button.prop('disabled', true); |
||
986 | |||
987 | OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', OC.PERMISSION_READ, itemSourceName, expireDateString, function(data) { |
||
988 | $loading.addClass('hidden'); |
||
989 | $button.removeClass('hidden'); |
||
990 | $button.prop('disabled', false); |
||
991 | OC.Share.showLink(data.token, null, itemSource); |
||
992 | $('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares})); |
||
993 | OC.Share.updateIcon(itemType, itemSource); |
||
994 | }); |
||
995 | } else { |
||
996 | $('#linkPass').slideToggle(OC.menuSpeed); |
||
997 | // TODO drop with IE8 drop |
||
998 | if($('html').hasClass('ie8')) { |
||
999 | $('#linkPassText').attr('placeholder', null); |
||
1000 | $('#linkPassText').val(''); |
||
1001 | } |
||
1002 | $('#linkPassText').focus(); |
||
1003 | } |
||
1004 | if (expireDateString !== '') { |
||
1005 | OC.Share.showExpirationDate(expireDateString); |
||
1006 | } |
||
1007 | } else { |
||
1008 | // Delete private link |
||
1009 | OC.Share.hideLink(); |
||
1010 | $('#expiration').slideUp(OC.menuSpeed); |
||
1011 | if ($('#linkText').val() !== '') { |
||
1012 | $loading.removeClass('hidden'); |
||
1013 | $button.addClass('hidden'); |
||
1014 | $button.prop('disabled', true); |
||
1015 | OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() { |
||
1016 | $loading.addClass('hidden'); |
||
1017 | $button.removeClass('hidden'); |
||
1018 | $button.prop('disabled', false); |
||
1019 | OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = false; |
||
1020 | $('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares})); |
||
1021 | OC.Share.updateIcon(itemType, itemSource); |
||
1022 | if (typeof OC.Share.statuses[itemSource] === 'undefined') { |
||
1023 | $('#expiration').slideUp(OC.menuSpeed); |
||
1024 | } |
||
1025 | }); |
||
1026 | } |
||
1027 | } |
||
1028 | }); |
||
1029 | |||
1030 | $(document).on('click', '#dropdown #linkText', function() { |
||
1031 | $(this).focus(); |
||
1032 | $(this).select(); |
||
1033 | }); |
||
1034 | |||
1035 | // Handle the Allow Public Upload Checkbox |
||
1036 | $(document).on('click', '#sharingDialogAllowPublicUpload', function() { |
||
1037 | |||
1038 | // Gather data |
||
1039 | var $dropDown = $('#dropdown'); |
||
1040 | var allowPublicUpload = $(this).is(':checked'); |
||
1041 | var itemType = $dropDown.data('item-type'); |
||
1042 | var itemSource = $dropDown.data('item-source'); |
||
1043 | var itemSourceName = $dropDown.data('item-source-name'); |
||
1044 | var expirationDate = ''; |
||
1045 | if ($('#expirationCheckbox').is(':checked') === true) { |
||
1046 | expirationDate = $( "#expirationDate" ).val(); |
||
1047 | } |
||
1048 | var permissions = 0; |
||
1049 | var $button = $(this); |
||
1050 | var $loading = $dropDown.find('#allowPublicUploadWrapper .icon-loading-small'); |
||
1051 | |||
1052 | if (!$loading.hasClass('hidden')) { |
||
1053 | // already in progress |
||
1054 | return false; |
||
1055 | } |
||
1056 | |||
1057 | // Calculate permissions |
||
1058 | if (allowPublicUpload) { |
||
1059 | permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ; |
||
1060 | } else { |
||
1061 | permissions = OC.PERMISSION_READ; |
||
1062 | } |
||
1063 | |||
1064 | // Update the share information |
||
1065 | $button.addClass('hidden'); |
||
1066 | $button.prop('disabled', true); |
||
1067 | $loading.removeClass('hidden'); |
||
1068 | OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', permissions, itemSourceName, expirationDate, function(data) { |
||
1069 | $loading.addClass('hidden'); |
||
1070 | $button.removeClass('hidden'); |
||
1071 | $button.prop('disabled', false); |
||
1072 | }); |
||
1073 | }); |
||
1074 | |||
1075 | $(document).on('click', '#dropdown #showPassword', function() { |
||
1076 | $('#linkPass').slideToggle(OC.menuSpeed); |
||
1077 | if (!$('#showPassword').is(':checked') ) { |
||
1078 | var itemType = $('#dropdown').data('item-type'); |
||
1079 | var itemSource = $('#dropdown').data('item-source'); |
||
1080 | var itemSourceName = $('#dropdown').data('item-source-name'); |
||
1081 | var allowPublicUpload = $('#sharingDialogAllowPublicUpload').is(':checked'); |
||
1082 | var permissions = 0; |
||
1083 | var $loading = $('#showPassword .icon-loading-small'); |
||
1084 | |||
1085 | // Calculate permissions |
||
1086 | if (allowPublicUpload) { |
||
1087 | permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ; |
||
1088 | } else { |
||
1089 | permissions = OC.PERMISSION_READ; |
||
1090 | } |
||
1091 | |||
1092 | $loading.removeClass('hidden'); |
||
1093 | OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', permissions, itemSourceName).then(function() { |
||
1094 | $loading.addClass('hidden'); |
||
1095 | $('#linkPassText').attr('placeholder', t('core', 'Choose a password for the public link')); |
||
1096 | }); |
||
1097 | } else { |
||
1098 | $('#linkPassText').focus(); |
||
1099 | } |
||
1100 | }); |
||
1101 | |||
1102 | $(document).on('focusout keyup', '#dropdown #linkPassText', function(event) { |
||
1103 | var linkPassText = $('#linkPassText'); |
||
1104 | if ( linkPassText.val() != '' && (event.type == 'focusout' || event.keyCode == 13) ) { |
||
0 ignored issues
–
show
It is recommended to use
!== to compare with .
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator. ![]() |
|||
1105 | var allowPublicUpload = $('#sharingDialogAllowPublicUpload').is(':checked'); |
||
1106 | var dropDown = $('#dropdown'); |
||
1107 | var itemType = dropDown.data('item-type'); |
||
1108 | var itemSource = dropDown.data('item-source'); |
||
1109 | var itemSourceName = $('#dropdown').data('item-source-name'); |
||
1110 | var permissions = 0; |
||
1111 | var $loading = dropDown.find('#linkPass .icon-loading-small'); |
||
1112 | |||
1113 | // Calculate permissions |
||
1114 | if (allowPublicUpload) { |
||
1115 | permissions = OC.PERMISSION_UPDATE + OC.PERMISSION_CREATE + OC.PERMISSION_READ; |
||
1116 | } else { |
||
1117 | permissions = OC.PERMISSION_READ; |
||
1118 | } |
||
1119 | |||
1120 | var expireDateString = OC.Share.getDefaultExpirationDate(); |
||
1121 | |||
1122 | $loading.removeClass('hidden'); |
||
1123 | OC.Share.share(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, $('#linkPassText').val(), permissions, itemSourceName, expireDateString, function(data) { |
||
1124 | $loading.addClass('hidden'); |
||
1125 | linkPassText.val(''); |
||
1126 | linkPassText.attr('placeholder', t('core', 'Password protected')); |
||
1127 | |||
1128 | if (oc_appconfig.core.enforcePasswordForPublicLink) { |
||
1129 | OC.Share.showLink(data.token, "password set", itemSource); |
||
1130 | OC.Share.updateIcon(itemType, itemSource); |
||
1131 | } |
||
1132 | $('#dropdown').trigger(new $.Event('sharesChanged', {shares: OC.Share.currentShares})); |
||
1133 | }, function(result) { |
||
1134 | $loading.addClass('hidden'); |
||
1135 | linkPassText.val(''); |
||
1136 | linkPassText.attr('placeholder', result.data.message); |
||
1137 | }); |
||
1138 | |||
1139 | if (expireDateString !== '') { |
||
1140 | OC.Share.showExpirationDate(expireDateString); |
||
1141 | } |
||
1142 | } |
||
1143 | }); |
||
1144 | |||
1145 | $(document).on('click', '#dropdown #expirationCheckbox', function() { |
||
1146 | if (this.checked) { |
||
1147 | OC.Share.showExpirationDate(''); |
||
1148 | } else { |
||
1149 | var itemType = $('#dropdown').data('item-type'); |
||
1150 | var itemSource = $('#dropdown').data('item-source'); |
||
1151 | $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: '' }, function(result) { |
||
1152 | if (!result || result.status !== 'success') { |
||
1153 | OC.dialogs.alert(t('core', 'Error unsetting expiration date'), t('core', 'Error')); |
||
1154 | } |
||
1155 | $('#expirationDate').slideUp(OC.menuSpeed); |
||
1156 | if (oc_appconfig.core.defaultExpireDateEnforced === false) { |
||
1157 | $('#defaultExpireMessage').slideDown(OC.menuSpeed); |
||
1158 | } |
||
1159 | }); |
||
1160 | } |
||
1161 | }); |
||
1162 | |||
1163 | $(document).on('change', '#dropdown #expirationDate', function() { |
||
1164 | var itemType = $('#dropdown').data('item-type'); |
||
1165 | var itemSource = $('#dropdown').data('item-source'); |
||
1166 | |||
1167 | $(this).tipsy('hide'); |
||
1168 | $(this).removeClass('error'); |
||
1169 | |||
1170 | $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'setExpirationDate', itemType: itemType, itemSource: itemSource, date: $(this).val() }, function(result) { |
||
1171 | if (!result || result.status !== 'success') { |
||
1172 | var expirationDateField = $('#dropdown #expirationDate'); |
||
1173 | if (!result.data.message) { |
||
1174 | expirationDateField.attr('original-title', t('core', 'Error setting expiration date')); |
||
1175 | } else { |
||
1176 | expirationDateField.attr('original-title', result.data.message); |
||
1177 | } |
||
1178 | expirationDateField.tipsy({gravity: 'n'}); |
||
1179 | expirationDateField.tipsy('show'); |
||
1180 | expirationDateField.addClass('error'); |
||
1181 | } else { |
||
1182 | if (oc_appconfig.core.defaultExpireDateEnforced === 'no') { |
||
1183 | $('#defaultExpireMessage').slideUp(OC.menuSpeed); |
||
1184 | } |
||
1185 | } |
||
1186 | }); |
||
1187 | }); |
||
1188 | |||
1189 | |||
1190 | $(document).on('submit', '#dropdown #emailPrivateLink', function(event) { |
||
1191 | event.preventDefault(); |
||
1192 | var link = $('#linkText').val(); |
||
1193 | var itemType = $('#dropdown').data('item-type'); |
||
1194 | var itemSource = $('#dropdown').data('item-source'); |
||
1195 | var file = $('tr').filterAttr('data-id', String(itemSource)).data('file'); |
||
1196 | var email = $('#email').val(); |
||
1197 | var expirationDate = ''; |
||
1198 | if ( $('#expirationCheckbox').is(':checked') === true ) { |
||
1199 | expirationDate = $( "#expirationDate" ).val(); |
||
1200 | } |
||
1201 | if (email != '') { |
||
0 ignored issues
–
show
It is recommended to use
!== to compare with .
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator. ![]() |
|||
1202 | $('#email').prop('disabled', true); |
||
1203 | $('#email').val(t('core', 'Sending ...')); |
||
1204 | $('#emailButton').prop('disabled', true); |
||
1205 | |||
1206 | $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'email', toaddress: email, link: link, itemType: itemType, itemSource: itemSource, file: file, expiration: expirationDate}, |
||
1207 | function(result) { |
||
1208 | $('#email').prop('disabled', false); |
||
1209 | $('#emailButton').prop('disabled', false); |
||
1210 | if (result && result.status == 'success') { |
||
1211 | $('#email').css('font-weight', 'bold').val(t('core','Email sent')); |
||
1212 | setTimeout(function() { |
||
1213 | $('#email').css('font-weight', 'normal').val(''); |
||
1214 | }, 2000); |
||
1215 | } else { |
||
1216 | OC.dialogs.alert(result.data.message, t('core', 'Error while sharing')); |
||
1217 | } |
||
1218 | }); |
||
1219 | } |
||
1220 | }); |
||
1221 | |||
1222 | $(document).on('click', '#dropdown input[name=mailNotification]', function() { |
||
1223 | var $li = $(this).closest('li'); |
||
1224 | var itemType = $('#dropdown').data('item-type'); |
||
1225 | var itemSource = $('#dropdown').data('item-source'); |
||
1226 | var action = ''; |
||
1227 | if (this.checked) { |
||
1228 | action = 'informRecipients'; |
||
1229 | } else { |
||
1230 | action = 'informRecipientsDisabled'; |
||
1231 | } |
||
1232 | |||
1233 | var shareType = $li.data('share-type'); |
||
1234 | var shareWith = $li.attr('data-share-with'); |
||
1235 | |||
1236 | $.post(OC.filePath('core', 'ajax', 'share.php'), {action: action, recipient: shareWith, shareType: shareType, itemSource: itemSource, itemType: itemType}, function(result) { |
||
1237 | if (result.status !== 'success') { |
||
1238 | OC.dialogs.alert(t('core', result.data.message), t('core', 'Warning')); |
||
1239 | } |
||
1240 | }); |
||
1241 | |||
1242 | }); |
||
1243 | |||
1244 | }); |
||
1245 | |||
1246 | })(OC); |
||
1247 |
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.
Read more about comparison operations.