diff --git a/doc/7/controllers/document/m-get/index.md b/doc/7/controllers/document/m-get/index.md index 872ba2280..eb5331830 100644 --- a/doc/7/controllers/document/m-get/index.md +++ b/doc/7/controllers/document/m-get/index.md @@ -15,6 +15,7 @@ Gets multiple documents. mGet(index, collection, ids, [options]); ``` + | Argument | Type | Description | | ------------ | --------------- | --------------- | | `index` |
string| Index name | @@ -29,6 +30,12 @@ Additional query options | Options | Type
boolean
string| (HTTP only) Forces the verb of the route | + +#### verb + +When instantiated with a HTTP protocol object, the SDK uses the GET API by default for this API route. +You can set the `verb` option to `POST` to force the SDK to use the POST API instead. ## Resolves diff --git a/doc/7/controllers/security/m-get-users/index.md b/doc/7/controllers/security/m-get-users/index.md new file mode 100644 index 000000000..6a64c2989 --- /dev/null +++ b/doc/7/controllers/security/m-get-users/index.md @@ -0,0 +1,43 @@ +--- +code: true +type: page +title: mGetUsers +description: Gets multiple security users +--- + +# mGetUsers + +Gets multiple security users. + +
string[]| User identifiers | +| `options` |
object| Query options | + +### options + +| Property | Type | Description | +| --- | --- | --- | +| `queuable` |
boolean| If true, queues the request during downtime, until connected to Kuzzle again | +| `verb` |
string| (HTTP only) Forces the verb of the API route | + +#### verb + +When instantiated with a HTTP protocol object, the SDK uses the GET API by default for this API route. +You can set the `verb` option to `POST` to force the SDK to use the POST API instead. + +## Resolves + +An array of retrieved [`User`](/sdk/js/7/core-classes/user/introduction) objects. + +## Usage + +<<< ./snippets/m-get-users.js diff --git a/doc/7/controllers/security/m-get-users/snippets/m-get-users.js b/doc/7/controllers/security/m-get-users/snippets/m-get-users.js new file mode 100644 index 000000000..3df52f0e0 --- /dev/null +++ b/doc/7/controllers/security/m-get-users/snippets/m-get-users.js @@ -0,0 +1,22 @@ +try { + const response = await kuzzle.security.mGetUsers([ + 'user1', + 'user2', + 'user3' + ]); + + console.log(response); + /* + [ User { + _id: 'user1', + profileIds: ['profile1'], + User { + _id: 'user2', + profileIds: ['profile2'], + User { + _id: 'user3', + profileIds: ['profile3'] ] + */ +} catch (e) { + console.error(e); +} diff --git a/doc/7/controllers/security/m-get-users/snippets/m-get-users.test.yml b/doc/7/controllers/security/m-get-users/snippets/m-get-users.test.yml new file mode 100644 index 000000000..b482c7fc0 --- /dev/null +++ b/doc/7/controllers/security/m-get-users/snippets/m-get-users.test.yml @@ -0,0 +1,24 @@ +name: security#mGetUsers +description: mget users +hooks: + before: | + for i in 1 2 3; do + curl -H "Content-type: application/json" -d '{ + "content": { + "profileIds": ["default"], + "fullname": "user'${i}'" + }, + "credentials": { + "local": { + "username": "user'${i}'", + "password": "bar" + } + } + }' kuzzle:7512/users/user${i}/_create + done + after: | + for i in 1 2 3; do + curl -XDELETE kuzzle:7512/users/user${i} + done +template: default +expected: '^ _id: ''user3'',$' diff --git a/doc/7/controllers/server/get-all-stats/snippets/get-all-stats.test.yml b/doc/7/controllers/server/get-all-stats/snippets/get-all-stats.test.yml index 11da5de67..e154cc024 100644 --- a/doc/7/controllers/server/get-all-stats/snippets/get-all-stats.test.yml +++ b/doc/7/controllers/server/get-all-stats/snippets/get-all-stats.test.yml @@ -4,4 +4,4 @@ hooks: before: after: template: default -expected: ongoingRequests \ No newline at end of file +expected: ongoingRequests diff --git a/src/Kuzzle.js b/src/Kuzzle.js index a8df7ad03..98696bf33 100644 --- a/src/Kuzzle.js +++ b/src/Kuzzle.js @@ -458,7 +458,7 @@ class Kuzzle extends KuzzleEventEmitter { Discarded request: ${JSON.stringify(request)}`)); } - return this.protocol.query(request); + return this.protocol.query(request, options); } /** diff --git a/src/controllers/auth.js b/src/controllers/auth.js index 028a4d729..95fe82b42 100644 --- a/src/controllers/auth.js +++ b/src/controllers/auth.js @@ -247,7 +247,7 @@ class AuthController extends BaseController { action: 'login' }; - return this.query(request, {queuable: false}) + return this.query(request, {queuable: false, verb: 'POST'}) .then(response => { try { this._authenticationToken = new Jwt(response.result.jwt); diff --git a/src/controllers/document.js b/src/controllers/document.js index ea2664098..1ac3f9623 100644 --- a/src/controllers/document.js +++ b/src/controllers/document.js @@ -136,10 +136,15 @@ class DocumentController extends BaseController { const request = { index, collection, - body: {ids}, action: 'mGet' }; + if (options.verb === 'POST') { + request.body = {ids}; + } + else { + request.ids = ids.join(); + } return this.query(request, options) .then(response => response.result); } diff --git a/src/controllers/security/index.js b/src/controllers/security/index.js index 15f39da63..fdf038160 100644 --- a/src/controllers/security/index.js +++ b/src/controllers/security/index.js @@ -355,6 +355,22 @@ class SecurityController extends BaseController { .then(response => response.result.hits.map(hit => new Profile(this.kuzzle, hit._id , hit._source.policies))); } + mGetUsers (ids, options = {}) { + const request = { + action: 'mGetUsers' + }; + + if (options.verb === 'POST') { + request.body = { ids }; + } + else { + request.ids = ids.join(); + } + + return this.query(request, options) + .then(response => response.result.hits.map(hit => new User(this.kuzzle, hit._id, hit._source))); + } + mGetRoles (ids, options = {}) { return this.query({ action: 'mGetRoles', diff --git a/src/protocols/abstract/common.js b/src/protocols/abstract/common.js index fec780fd9..730716aba 100644 --- a/src/protocols/abstract/common.js +++ b/src/protocols/abstract/common.js @@ -81,7 +81,7 @@ class AbstractWrapper extends KuzzleEventEmitter { this.clear(); } - query (request) { + query (request, options) { if (!this.isReady()) { this.emit('discarded', request); return Promise.reject(new Error(`Unable to execute request: not connected to a Kuzzle server. @@ -109,7 +109,7 @@ Discarded request: ${JSON.stringify(request)}`)); pending.resolve(response); }); - this.send(request); + this.send(request, options); return pending.promise; } diff --git a/src/protocols/http.js b/src/protocols/http.js index e6f279206..3198547aa 100644 --- a/src/protocols/http.js +++ b/src/protocols/http.js @@ -135,7 +135,7 @@ class HttpWrapper extends KuzzleAbstractProtocol { * @param {Object} data * @returns {Promise