Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ try {
'profile3'
]);

console.log(response);
console.log(`Successfully retrieved ${response.length} profiles`);
/*
[ Profile {
_id: 'profile1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 15 additions & 4 deletions doc/7/controllers/security/search-profiles/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<SinceBadge version="auto-version" />
<SinceBadge version="Kuzzle 2.14.1" />

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.

<br />

Expand All @@ -19,21 +27,24 @@ searchProfiles([body], [options]);

| Property | Type | Description |
|--- |--- |--- |
| `body` | <pre>object</pre> | Query including role identifiers to search for |
| `body` | <pre>object</pre> | Search query |
| `options` | <pre>object</pre> | Query options |

### body

| Property | Type | Description |
| --- | --- | --- |
| `roles` | <pre>array&lt;string&gt;</pre> | Role identifiers |
| `roles` | <pre>array&lt;string&gt;</pre> | Role identifiers <DeprecatedBadge version="auto-version"/>|
| `query` | <pre>object</pre> | 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. <SinceBadge version="auto-version"/>|

If the body is left empty, the result will return all available profiles.

### options

| Property | Type<br/>(default) | Description |
| ---------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `queuable` | <pre>boolean</pre><br/>(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |
| `from` | <pre>number</pre><br/>(`0`) | Offset of the first document to fetch |
| `lang` | <pre>string</pre> | Specify the query language to use. By default, it's `elasticsearch` but `koncorde` can also be used. |
| `size` | <pre>number</pre><br/>(`10`) | Maximum number of documents to retrieve per page |
| `scroll` | <pre>string</pre><br/>(`""`) | 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)) |

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
try {
const results = await kuzzle.security.searchProfiles({
roles: [ 'default' ]
query: {
term: { 'policies.roleId': 'default' }
}
});

console.log(results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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$
8 changes: 4 additions & 4 deletions src/controllers/Security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ export class SecurityController extends BaseController {
body,
action: 'searchProfiles'
};
for (const opt of ['from', 'size', 'scroll']) {
request[opt] = options[opt];
for (const [key, value] of Object.entries(options)) {
request[key] = value;
}

return this.query(request, options)
Expand All @@ -454,8 +454,8 @@ export class SecurityController extends BaseController {
body,
action: 'searchRoles'
};
for (const opt of ['from', 'size']) {
request[opt] = options[opt];
for (const [key, value] of Object.entries(options)) {
request[key] = value;
}

return this.query(request, options)
Expand Down
6 changes: 5 additions & 1 deletion src/core/Observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '../controllers/Document';
import {
ArgsDocumentControllerGet,
ArgsDocumentControllerMGet,
ArgsDocumentControllerSearch,
} from '../controllers/Document';

/**
* Class based on a Set<string> that holds the observed documents IDs of
Expand Down
16 changes: 14 additions & 2 deletions src/core/security/Profile.ts
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -17,21 +20,30 @@ export class Profile {
*/
policies: Array<ProfilePolicy>;

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
});

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 () {
Expand Down
7 changes: 2 additions & 5 deletions test/controllers/security.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1003,9 +1003,7 @@ describe('Security Controller', () => {
controller: 'security',
action: 'searchProfiles',
body: {roles: ['foo', 'bar']},
from: undefined,
size: undefined,
scroll: undefined
opt: 'in'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer to add a test than to modify an existing one even if you copy/paste it

}, options);

should(res).be.an.instanceOf(ProfileSearchResult);
Expand Down Expand Up @@ -1067,8 +1065,7 @@ describe('Security Controller', () => {
controller: 'security',
action: 'searchRoles',
body: {controllers: ['foo', 'bar']},
from: undefined,
size: undefined
opt: 'in',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer to add a test than to modify an existing one even if you copy/paste it

}, options);

should(res).be.an.instanceOf(RoleSearchResult);
Expand Down