Skip to content

Commit

Permalink
Merge pull request #9237 from nextcloud/fix-ids-of-permission-checkbo…
Browse files Browse the repository at this point in the history
…xes-for-shares

Fix ids of permission checkboxes for shares
  • Loading branch information
MorrisJobke authored Apr 19, 2018
2 parents 7ca526f + f8e3b57 commit 4d71e12
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
24 changes: 11 additions & 13 deletions core/js/sharedialogshareelistview.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
'<span class="sharingOptionsGroup">' +
'{{#if editPermissionPossible}}' +
'<span class="shareOption">' +
'<input id="canEdit-{{cid}}-{{shareWith}}" type="checkbox" name="edit" class="permissions checkbox" />' +
'<label for="canEdit-{{cid}}-{{shareWith}}">{{canEditLabel}}</label>' +
'<input id="canEdit-{{cid}}-{{shareId}}" type="checkbox" name="edit" class="permissions checkbox" />' +
'<label for="canEdit-{{cid}}-{{shareId}}">{{canEditLabel}}</label>' +
'</span>' +
'{{/if}}' +
'<a href="#"><span class="icon icon-more"></span></a>' +
Expand All @@ -58,33 +58,33 @@
'{{#if isResharingAllowed}} {{#if sharePermissionPossible}} {{#unless isMailShare}}' +
'<li>' +
'<span class="shareOption menuitem">' +
'<input id="canShare-{{cid}}-{{shareWith}}" type="checkbox" name="share" class="permissions checkbox" {{#if hasSharePermission}}checked="checked"{{/if}} data-permissions="{{sharePermission}}" />' +
'<label for="canShare-{{cid}}-{{shareWith}}">{{canShareLabel}}</label>' +
'<input id="canShare-{{cid}}-{{shareId}}" type="checkbox" name="share" class="permissions checkbox" {{#if hasSharePermission}}checked="checked"{{/if}} data-permissions="{{sharePermission}}" />' +
'<label for="canShare-{{cid}}-{{shareId}}">{{canShareLabel}}</label>' +
'</span>' +
'</li>' +
'{{/unless}} {{/if}} {{/if}}' +
'{{#if isFolder}}' +
'{{#if createPermissionPossible}}{{#unless isMailShare}}' +
'<li>' +
'<span class="shareOption menuitem">' +
'<input id="canCreate-{{cid}}-{{shareWith}}" type="checkbox" name="create" class="permissions checkbox" {{#if hasCreatePermission}}checked="checked"{{/if}} data-permissions="{{createPermission}}"/>' +
'<label for="canCreate-{{cid}}-{{shareWith}}">{{createPermissionLabel}}</label>' +
'<input id="canCreate-{{cid}}-{{shareId}}" type="checkbox" name="create" class="permissions checkbox" {{#if hasCreatePermission}}checked="checked"{{/if}} data-permissions="{{createPermission}}"/>' +
'<label for="canCreate-{{cid}}-{{shareId}}">{{createPermissionLabel}}</label>' +
'</span>' +
'</li>' +
'{{/unless}}{{/if}}' +
'{{#if updatePermissionPossible}}{{#unless isMailShare}}' +
'<li>' +
'<span class="shareOption menuitem">' +
'<input id="canUpdate-{{cid}}-{{shareWith}}" type="checkbox" name="update" class="permissions checkbox" {{#if hasUpdatePermission}}checked="checked"{{/if}} data-permissions="{{updatePermission}}"/>' +
'<label for="canUpdate-{{cid}}-{{shareWith}}">{{updatePermissionLabel}}</label>' +
'<input id="canUpdate-{{cid}}-{{shareId}}" type="checkbox" name="update" class="permissions checkbox" {{#if hasUpdatePermission}}checked="checked"{{/if}} data-permissions="{{updatePermission}}"/>' +
'<label for="canUpdate-{{cid}}-{{shareId}}">{{updatePermissionLabel}}</label>' +
'</span>' +
'</li>' +
'{{/unless}}{{/if}}' +
'{{#if deletePermissionPossible}}{{#unless isMailShare}}' +
'<li>' +
'<span class="shareOption menuitem">' +
'<input id="canDelete-{{cid}}-{{shareWith}}" type="checkbox" name="delete" class="permissions checkbox" {{#if hasDeletePermission}}checked="checked"{{/if}} data-permissions="{{deletePermission}}"/>' +
'<label for="canDelete-{{cid}}-{{shareWith}}">{{deletePermissionLabel}}</label>' +
'<input id="canDelete-{{cid}}-{{shareId}}" type="checkbox" name="delete" class="permissions checkbox" {{#if hasDeletePermission}}checked="checked"{{/if}} data-permissions="{{deletePermission}}"/>' +
'<label for="canDelete-{{cid}}-{{shareId}}">{{deletePermissionLabel}}</label>' +
'</span>' +
'</li>' +
'{{/unless}}{{/if}}' +
Expand Down Expand Up @@ -383,9 +383,7 @@

var _this = this;
this.getShareeList().forEach(function(sharee) {
var checkBoxId = 'canEdit-' + _this.cid + '-' + sharee.shareWith;
checkBoxId = '#' + checkBoxId.replace( /(:|\.|\[|\]|,|=|@|\/)/g, "\\$1");
var $edit = _this.$(checkBoxId);
var $edit = _this.$('#canEdit-' + _this.cid + '-' + sharee.shareId);
if($edit.length === 1) {
$edit.prop('checked', sharee.editPermissionState === 'checked');
$edit.prop('indeterminate', sharee.editPermissionState === 'indeterminate');
Expand Down
30 changes: 30 additions & 0 deletions core/js/tests/specs/sharedialogshareelistview.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ describe('OC.Share.ShareDialogShareeListView', function () {
expect(listView.$el.find("input[name='edit']").is(':indeterminate')).toEqual(true);
});

it('marks edit box as indeterminate when only some permissions are given for sharee with special characters', function () {
shareModel.set('shares', [{
id: 100,
item_source: 123,
permissions: 1 | OC.PERMISSION_UPDATE,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user _.@-\'',
share_with_displayname: 'User One',
itemType: 'folder'
}]);
shareModel.set('itemType', 'folder');
listView.render();
expect(listView.$el.find("input[name='edit']").is(':indeterminate')).toEqual(true);
});

it('Checks edit box when all permissions are given', function () {
shareModel.set('shares', [{
id: 100,
Expand All @@ -119,6 +134,21 @@ describe('OC.Share.ShareDialogShareeListView', function () {
listView.render();
expect(listView.$el.find("input[name='edit']").is(':checked')).toEqual(true);
});

it('Checks edit box when all permissions are given for sharee with special characters', function () {
shareModel.set('shares', [{
id: 100,
item_source: 123,
permissions: 1 | OC.PERMISSION_CREATE | OC.PERMISSION_UPDATE | OC.PERMISSION_DELETE,
share_type: OC.Share.SHARE_TYPE_USER,
share_with: 'user _.@-\'',
share_with_displayname: 'User One',
itemType: 'folder'
}]);
shareModel.set('itemType', 'folder');
listView.render();
expect(listView.$el.find("input[name='edit']").is(':checked')).toEqual(true);
});
});
describe('Manages checkbox events correctly', function () {
it('Checks cruds boxes when edit box checked', function () {
Expand Down

0 comments on commit 4d71e12

Please sign in to comment.