Merge pull request #11201 from nextcloud/backport/11036/stable14

[stable14]  fix check for more users in sharing dialogue
This commit is contained in:
Joas Schilling 2018-09-13 11:21:08 +02:00 committed by GitHub
commit 5bf377463e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 224 additions and 71 deletions

View File

@ -326,7 +326,23 @@
var suggestions = exactMatches.concat(users).concat(groups).concat(remotes).concat(remoteGroups).concat(emails).concat(circles).concat(rooms).concat(lookup); var suggestions = exactMatches.concat(users).concat(groups).concat(remotes).concat(remoteGroups).concat(emails).concat(circles).concat(rooms).concat(lookup);
deferred.resolve(suggestions, exactMatches); var moreResultsAvailable =
(
oc_config['sharing.maxAutocompleteResults'] > 0
&& Math.min(perPage, oc_config['sharing.maxAutocompleteResults'])
<= Math.max(
users.length + exactUsers.length,
groups.length + exactGroups.length,
remoteGroups.length + exactRemoteGroups.length,
remotes.length + exactRemotes.length,
emails.length + exactEmails.length,
circles.length + exactCircles.length,
rooms.length + exactRooms.length,
lookup.length
)
);
deferred.resolve(suggestions, exactMatches, moreResultsAvailable);
} else { } else {
deferred.reject(result.ocs.meta.message); deferred.reject(result.ocs.meta.message);
} }
@ -380,12 +396,12 @@
$shareWithField.removeClass('error') $shareWithField.removeClass('error')
.tooltip('hide'); .tooltip('hide');
var perPage = 200; var perPage = parseInt(oc_config['sharing.maxAutocompleteResults'], 10) || 200;
this._getSuggestions( this._getSuggestions(
search.term.trim(), search.term.trim(),
perPage, perPage,
view.model view.model
).done(function(suggestions) { ).done(function(suggestions, exactMatches, moreResultsAvailable) {
view._pendingOperationsCount--; view._pendingOperationsCount--;
if (view._pendingOperationsCount === 0) { if (view._pendingOperationsCount === 0) {
$loading.addClass('hidden'); $loading.addClass('hidden');
@ -401,10 +417,7 @@
// show a notice that the list is truncated // show a notice that the list is truncated
// this is the case if one of the search results is at least as long as the max result config option // this is the case if one of the search results is at least as long as the max result config option
if(oc_config['sharing.maxAutocompleteResults'] > 0 && if(moreResultsAvailable) {
Math.min(perPage, oc_config['sharing.maxAutocompleteResults'])
<= Math.max(users.length, groups.length, remotes.length, emails.length, lookup.length)) {
var message = t('core', 'This list is maybe truncated - please refine your search term to see more results.'); var message = t('core', 'This list is maybe truncated - please refine your search term to see more results.');
$('.ui-autocomplete').append('<li class="autocomplete-note">' + message + '</li>'); $('.ui-autocomplete').append('<li class="autocomplete-note">' + message + '</li>');
} }
@ -557,7 +570,7 @@
$shareWithField.focus(); $shareWithField.focus();
}; };
var perPage = 200; var perPage = parseInt(oc_config['sharing.maxAutocompleteResults'], 10) || 200;
var onlyExactMatches = true; var onlyExactMatches = true;
this._getSuggestions( this._getSuggestions(
$shareWithField.val(), $shareWithField.val(),

View File

@ -22,6 +22,7 @@
/* global oc_appconfig, sinon */ /* global oc_appconfig, sinon */
describe('OC.Share.ShareDialogView', function() { describe('OC.Share.ShareDialogView', function() {
var $container; var $container;
var oldConfig;
var oldAppConfig; var oldAppConfig;
var autocompleteStub; var autocompleteStub;
var avatarStub; var avatarStub;
@ -40,6 +41,9 @@ describe('OC.Share.ShareDialogView', function() {
// horrible parameters // horrible parameters
$('#testArea').append('<input id="allowShareWithLink" type="hidden" value="yes">'); $('#testArea').append('<input id="allowShareWithLink" type="hidden" value="yes">');
$container = $('#shareContainer'); $container = $('#shareContainer');
oldConfig = window.oc_config;
window.oc_config = window.oc_config || {};
window.oc_config['sharing.maxAutocompleteResults'] = 0;
/* jshint camelcase:false */ /* jshint camelcase:false */
oldAppConfig = _.extend({}, oc_appconfig.core); oldAppConfig = _.extend({}, oc_appconfig.core);
oc_appconfig.core.enforcePasswordForPublicLink = false; oc_appconfig.core.enforcePasswordForPublicLink = false;
@ -108,6 +112,7 @@ describe('OC.Share.ShareDialogView', function() {
}); });
afterEach(function() { afterEach(function() {
OC.currentUser = oldCurrentUser; OC.currentUser = oldCurrentUser;
window.oc_config = oldConfig;
/* jshint camelcase:false */ /* jshint camelcase:false */
oc_appconfig.core = oldAppConfig; oc_appconfig.core = oldAppConfig;
@ -357,9 +362,10 @@ describe('OC.Share.ShareDialogView', function() {
); );
expect(doneStub.calledOnce).toEqual(true); expect(doneStub.calledOnce).toEqual(true);
expect(doneStub.calledWithExactly([], [])).toEqual(true); expect(doneStub.calledWithExactly([], [], false)).toEqual(true);
expect(failStub.called).toEqual(false); expect(failStub.called).toEqual(false);
}); });
it('single partial match', function() { it('single partial match', function() {
var doneStub = sinon.stub(); var doneStub = sinon.stub();
var failStub = sinon.stub(); var failStub = sinon.stub();
@ -407,11 +413,14 @@ describe('OC.Share.ShareDialogView', function() {
); );
expect(doneStub.calledOnce).toEqual(true); expect(doneStub.calledOnce).toEqual(true);
expect(doneStub.calledWithExactly([{ expect(doneStub.calledWithExactly(
'label': 'bobby', [{
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'} 'label': 'bobby',
}], [ 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
])).toEqual(true); }],
[],
false
)).toEqual(true);
expect(failStub.called).toEqual(false); expect(failStub.called).toEqual(false);
}); });
it('single exact match', function() { it('single exact match', function() {
@ -461,13 +470,17 @@ describe('OC.Share.ShareDialogView', function() {
); );
expect(doneStub.calledOnce).toEqual(true); expect(doneStub.calledOnce).toEqual(true);
expect(doneStub.calledWithExactly([{ expect(doneStub.calledWithExactly(
'label': 'bob', [{
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'} 'label': 'bob',
}], [{ 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
'label': 'bob', }],
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'} [{
}])).toEqual(true); 'label': 'bob',
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
}],
false
)).toEqual(true);
expect(failStub.called).toEqual(false); expect(failStub.called).toEqual(false);
}); });
it('mixed matches', function() { it('mixed matches', function() {
@ -548,28 +561,140 @@ describe('OC.Share.ShareDialogView', function() {
); );
expect(doneStub.calledOnce).toEqual(true); expect(doneStub.calledOnce).toEqual(true);
expect(doneStub.calledWithExactly([{ expect(doneStub.calledWithExactly(
'label': 'bob', [{
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'} 'label': 'bob',
}, { 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
'label': 'bob', }, {
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group1'} 'label': 'bob',
}, { 'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group1'}
'label': 'bobby', }, {
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'} 'label': 'bobby',
}, { 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
'label': 'bob the second', }, {
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user2'} 'label': 'bob the second',
}, { 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user2'}
'label': 'bobfans', }, {
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'fans'} 'label': 'bobfans',
}], [{ 'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'fans'}
'label': 'bob', }],
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'} [{
}, { 'label': 'bob',
'label': 'bob', 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group1'} }, {
}])).toEqual(true); 'label': 'bob',
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group1'}
}],
false
)).toEqual(true);
expect(failStub.called).toEqual(false);
});
it('capped mixed matches', function() {
window.oc_config['sharing.maxAutocompleteResults'] = 3;
var doneStub = sinon.stub();
var failStub = sinon.stub();
dialog._getSuggestions('bob', 42, shareModel).done(doneStub).fail(failStub);
var jsonData = JSON.stringify({
'ocs': {
'meta': {
'status': 'success',
'statuscode': 100,
'message': null
},
'data': {
'exact': {
'users': [
{
'label': 'bob',
'value': {
'shareType': OC.Share.SHARE_TYPE_USER,
'shareWith': 'user1'
}
}
],
'groups': [
{
'label': 'bob',
'value': {
'shareType': OC.Share.SHARE_TYPE_GROUP,
'shareWith': 'group1'
}
}
],
'remotes': [],
'remote_groups': [],
},
'users': [
{
'label': 'bobby',
'value': {
'shareType': OC.Share.SHARE_TYPE_USER,
'shareWith': 'imbob'
}
},
{
'label': 'bob the second',
'value': {
'shareType': OC.Share.SHARE_TYPE_USER,
'shareWith': 'user2'
}
}
],
'groups': [
{
'label': 'bobfans',
'value': {
'shareType': OC.Share.SHARE_TYPE_GROUP,
'shareWith': 'fans'
}
}
],
'remotes': [],
'remote_groups': [],
'lookup': []
}
}
});
expect(doneStub.called).toEqual(false);
expect(failStub.called).toEqual(false);
fakeServer.requests[0].respond(
200,
{'Content-Type': 'application/json'},
jsonData
);
expect(doneStub.calledOnce).toEqual(true);
expect(doneStub.calledWithExactly(
[{
'label': 'bob',
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
}, {
'label': 'bob',
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group1'}
}, {
'label': 'bobby',
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
}, {
'label': 'bob the second',
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user2'}
}, {
'label': 'bobfans',
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'fans'}
}],
[{
'label': 'bob',
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
}, {
'label': 'bob',
'value': {'shareType': OC.Share.SHARE_TYPE_GROUP, 'shareWith': 'group1'}
}],
true
)).toEqual(true);
expect(failStub.called).toEqual(false); expect(failStub.called).toEqual(false);
}); });
@ -620,13 +745,16 @@ describe('OC.Share.ShareDialogView', function() {
); );
expect(doneStub.calledOnce).toEqual(true); expect(doneStub.calledOnce).toEqual(true);
expect(doneStub.calledWithExactly([{ expect(doneStub.calledWithExactly(
'label': 'bob', [{
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'} 'label': 'bob',
}], [{ 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
'label': 'bob', }], [{
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'} 'label': 'bob',
}])).toEqual(true); 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
}],
false
)).toEqual(true);
expect(failStub.called).toEqual(false); expect(failStub.called).toEqual(false);
var done2Stub = sinon.stub(); var done2Stub = sinon.stub();
@ -638,13 +766,17 @@ describe('OC.Share.ShareDialogView', function() {
expect(failStub.called).toEqual(false); expect(failStub.called).toEqual(false);
expect(done2Stub.calledOnce).toEqual(true); expect(done2Stub.calledOnce).toEqual(true);
expect(done2Stub.calledWithExactly([{ expect(done2Stub.calledWithExactly(
'label': 'bob', [{
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'} 'label': 'bob',
}], [{ 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
'label': 'bob', }],
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'} [{
}])).toEqual(true); 'label': 'bob',
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
}],
false
)).toEqual(true);
expect(fail2Stub.called).toEqual(false); expect(fail2Stub.called).toEqual(false);
}); });
@ -695,13 +827,17 @@ describe('OC.Share.ShareDialogView', function() {
); );
expect(doneStub.calledOnce).toEqual(true); expect(doneStub.calledOnce).toEqual(true);
expect(doneStub.calledWithExactly([{ expect(doneStub.calledWithExactly(
'label': 'bob', [{
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'} 'label': 'bob',
}], [{ 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
'label': 'bob', }],
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'} [{
}])).toEqual(true); 'label': 'bob',
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
}],
false
)).toEqual(true);
expect(failStub.called).toEqual(false); expect(failStub.called).toEqual(false);
var done2Stub = sinon.stub(); var done2Stub = sinon.stub();
@ -741,13 +877,17 @@ describe('OC.Share.ShareDialogView', function() {
expect(fail2Stub.called).toEqual(false); expect(fail2Stub.called).toEqual(false);
expect(done3Stub.calledOnce).toEqual(true); expect(done3Stub.calledOnce).toEqual(true);
expect(done3Stub.calledWithExactly([{ expect(done3Stub.calledWithExactly(
'label': 'bob', [{
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'} 'label': 'bob',
}], [{ 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
'label': 'bob', }],
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'} [{
}])).toEqual(true); 'label': 'bob',
'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'user1'}
}],
false
)).toEqual(true);
expect(fail3Stub.called).toEqual(false); expect(fail3Stub.called).toEqual(false);
}); });
}); });