mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-20 03:19:07 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
419c063c6c | ||
|
|
2aed66d371 |
-234
@@ -20,14 +20,6 @@
|
|||||||
],
|
],
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "host",
|
|
||||||
"required": true,
|
|
||||||
"in": "header",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
@@ -72,14 +64,6 @@
|
|||||||
],
|
],
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "host",
|
|
||||||
"required": true,
|
|
||||||
"in": "header",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
@@ -558,123 +542,6 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/auth/users/block": {
|
|
||||||
"post": {
|
|
||||||
"operationId": "AuthController_blockUsers",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "dadosfera-lang",
|
|
||||||
"in": "header",
|
|
||||||
"required": false,
|
|
||||||
"schema": {
|
|
||||||
"enum": [
|
|
||||||
"pt-br",
|
|
||||||
"en-us"
|
|
||||||
],
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"tags": [
|
|
||||||
"Auth"
|
|
||||||
],
|
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"access-token": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/auth/users/unblock": {
|
|
||||||
"post": {
|
|
||||||
"operationId": "AuthController_unblockUsers",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "dadosfera-lang",
|
|
||||||
"in": "header",
|
|
||||||
"required": false,
|
|
||||||
"schema": {
|
|
||||||
"enum": [
|
|
||||||
"pt-br",
|
|
||||||
"en-us"
|
|
||||||
],
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"tags": [
|
|
||||||
"Auth"
|
|
||||||
],
|
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"access-token": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/auth/users/reset": {
|
|
||||||
"post": {
|
|
||||||
"operationId": "AuthController_resetUsers",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "dadosfera-lang",
|
|
||||||
"in": "header",
|
|
||||||
"required": false,
|
|
||||||
"schema": {
|
|
||||||
"enum": [
|
|
||||||
"pt-br",
|
|
||||||
"en-us"
|
|
||||||
],
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"tags": [
|
|
||||||
"Auth"
|
|
||||||
],
|
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"access-token": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/connections": {
|
"/connections": {
|
||||||
"post": {
|
"post": {
|
||||||
"operationId": "ConnectionController_createConnection",
|
"operationId": "ConnectionController_createConnection",
|
||||||
@@ -5753,93 +5620,6 @@
|
|||||||
"Health"
|
"Health"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"/network-policy": {
|
|
||||||
"get": {
|
|
||||||
"operationId": "NetworkPolicyController_getNetworks",
|
|
||||||
"parameters": [],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/NetworkPoliciesDTO"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"access-token": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"access-token": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"post": {
|
|
||||||
"operationId": "NetworkPolicyController_applyNetworkPolicies",
|
|
||||||
"parameters": [],
|
|
||||||
"requestBody": {
|
|
||||||
"required": true,
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/NetworkPoliciesDTO"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"responses": {
|
|
||||||
"201": {
|
|
||||||
"description": "",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"type": "object"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"access-token": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"access-token": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"delete": {
|
|
||||||
"operationId": "NetworkPolicyController_removeNetworkPolicies",
|
|
||||||
"parameters": [],
|
|
||||||
"requestBody": {
|
|
||||||
"required": true,
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/NetworkPoliciesDTO"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"access-token": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"access-token": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"info": {
|
"info": {
|
||||||
@@ -8691,20 +8471,6 @@
|
|||||||
"required": [
|
"required": [
|
||||||
"theme"
|
"theme"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"NetworkPoliciesDTO": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"policies": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"policies"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+494
-1556
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -30,7 +30,7 @@
|
|||||||
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
||||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack": "2.5.3",
|
"@dadosfera/protospack": "2.5.3",
|
||||||
"@dadosfera/protospack-v2": "3.37.0-alpha.20",
|
"@dadosfera/protospack-v2": "^3.37.0-beta.10 ",
|
||||||
"@grpc/grpc-js": "^1.9.3",
|
"@grpc/grpc-js": "^1.9.3",
|
||||||
"@grpc/proto-loader": "^0.7.9",
|
"@grpc/proto-loader": "^0.7.9",
|
||||||
"@nestjs/cli": "^9.5.0",
|
"@nestjs/cli": "^9.5.0",
|
||||||
|
|||||||
+1
-3
@@ -28,7 +28,6 @@ import { MixpanelModule } from './modules/mixpanel/mixpanel.module';
|
|||||||
import { CustomersModule } from './modules/customers/customers.module';
|
import { CustomersModule } from './modules/customers/customers.module';
|
||||||
import { OpenDataModule } from './modules/open-data/open-data.module';
|
import { OpenDataModule } from './modules/open-data/open-data.module';
|
||||||
import { ThemeModule } from './modules/theme/theme.module';
|
import { ThemeModule } from './modules/theme/theme.module';
|
||||||
import { NetworkPolicyModule } from './modules/network-policy/network-policy.module';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [
|
providers: [
|
||||||
@@ -63,8 +62,7 @@ import { NetworkPolicyModule } from './modules/network-policy/network-policy.mod
|
|||||||
OpenDataModule,
|
OpenDataModule,
|
||||||
ThemeModule,
|
ThemeModule,
|
||||||
//Always leave HealthModule last, so it is on the bottom of swagger
|
//Always leave HealthModule last, so it is on the bottom of swagger
|
||||||
HealthModule,
|
HealthModule
|
||||||
NetworkPolicyModule
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ export class AuthenticationGuard
|
|||||||
customer_id: accessTokenPayload.customer_id,
|
customer_id: accessTokenPayload.customer_id,
|
||||||
customer_name: accessTokenPayload.customer_name,
|
customer_name: accessTokenPayload.customer_name,
|
||||||
customer_tier: accessTokenPayload.customer_tier,
|
customer_tier: accessTokenPayload.customer_tier,
|
||||||
|
customer_modules: accessTokenPayload.customer_modules,
|
||||||
access_token: accessToken,
|
access_token: accessToken,
|
||||||
};
|
};
|
||||||
// TODO: for backwards compatibility. remove in the future
|
// TODO: for backwards compatibility. remove in the future
|
||||||
|
|||||||
@@ -609,6 +609,12 @@ export interface DadosferaModule {
|
|||||||
key: string;
|
key: string;
|
||||||
permissionSeqId: number;
|
permissionSeqId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const DADOSFERA_MODULES_KEYS = {
|
||||||
|
LOG_DASHBOARD: 'logs-dashboard',
|
||||||
|
ACCESS_DASHBOARD: 'access-dashboard'
|
||||||
|
}
|
||||||
|
|
||||||
export const DADOSFERA_MODULES: Array<DadosferaModule> = [
|
export const DADOSFERA_MODULES: Array<DadosferaModule> = [
|
||||||
{
|
{
|
||||||
name: 'Intelligence Module',
|
name: 'Intelligence Module',
|
||||||
|
|||||||
@@ -25,6 +25,14 @@ export function RequireSomePermission(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function RequireModule(
|
||||||
|
key: string
|
||||||
|
) {
|
||||||
|
return createAuthenticatedDecorator((_, user: RequestUser) =>
|
||||||
|
user.customer_modules.some(module => module === key),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function AuthenticateCondition(func: AuthenticationFunction) {
|
export function AuthenticateCondition(func: AuthenticationFunction) {
|
||||||
return createAuthenticatedDecorator(func);
|
return createAuthenticatedDecorator(func);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export interface RequestUser {
|
|||||||
customer_name: string;
|
customer_name: string;
|
||||||
customer_tier: string;
|
customer_tier: string;
|
||||||
access_token: string;
|
access_token: string;
|
||||||
|
customer_modules: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const User: (options?: { required?: boolean }) => ParameterDecorator =
|
export const User: (options?: { required?: boolean }) => ParameterDecorator =
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ import {
|
|||||||
AuthRefreshAccessTokenRes,
|
AuthRefreshAccessTokenRes,
|
||||||
AuthSignInReq,
|
AuthSignInReq,
|
||||||
AuthSignInRes,
|
AuthSignInRes,
|
||||||
BulkEditRequest,
|
|
||||||
} from './dtos/login';
|
} from './dtos/login';
|
||||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
import { AuthGuard } from '@nestjs/passport';
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
@@ -54,7 +53,6 @@ import { LanguageEnum } from 'src/utils/languages.enum';
|
|||||||
import { Language } from 'src/decorators/language.decorator';
|
import { Language } from 'src/decorators/language.decorator';
|
||||||
import { ApiInternalOnlyEndpoint } from 'src/decorators/swagger.decorator';
|
import { ApiInternalOnlyEndpoint } from 'src/decorators/swagger.decorator';
|
||||||
|
|
||||||
|
|
||||||
@ApiTags('Auth')
|
@ApiTags('Auth')
|
||||||
@ApiHeaders([{ name: 'dadosfera-lang', enum: LanguageEnum, required: false }])
|
@ApiHeaders([{ name: 'dadosfera-lang', enum: LanguageEnum, required: false }])
|
||||||
@UseFilters(new GrpcToHttpExceptionFilter())
|
@UseFilters(new GrpcToHttpExceptionFilter())
|
||||||
@@ -63,7 +61,6 @@ export class AuthController {
|
|||||||
logger: DadosferaLogger;
|
logger: DadosferaLogger;
|
||||||
redirectUrl: string;
|
redirectUrl: string;
|
||||||
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DadosferaLogger)
|
@Inject(DadosferaLogger)
|
||||||
dadosferaLogger: DadosferaLogger,
|
dadosferaLogger: DadosferaLogger,
|
||||||
@@ -88,12 +85,9 @@ export class AuthController {
|
|||||||
async signIn(
|
async signIn(
|
||||||
@Body() { username, password, totp }: AuthSignInReq,
|
@Body() { username, password, totp }: AuthSignInReq,
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
@Headers('origin') origin: string
|
|
||||||
): Promise<AuthSignInRes> {
|
): Promise<AuthSignInRes> {
|
||||||
this.logger.info('/auth - SignIn');
|
this.logger.info('/auth - SignIn');
|
||||||
const frontHost = origin.replace(/^https?:\/\//, '');
|
const metadata = PackTheMetadata({ language });
|
||||||
const metadata = PackTheMetadata({ language, custom_host: frontHost });
|
|
||||||
this.logger.info('metadata: ' + JSON.stringify(metadata.toJSON()));
|
|
||||||
return this.authClient.signIn({ username, password, totp }, metadata);
|
return this.authClient.signIn({ username, password, totp }, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +97,6 @@ export class AuthController {
|
|||||||
async refreshAccessToken(
|
async refreshAccessToken(
|
||||||
@Body() body: AuthRefreshAccessTokenReq,
|
@Body() body: AuthRefreshAccessTokenReq,
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
@Headers('host') host: string
|
|
||||||
) {
|
) {
|
||||||
this.logger.info('/auth - RefreshAccessToken');
|
this.logger.info('/auth - RefreshAccessToken');
|
||||||
const { refreshToken, customerName: customer_name } = body;
|
const { refreshToken, customerName: customer_name } = body;
|
||||||
@@ -111,7 +104,6 @@ export class AuthController {
|
|||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata({
|
||||||
customer_name,
|
customer_name,
|
||||||
language,
|
language,
|
||||||
host
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.authClient.refreshAccessToken({ refreshToken }, metadata);
|
return this.authClient.refreshAccessToken({ refreshToken }, metadata);
|
||||||
@@ -352,67 +344,4 @@ export class AuthController {
|
|||||||
|
|
||||||
return { token, email, url, language };
|
return { token, email, url, language };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiInternalOnlyEndpoint()
|
|
||||||
@Post('users/block')
|
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
@HttpCode(HttpStatus.OK)
|
|
||||||
async blockUsers(
|
|
||||||
@Language() language: LanguageEnum,
|
|
||||||
@User() user: RequestUser,
|
|
||||||
@Body() body: BulkEditRequest
|
|
||||||
) {
|
|
||||||
this.logger.info('blockUsers - Starting request');
|
|
||||||
|
|
||||||
try {
|
|
||||||
const metadata = PackTheMetadata(user);
|
|
||||||
|
|
||||||
this.logger.debug('Calling blockUsers service', {
|
|
||||||
metadata: {
|
|
||||||
access_token: metadata.get('access_token'),
|
|
||||||
language: metadata.get('language')
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await this.authClient.blockUsers(body.users, metadata);
|
|
||||||
this.logger.info('blockUsers - Success', { result });
|
|
||||||
return result;
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error('blockUsers - Error', {
|
|
||||||
error: error.message,
|
|
||||||
stack: error.stack
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiInternalOnlyEndpoint()
|
|
||||||
@Post('users/unblock')
|
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
@HttpCode(HttpStatus.OK)
|
|
||||||
async unblockUsers(
|
|
||||||
@Language() language: LanguageEnum,
|
|
||||||
@User() user: RequestUser,
|
|
||||||
@Body() body: BulkEditRequest
|
|
||||||
) {
|
|
||||||
this.logger.info('unblockUsers');
|
|
||||||
const metadata = PackTheMetadata(user);
|
|
||||||
|
|
||||||
return this.authClient.unblockUsers(body.users, metadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiInternalOnlyEndpoint()
|
|
||||||
@Post('users/reset')
|
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
@HttpCode(HttpStatus.OK)
|
|
||||||
async resetUsers(
|
|
||||||
@Language() language: LanguageEnum,
|
|
||||||
@User() user: RequestUser,
|
|
||||||
@Body() body: BulkEditRequest
|
|
||||||
) {
|
|
||||||
this.logger.info('resetUsers');
|
|
||||||
const metadata = PackTheMetadata(user);
|
|
||||||
|
|
||||||
return this.authClient.resetUsers(body.users, metadata);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import {
|
|||||||
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
} from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||||
import { DucClient } from '../duc/client.config';
|
import { DucClient } from '../duc/client.config';
|
||||||
import { Metadata } from '@grpc/grpc-js';
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
import { BulkEditResponse } from './dtos/login';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthClientService implements OnModuleInit {
|
export class AuthClientService implements OnModuleInit {
|
||||||
@@ -169,63 +168,4 @@ export class AuthClientService implements OnModuleInit {
|
|||||||
this.authService.AuthOauthSignIn({ token, username, refreshToken: '' }),
|
this.authService.AuthOauthSignIn({ token, username, refreshToken: '' }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async blockUsers(users: string[],metadata: Metadata): Promise<BulkEditResponse> {
|
|
||||||
this.logger.info('blockUsers - Service starting');
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.logger.debug('Calling BlockUser gRPC method', {
|
|
||||||
metadata: {
|
|
||||||
access_token: metadata.get('access_token'),
|
|
||||||
language: metadata.get('language')
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const response = await lastValueFrom<BulkEditResponse>(
|
|
||||||
this.authService.BlockUser({ users }, metadata),
|
|
||||||
);
|
|
||||||
|
|
||||||
this.logger.info('blockUsers - Service success', { response });
|
|
||||||
return response;
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error('blockUsers - Service error', {
|
|
||||||
error: error.message,
|
|
||||||
stack: error.stack,
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async unblockUsers(users: string[],metadata: Metadata): Promise<BulkEditResponse> {
|
|
||||||
this.logger.info('unblockUsers');
|
|
||||||
return await lastValueFrom(
|
|
||||||
this.authService.UnblockUser({ users }, metadata),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async resetUsers(users: string[], metadata: Metadata): Promise<BulkEditResponse> {
|
|
||||||
this.logger.info('resetUsers');
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.logger.debug('Calling ResetUser gRPC method', {
|
|
||||||
metadata: {
|
|
||||||
access_token: metadata.get('access_token'),
|
|
||||||
language: metadata.get('language')
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const response = await lastValueFrom<BulkEditResponse>(
|
|
||||||
this.authService.ResetUser({ users }, metadata)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.logger.info('resetUsers - Success', { response });
|
|
||||||
return response;
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error('resetUsers - Error', {
|
|
||||||
error: error.message,
|
|
||||||
stack: error.stack
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,24 +67,18 @@ export class AuthUser {
|
|||||||
export class AuthCustomer {
|
export class AuthCustomer {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
modules: string[];
|
modules: string[];
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
displayName: string;
|
displayName: string;
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
tier: string;
|
tier: string;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
scheduleLimit: string;
|
scheduleLimit: string;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
links: Link[];
|
links: Link[];
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
themeEnabled: boolean;
|
themeEnabled: boolean;
|
||||||
}
|
}
|
||||||
@@ -128,13 +122,3 @@ export class AuthRefreshAccessTokenRes {
|
|||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BulkEditRequest {
|
|
||||||
users: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BulkEditResponse {
|
|
||||||
message: string;
|
|
||||||
successfulUsers: string[];
|
|
||||||
failedUsers: string[];
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ import {
|
|||||||
UseFilters,
|
UseFilters,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiOkResponse, ApiProduces, ApiTags } from '@nestjs/swagger';
|
import { ApiOkResponse, ApiProduces, ApiTags } from '@nestjs/swagger';
|
||||||
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
import { DADOSFERA_MODULES_KEYS, PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
import {
|
import {
|
||||||
Authenticated,
|
Authenticated,
|
||||||
RequireAllPermissions,
|
RequireAllPermissions,
|
||||||
|
RequireModule,
|
||||||
} from 'src/decorators/authentication.decorator';
|
} from 'src/decorators/authentication.decorator';
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
import { CustomersService } from './customers.service';
|
import { CustomersService } from './customers.service';
|
||||||
@@ -97,15 +98,30 @@ export class CustomersController {
|
|||||||
@RequireAllPermissions(
|
@RequireAllPermissions(
|
||||||
PERMISSIONS_GROUPS.USERS.permissions.ADMIN,
|
PERMISSIONS_GROUPS.USERS.permissions.ADMIN,
|
||||||
)
|
)
|
||||||
|
@RequireModule(DADOSFERA_MODULES_KEYS.LOG_DASHBOARD)
|
||||||
async getCustomerMixPanelLogsDashboard(
|
async getCustomerMixPanelLogsDashboard(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
): Promise<{ url: string }> {
|
): Promise<{ url: string }> {
|
||||||
this.logger.info('getLogsDashboardUrl');
|
this.logger.info('getLogsDashboardUrl');
|
||||||
const metadata = PackTheMetadata(user);
|
const metadata = PackTheMetadata(user);
|
||||||
|
|
||||||
const result = await this.customersService.getLogsDashboardUrl(metadata);
|
const result = await this.customersService.getLogsDashboardUrl(metadata);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Get('access-dashboard')
|
||||||
|
@Authenticated()
|
||||||
|
@RequireAllPermissions(
|
||||||
|
PERMISSIONS_GROUPS.USERS.permissions.ADMIN,
|
||||||
|
)
|
||||||
|
@RequireModule(DADOSFERA_MODULES_KEYS.ACCESS_DASHBOARD)
|
||||||
|
async getAccessDashboard(
|
||||||
|
@User() user: RequestUser,
|
||||||
|
): Promise<{ url: string }> {
|
||||||
|
this.logger.info('getAccessDashboard');
|
||||||
|
const metadata = PackTheMetadata(user);
|
||||||
|
|
||||||
|
const result = await this.customersService.getAccessDashboardUrl(user.customer_name, metadata);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
HttpException,
|
HttpException,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
InternalServerErrorException,
|
InternalServerErrorException,
|
||||||
|
ForbiddenException,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
|
|
||||||
import { firstValueFrom, lastValueFrom } from 'rxjs';
|
import { firstValueFrom, lastValueFrom } from 'rxjs';
|
||||||
@@ -173,4 +174,33 @@ export class CustomersService implements OnModuleInit {
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getAccessDashboardUrl(customerName: string, metadata: Metadata) {
|
||||||
|
/*
|
||||||
|
* TODO(Refactor): dar um jeito de exibir o dash da sbm diferente dos outros customer
|
||||||
|
* pois o signicado de department para sbm significa as instituições do usuários
|
||||||
|
*/
|
||||||
|
if (customerName !== 'sbmoffshorecom') {
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
logger.info('CustomersService - getAccessDashboardUrl');
|
||||||
|
|
||||||
|
const res = await this.getDashboardUrl('105', metadata);
|
||||||
|
logger.info('Done');
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getDashboardUrl(dashboardId: string, metadata: Metadata) {
|
||||||
|
return await lastValueFrom(
|
||||||
|
this.pipelineReadService.PipelineV2GetDashboardUrl(
|
||||||
|
{
|
||||||
|
dashboard_id: dashboardId,
|
||||||
|
exp: '15m',
|
||||||
|
metabase_customer_name: 'dadosferatech',
|
||||||
|
},
|
||||||
|
metadata
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Body, Controller, Inject, Param, Post, Req } from '@nestjs/common';
|
import { Body, Controller, Inject, Param, Post } from '@nestjs/common';
|
||||||
import { init } from 'mixpanel';
|
import { init } from 'mixpanel';
|
||||||
import { Authenticated } from 'src/decorators/authentication.decorator';
|
import { Authenticated } from 'src/decorators/authentication.decorator';
|
||||||
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
||||||
@@ -13,12 +13,7 @@ export class MixpanelController {
|
|||||||
private readonly mixpanelToken: string,
|
private readonly mixpanelToken: string,
|
||||||
) {}
|
) {}
|
||||||
@Post(':id')
|
@Post(':id')
|
||||||
async trackEvent(
|
async trackEvent(@Param('id') id, @Body() body, @User() user: RequestUser) {
|
||||||
@Param('id') id,
|
|
||||||
@Body() body,
|
|
||||||
@User() user: RequestUser,
|
|
||||||
@Req() request
|
|
||||||
) {
|
|
||||||
delete body.info;
|
delete body.info;
|
||||||
const mixpanel = init(this.mixpanelToken);
|
const mixpanel = init(this.mixpanelToken);
|
||||||
|
|
||||||
@@ -71,16 +66,13 @@ export class MixpanelController {
|
|||||||
$email: user.username.includes('@')
|
$email: user.username.includes('@')
|
||||||
? user.username
|
? user.username
|
||||||
: user.username + '@dadosfera.ai',
|
: user.username + '@dadosfera.ai',
|
||||||
customer_name: user.customer_name
|
customer_name: user.customer_name,
|
||||||
});
|
});
|
||||||
|
|
||||||
await mixpanel.track(id, {
|
await mixpanel.track(id, {
|
||||||
distinct_id: user.username,
|
distinct_id: user.username,
|
||||||
customer: user.customer_name,
|
customer: user.customer_name,
|
||||||
env: process.env.ENV,
|
env: process.env.ENV,
|
||||||
$ip: request.ip,
|
|
||||||
$os: request.headers['sec-ch-ua-platform'] || '',
|
|
||||||
$browser: request.headers['user-agent'],
|
|
||||||
...body,
|
...body,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
import { ApiProperty } from "@nestjs/swagger";
|
|
||||||
|
|
||||||
export class NetworkPoliciesDTO {
|
|
||||||
@ApiProperty()
|
|
||||||
policies: string []
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Post } from '@nestjs/common';
|
|
||||||
import { ApiOkResponse } from '@nestjs/swagger';
|
|
||||||
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
|
||||||
import {
|
|
||||||
Authenticated,
|
|
||||||
RequireAllPermissions,
|
|
||||||
} from 'src/decorators/authentication.decorator';
|
|
||||||
import { NetworkPoliciesDTO } from './dto/network-policy.dto';
|
|
||||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
|
||||||
import { NetworkPolicyService } from './network-policy.service';
|
|
||||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
|
||||||
|
|
||||||
@Controller('network-policy')
|
|
||||||
export class NetworkPolicyController {
|
|
||||||
constructor(private networkPolicyService: NetworkPolicyService) {}
|
|
||||||
|
|
||||||
@Get()
|
|
||||||
@Authenticated()
|
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
@HttpCode(HttpStatus.OK)
|
|
||||||
async getNetworks(
|
|
||||||
@User() user: RequestUser,
|
|
||||||
) {
|
|
||||||
return await this.networkPolicyService.getByCustomer(
|
|
||||||
user.customer_id
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post()
|
|
||||||
@Authenticated()
|
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
@ApiOkResponse()
|
|
||||||
@HttpCode(HttpStatus.CREATED)
|
|
||||||
async applyNetworkPolicies(
|
|
||||||
@User() user: RequestUser,
|
|
||||||
@Body() data: NetworkPoliciesDTO,
|
|
||||||
) {
|
|
||||||
const metadata = PackTheMetadata(user);
|
|
||||||
|
|
||||||
return await this.networkPolicyService.apply(
|
|
||||||
data.policies,
|
|
||||||
user.customer_id,
|
|
||||||
metadata,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete()
|
|
||||||
@Authenticated()
|
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
@ApiOkResponse()
|
|
||||||
@HttpCode(HttpStatus.OK)
|
|
||||||
async removeNetworkPolicies(
|
|
||||||
@User() user: RequestUser,
|
|
||||||
@Body() data: NetworkPoliciesDTO,
|
|
||||||
) {
|
|
||||||
const metadata = PackTheMetadata(user);
|
|
||||||
|
|
||||||
return await this.networkPolicyService.delete(
|
|
||||||
data.policies,
|
|
||||||
user.customer_id,
|
|
||||||
metadata,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { NetworkPolicyController } from './network-policy.controller';
|
|
||||||
import { NetworkPolicyService } from './network-policy.service';
|
|
||||||
import { ClientsModule } from '@nestjs/microservices';
|
|
||||||
import { DucClient } from '../duc/client.config';
|
|
||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
|
||||||
|
|
||||||
const ducClient = new DucClient();
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
imports: [
|
|
||||||
ClientsModule.register([
|
|
||||||
ducClient.providerOptions
|
|
||||||
]),
|
|
||||||
],
|
|
||||||
controllers: [NetworkPolicyController],
|
|
||||||
providers: [NetworkPolicyService, DadosferaLogger]
|
|
||||||
})
|
|
||||||
export class NetworkPolicyModule {}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
import { Inject, Injectable } from '@nestjs/common';
|
|
||||||
import { DucClient } from '../duc/client.config';
|
|
||||||
import { ClientGrpc } from '@nestjs/microservices';
|
|
||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
|
||||||
import { CustomersProtoService } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/write-service';
|
|
||||||
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
|
||||||
import { Metadata } from '@grpc/grpc-js';
|
|
||||||
import { lastValueFrom } from 'rxjs';
|
|
||||||
import { NetworkPoliciesDTO } from './dto/network-policy.dto';
|
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class NetworkPolicyService {
|
|
||||||
private customerService: CustomersProtoService;
|
|
||||||
private logger: DadosferaLogger;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
@Inject(DucClient.name) private readonly grpcClient: ClientGrpc,
|
|
||||||
@Inject(DadosferaLogger)
|
|
||||||
dadosferaLogger: DadosferaLogger,
|
|
||||||
) {
|
|
||||||
this.logger = dadosferaLogger.logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
onModuleInit() {
|
|
||||||
this.customerService = this.grpcClient.getService<CustomersProtoService>(
|
|
||||||
ProtoServices.CustomersProtoService,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getByCustomer(id: string): Promise<NetworkPoliciesDTO> {
|
|
||||||
const {
|
|
||||||
customer
|
|
||||||
} = await lastValueFrom(this.customerService.CustomerFindOneById({
|
|
||||||
id
|
|
||||||
}));
|
|
||||||
|
|
||||||
return {
|
|
||||||
policies: customer.networkPolicies
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async apply(
|
|
||||||
networkPolicies: string[],
|
|
||||||
customerId: string,
|
|
||||||
metadata: Metadata,
|
|
||||||
) {
|
|
||||||
return await lastValueFrom(
|
|
||||||
this.customerService.CustomerCreateNetworkPolicy(
|
|
||||||
{
|
|
||||||
customerId,
|
|
||||||
networkPolicies,
|
|
||||||
},
|
|
||||||
metadata,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async delete(
|
|
||||||
networkPolicies: string[],
|
|
||||||
customerId: string,
|
|
||||||
metadata: Metadata,
|
|
||||||
) {
|
|
||||||
return await lastValueFrom(
|
|
||||||
this.customerService.CustomerRemoveNetworkPolicy(
|
|
||||||
{
|
|
||||||
customerId,
|
|
||||||
networkPolicies,
|
|
||||||
},
|
|
||||||
metadata,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,9 +11,6 @@ interface IMetadata {
|
|||||||
roles?: string[];
|
roles?: string[];
|
||||||
is_data_manager?: boolean;
|
is_data_manager?: boolean;
|
||||||
access_token?: string;
|
access_token?: string;
|
||||||
host?: string;
|
|
||||||
origin?: string;
|
|
||||||
custom_host?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PackTheMetadata(info: IMetadata): Metadata {
|
export function PackTheMetadata(info: IMetadata): Metadata {
|
||||||
|
|||||||
@@ -77,13 +77,6 @@ export function EnrichErrorCode(code: string) {
|
|||||||
message: 'Token para recuperar senha inválido',
|
message: 'Token para recuperar senha inválido',
|
||||||
code,
|
code,
|
||||||
};
|
};
|
||||||
case ErrorCodes.AUTH.REQUIRED_PASSWORD_RESET:
|
|
||||||
return {
|
|
||||||
statusCode: HttpStatus.UNAUTHORIZED,
|
|
||||||
error: 'Não permitido',
|
|
||||||
message: 'Seu usuário foi resetado por um administrador, resete a senha pelo link "Esqueci a senha", para prosseguir',
|
|
||||||
code,
|
|
||||||
};
|
|
||||||
|
|
||||||
case ErrorCodes.AUTH.WEAK_NEW_PASSWORD:
|
case ErrorCodes.AUTH.WEAK_NEW_PASSWORD:
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ export const AUTH = {
|
|||||||
RESET_PASSWORD_CODE_EXPIRED: 'AUTH.RESET_PASSWORD_CODE_EXPIRED',
|
RESET_PASSWORD_CODE_EXPIRED: 'AUTH.RESET_PASSWORD_CODE_EXPIRED',
|
||||||
RESET_PASSWORD_CODE_INVALID: 'AUTH.RESET_PASSWORD_CODE_INVALID',
|
RESET_PASSWORD_CODE_INVALID: 'AUTH.RESET_PASSWORD_CODE_INVALID',
|
||||||
WEAK_NEW_PASSWORD: 'AUTH.WEAK_NEW_PASSWORD',
|
WEAK_NEW_PASSWORD: 'AUTH.WEAK_NEW_PASSWORD',
|
||||||
REQUIRED_PASSWORD_RESET: 'AUTH.REQUIRED_PASSWORD_RESET'
|
|
||||||
};
|
};
|
||||||
export const ROLE = {
|
export const ROLE = {
|
||||||
INVALID_ID: 'ROLE.INVALID_ID',
|
INVALID_ID: 'ROLE.INVALID_ID',
|
||||||
|
|||||||
Reference in New Issue
Block a user