From 50f5830e57eaff65602170f2c404f454fc7994ad Mon Sep 17 00:00:00 2001 From: Aschen Date: Sat, 2 Oct 2021 20:32:19 +0200 Subject: [PATCH 1/7] SUpport new syntax for searchProfiles --- .../security/search-profiles/index.md | 19 +++++++++++++++---- .../snippets/search-profiles.js | 4 +++- src/controllers/Security.ts | 4 ++-- src/core/security/Profile.ts | 16 ++++++++++++++-- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/doc/7/controllers/security/search-profiles/index.md b/doc/7/controllers/security/search-profiles/index.md index 9b2fcff84..fb76e8d9d 100644 --- a/doc/7/controllers/security/search-profiles/index.md +++ b/doc/7/controllers/security/search-profiles/index.md @@ -7,7 +7,15 @@ description: Searches security profiles, optionally returning only those linked # searchProfiles -Searches security profiles, optionally returning only those linked to the provided list of security roles. +Searches security profiles. + + + + +Support for search using a search query with the `query` property. + +This method also supports the [Koncorde Filters DSL](/core/2/api/koncorde-filters-syntax) to match documents by passing the `lang` argument with the value `koncorde`. +Koncorde filters will be translated into an Elasticsearch query.
@@ -19,14 +27,16 @@ searchProfiles([body], [options]); | Property | Type | Description | |--- |--- |--- | -| `body` |
object
| Query including role identifiers to search for | +| `body` |
object
| Search query | | `options` |
object
| Query options | ### body - | Property | Type | Description | | --- | --- | --- | -| `roles` |
array<string>
| Role identifiers | +| `roles` |
array<string>
| Role identifiers | +| `query` |
object
| Search query using the [ElasticSearch Query DSL](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/query-dsl.html) or the [Koncorde Filters DSL](/core/2/api/koncorde-filters-syntax) syntax. | + +If the body is left empty, the result will return all available profiles. ### options @@ -34,6 +44,7 @@ searchProfiles([body], [options]); | ---------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `queuable` |
boolean

(`true`) | If true, queues the request during downtime, until connected to Kuzzle again | | `from` |
number

(`0`) | Offset of the first document to fetch | +| `lang` |
string
| Specify the query language to use. By default, it's `elasticsearch` but `koncorde` can also be used. | | `size` |
number

(`10`) | Maximum number of documents to retrieve per page | | `scroll` |
string

(`""`) | When set, gets a forward-only cursor having its ttl set to the given value (ie `30s`; cf [elasticsearch time limits](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/common-options.html#time-units)) | diff --git a/doc/7/controllers/security/search-profiles/snippets/search-profiles.js b/doc/7/controllers/security/search-profiles/snippets/search-profiles.js index fd43b196f..5efa28731 100644 --- a/doc/7/controllers/security/search-profiles/snippets/search-profiles.js +++ b/doc/7/controllers/security/search-profiles/snippets/search-profiles.js @@ -1,6 +1,8 @@ try { const results = await kuzzle.security.searchProfiles({ - roles: [ 'default' ] + query: { + term: { 'policies.roleId': 'default' } + } }); console.log(results); diff --git a/src/controllers/Security.ts b/src/controllers/Security.ts index f0925842f..6c84e3c8b 100644 --- a/src/controllers/Security.ts +++ b/src/controllers/Security.ts @@ -454,7 +454,7 @@ export class SecurityController extends BaseController { body, action: 'searchProfiles' }; - for (const opt of ['from', 'size', 'scroll']) { + for (const opt of ['from', 'size', 'scroll', 'lang']) { request[opt] = options[opt]; } @@ -467,7 +467,7 @@ export class SecurityController extends BaseController { body, action: 'searchRoles' }; - for (const opt of ['from', 'size']) { + for (const opt of ['from', 'size', 'lang']) { request[opt] = options[opt]; } diff --git a/src/core/security/Profile.ts b/src/core/security/Profile.ts index e52ded6f5..c0924b499 100644 --- a/src/core/security/Profile.ts +++ b/src/core/security/Profile.ts @@ -1,7 +1,10 @@ import { Role } from './Role'; import { JSONObject, ProfilePolicy } from '../../types'; +import { Kuzzle } from '../../Kuzzle'; export class Profile { + private _kuzzle: Kuzzle; + /** * Profile unique ID */ @@ -17,14 +20,15 @@ export class Profile { */ policies: Array; - private _kuzzle: any; + // Other properties + [property: string]: any; /** * * @param {Kuzzle} kuzzle * @param {Object} data */ - constructor (kuzzle, _id = null, content = null) { + constructor (kuzzle: Kuzzle, _id: string = null, content: JSONObject = {}) { Reflect.defineProperty(this, '_kuzzle', { value: kuzzle }); @@ -32,6 +36,14 @@ export class Profile { this._id = _id; this.rateLimit = content && content.rateLimit ? content.rateLimit : 0; this.policies = content && content.policies ? content.policies : []; + + for (const [key, value] of Object.entries(content)) { + if (this[key]) { + continue; + } + + this[key] = value; + } } protected get kuzzle () { From b86d236bb40b23bd288e31b707edca111aa7c4ab Mon Sep 17 00:00:00 2001 From: Aschen Date: Sun, 3 Oct 2021 09:36:43 +0200 Subject: [PATCH 2/7] fix tests --- src/controllers/Security.ts | 8 ++++---- test/controllers/security.test.js | 7 ++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/controllers/Security.ts b/src/controllers/Security.ts index 6c84e3c8b..41516453e 100644 --- a/src/controllers/Security.ts +++ b/src/controllers/Security.ts @@ -454,8 +454,8 @@ export class SecurityController extends BaseController { body, action: 'searchProfiles' }; - for (const opt of ['from', 'size', 'scroll', 'lang']) { - request[opt] = options[opt]; + for (const [key, value] of Object.entries(options)) { + request[key] = value; } return this.query(request, options) @@ -467,8 +467,8 @@ export class SecurityController extends BaseController { body, action: 'searchRoles' }; - for (const opt of ['from', 'size', 'lang']) { - request[opt] = options[opt]; + for (const [key, value] of Object.entries(options)) { + request[key] = value; } return this.query(request, options) diff --git a/test/controllers/security.test.js b/test/controllers/security.test.js index e88c62fe9..2c7ff3cfd 100644 --- a/test/controllers/security.test.js +++ b/test/controllers/security.test.js @@ -1003,9 +1003,7 @@ describe('Security Controller', () => { controller: 'security', action: 'searchProfiles', body: {roles: ['foo', 'bar']}, - from: undefined, - size: undefined, - scroll: undefined + opt: 'in' }, options); should(res).be.an.instanceOf(ProfileSearchResult); @@ -1067,8 +1065,7 @@ describe('Security Controller', () => { controller: 'security', action: 'searchRoles', body: {controllers: ['foo', 'bar']}, - from: undefined, - size: undefined + opt: 'in', }, options); should(res).be.an.instanceOf(RoleSearchResult); From add6ef46981d18515fc45923171254ad9e22e9dc Mon Sep 17 00:00:00 2001 From: Aschen Date: Mon, 4 Oct 2021 14:32:45 +0200 Subject: [PATCH 3/7] teest --- .../security/m-get-profiles/snippets/m-get-profiles.js | 2 +- .../security/m-get-profiles/snippets/m-get-profiles.test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/7/controllers/security/m-get-profiles/snippets/m-get-profiles.js b/doc/7/controllers/security/m-get-profiles/snippets/m-get-profiles.js index 365cdba4e..b0cb406e2 100644 --- a/doc/7/controllers/security/m-get-profiles/snippets/m-get-profiles.js +++ b/doc/7/controllers/security/m-get-profiles/snippets/m-get-profiles.js @@ -5,7 +5,7 @@ try { 'profile3' ]); - console.log(response); + console.log(`Successfully retrieved ${response.length} profiles`); /* [ Profile { _id: 'profile1', diff --git a/doc/7/controllers/security/m-get-profiles/snippets/m-get-profiles.test.yml b/doc/7/controllers/security/m-get-profiles/snippets/m-get-profiles.test.yml index df683ef23..171c26967 100644 --- a/doc/7/controllers/security/m-get-profiles/snippets/m-get-profiles.test.yml +++ b/doc/7/controllers/security/m-get-profiles/snippets/m-get-profiles.test.yml @@ -12,4 +12,4 @@ hooks: curl -XDELETE kuzzle:7512/profiles/profile${i} done template: default -expected: '.*Profile.*_id.*rateLimit.*policies.*' +expected: Successfully retrieved 3 profiles From a770c4de7b905b4e63699a3ff07994fd25aa843c Mon Sep 17 00:00:00 2001 From: Aschen Date: Tue, 19 Oct 2021 10:33:10 +0200 Subject: [PATCH 4/7] tests --- .../security/search-profiles/snippets/search-profiles.test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/7/controllers/security/search-profiles/snippets/search-profiles.test.yml b/doc/7/controllers/security/search-profiles/snippets/search-profiles.test.yml index 317755d03..603a3c08a 100644 --- a/doc/7/controllers/security/search-profiles/snippets/search-profiles.test.yml +++ b/doc/7/controllers/security/search-profiles/snippets/search-profiles.test.yml @@ -12,4 +12,4 @@ hooks: curl -XDELETE kuzzle:7512/profiles/profile${i} done template: default -expected: ^Successfully retrieved 4 profiles$ +expected: ^Successfully retrieved \d+ profiles$ From 49927f033bab17feaa256e3102ced706ad86b383 Mon Sep 17 00:00:00 2001 From: Aschen Date: Thu, 25 Nov 2021 19:23:56 +0100 Subject: [PATCH 5/7] trigger CI --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 18de7c72e..f175e585e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "kuzzle-sdk", "version": "7.7.5", "description": "Official Javascript SDK for Kuzzle", - "author": "The Kuzzle Team ", + "author": "The Kuzzle Team Date: Thu, 25 Nov 2021 19:24:02 +0100 Subject: [PATCH 6/7] trigger CI --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f175e585e..18de7c72e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "kuzzle-sdk", "version": "7.7.5", "description": "Official Javascript SDK for Kuzzle", - "author": "The Kuzzle Team ", "repository": { "type": "git", "url": "https://github.com/kuzzleio/sdk-javascript.git" From a9a8b71df7ea9a28e847d32ff15c872ced5e3ed0 Mon Sep 17 00:00:00 2001 From: Aschen Date: Mon, 3 Jan 2022 17:18:10 +0100 Subject: [PATCH 7/7] Fix bad import --- .eslintignore | 4 ++++ .gitignore | 4 ++++ src/core/Observer.ts | 6 +++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.eslintignore b/.eslintignore index c4a2e98ad..fb89da8c2 100644 --- a/.eslintignore +++ b/.eslintignore @@ -32,3 +32,7 @@ src/core/searchResult/Specifications.js src/core/searchResult/User.js src/utils/Deprecation.js src/utils/interfaces.js +src/controllers/Server.js +src/core/Observer.js +src/core/RealtimeDocument.js +src/core/searchResult/RealtimeDocument.js \ No newline at end of file diff --git a/.gitignore b/.gitignore index d69682a59..399f56e32 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,7 @@ src/core/searchResult/Specifications.js src/core/searchResult/User.js src/utils/Deprecation.js src/utils/interfaces.js +src/controllers/Server.js +src/core/Observer.js +src/core/RealtimeDocument.js +src/core/searchResult/RealtimeDocument.js \ No newline at end of file diff --git a/src/core/Observer.ts b/src/core/Observer.ts index f6d6bcc83..21d08df02 100644 --- a/src/core/Observer.ts +++ b/src/core/Observer.ts @@ -2,7 +2,11 @@ import { Kuzzle } from '../Kuzzle'; import { RealtimeDocument } from './RealtimeDocument'; import { Document, DocumentNotification, JSONObject } from '../types'; import { RealtimeDocumentSearchResult } from './searchResult/RealtimeDocument'; -import { ArgsDocumentControllerGet, ArgsDocumentControllerMGet, ArgsDocumentControllerSearch } from 'src/controllers/Document'; +import { + ArgsDocumentControllerGet, + ArgsDocumentControllerMGet, + ArgsDocumentControllerSearch, +} from '../controllers/Document'; /** * Class based on a Set that holds the observed documents IDs of