]> source.dussan.org Git - nextcloud-server.git/commitdiff
add secure drop functionallity to mail shares
authorBjoern Schiessle <bjoern@schiessle.org>
Wed, 29 Mar 2017 09:58:04 +0000 (11:58 +0200)
committerBjoern Schiessle <bjoern@schiessle.org>
Mon, 3 Apr 2017 08:29:32 +0000 (10:29 +0200)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
core/js/sharedialogshareelistview.js
core/js/shareitemmodel.js
lib/private/Share20/Manager.php

index 6679078a4955b797789758e208c1fed6c0fcb056..2f701ace759c017779e19692536adacb6c3871b5 100644 (file)
                                        '</li>' +
                                        '{{/unless}}{{/if}}' +
                                '{{/if}}' +
+                               '{{#if isMailShare}}' +
+                                       '{{#if hasCreatePermission}}' +
+                                               '<li>' +
+                                                       '<span class="shareOption menuitem">' +
+                                                               '<input id="secureDrop-{{cid}}-{{shareId}}" type="checkbox" name="secureDrop" class="checkbox secureDrop" {{#if secureDropMode}}checked="checked"{{/if}} data-permissions="{{readPermission}}"/>' +
+                                                               '<label for="secureDrop-{{cid}}-{{shareId}}">{{secureDropLabel}}</label>' +
+                                                       '</span>' +
+                                               '</li>' +
+                                       '{{/if}}' +
+                               '{{/if}}' +
                                '<li>' +
                                        '<span class="shareOption menuitem">' +
-                                               '<input id="expireDate-{{cid}}-{{shareId}}" type="checkbox" name="expirationDate" class="expireDate checkbox" {{#if hasExpireDate}}checked="checked"{{/if}} data-permissions="{{expireDate}}" />' +
+                                               '<input id="expireDate-{{cid}}-{{shareId}}" type="checkbox" name="expirationDate" class="expireDate checkbox" {{#if hasExpireDate}}checked="checked"{{/if}}" />' +
                                                '<label for="expireDate-{{cid}}-{{shareId}}">{{expireDateLabel}}</label>' +
                                                '<div class="expirationDateContainer-{{cid}}-{{shareId}} {{#unless isExpirationSet}}hidden{{/unless}}">' +
                                                '    <label for="expirationDatePicker-{{cid}}-{{shareId}}" class="hidden-visually" value="{{expirationDate}}">{{expirationLabel}}</label>' +
                        'click .permissions': 'onPermissionChange',
                        'click .expireDate' : 'onExpireDateChange',
                        'click .password' : 'onMailSharePasswordProtectChange',
+                       'click .secureDrop' : 'onSecureDropChange',
                        'keyup input.passwordField': 'onMailSharePasswordKeyUp',
                        'focusout input.passwordField': 'onMailSharePasswordEntered'
                },
                                isCircleShare: shareType === OC.Share.SHARE_TYPE_CIRCLE,
                                isFileSharedByMail: shareType === OC.Share.SHARE_TYPE_EMAIL && !this.model.isFolder(),
                                isPasswordSet: hasPassword,
+                               secureDropMode: !this.model.hasReadPermission(shareIndex),
                                passwordPlaceholder: hasPassword ? PASSWORD_PLACEHOLDER : PASSWORD_PLACEHOLDER_MESSAGE,
                        });
                },
                                createPermissionLabel: t('core', 'can create'),
                                updatePermissionLabel: t('core', 'can change'),
                                deletePermissionLabel: t('core', 'can delete'),
+                               secureDropLabel: t('core', 'Secure drop (upload only)'),
                                expireDateLabel: t('core', 'set expiration data'),
                                passwordLabel: t('core', 'password protect'),
                                crudsLabel: t('core', 'access control'),
                                createPermission: OC.PERMISSION_CREATE,
                                updatePermission: OC.PERMISSION_UPDATE,
                                deletePermission: OC.PERMISSION_DELETE,
+                               readPermission: OC.PERMISSION_READ,
                                isFolder: this.model.isFolder()
                        };
                },
 
                        this._renderPermissionChange = shareId;
                },
+
+               onSecureDropChange: function(event) {
+                       event.preventDefault();
+                       event.stopPropagation();
+                       var $element = $(event.target);
+                       var $li = $element.closest('li[data-share-id]');
+                       var shareId = $li.data('share-id');
+
+                       var permissions = OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE;
+
+                       if ($element.is(':checked')) {
+                               var permissions = OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE;
+                       } else {
+                               var permissions = OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE | OC.PERMISSION_READ;
+                       }
+
+                       /** disable checkboxes during save operation to avoid race conditions **/
+                       $li.find('input[type=checkbox]').prop('disabled', true);
+                       var enableCb = function() {
+                               $li.find('input[type=checkbox]').prop('disabled', false);
+                       };
+                       var errorCb = function(elem, msg) {
+                               OC.dialogs.alert(msg, t('core', 'Error while sharing'));
+                               enableCb();
+                       };
+
+                       this.model.updateShare(shareId, {permissions: permissions}, {error: errorCb, success: enableCb});
+
+                       this._renderPermissionChange = shareId;
+               }
+
        });
 
        OC.Share.ShareDialogShareeListView = ShareDialogShareeListView;
index 87d0556b996a013e0511e73cce31e35072891063..8b0f71568c9e6d881637a5475946f6226ed7046e 100644 (file)
                        return this._shareHasPermission(shareIndex, OC.PERMISSION_DELETE);
                },
 
+               hasReadPermission: function(shareIndex) {
+                       return this._shareHasPermission(shareIndex, OC.PERMISSION_READ);
+               },
+
                /**
                 * @returns {boolean}
                 */
index 5eea40d3773397197442aa5c9b36ed9089cd8fc6..79429c44ffa8934347f7681a7f0ce661202f2a3e 100644 (file)
@@ -266,7 +266,9 @@ class Manager implements IManager {
 
                // Check that read permissions are always set
                // Link shares are allowed to have no read permissions to allow upload to hidden folders
-               if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK &&
+               $noReadPermissionRequired = $share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK
+                       || $share->getShareType() !== \OCP\Share::SHARE_TYPE_EMAIL;
+               if (!$noReadPermissionRequired &&
                        ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) {
                        throw new \InvalidArgumentException('Shares need at least read permissions');
                }