mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-13 16:04:49 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7da68241e | ||
|
|
7245942707 | ||
|
|
c29cf5aee1 | ||
|
|
3d39affc61 | ||
|
|
5d045b675c |
Generated
+14
-14
@@ -11,8 +11,8 @@
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.3",
|
||||
"@dadosfera/protospack-v2": "3.17.5",
|
||||
"@dadosfera/dadosfera-logs": "1.0.0-beta.4",
|
||||
"@dadosfera/protospack-v2": "3.17.6",
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"@grpc/proto-loader": "^0.6.13",
|
||||
"@nestjs/common": "^8.4.7",
|
||||
@@ -1716,9 +1716,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@dadosfera/dadosfera-logs": {
|
||||
"version": "1.0.0-beta.3",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/dadosfera-logs/-/dadosfera-logs-1.0.0-beta.3.tgz",
|
||||
"integrity": "sha512-VuGiQlpDulcl1+FSFoT4/6PA9Pr+DAzbFHAYesz9rPinR46ejG7ZBZk3m86NYqQtgMyurqXvgCR8GPy9FpwqFw==",
|
||||
"version": "1.0.0-beta.4",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/dadosfera-logs/-/dadosfera-logs-1.0.0-beta.4.tgz",
|
||||
"integrity": "sha512-fFncbNVMbfQa2EFl7NJgmtuSRWHGtmwCbl5p++lSLvGcTIMjLGJ4HAMzSMemQhSxiiYlokdwweb7jJY7Ms62SQ==",
|
||||
"dependencies": {
|
||||
"@elastic/ecs-winston-format": "^1.3.1",
|
||||
"winston": "^3.7.2",
|
||||
@@ -1726,9 +1726,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@dadosfera/protospack-v2": {
|
||||
"version": "3.17.5",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.17.5.tgz",
|
||||
"integrity": "sha512-pVi9yCqCIngreW/z75jDqo7dladmN/z49K5m2vdd4ljS7yR21XicrCIg+YxSOwFga4wa3c8bI6WZ40Mp8ah8IA==",
|
||||
"version": "3.17.6",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.17.6.tgz",
|
||||
"integrity": "sha512-PuG2nWiCq7WWdHtWPBJVMDS6G2OggXT6rnBONGIRvUCpoBFI3MFTao2Z51Z8xVsV3HG79O9VyQnS4N+350Dtmw==",
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"rxjs": "^7.5.5",
|
||||
@@ -12295,9 +12295,9 @@
|
||||
}
|
||||
},
|
||||
"@dadosfera/dadosfera-logs": {
|
||||
"version": "1.0.0-beta.3",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/dadosfera-logs/-/dadosfera-logs-1.0.0-beta.3.tgz",
|
||||
"integrity": "sha512-VuGiQlpDulcl1+FSFoT4/6PA9Pr+DAzbFHAYesz9rPinR46ejG7ZBZk3m86NYqQtgMyurqXvgCR8GPy9FpwqFw==",
|
||||
"version": "1.0.0-beta.4",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/dadosfera-logs/-/dadosfera-logs-1.0.0-beta.4.tgz",
|
||||
"integrity": "sha512-fFncbNVMbfQa2EFl7NJgmtuSRWHGtmwCbl5p++lSLvGcTIMjLGJ4HAMzSMemQhSxiiYlokdwweb7jJY7Ms62SQ==",
|
||||
"requires": {
|
||||
"@elastic/ecs-winston-format": "^1.3.1",
|
||||
"winston": "^3.7.2",
|
||||
@@ -12305,9 +12305,9 @@
|
||||
}
|
||||
},
|
||||
"@dadosfera/protospack-v2": {
|
||||
"version": "3.17.5",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.17.5.tgz",
|
||||
"integrity": "sha512-pVi9yCqCIngreW/z75jDqo7dladmN/z49K5m2vdd4ljS7yR21XicrCIg+YxSOwFga4wa3c8bI6WZ40Mp8ah8IA==",
|
||||
"version": "3.17.6",
|
||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com:443/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.17.6.tgz",
|
||||
"integrity": "sha512-PuG2nWiCq7WWdHtWPBJVMDS6G2OggXT6rnBONGIRvUCpoBFI3MFTao2Z51Z8xVsV3HG79O9VyQnS4N+350Dtmw==",
|
||||
"requires": {
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"rxjs": "^7.5.5",
|
||||
|
||||
+2
-2
@@ -26,8 +26,8 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-secrets-manager": "^3.112.0",
|
||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.3",
|
||||
"@dadosfera/protospack-v2": "3.17.5",
|
||||
"@dadosfera/dadosfera-logs": "1.0.0-beta.4",
|
||||
"@dadosfera/protospack-v2": "3.17.6",
|
||||
"@grpc/grpc-js": "^1.6.7",
|
||||
"@grpc/proto-loader": "^0.6.13",
|
||||
"@nestjs/common": "^8.4.7",
|
||||
|
||||
@@ -166,16 +166,16 @@ export const PERMISSIONS_GROUPS = {
|
||||
'es-es': 'Crear VPN',
|
||||
},
|
||||
},
|
||||
DELETE: {
|
||||
seqid: 36,
|
||||
claim: 'network_config:delete',
|
||||
usage: PermissionUsages.PUBLIC,
|
||||
name: {
|
||||
'pt-br': 'Excluir VPN',
|
||||
'en-us': 'Remove VPN',
|
||||
'es-es': 'Eliminar VPN',
|
||||
},
|
||||
},
|
||||
// DELETE: {
|
||||
// seqid: 36,
|
||||
// claim: 'network_config:delete',
|
||||
// usage: PermissionUsages.PUBLIC,
|
||||
// name: {
|
||||
// 'pt-br': 'Excluir VPN',
|
||||
// 'en-us': 'Remove VPN',
|
||||
// 'es-es': 'Eliminar VPN',
|
||||
// },
|
||||
// },
|
||||
},
|
||||
},
|
||||
|
||||
@@ -504,7 +504,7 @@ export const PERMISSIONS_GROUPS = {
|
||||
'es-es': 'Usuarios',
|
||||
},
|
||||
permissions: {
|
||||
ADMIN: {
|
||||
CONNECTIONS_MIGRATION: {
|
||||
seqid: 40,
|
||||
claim: 'dadosfera:connections-migration',
|
||||
usage: PermissionUsages.INTERNAL,
|
||||
@@ -514,6 +514,16 @@ export const PERMISSIONS_GROUPS = {
|
||||
'es-es': 'connections-migration',
|
||||
},
|
||||
},
|
||||
SYNC_USER: {
|
||||
seqid: 41,
|
||||
claim: 'dadosfera:sync-user',
|
||||
usage: PermissionUsages.INTERNAL,
|
||||
name: {
|
||||
'pt-br': 'sync-user',
|
||||
'en-us': 'sync-user',
|
||||
'es-es': 'sync-user',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -45,7 +45,9 @@ export class ConnectionController {
|
||||
}
|
||||
|
||||
@Get('connections-migration')
|
||||
@RequireAllPermissions(PERMISSIONS_GROUPS.DADOSFERA.permissions.ADMIN)
|
||||
@RequireAllPermissions(
|
||||
PERMISSIONS_GROUPS.DADOSFERA.permissions.CONNECTIONS_MIGRATION,
|
||||
)
|
||||
async synchronizeConnections(@Query('apply') apply: string) {
|
||||
return this.clientService.synchronizeConnections(apply === 'true');
|
||||
}
|
||||
@@ -103,29 +105,29 @@ export class ConnectionController {
|
||||
return response;
|
||||
}
|
||||
|
||||
@Delete('/:id')
|
||||
// @Delete('/:id')
|
||||
// @RequireAllPermissions(connectionPermissions.DELETE)
|
||||
async deleteConnection(
|
||||
@User() user: RequestUser,
|
||||
@Param('id') id: string,
|
||||
): Promise<ConnectionRes> {
|
||||
this.logger.info('/connections - Delete Connection');
|
||||
// async deleteConnection(
|
||||
// @User() user: RequestUser,
|
||||
// @Param('id') id: string,
|
||||
// ): Promise<ConnectionRes> {
|
||||
// this.logger.info('/connections - Delete Connection');
|
||||
|
||||
const { user_id, customer_id, customer_name, username } = user;
|
||||
const metadata = PackTheMetadata({
|
||||
user_id,
|
||||
customer_id,
|
||||
customer_name,
|
||||
username,
|
||||
});
|
||||
// const { user_id, customer_id, customer_name, username } = user;
|
||||
// const metadata = PackTheMetadata({
|
||||
// user_id,
|
||||
// customer_id,
|
||||
// customer_name,
|
||||
// username,
|
||||
// });
|
||||
|
||||
const response: any = await this.clientService.deleteConnection({
|
||||
body: { id },
|
||||
metadata,
|
||||
});
|
||||
// const response: any = await this.clientService.deleteConnection({
|
||||
// body: { id },
|
||||
// metadata,
|
||||
// });
|
||||
|
||||
return response;
|
||||
}
|
||||
// return response;
|
||||
// }
|
||||
|
||||
@Get()
|
||||
async getAllConnections(
|
||||
|
||||
@@ -25,7 +25,10 @@ import {
|
||||
UpdateNetworkConfigRes,
|
||||
} from './dto/network-config';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||
import { RequireAllPermissions } from 'src/authentication/authentication.decorator';
|
||||
|
||||
const networkConfigPermissions = PERMISSIONS_GROUPS.NETWORK_CONFIG.permissions;
|
||||
@ApiTags('Network Config')
|
||||
@Controller('network-config')
|
||||
export class NetworkConfigController {
|
||||
@@ -92,6 +95,7 @@ export class NetworkConfigController {
|
||||
|
||||
@Post()
|
||||
@ApiOkResponse({ type: CreateNetworkConfigRes })
|
||||
@RequireAllPermissions(networkConfigPermissions.CREATE)
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@UseInterceptors(FileInterceptor('ovpn_file'))
|
||||
async createNetworkConfigs(
|
||||
@@ -111,36 +115,37 @@ export class NetworkConfigController {
|
||||
});
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@ApiOkResponse({ type: UpdateNetworkConfigRes })
|
||||
async updateNetworkConfig(
|
||||
@User() user: RequestUser,
|
||||
@Param('id') network_config_id: string,
|
||||
@Body() body: UpdateNetworkConfigReq,
|
||||
) {
|
||||
this.logger.info('PATCH /network-config/:id', {
|
||||
user: user.user_id,
|
||||
customer: user.customer_name,
|
||||
});
|
||||
return this.networkConfigService.updateNetworkConfig(
|
||||
body,
|
||||
network_config_id,
|
||||
);
|
||||
}
|
||||
// @Patch(':id')
|
||||
// @ApiOkResponse({ type: UpdateNetworkConfigRes })
|
||||
// @RequireAllPermissions(networkConfigPermissions.CREATE)
|
||||
// async updateNetworkConfig(
|
||||
// @User() user: RequestUser,
|
||||
// @Param('id') network_config_id: string,
|
||||
// @Body() body: UpdateNetworkConfigReq,
|
||||
// ) {
|
||||
// this.logger.info('PATCH /network-config/:id', {
|
||||
// user: user.user_id,
|
||||
// customer: user.customer_name,
|
||||
// });
|
||||
// return this.networkConfigService.updateNetworkConfig(
|
||||
// body,
|
||||
// network_config_id,
|
||||
// );
|
||||
// }
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOkResponse({ type: DeleteNetworkConfigRes })
|
||||
async deleteNetworkConfig(
|
||||
@User() user: RequestUser,
|
||||
@Param('id') network_config_id: string,
|
||||
) {
|
||||
this.logger.info('DELETE /network-config', {
|
||||
user: user.user_id,
|
||||
customer: user.customer_name,
|
||||
});
|
||||
return this.networkConfigService.deleteNetworkConfig(network_config_id, {
|
||||
customer_name: user.customer_name,
|
||||
customer_id: user.customer_id,
|
||||
});
|
||||
}
|
||||
// @Delete(':id')
|
||||
// @ApiOkResponse({ type: DeleteNetworkConfigRes })
|
||||
// async deleteNetworkConfig(
|
||||
// @User() user: RequestUser,
|
||||
// @Param('id') network_config_id: string,
|
||||
// ) {
|
||||
// this.logger.info('DELETE /network-config', {
|
||||
// user: user.user_id,
|
||||
// customer: user.customer_name,
|
||||
// });
|
||||
// return this.networkConfigService.deleteNetworkConfig(network_config_id, {
|
||||
// customer_name: user.customer_name,
|
||||
// customer_id: user.customer_id,
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ import {
|
||||
UserByCustomer,
|
||||
} from './dtos/entities';
|
||||
import { UsersService } from './users.service';
|
||||
import { Metadata } from '@grpc/grpc-js';
|
||||
|
||||
// TODO GET de hierarquias e do PATCH em usuário
|
||||
@ApiTags('Users')
|
||||
@@ -141,9 +142,12 @@ export class UsersController {
|
||||
@Body() body: CreateUserReq,
|
||||
@Headers('dadosfera-lang') language,
|
||||
) {
|
||||
const meta = new Metadata();
|
||||
meta.add('access_token', user.access_token);
|
||||
this.logger.info('createUser', { user });
|
||||
this.userService.setLanguage(language);
|
||||
return await this.userService.createUser(body);
|
||||
|
||||
return await this.userService.createUser(body, meta);
|
||||
}
|
||||
|
||||
@Post('batch')
|
||||
@@ -154,9 +158,11 @@ export class UsersController {
|
||||
@Body() body: BatchCreateUserReq,
|
||||
@Headers('dadosfera-lang') language,
|
||||
) {
|
||||
const meta = new Metadata();
|
||||
meta.add('access_token', user.access_token);
|
||||
this.logger.info('batchCreateUser', { user });
|
||||
this.userService.setLanguage(language);
|
||||
return await this.userService.batchCreateUser(body);
|
||||
return await this.userService.batchCreateUser(body, meta);
|
||||
}
|
||||
|
||||
@Post(':id/resend-invite')
|
||||
@@ -235,4 +241,12 @@ export class UsersController {
|
||||
this.userService.setLanguage(language);
|
||||
return await this.userService.updateUser(body, id, user.customer_id);
|
||||
}
|
||||
|
||||
@Post('synchronize/:id')
|
||||
@RequireAllPermissions(PERMISSIONS_GROUPS.DADOSFERA.permissions.SYNC_USER)
|
||||
@ApiOkResponse({ type: UpdateUserRes })
|
||||
async synchronizeUser(@User() user: RequestUser, @Param('id') id: string) {
|
||||
this.logger.info('synchronizeUser', { user });
|
||||
return await this.userService.synchronizeUser(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import { LanguageEnum } from 'src/utils/languages.enum';
|
||||
import { UserByCustomer } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/entities';
|
||||
import { EnrichErrorCode } from 'src/utils/ErrorBuilder';
|
||||
import { DucClient } from '../duc/client.config';
|
||||
import { Metadata } from '@grpc/grpc-js';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService implements OnModuleInit {
|
||||
@@ -83,18 +84,21 @@ export class UsersService implements OnModuleInit {
|
||||
return { user: this.adjustUsersPayload([user])[0] };
|
||||
}
|
||||
|
||||
async createUser(req: CreateUserReq) {
|
||||
async createUser(req: CreateUserReq, meta?: Metadata) {
|
||||
const { email, department, hierarchy, jobTitle, name, roleNames } = req;
|
||||
const { user } = await lastValueFrom(
|
||||
this.usersClientService.UserCreate({
|
||||
email,
|
||||
hierarchy,
|
||||
name,
|
||||
roleIds: [],
|
||||
department,
|
||||
jobTitle,
|
||||
roleNames,
|
||||
}),
|
||||
this.usersClientService.UserCreate(
|
||||
{
|
||||
email,
|
||||
hierarchy,
|
||||
name,
|
||||
roleIds: [],
|
||||
department,
|
||||
jobTitle,
|
||||
roleNames,
|
||||
},
|
||||
meta,
|
||||
),
|
||||
);
|
||||
return { user: this.adjustUsersPayload([user])[0] };
|
||||
}
|
||||
@@ -134,7 +138,8 @@ export class UsersService implements OnModuleInit {
|
||||
return { user: this.adjustUsersPayload([user])[0] };
|
||||
}
|
||||
|
||||
async batchCreateUser({ users }: BatchCreateUserReq) {
|
||||
async batchCreateUser(req: BatchCreateUserReq, meta?: Metadata) {
|
||||
const { users } = req;
|
||||
const usersToCreate: UserCreateRequest[] = users.map(
|
||||
({ roleNames, email, department, hierarchy, jobTitle, name }) => ({
|
||||
roleNames,
|
||||
@@ -147,14 +152,16 @@ export class UsersService implements OnModuleInit {
|
||||
}),
|
||||
);
|
||||
const { errorUsers, usersCreated } = await lastValueFrom(
|
||||
this.usersClientService.UserBatchCreate({
|
||||
users: usersToCreate,
|
||||
}),
|
||||
this.usersClientService.UserBatchCreate(
|
||||
{
|
||||
users: usersToCreate,
|
||||
},
|
||||
meta,
|
||||
),
|
||||
);
|
||||
|
||||
return {
|
||||
usersCreated: this.adjustUsersPayload(usersCreated),
|
||||
// mapping error code to message
|
||||
errorUsers: errorUsers.map(({ user, error }) => ({
|
||||
user,
|
||||
error: EnrichErrorCode(error).message,
|
||||
@@ -212,4 +219,10 @@ export class UsersService implements OnModuleInit {
|
||||
async findAllCustomers() {
|
||||
return await lastValueFrom(this.customersClientService.CustomerFindAll({}));
|
||||
}
|
||||
|
||||
async synchronizeUser(userId: string) {
|
||||
return await lastValueFrom(
|
||||
this.usersClientService.INTERNAL_UserSynchronize({ userId }),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,6 +185,14 @@ export function EnrichErrorCode(code: string) {
|
||||
code,
|
||||
};
|
||||
|
||||
case ErrorCodes.USER.NOT_CREATED:
|
||||
return {
|
||||
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
error: 'Ocorreu um erro ao criar seu usúario',
|
||||
message: 'Tente novamente ou entre em contato com o suporte',
|
||||
code,
|
||||
};
|
||||
|
||||
case ErrorCodes.USER.NOT_FOUND:
|
||||
return {
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
|
||||
@@ -31,6 +31,7 @@ export const USER = {
|
||||
ALREADY_EXISTS: 'USER.ALREADY_EXISTS',
|
||||
ROLE_ALREADY_ASSIGNED: 'USER.ROLE_ALREADY_ASSIGNED',
|
||||
ROLE_NOT_ASSIGNED: 'USER.ROLE_NOT_ASSIGNED',
|
||||
NOT_CREATED: 'USER.NOT_CREATED',
|
||||
};
|
||||
|
||||
export const CUSTOMER = {
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user