]> source.dussan.org Git - nextcloud-server.git/commitdiff
Prevent resharing in UI if share permission not granted
authorMichael Gapczynski <mtgap@owncloud.com>
Thu, 23 Aug 2012 18:48:35 +0000 (14:48 -0400)
committerMichael Gapczynski <mtgap@owncloud.com>
Fri, 24 Aug 2012 14:05:37 +0000 (10:05 -0400)
apps/files_sharing/js/share.js
core/js/share.js

index bcfd42ce21e821f583e64d343c5c0f39283229ff..12c1a3332c916f42feeeee705a4afd26cbf24637 100644 (file)
@@ -2,7 +2,7 @@ $(document).ready(function() {
 
        if (typeof FileActions !== 'undefined') {
                OC.Share.loadIcons('file');
-               FileActions.register('all', 'Share', FileActions.PERMISSION_SHARE, function(filename) {
+               FileActions.register('all', 'Share', FileActions.PERMISSION_READ, function(filename) {
                        // Return the correct sharing icon
                        if (scanFiles.scanning) { return; } // workaround to prevent additional http request block scanning feedback
                        if ($('#dir').val() == '/') {
@@ -36,13 +36,13 @@ $(document).ready(function() {
                        } else {
                                var item = $('#dir').val() + '/' + filename;
                        }
-                       if ($('tr').filterAttr('data-file', filename).data('type') == 'dir') {
+                       var tr = $('tr').filterAttr('data-file', filename);
+                       if ($(tr).data('type') == 'dir') {
                                var itemType = 'folder';
-                               var possiblePermissions = OC.Share.PERMISSION_CREATE | OC.Share.PERMISSION_UPDATE | OC.Share.PERMISSION_DELETE | OC.Share.PERMISSION_SHARE;
                        } else {
                                var itemType = 'file';
-                               var possiblePermissions = OC.Share.PERMISSION_UPDATE | OC.Share.PERMISSION_DELETE | OC.Share.PERMISSION_SHARE;
                        }
+                       var possiblePermissions = $(tr).data('permissions');
                        var appendTo = $('tr').filterAttr('data-file', filename).find('td.filename');
                        // Check if drop down is already visible for a different file
                        if (OC.Share.droppedDown) {
index e765303a267ded1b5bc2e548034e53c89cd64430..1c96cfa2232fb8ad10271230d557294bbd8cf135 100644 (file)
@@ -86,65 +86,71 @@ OC.Share={
                        }
                        html += '<br />';
                }
-               html += '<input id="shareWith" type="text" placeholder="Share with" style="width:90%;"/>';
-               html += '<ul id="shareWithList">';
-               html += '</ul>';
-               if (privateLink) {
-                       html += '<div id="privateLink">';
-                       html += '<input type="checkbox" name="privateLinkCheckbox" id="privateLinkCheckbox" value="1" /><label for="privateLinkCheckbox">Share with private link</label>';
-                       html += '<br />';
-                       html += '<input id="privateLinkText" style="display:none; width:90%;" readonly="readonly" />';
+               if (possiblePermissions & OC.Share.PERMISSION_SHARE) {
+                       html += '<input id="shareWith" type="text" placeholder="Share with" style="width:90%;"/>';
+                       html += '<ul id="shareWithList">';
+                       html += '</ul>';
+                       if (privateLink) {
+                               html += '<div id="privateLink">';
+                               html += '<input type="checkbox" name="privateLinkCheckbox" id="privateLinkCheckbox" value="1" /><label for="privateLinkCheckbox">Share with private link</label>';
+                               html += '<br />';
+                               html += '<input id="privateLinkText" style="display:none; width:90%;" readonly="readonly" />';
+                               html += '</div>';
+                       }
                        html += '</div>';
-               }
-               html += '</div>';
-               $(html).appendTo(appendTo);
-               // Reset item shares
-               OC.Share.itemShares = [];
-               if (data.shares) {
-                       $.each(data.shares, function(index, share) {
-                               if (share.share_type == OC.Share.SHARE_TYPE_PRIVATE_LINK) {
-                                       OC.Share.showPrivateLink(item, share.share_with);
-                               } else {
-                                       OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions);
-
-                               }
-                       });
-               }
-               $('#shareWith').autocomplete({minLength: 2, source: function(search, response) {
-//                     if (cache[search.term]) {
-//                             response(cache[search.term]);
-//                     } else {
-                               $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWith', search: search.term, itemShares: OC.Share.itemShares }, function(result) {
-                                       if (result.status == 'success' && result.data.length > 0) {
-                                               response(result.data);
+                       $(html).appendTo(appendTo);
+                       // Reset item shares
+                       OC.Share.itemShares = [];
+                       if (data.shares) {
+                               $.each(data.shares, function(index, share) {
+                                       if (share.share_type == OC.Share.SHARE_TYPE_PRIVATE_LINK) {
+                                               OC.Share.showPrivateLink(item, share.share_with);
                                        } else {
-                                               // Suggest sharing via email if valid email address
-                                               var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
-                                               if (pattern.test(search.term)) {
-                                                       response([{label: 'Share via email: '+search.term, value: {shareType: OC.Share.SHARE_TYPE_EMAIL, shareWith: search.term}}]);
+                                               OC.Share.addShareWith(share.share_type, share.share_with, share.permissions, possiblePermissions);
+                                               
+                                       }
+                               });
+                       }
+                       $('#shareWith').autocomplete({minLength: 2, source: function(search, response) {
+       //                      if (cache[search.term]) {
+       //                              response(cache[search.term]);
+       //                      } else {
+                                       $.get(OC.filePath('core', 'ajax', 'share.php'), { fetch: 'getShareWith', search: search.term, itemShares: OC.Share.itemShares }, function(result) {
+                                               if (result.status == 'success' && result.data.length > 0) {
+                                                       response(result.data);
                                                } else {
-                                                       response(['No people found']);
+                                                       // Suggest sharing via email if valid email address
+                                                       var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
+                                                       if (pattern.test(search.term)) {
+                                                               response([{label: 'Share via email: '+search.term, value: {shareType: OC.Share.SHARE_TYPE_EMAIL, shareWith: search.term}}]);
+                                                       } else {
+                                                               response(['No people found']);
+                                                       }
                                                }
-                                       }
+                                       });
+       //                      }
+                       },
+                       focus: function(event, focused) {
+                               event.preventDefault();
+                       },
+                       select: function(event, selected) {
+                               var shareType = selected.item.value.shareType;
+                               var shareWith = selected.item.value.shareWith;
+                               $(this).val(shareWith);
+                               // Default permissions are Read and Share
+                               var permissions = OC.Share.PERMISSION_READ | OC.Share.PERMISSION_SHARE;
+                               OC.Share.share($('#dropdown').data('item-type'), $('#dropdown').data('item-source'), shareType, shareWith, permissions, function() {
+                                       OC.Share.addShareWith(shareType, shareWith, permissions, possiblePermissions);
+                                       $('#shareWith').val('');
                                });
-//                     }
-               },
-               focus: function(event, focused) {
-                       event.preventDefault();
-               },
-               select: function(event, selected) {
-                       var shareType = selected.item.value.shareType;
-                       var shareWith = selected.item.value.shareWith;
-                       $(this).val(shareWith);
-                       // Default permissions are Read and Share
-                       var permissions = OC.Share.PERMISSION_READ | OC.Share.PERMISSION_SHARE;
-                       OC.Share.share($('#dropdown').data('item-type'), $('#dropdown').data('item-source'), shareType, shareWith, permissions, function() {
-                               OC.Share.addShareWith(shareType, shareWith, permissions, possiblePermissions);
-                               $('#shareWith').val('');
+                               return false;
+                       }
                        });
-                       return false;
+               } else {
+                       html += '<input id="shareWith" type="text" placeholder="Resharing is not allowed" style="width:90%;" disabled="disabled"/>';
+                       html += '</div>';
+                       $(html).appendTo(appendTo);
                }
-               });
                $('#dropdown').show('blind', function() {
                        OC.Share.droppedDown = true;
                });