Compare commits

...
13 Commits
9 changed files with 126 additions and 35 deletions
+24 -1
View File
@@ -1587,6 +1587,17 @@
], ],
"type": "string" "type": "string"
} }
},
{
"name": "canUntoggleLogic",
"required": false,
"in": "query",
"schema": {
"enum": [
"data_assets_sharing"
],
"type": "string"
}
} }
], ],
"responses": { "responses": {
@@ -3339,7 +3350,7 @@
} }
}, },
"info": { "info": {
"title": "Maestro - main", "title": "Maestro - fix/can-untoggle",
"description": "Documentation for Maestro gateway", "description": "Documentation for Maestro gateway",
"version": "1.0.0", "version": "1.0.0",
"contact": {} "contact": {}
@@ -3993,6 +4004,10 @@
}, },
"usage": { "usage": {
"type": "string" "type": "string"
},
"canUntoggle": {
"type": "boolean",
"description": "Whether this role can be untoggled"
} }
}, },
"required": [ "required": [
@@ -4470,6 +4485,10 @@
}, },
"usage": { "usage": {
"type": "string" "type": "string"
},
"canUntoggle": {
"type": "boolean",
"description": "Whether this role can be untoggled"
} }
}, },
"required": [ "required": [
@@ -4560,6 +4579,10 @@
}, },
"usage": { "usage": {
"type": "string" "type": "string"
},
"canUntoggle": {
"type": "boolean",
"description": "Whether this role can be untoggled"
} }
}, },
"required": [ "required": [
+7 -7
View File
@@ -12,7 +12,7 @@
"dependencies": { "dependencies": {
"@aws-sdk/client-secrets-manager": "^3.112.0", "@aws-sdk/client-secrets-manager": "^3.112.0",
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4", "@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
"@dadosfera/protospack-v2": "3.27.1", "@dadosfera/protospack-v2": "3.27.2",
"@grpc/grpc-js": "^1.6.7", "@grpc/grpc-js": "^1.6.7",
"@grpc/proto-loader": "^0.6.13", "@grpc/proto-loader": "^0.6.13",
"@nestjs/common": "^8.4.7", "@nestjs/common": "^8.4.7",
@@ -1727,9 +1727,9 @@
} }
}, },
"node_modules/@dadosfera/protospack-v2": { "node_modules/@dadosfera/protospack-v2": {
"version": "3.27.1", "version": "3.27.2",
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.27.1.tgz", "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.27.2.tgz",
"integrity": "sha512-bAhHSS1cquIJadHiWSO1FFJFfugrJXEIWKFzE7PByeC9XldGru/qlART7KXbxqYHQq8lALKJy1ILyMyG91BsTA==", "integrity": "sha512-WDdneA/+AuRMrgbqU84NgaTw9HLp7HYWbVMEqxTEli+JizoiSYpAQ9ZmG6TnXgsTAdjZf7DOOVdY3OKNxRjWig==",
"dependencies": { "dependencies": {
"@grpc/grpc-js": "^1.6.7", "@grpc/grpc-js": "^1.6.7",
"rxjs": "^7.5.5", "rxjs": "^7.5.5",
@@ -12284,9 +12284,9 @@
} }
}, },
"@dadosfera/protospack-v2": { "@dadosfera/protospack-v2": {
"version": "3.27.1", "version": "3.27.2",
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.27.1.tgz", "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.27.2.tgz",
"integrity": "sha512-bAhHSS1cquIJadHiWSO1FFJFfugrJXEIWKFzE7PByeC9XldGru/qlART7KXbxqYHQq8lALKJy1ILyMyG91BsTA==", "integrity": "sha512-WDdneA/+AuRMrgbqU84NgaTw9HLp7HYWbVMEqxTEli+JizoiSYpAQ9ZmG6TnXgsTAdjZf7DOOVdY3OKNxRjWig==",
"requires": { "requires": {
"@grpc/grpc-js": "^1.6.7", "@grpc/grpc-js": "^1.6.7",
"rxjs": "^7.5.5", "rxjs": "^7.5.5",
+1 -1
View File
@@ -28,7 +28,7 @@
"dependencies": { "dependencies": {
"@aws-sdk/client-secrets-manager": "^3.112.0", "@aws-sdk/client-secrets-manager": "^3.112.0",
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4", "@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
"@dadosfera/protospack-v2": "3.27.1", "@dadosfera/protospack-v2": "3.27.2",
"@grpc/grpc-js": "^1.6.7", "@grpc/grpc-js": "^1.6.7",
"@grpc/proto-loader": "^0.6.13", "@grpc/proto-loader": "^0.6.13",
"@nestjs/common": "^8.4.7", "@nestjs/common": "^8.4.7",
+9 -5
View File
@@ -29,7 +29,6 @@ import { AuthClientService } from './auth.service';
import { DadosferaLogger } from '@dadosfera/dadosfera-logs'; import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
import { GrpcToHttpExceptionFilter } from '../../error/grpc-to-http-exception.filter'; import { GrpcToHttpExceptionFilter } from '../../error/grpc-to-http-exception.filter';
import { RequestUser, User } from 'src/authentication/user.decorator'; import { RequestUser, User } from 'src/authentication/user.decorator';
import { Metadata } from '@grpc/grpc-js';
import { import {
AuthRefreshAccessTokenReq, AuthRefreshAccessTokenReq,
AuthSignInReq, AuthSignInReq,
@@ -58,8 +57,7 @@ export class AuthController {
@Headers('Dadosfera-Lang') language: string, @Headers('Dadosfera-Lang') language: string,
): Promise<AuthSignInRes> { ): Promise<AuthSignInRes> {
this.logger.info('/auth - SignIn'); this.logger.info('/auth - SignIn');
const metadata = new Metadata(); const metadata = PackTheMetadata({ language: language || 'pt-br' });
metadata.add('language', language || 'pt-br');
return this.authClient.signIn({ username, password, totp }, metadata); return this.authClient.signIn({ username, password, totp }, metadata);
} }
@@ -115,12 +113,18 @@ export class AuthController {
@Post('reset-password') @Post('reset-password')
@HttpCode(HttpStatus.OK) @HttpCode(HttpStatus.OK)
async resetPassword(@Body() body: AuthResetPasswordRequest) { async resetPassword(
@Body() body: AuthResetPasswordRequest,
@Headers('dadosfera-lang') language,
) {
this.logger.info('/auth - reset-password'); this.logger.info('/auth - reset-password');
const metadata = PackTheMetadata({
language: language,
});
const { username } = body; const { username } = body;
return this.authClient.resetPassword({ username }); return this.authClient.resetPassword({ username }, metadata);
} }
@Post('verify-reset-password-code') @Post('verify-reset-password-code')
+7 -2
View File
@@ -90,10 +90,15 @@ export class AuthClientService implements OnModuleInit {
); );
} }
async resetPassword({ username }: AuthResetPasswordRequest) { async resetPassword(
{ username }: AuthResetPasswordRequest,
metadata: Metadata,
) {
this.logger.info('resetPassword'); this.logger.info('resetPassword');
return lastValueFrom(this.authService.AuthResetPassword({ username })); return lastValueFrom(
this.authService.AuthResetPassword({ username }, metadata),
);
} }
async verifyResetPasswordCode({ async verifyResetPasswordCode({
+60 -2
View File
@@ -15,9 +15,55 @@ export class MixpanelController {
delete body.info; delete body.info;
const mixpanel = init(this.mixpanelToken); const mixpanel = init(this.mixpanelToken);
const separator = user.username.includes('-') ? '-' : '.';
const removeValues = [
'.dadosferatech.dadosfera',
'.demo.dadosfera',
'.dadosferademo',
'.dadosferarh.dadosfera',
'.dadosferatech.dadosfera2',
'.dadosferatech.dadosfera',
'.dadosfera.fin',
'.dadosferafin.dadosfera',
'.praxio.dadosfera',
'.dadosfera.tech',
'.treinamentos@dadosfera.ai',
'.dadosfera2',
'.treinamentosfera',
'.dadosfera',
];
let username = user.username;
removeValues.forEach((value) => {
username = username.replace(value, '');
});
username = username.split('@')?.[0];
username = username.split('+')?.[0];
let firstName = username
.substring(0, username.indexOf(separator))
.replace('dadosfera', '');
let lastName = username
.substring(username.lastIndexOf(separator) + 1)
.replace('dadosfera', '');
if (!firstName) {
firstName = lastName;
lastName = '';
}
firstName = this.capitalize(firstName);
lastName = this.capitalize(lastName);
await mixpanel.people.set(user.username, { await mixpanel.people.set(user.username, {
$name: user.username, $first_name: firstName,
$email: user.username, $last_name: lastName,
$name: this.getFullName(firstName, lastName),
$email: user.username.includes('@')
? user.username
: user.username + '@dadosfera.ai',
customer_name: user.customer_name, customer_name: user.customer_name,
}); });
@@ -30,4 +76,16 @@ export class MixpanelController {
return { id, body, user: user.username }; return { id, body, user: user.username };
} }
capitalize(sentence: string): string {
if (!sentence) {
return '';
}
return sentence[0].toUpperCase() + sentence.substring(1);
}
getFullName(firstName: string, lastName: string) {
return `${firstName}${lastName ? ' ' + lastName : ''}`;
}
} }
+8
View File
@@ -25,6 +25,8 @@ export class RoleDto {
customer?: Customer; customer?: Customer;
@ApiProperty() @ApiProperty()
usage: string; usage: string;
@ApiPropertyOptional({ description: 'Whether this role can be untoggled' })
canUntoggle?: boolean;
} }
export class CustomerRole extends OmitType(RoleDto, ['customer']) {} export class CustomerRole extends OmitType(RoleDto, ['customer']) {}
@@ -34,11 +36,17 @@ export enum TrueOrFalseEnum {
true = 'true', true = 'true',
false = 'false', false = 'false',
} }
export enum CanUntoggleLogicEnum {
data_assets_sharing = 'data_assets_sharing',
}
export class GetRolesByCustomerReq { export class GetRolesByCustomerReq {
@ApiPropertyOptional() @ApiPropertyOptional()
permissionId?: string[]; permissionId?: string[];
@ApiPropertyOptional({ enum: TrueOrFalseEnum }) @ApiPropertyOptional({ enum: TrueOrFalseEnum })
getUsers?: TrueOrFalseEnum; getUsers?: TrueOrFalseEnum;
@ApiPropertyOptional({ enum: CanUntoggleLogicEnum })
canUntoggleLogic?: CanUntoggleLogicEnum;
} }
export class GetRolesByCustomerRes { export class GetRolesByCustomerRes {
+2 -2
View File
@@ -71,12 +71,12 @@ export class RolesController {
@ApiOkResponse({ type: GetRolesByCustomerRes }) @ApiOkResponse({ type: GetRolesByCustomerRes })
async searchRoles( async searchRoles(
@User() user: RequestUser, @User() user: RequestUser,
@Query() filters: GetRolesByCustomerReq, @Query() params: GetRolesByCustomerReq,
@Headers('dadosfera-lang') language, @Headers('dadosfera-lang') language,
) { ) {
this.logger.info('searchRoles', { user }); this.logger.info('searchRoles', { user });
this.rolesService.setLanguage(language); this.rolesService.setLanguage(language);
return await this.rolesService.roleSearch(filters, user); return await this.rolesService.roleSearch(params, user);
} }
@Post() @Post()
+8 -15
View File
@@ -70,12 +70,7 @@ export class RolesService {
return { role: roleTreated }; return { role: roleTreated };
} }
async roleSearch( async roleSearch(filters: GetRolesByCustomerReq, { customer_id }) {
filters: GetRolesByCustomerReq,
{ customer_id, access_token }: any,
) {
const meta = new Metadata();
meta.add('access_token', access_token);
let { permissionId: permissionIds } = filters; let { permissionId: permissionIds } = filters;
if (permissionIds && !Array.isArray(permissionIds)) if (permissionIds && !Array.isArray(permissionIds))
permissionIds = [permissionIds]; permissionIds = [permissionIds];
@@ -89,15 +84,13 @@ export class RolesService {
return seqId; return seqId;
}) || []; }) || [];
const roles = await lastValueFrom( const roles = await lastValueFrom(
this.rolesClientService.RoleSearch( this.rolesClientService.RoleSearch({
{ customerId: customer_id,
customerId: customer_id, getUsers: isGetUsers,
getUsers: isGetUsers, permissionIds: [],
permissionIds: [], permissionSeqIds,
permissionSeqIds, canUntoggleLogic: filters.canUntoggleLogic,
}, }),
meta,
),
); );
const rolesTreated = this.getRolesPermissionsName(roles.roles); const rolesTreated = this.getRolesPermissionsName(roles.roles);
return { roles: rolesTreated }; return { roles: rolesTreated };