summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2018-03-19 17:16:11 +0100
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2018-03-20 19:09:04 +0100
commit5e2a8cca1b79d7ab5574bcc4d7309bcf0f7a2522 (patch)
tree9e60d4f7a8854535d986de52091b79c981e33f9f /core
parent89b0e34d9b0d80315839ce022439b58466b3d5db (diff)
downloadnextcloud-server-5e2a8cca1b79d7ab5574bcc4d7309bcf0f7a2522.tar.gz
nextcloud-server-5e2a8cca1b79d7ab5574bcc4d7309bcf0f7a2522.zip
Return also exact matches besides all suggestions
"_getSuggestions" returned all the suggestions from the server, which are composed by exact matches and partial matches. Now the exact matches are also returned on their own parameter. This will be used by the button to confirm a share. Note that until now the order of the suggestions was "exact users, partial users, exact groups, partial groups, exact..."; this commit also changes that order to become "exact users, exact groups, exact..., partial users, partial groups, partial...". This is not a problem, as the suggestions were used in the autocomplete dropdown, and this new order is arguably better than the old one, as all exact matches appear now at the beginning. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'core')
-rw-r--r--core/js/sharedialogview.js67
-rw-r--r--core/js/tests/specs/sharedialogviewSpec.js248
2 files changed, 299 insertions, 16 deletions
diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js
index bfa63a63bd1..d67ff89e281 100644
--- a/core/js/sharedialogview.js
+++ b/core/js/sharedialogview.js
@@ -147,20 +147,14 @@
},
function (result) {
if (result.ocs.meta.statuscode === 100) {
- var users = result.ocs.data.exact.users.concat(result.ocs.data.users);
- var groups = result.ocs.data.exact.groups.concat(result.ocs.data.groups);
- var remotes = result.ocs.data.exact.remotes.concat(result.ocs.data.remotes);
- var lookup = result.ocs.data.lookup;
- var emails = [],
- circles = [];
- if (typeof(result.ocs.data.emails) !== 'undefined') {
- emails = result.ocs.data.exact.emails.concat(result.ocs.data.emails);
- }
- if (typeof(result.ocs.data.circles) !== 'undefined') {
- circles = result.ocs.data.exact.circles.concat(result.ocs.data.circles);
- }
-
var filter = function(users, groups, remotes, emails, circles) {
+ if (typeof(emails) === 'undefined') {
+ emails = [];
+ }
+ if (typeof(circles) === 'undefined') {
+ circles = [];
+ }
+
var usersLength;
var groupsLength;
var remotesLength;
@@ -240,11 +234,52 @@
}
};
- filter(users, groups, remotes, emails, circles);
+ filter(
+ result.ocs.data.exact.users,
+ result.ocs.data.exact.groups,
+ result.ocs.data.exact.remotes,
+ result.ocs.data.exact.emails,
+ result.ocs.data.exact.circles
+ );
+
+ var exactUsers = result.ocs.data.exact.users;
+ var exactGroups = result.ocs.data.exact.groups;
+ var exactRemotes = result.ocs.data.exact.remotes;
+ var exactEmails = [];
+ if (typeof(result.ocs.data.emails) !== 'undefined') {
+ exactEmails = result.ocs.data.exact.emails;
+ }
+ var exactCircles = [];
+ if (typeof(result.ocs.data.circles) !== 'undefined') {
+ exactCircles = result.ocs.data.exact.circles;
+ }
+
+ var exactMatches = exactUsers.concat(exactGroups).concat(exactRemotes).concat(exactEmails).concat(exactCircles);
+
+ filter(
+ result.ocs.data.users,
+ result.ocs.data.groups,
+ result.ocs.data.remotes,
+ result.ocs.data.emails,
+ result.ocs.data.circles
+ );
+
+ var users = result.ocs.data.users;
+ var groups = result.ocs.data.groups;
+ var remotes = result.ocs.data.remotes;
+ var lookup = result.ocs.data.lookup;
+ var emails = [];
+ if (typeof(result.ocs.data.emails) !== 'undefined') {
+ emails = result.ocs.data.emails;
+ }
+ var circles = [];
+ if (typeof(result.ocs.data.circles) !== 'undefined') {
+ circles = result.ocs.data.circles;
+ }
- var suggestions = users.concat(groups).concat(remotes).concat(emails).concat(circles).concat(lookup);
+ var suggestions = exactMatches.concat(users).concat(groups).concat(remotes).concat(emails).concat(circles).concat(lookup);
- deferred.resolve(suggestions);
+ deferred.resolve(suggestions, exactMatches);
} else {
deferred.reject(result.ocs.meta.message);
}
diff --git a/core/js/tests/specs/sharedialogviewSpec.js b/core/js/tests/specs/sharedialogviewSpec.js
index be1aa4c9a8e..e35e8df15a1 100644
--- a/core/js/tests/specs/sharedialogviewSpec.js
+++ b/core/js/tests/specs/sharedialogviewSpec.js
@@ -471,6 +471,254 @@ describe('OC.Share.ShareDialogView', function() {
});
});
});
+ describe('get suggestions', function() {
+ it('no matches', function() {
+ 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': [],
+ 'groups': [],
+ 'remotes': []
+ },
+ 'users': [],
+ 'groups': [],
+ 'remotes': [],
+ '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([], [])).toEqual(true);
+ expect(failStub.called).toEqual(false);
+ });
+ it('single partial match', function() {
+ 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': [],
+ 'groups': [],
+ 'remotes': []
+ },
+ 'users': [
+ {
+ 'label': 'bobby',
+ 'value': {
+ 'shareType': OC.Share.SHARE_TYPE_USER,
+ 'shareWith': 'imbob'
+ }
+ }
+ ],
+ 'groups': [],
+ 'remotes': [],
+ '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': 'bobby',
+ 'value': {'shareType': OC.Share.SHARE_TYPE_USER, 'shareWith': 'imbob'}
+ }], [
+ ])).toEqual(true);
+ expect(failStub.called).toEqual(false);
+ });
+ it('single exact match', function() {
+ 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': [],
+ 'remotes': []
+ },
+ 'users': [],
+ 'groups': [],
+ 'remotes': [],
+ '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_USER, 'shareWith': 'user1'}
+ }])).toEqual(true);
+ expect(failStub.called).toEqual(false);
+ });
+ it('mixed matches', function() {
+ 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': []
+ },
+ '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': [],
+ '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'}
+ }])).toEqual(true);
+ expect(failStub.called).toEqual(false);
+ });
+ });
describe('autocompletion of users', function() {
var showTemporaryNotificationStub;