Skip to content

Commit

Permalink
Hotfix 2.25.1: DR support for roles, fix to "429" error (#3753)
Browse files Browse the repository at this point in the history
* GITBOOK-136: Added Filebase docs

* added bad_request const for status code

* added publishing contract file script

Signed-off-by: artembuslaev <[email protected]>

* fix: migrate to redict cache store

* Revert "Merge branch 'develop' into feat/move-to-es-modules-develop"

This reverts commit 6da2788, reversing
changes made to 0c8b832.

* Revert "fix: merge with develop"

This reverts commit 0c8b832, reversing
changes made to 0fec16a.

* Revert "Revert "fix: merge with develop""

This reverts commit 5610fa5.

* Revert "Revert "Merge branch 'develop' into feat/move-to-es-modules-develop""

This reverts commit c48aa0f.

* added nfts limit in contracts

Signed-off-by: Artem Buslaev <[email protected]>

* upd contracts [skip ci]

Signed-off-by: Artem Buslaev <[email protected]>

* fix script [skip ci]

Signed-off-by: Artem Buslaev <[email protected]>

* GITBOOK-137: Updated Changing Tools in UI section

* Update readme.md of ML readme

* remove output [skip ci]

Signed-off-by: Artem Buslaev <[email protected]>

* fix

Signed-off-by: Artem Buslaev <[email protected]>

* GITBOOK-139: Added section on how to deploy contracts using your own account

* Update readme.md

* GITBOOK-140: Added Atma Scope 3 policy demo

* GITBOOK-142: Added Dovu MMCM

* update iii.f [skip ci]

Signed-off-by: Artem Buslaev <[email protected]>

* feat: performance interceptor

* cache-endpoints
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* update policies [skip ci]

Signed-off-by: Artem Buslaev <[email protected]>

* fix: extentions gulp files in description dockerfiles

* update policies [skip ci]

Signed-off-by: Artem Buslaev <[email protected]>

* feat: wrap endpoinds in cache

* GITBOOK-143: added ExternalDataBlock details

* feat: use cache with apply decorators

* fix: file name import

* fix: get user only if auth token exist

* feat: add perf hooks in performance interceptor

* fix: add express flag for projects/properties route

* setup user profile
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* sign with fireblocks
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* user fireblocks config
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix serials column

Signed-off-by: Artem Buslaev <[email protected]>

* remove res where it possible and add res.locals.data

* GITBOOK-144: Added Changing of Tools during Policy import APIs added

* fix fireblocks sign bug
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* add ui validators, add exception
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* temp fix validators
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* GITBOOK-145: Added youtube demo video for PWRM0002

* GITBOOK-146: Updated Guardian Introduction

* fix: remove cache from policies/:policyId/groups

* fix
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* Policy Preview/Import performance optimisations

Signed-off-by: Alexander Pyatakov <[email protected]>

* fixed fields parsing for compare

Signed-off-by: Alexander Pyatakov <[email protected]>

* parseConditions function improvements

Signed-off-by: Alexander Pyatakov <[email protected]>

* fix generate xlsx

Signed-off-by: Stepan Kiryakov <[email protected]>

* GITBOOK-147: Made some minor corrections

* test
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* added policy data migration

Signed-off-by: Artem Buslaev <[email protected]>

* [skip ci] Add swagger.yaml

* fix

Signed-off-by: Artem Buslaev <[email protected]>

* fix

Signed-off-by: Artem Buslaev <[email protected]>

* fix lint

Signed-off-by: Artem Buslaev <[email protected]>

* remove types/mime resolution
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* Add files via upload

* fix signing
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix linting
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix autocomplete
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* remove singleton from fireblocks-helper.ts
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* docs: add instruction for launch cache container in readme file

* bump version
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* [skip ci] Add swagger.yaml

* GITBOOK-148: Added Live Project Data Migration UI

* GITBOOK-149: Fireblocks Docs added

* added migrating retire pools and dynamic tokens

Signed-off-by: Artem Buslaev <[email protected]>

* [skip ci] Add swagger.yaml

* fix

Signed-off-by: Artem Buslaev <[email protected]>

* GITBOOK-150: ACM0001 guide added

* fix lint

Signed-off-by: Artem Buslaev <[email protected]>

* Update readme.md of ACM0001

* fix

Signed-off-by: Artem Buslaev <[email protected]>

* GITBOOK-151: Added migration policy data APIs

* hotfix: remove cache for contract routes

* GITBOOK-152: Added redict in Prerequisites

* GITBOOK-153: Added Prerequisites

* GITBOOK-154: Added Token template to migration

* GITBOOK-155: Added fireblocks note

* hotfix/remove-cache-from-tags-schemas

* GITBOOK-156: Updated roadmap

* GITBOOK-157: Updated roadmap

* fix: remove cache from navigation

* GITBOOK-158: Made some changes in SD

* feat:basic fastify solution

* feat: add body parser for json and binary/octet-stream and send method

* feat: implement interceptor for multipart formdata

* refactor: put same names as base nest

* fix cache document id

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix cache document id

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix cache document id

Signed-off-by: Stepan Kiryakov <[email protected]>

* GITBOOK-159: made some minor corrections

* GITBOOK-160: updated extractdatablock

* fix: error status if token is not correct

* bump version
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* [skip ci] Add swagger.yaml

* fix: size of limit json to 1gb

* GITBOOK-161: Updated Live Project Data UI

* update mamual tests flow
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix: auth accross decorator in get account

* feat: add option ignoreTrailingSlash in fastify adapter

* [skip ci] Add swagger.yaml

* fix: remove local data for cache from contracts

* fix: remove local data for cache from tags schemas

* GITBOOK-162: Added note in Topics Architecture

* fix: export strime for schema file

* update api workflows (#3640)

Signed-off-by: simvalery <[email protected]>

* fix: setHeader to header for fastify

* fix: linter errors

* fix: req body is undefined for logger

* gzip compression enabled for web-proxy

Signed-off-by: Alexander Pyatakov <[email protected]>

* fix: multipart intercepter for artifats

* GITBOOK-163: Updated Fireblocks UI screens

* GITBOOK-164: Removed Fireblocks note

* fix: sypress 500 error instead 400 in artifact

* remove port sharing from cache container
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* GITBOOK-165: Updated tools for AMS-II.G

* GITBOOK-166: Corrected gold Standard policy

* GITBOOK-167: Updated Verra titles

* GITBOOK-168: updated VM0017 title

* GITBOOK-169: updated Verra

* GITBOOK-171: updated grid spelling

* GITBOOK-172: correcting grid spelling

* GITBOOK-173: Updated High level architecture

* data comparation
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix 3449
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* GITBOOK-174: fireblocks diagram updated

* add api-version
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* [skip ci] Add swagger.yaml

* fix swagger generated files
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* [skip ci] Add swagger.yaml

* fix 3449
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* GITBOOK-174: fireblocks diagram updated

* fix swagger generated files
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix swagger
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* [skip ci] Add swagger.yaml

* fix labels
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix labels
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix irec7 comparation
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix irec5 comparison
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix crash
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix ui
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix sizing
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix schema title
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* status code added

* fix lint
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* GITBOOK-175: Added VP Document Comparison for projects

* GITBOOK-176: Added VP Compare in Projects docs

* GITBOOK-177: Added Methane Emission GS demo guide

* GITBOOK-178: Added operations section for Fireblocks

* Revamp Guardian user/roles and permissions model (#3717)

Revamp Guardian user/roles and permissions model 

---------

Signed-off-by: Stepan Kiryakov <[email protected]>
Co-authored-by: envision-ci-agent <[email protected]>

* fix: issue-3447-redundant-fields-in-session-api (#3664)

Signed-off-by: Ihar Tsykala <[email protected]>
Co-authored-by: Ihar <[email protected]>

* fix connection refused error
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix application-events service
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix ipfs get file
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* [skip ci] Add swagger.yaml

* fix upload in ipfs from dryRun mode
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix download in ipfs from dryRun mode
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix gridfs bug
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix gridfs bug
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* Feature/2629 upd (#3720)

* add indexer

Signed-off-by: Stepan Kiryakov <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* fix

Signed-off-by: Stepan Kiryakov <[email protected]>

* add services

Signed-off-by: Stepan Kiryakov <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* update elastic

Signed-off-by: Stepan Kiryakov <[email protected]>

* add page templates

Signed-off-by: Stepan Kiryakov <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* update

Signed-off-by: Stepan Kiryakov <[email protected]>

* update indexer [skip ci]

Signed-off-by: Artem Buslaev <[email protected]>

* update yarn lock [skip ci]

Signed-off-by: Artem Buslaev <[email protected]>

* fix [skip ci]

Signed-off-by: Artem Buslaev <[email protected]>

* fix [skip ci]

Signed-off-by: Artem Buslaev <[email protected]>

* fix [skip ci]

Signed-off-by: Artem Buslaev <[email protected]>

* fix swagger [skip ci]

Signed-off-by: Artem Buslaev <[email protected]>

---------

Signed-off-by: Stepan Kiryakov <[email protected]>
Signed-off-by: Artem Buslaev <[email protected]>
Co-authored-by: Stepan Kiryakov <[email protected]>

* bump version
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* [skip ci] Add swagger.yaml

* update default masks [skip ci]

Signed-off-by: Artem Buslaev <[email protected]>

* Revamp Guardian user/roles and permissions model (#3722)

Add messages

* GITBOOK-179: Added Step by step to GS methodology

* Create readme.md of Methane Emission Reduction by Adjusted Water Management Practice in Rice Cultivation

Signed-off-by: prernaadev01 <[email protected]>

* bump version
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* add gs policy
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* Add files via upload

Signed-off-by: prernaadev01 <[email protected]>

* Update readme.md of Rice Cultivation

Signed-off-by: prernaadev01 <[email protected]>

* GITBOOK-180: Indexer User Guide added

* GITBOOK-181: Added Roles & Permissions section

* GITBOOK-182: corrected docs

* fix session response
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix session response
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* remove unnesessary cache
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* remove unnesessary cache
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* update gitignore
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* update gitignore
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix roles
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* fix roles
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* bump version
Signed-off-by: simvalery <[email protected]>

Signed-off-by: simvalery <[email protected]>

* [skip ci] Add swagger.yaml

* GITBOOK-183: Updated roadmap

* fix migrate data from dry-run (#3754)

Signed-off-by: Artem Buslaev <[email protected]>

* fix (#3748)

Signed-off-by: Artem Buslaev <[email protected]>

* Fix restore (#3750)

Update user restore

* fix restore role uuid

Signed-off-by: Stepan Kiryakov <[email protected]>

---------

Signed-off-by: artembuslaev <[email protected]>
Signed-off-by: Artem Buslaev <[email protected]>
Signed-off-by: simvalery <[email protected]>
Signed-off-by: Alexander Pyatakov <[email protected]>
Signed-off-by: Stepan Kiryakov <[email protected]>
Signed-off-by: Ihar Tsykala <[email protected]>
Signed-off-by: prernaadev01 <[email protected]>
Co-authored-by: prernaa.agarwal <[email protected]>
Co-authored-by: Celiant <[email protected]>
Co-authored-by: artembuslaev <[email protected]>
Co-authored-by: Ihar <[email protected]>
Co-authored-by: Alexander Pyatakov <[email protected]>
Co-authored-by: Stepan Kiryakov <[email protected]>
Co-authored-by: envision-ci-agent <[email protected]>
Co-authored-by: Ihar Tsykala <[email protected]>
  • Loading branch information
9 people authored Jun 6, 2024
1 parent 5f03f0c commit 1f01aba
Show file tree
Hide file tree
Showing 48 changed files with 737 additions and 379 deletions.
5 changes: 2 additions & 3 deletions ai-service/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/faiss-vector
/data

/faiss-vector/
/data/
6 changes: 3 additions & 3 deletions ai-service/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "ai-service",
"version": "2.25.0",
"version": "2.25.1",
"main": "dist/app.js",
"license": "Apache-2.0",
"dependencies": {
"@guardian/common": "^2.25.0",
"@guardian/interfaces": "^2.25.0",
"@guardian/common": "^2.25.1",
"@guardian/interfaces": "^2.25.1",
"@mikro-orm/core": "6.2.2",
"@mikro-orm/mongodb": "6.2.2",
"@nestjs/common": "^9.4.1",
Expand Down
6 changes: 3 additions & 3 deletions analytics-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
},
"author": "Envision Blockchain Solutions <[email protected]>",
"dependencies": {
"@guardian/common": "^2.25.0",
"@guardian/interfaces": "^2.25.0",
"@guardian/common": "^2.25.1",
"@guardian/interfaces": "^2.25.1",
"@nestjs/common": "^9.4.1",
"@nestjs/core": "^9.4.1",
"@nestjs/jwt": "^10.0.3",
Expand Down Expand Up @@ -82,5 +82,5 @@
"test": "mocha tests/**/*.test.js --reporter mocha-junit-reporter --reporter-options mochaFile=../test_results/ui-service.xml"
},
"type": "module",
"version": "2.25.0"
"version": "2.25.1"
}
6 changes: 3 additions & 3 deletions api-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"@fastify/formbody": "^7.4.0",
"@fastify/multipart": "^8.2.0",
"@fastify/static": "^7.0.0",
"@guardian/common": "^2.25.0",
"@guardian/interfaces": "^2.25.0",
"@guardian/common": "^2.25.1",
"@guardian/interfaces": "^2.25.1",
"@nestjs/common": "^9.4.1",
"@nestjs/core": "^9.4.1",
"@nestjs/jwt": "^10.0.3",
Expand Down Expand Up @@ -87,5 +87,5 @@
"test": "mocha tests/**/*.test.js --reporter mocha-junit-reporter --reporter-options mochaFile=../test_results/ui-service.xml"
},
"type": "module",
"version": "2.25.0"
"version": "2.25.1"
}
12 changes: 6 additions & 6 deletions api-gateway/src/api/service/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export class PermissionsApi {
try {
const owner = user.parent || user.did;
const users = new Users();
const row = await users.getUser(username);
const row = await users.getUserPermissions(username);
if (!row || row.parent !== owner || row.did === user.did) {
throw new HttpException('User does not exist.', HttpStatus.NOT_FOUND);
}
Expand Down Expand Up @@ -500,7 +500,7 @@ export class PermissionsApi {
let row: any;
const users = new Users();
try {
row = await users.getUser(username);
row = await users.getUserPermissions(username);
} catch (error) {
await InternalException(error);
}
Expand Down Expand Up @@ -583,7 +583,7 @@ export class PermissionsApi {
const owner = user.parent || user.did;
let target: any;
try {
target = await (new Users()).getUser(username);
target = await (new Users()).getUserPermissions(username);
} catch (error) {
await InternalException(error);
}
Expand Down Expand Up @@ -648,7 +648,7 @@ export class PermissionsApi {
let row: any;
const users = new Users();
try {
row = await users.getUser(username);
row = await users.getUserPermissions(username);
} catch (error) {
await InternalException(error);
}
Expand Down Expand Up @@ -713,7 +713,7 @@ export class PermissionsApi {
let row: any;
const users = new Users();
try {
row = await users.getUser(username);
row = await users.getUserPermissions(username);
} catch (error) {
await InternalException(error);
}
Expand Down Expand Up @@ -773,7 +773,7 @@ export class PermissionsApi {
let row: any;
const users = new Users();
try {
row = await users.getUser(username);
row = await users.getUserPermissions(username);
} catch (error) {
await InternalException(error);
}
Expand Down
8 changes: 8 additions & 0 deletions api-gateway/src/helpers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ export class Users extends NatsService {
return await this.sendMessage(AuthEvents.GET_USER, { username });
}

/**
* Return user by username
* @param username
*/
public async getUserPermissions(username: string): Promise<IAuthUser> {
return await this.sendMessage(AuthEvents.GET_USER_PERMISSIONS, { username });
}

/**
* Return user by did
* @param did
Expand Down
2 changes: 1 addition & 1 deletion api-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api-tests",
"version": "2.25.0",
"version": "2.25.1",
"description": "API Tests",
"main": "index.js",
"type": "module",
Expand Down
6 changes: 3 additions & 3 deletions auth-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"image-size": "1.0.2"
},
"dependencies": {
"@guardian/common": "^2.25.0",
"@guardian/interfaces": "^2.25.0",
"@guardian/common": "^2.25.1",
"@guardian/interfaces": "^2.25.1",
"@meeco/cryppo": "^2.0.2",
"@mikro-orm/core": "6.2.2",
"@mikro-orm/mongodb": "6.2.2",
Expand Down Expand Up @@ -75,5 +75,5 @@
"test": "mocha tests/**/*.test.js --reporter mocha-junit-reporter --reporter-options mochaFile=../test_results/ui-service.xml"
},
"type": "module",
"version": "2.25.0"
"version": "2.25.1"
}
107 changes: 80 additions & 27 deletions auth-service/src/api/account-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
IGetUsersByAccountMessage,
IGetUsersByIdMessage,
IGetUsersByIRoleMessage,
IGroup,
IRegisterNewUserMessage,
ISaveUserMessage,
IStandardRegistryUserResponse,
Expand Down Expand Up @@ -71,7 +72,12 @@ export async function createNewUser(
default: true,
readonly: true
});
const permissionsGroup = defaultRole ? [defaultRole.id] : [];
const permissionsGroup: IGroup[] = defaultRole ? [{
uuid: defaultRole.uuid,
roleId: defaultRole.id,
roleName: defaultRole.name,
owner: null
}] : [];
const permissions = defaultRole ? defaultRole.permissions : [];
const user = (new DataBaseHelper(User)).create({
username,
Expand All @@ -88,6 +94,14 @@ export async function createNewUser(
return await (new DataBaseHelper(User)).save(user);
}

export function getRequiredProps(user: User): IUser {
const userRequiredProps: IUser = {}
for (const prop of Object.values(USER_REQUIRED_PROPS)) {
userRequiredProps[prop] = user[prop];
}
return userRequiredProps;
}

/**
* Account service
*/
Expand Down Expand Up @@ -125,15 +139,7 @@ export class AccountService extends NatsService {
}

const user = await new DataBaseHelper(User).findOne({ username: decryptedToken.username });
const puser = setDefaultPermissions(user)

const userRequiredProps = {}

for (const prop of Object.values(USER_REQUIRED_PROPS)) {
userRequiredProps[prop] = puser[prop];
}

return new MessageResponse(userRequiredProps);
return new MessageResponse(getRequiredProps(setDefaultPermissions(user)));
} catch (error) {
return new MessageError(error);
}
Expand Down Expand Up @@ -221,7 +227,7 @@ export class AccountService extends NatsService {
this.getMessages<IGetUsersByIdMessage, IUser[]>(AuthEvents.GET_USERS_BY_ID, async (msg: any) => {
const { dids } = msg;
try {
return new MessageResponse(await new DataBaseHelper(User).find({ where: { did: { $in: dids } } }));
return new MessageResponse(await new DataBaseHelper(User).find({ did: { $in: dids } }));
} catch (error) {
new Logger().error(error, ['AUTH_SERVICE']);
return new MessageError(error);
Expand All @@ -247,11 +253,13 @@ export class AccountService extends NatsService {
*/
this.getMessages<any, IGetAllUserResponse[]>(AuthEvents.GET_ALL_USER_ACCOUNTS, async (_: any) => {
try {
const userAccounts = (await new DataBaseHelper(User).find({ role: UserRole.USER })).map((e) => ({
username: e.username,
parent: e.parent,
did: e.did
}));
const userAccounts = (await new DataBaseHelper(User)
.find({ role: UserRole.USER }))
.map((e) => ({
username: e.username,
parent: e.parent,
did: e.did
}));
return new MessageResponse(userAccounts);
} catch (error) {
new Logger().error(error, ['AUTH_SERVICE']);
Expand All @@ -264,10 +272,12 @@ export class AccountService extends NatsService {
*/
this.getMessages<any, IStandardRegistryUserResponse[]>(AuthEvents.GET_ALL_STANDARD_REGISTRY_ACCOUNTS, async (_) => {
try {
const userAccounts = (await new DataBaseHelper(User).find({ role: UserRole.STANDARD_REGISTRY })).map((e) => ({
username: e.username,
did: e.did
}));
const userAccounts = (await new DataBaseHelper(User)
.find({ role: UserRole.STANDARD_REGISTRY }))
.map((e) => ({
username: e.username,
did: e.did
}));
return new MessageResponse(userAccounts);
} catch (error) {
new Logger().error(error, ['AUTH_SERVICE']);
Expand All @@ -280,7 +290,9 @@ export class AccountService extends NatsService {
*/
this.getMessages<any, IGetDemoUserResponse[]>(AuthEvents.GET_ALL_USER_ACCOUNTS_DEMO, async (_) => {
try {
const userAccounts = (await new DataBaseHelper(User).findAll()).map((e) => ({
const userAccounts = (await new DataBaseHelper(User).find({
template: { $ne: true }
})).map((e) => ({
parent: e.parent,
did: e.did,
username: e.username,
Expand Down Expand Up @@ -322,10 +334,31 @@ export class AccountService extends NatsService {
}
});

this.getMessages<IRegisterNewUserMessage, User>(AuthEvents.REGISTER_NEW_TEMPLATE,
async (msg: { role: string, did: string, parent: string }) => {
try {
const { role, did, parent } = msg;
const username = `template_${Date.now()}${Math.round(Math.random() * 1000)}`;
const row = (new DataBaseHelper(User)).create({
username,
role,
parent,
did,
template: true
});
const user = await (new DataBaseHelper(User)).save(row);
return new MessageResponse(user);
} catch (error) {
new Logger().error(error, ['AUTH_SERVICE']);
return new MessageError(error)
}
});

this.getMessages<IRegisterNewUserMessage, User>(AuthEvents.GENERATE_NEW_TOKEN_BASED_ON_USER_PROVIDER,
async (msg: ProviderAuthUser) => {
try {
let user = await (new DataBaseHelper(User)).findOne({ username: msg.username });
let user = await (new DataBaseHelper(User))
.findOne({ username: msg.username, template: { $ne: true } });
if (!user) {
user = await createNewUser(
msg.username,
Expand Down Expand Up @@ -368,7 +401,10 @@ export class AccountService extends NatsService {

const REFRESH_TOKEN_UPDATE_INTERVAL = process.env.REFRESH_TOKEN_UPDATE_INTERVAL || '31536000000' // 1 year

const user = await new DataBaseHelper(User).findOne({ username });
const user = await new DataBaseHelper(User).findOne({
username,
template: { $ne: true }
});
if (user && passwordDigest === user.password) {
const tokenId = GenerateUUIDv4();
const refreshToken = sign({
Expand Down Expand Up @@ -405,7 +441,11 @@ export class AccountService extends NatsService {
return new MessageResponse({})
}

const user = await new DataBaseHelper(User).findOne({ refreshToken: decryptedToken.id, username: decryptedToken.name });
const user = await new DataBaseHelper(User).findOne({
refreshToken: decryptedToken.id,
username: decryptedToken.name,
template: { $ne: true }
});
if (!user) {
return new MessageResponse({})
}
Expand All @@ -424,9 +464,22 @@ export class AccountService extends NatsService {

this.getMessages<IUpdateUserMessage, any>(AuthEvents.UPDATE_USER, async (msg) => {
const { username, item } = msg;

try {
return new MessageResponse(await new DataBaseHelper(User).update(item, { username }));
const user = await (new DataBaseHelper(User))
.findOne({ username });
if (!user) {
return new MessageResponse(null);
}
Object.assign(user, item);
const template = await (new DataBaseHelper(User))
.findOne({ did: item.did, template: true });
if (template) {
user.permissions = template.permissions;
user.permissionsGroup = template.permissionsGroup;
await new DataBaseHelper(User).delete(template);
}
const result = await new DataBaseHelper(User).update(user);
return new MessageResponse(result);
} catch (error) {
new Logger().error(error, ['AUTH_SERVICE']);
return new MessageError(error);
Expand All @@ -435,7 +488,6 @@ export class AccountService extends NatsService {

this.getMessages<ISaveUserMessage, IUser>(AuthEvents.SAVE_USER, async (msg) => {
const { user } = msg;

try {
return new MessageResponse(await new DataBaseHelper(User).save(user));
} catch (error) {
Expand All @@ -459,6 +511,7 @@ export class AccountService extends NatsService {
'role',
'permissionsGroup',
'permissions',
'template'
]
};
const _pageSize = parseInt(pageSize, 10);
Expand Down
Loading

0 comments on commit 1f01aba

Please sign in to comment.