mirror of
https://github.com/dadosfera/maestro.git
synced 2026-12-02 16:50:05 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
667d3f874d | ||
|
|
11f1df5537 | ||
|
|
e3b02571c8 | ||
|
|
979a12aa7f | ||
|
|
8f0e851a88 | ||
|
|
6e6d03f302 | ||
|
|
3d5ce59b52 | ||
|
|
1c63271f64 | ||
|
|
31a51c20aa | ||
|
|
62730eb969 |
@@ -27,6 +27,7 @@ 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';
|
||||||
|
|
||||||
@ApiTags('Auth')
|
@ApiTags('Auth')
|
||||||
@UseFilters(new GrpcToHttpExceptionFilter())
|
@UseFilters(new GrpcToHttpExceptionFilter())
|
||||||
@@ -59,20 +60,27 @@ export class AuthController {
|
|||||||
|
|
||||||
@Post('sign-in')
|
@Post('sign-in')
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
async signIn(@Body() { username, password, totp }: AuthSignInRequest) {
|
async signIn(
|
||||||
|
@Body() { username, password, totp }: AuthSignInRequest,
|
||||||
|
@Headers('Dadosfera-Lang') language: string,
|
||||||
|
) {
|
||||||
this.logger.info('/auth - SignIn');
|
this.logger.info('/auth - SignIn');
|
||||||
|
const metadata = new Metadata();
|
||||||
return this.authClient.signIn({ username, password, totp });
|
metadata.add('language', language || 'pt-br');
|
||||||
|
return this.authClient.signIn({ username, password, totp }, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('refresh-access-token')
|
@Post('refresh-access-token')
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
async refreshAccessToken(
|
async refreshAccessToken(
|
||||||
@Body() { refreshToken }: AuthRefreshAccessTokenRequest,
|
@Body() { refreshToken }: AuthRefreshAccessTokenRequest,
|
||||||
|
@Headers('Dadosfera-Lang') language: string,
|
||||||
) {
|
) {
|
||||||
this.logger.info('/auth - RefreshAccessToken');
|
this.logger.info('/auth - RefreshAccessToken');
|
||||||
|
const metadata = new Metadata();
|
||||||
|
metadata.add('language', language || 'pt-br');
|
||||||
|
|
||||||
return this.authClient.refreshAccessToken({ refreshToken });
|
return this.authClient.refreshAccessToken({ refreshToken }, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('change-password')
|
@Post('change-password')
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
AuthConfirmResetPasswordRequest,
|
AuthConfirmResetPasswordRequest,
|
||||||
} 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';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthClientService implements OnModuleInit {
|
export class AuthClientService implements OnModuleInit {
|
||||||
@@ -51,19 +52,25 @@ export class AuthClientService implements OnModuleInit {
|
|||||||
return lastValueFrom(this.authService.AuthSnowflakeSignIn(input));
|
return lastValueFrom(this.authService.AuthSnowflakeSignIn(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
async signIn({ username, password, totp }: AuthSignInRequest) {
|
async signIn(
|
||||||
|
{ username, password, totp }: AuthSignInRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
) {
|
||||||
this.logger.info('SignIn');
|
this.logger.info('SignIn');
|
||||||
|
|
||||||
return lastValueFrom(
|
return lastValueFrom(
|
||||||
this.authService.AuthSignIn({ username, password, totp }),
|
this.authService.AuthSignIn({ username, password, totp }, metadata),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshAccessToken({ refreshToken }: AuthRefreshAccessTokenRequest) {
|
async refreshAccessToken(
|
||||||
|
{ refreshToken }: AuthRefreshAccessTokenRequest,
|
||||||
|
metadata: Metadata,
|
||||||
|
) {
|
||||||
this.logger.info('RefreshAccessToken');
|
this.logger.info('RefreshAccessToken');
|
||||||
|
|
||||||
return lastValueFrom(
|
return lastValueFrom(
|
||||||
this.authService.AuthRefreshAccessToken({ refreshToken }),
|
this.authService.AuthRefreshAccessToken({ refreshToken }, metadata),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -407,7 +407,7 @@ class CatalogService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createDataDescription(body, metadata) {
|
async createDataDescription(body, metadata) {
|
||||||
const response = await lastValueFrom(
|
await lastValueFrom(
|
||||||
this.catalogWriteService.UpdateDataAsset(
|
this.catalogWriteService.UpdateDataAsset(
|
||||||
{
|
{
|
||||||
id: `dataset-${body.table_id}`,
|
id: `dataset-${body.table_id}`,
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ import { ConnectionClientService } from '../connection/client.service';
|
|||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs/dist';
|
import DadosferaLogger from '@dadosfera/dadosfera-logs/dist';
|
||||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
import { Authenticated } from 'src/authentication/authentication.decorator';
|
|
||||||
@ApiTags('oauth')
|
@ApiTags('oauth')
|
||||||
@Authenticated()
|
|
||||||
@Controller('oauth')
|
@Controller('oauth')
|
||||||
export class OauthController {
|
export class OauthController {
|
||||||
redirectUrl: string;
|
redirectUrl: string;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ 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 '../../authentication/user.decorator';
|
import { RequestUser, User } from '../../authentication/user.decorator';
|
||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
|
||||||
@ApiTags('TermsOfUse')
|
@ApiTags('TermsOfUse')
|
||||||
@UseFilters(new GrpcToHttpExceptionFilter())
|
@UseFilters(new GrpcToHttpExceptionFilter())
|
||||||
@@ -33,10 +34,15 @@ export class TermsOfUseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('token')
|
@Get('token')
|
||||||
async getToken(@User({ required: true }) user: RequestUser) {
|
async getToken(
|
||||||
|
@User({ required: true }) user: RequestUser,
|
||||||
|
@Headers('Dadosfera-Lang') language: string,
|
||||||
|
) {
|
||||||
this.logger.info('/terms-of-use - get token');
|
this.logger.info('/terms-of-use - get token');
|
||||||
|
const metadata = new Metadata();
|
||||||
|
metadata.add('language', language || 'pt-br');
|
||||||
|
|
||||||
return this.termsOfUseClient.getToken({ userId: user.user_id });
|
return this.termsOfUseClient.getToken({ userId: user.user_id }, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('accept')
|
@Post('accept')
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
TermsOfUseAcceptRequest,
|
TermsOfUseAcceptRequest,
|
||||||
} 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';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TermsOfUseClientService implements OnModuleInit {
|
export class TermsOfUseClientService implements OnModuleInit {
|
||||||
@@ -31,8 +32,10 @@ export class TermsOfUseClientService implements OnModuleInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getToken(data: TermsOfUseGetTokenRequest) {
|
async getToken(data: TermsOfUseGetTokenRequest, metadata: Metadata) {
|
||||||
return lastValueFrom(this.termsOfUseService.TermsOfUseGetToken(data));
|
return lastValueFrom(
|
||||||
|
this.termsOfUseService.TermsOfUseGetToken(data, metadata),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async accept(data: TermsOfUseAcceptRequest) {
|
async accept(data: TermsOfUseAcceptRequest) {
|
||||||
|
|||||||
@@ -55,7 +55,10 @@ export class UserNoRoles extends OmitType(User, ['roles']) {}
|
|||||||
export class UserNoRolesAndCustomer extends OmitType(UserNoRoles, [
|
export class UserNoRolesAndCustomer extends OmitType(UserNoRoles, [
|
||||||
'customer',
|
'customer',
|
||||||
]) {}
|
]) {}
|
||||||
export class UserByCustomer extends OmitType(User, ['customer']) {}
|
export class IUserByCustomer extends OmitType(User, ['customer']) {
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
permissions?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export class CreateUserReq {
|
export class CreateUserReq {
|
||||||
@ApiPropertyOptional()
|
@ApiPropertyOptional()
|
||||||
@@ -111,11 +114,11 @@ export class UpdateUserReq {
|
|||||||
|
|
||||||
export class UpdateUserRes {
|
export class UpdateUserRes {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
user: UserByCustomer;
|
user: IUserByCustomer;
|
||||||
}
|
}
|
||||||
export class GetAllUsersByCustomerIdRes {
|
export class GetAllUsersByCustomerIdRes {
|
||||||
@ApiProperty({ type: [UserByCustomer] })
|
@ApiProperty({ type: [IUserByCustomer] })
|
||||||
users: UserByCustomer[];
|
users: IUserByCustomer[];
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
departments: string[];
|
departments: string[];
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
@@ -153,7 +156,7 @@ export class SetUserRolesReq {
|
|||||||
|
|
||||||
export class SetUserRolesRes {
|
export class SetUserRolesRes {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
user: UserByCustomer;
|
user: IUserByCustomer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SearchUserRes extends GetAllUsersByCustomerIdRes {}
|
export class SearchUserRes extends GetAllUsersByCustomerIdRes {}
|
||||||
|
|||||||
@@ -45,10 +45,12 @@ import {
|
|||||||
UnassignRoleToUserReq,
|
UnassignRoleToUserReq,
|
||||||
UpdateUserReq,
|
UpdateUserReq,
|
||||||
UpdateUserRes,
|
UpdateUserRes,
|
||||||
UserByCustomer,
|
IUserByCustomer,
|
||||||
} from './dtos/entities';
|
} from './dtos/entities';
|
||||||
import { UsersService } from './users.service';
|
import { UsersService } from './users.service';
|
||||||
import { Metadata } from '@grpc/grpc-js';
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
import ErrorBuilder from 'src/utils/ErrorBuilder';
|
||||||
|
import ErrorCodes from 'src/utils/errorCodes';
|
||||||
|
|
||||||
// TODO GET de hierarquias e do PATCH em usuário
|
// TODO GET de hierarquias e do PATCH em usuário
|
||||||
@ApiTags('Users')
|
@ApiTags('Users')
|
||||||
@@ -123,9 +125,8 @@ export class UsersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
@ApiOkResponse({
|
@ApiOkResponse({
|
||||||
type: UserByCustomer,
|
type: IUserByCustomer,
|
||||||
})
|
})
|
||||||
async findOneById(
|
async findOneById(
|
||||||
@User() user: RequestUser,
|
@User() user: RequestUser,
|
||||||
@@ -134,6 +135,14 @@ export class UsersController {
|
|||||||
) {
|
) {
|
||||||
this.logger.info('findOneById', { user });
|
this.logger.info('findOneById', { user });
|
||||||
this.userService.setLanguage(language);
|
this.userService.setLanguage(language);
|
||||||
|
if (
|
||||||
|
id !== user.user_id &&
|
||||||
|
!user.permissions.includes(
|
||||||
|
PERMISSIONS_GROUPS.USERS.permissions.ADMIN.seqid,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
throw new ErrorBuilder(ErrorCodes.AUTH.FORBIDDEN);
|
||||||
|
}
|
||||||
return await this.userService.findOneById(id);
|
return await this.userService.findOneById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
BatchCreateUserReq,
|
BatchCreateUserReq,
|
||||||
CreateUserReq,
|
CreateUserReq,
|
||||||
Hierarchy,
|
Hierarchy,
|
||||||
|
IUserByCustomer,
|
||||||
SetUserRolesReq,
|
SetUserRolesReq,
|
||||||
UpdateUserReq,
|
UpdateUserReq,
|
||||||
} from './dtos/entities';
|
} from './dtos/entities';
|
||||||
@@ -77,11 +78,21 @@ export class UsersService implements OnModuleInit {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOneById(id: string) {
|
async findOneById(id: string): Promise<{ user: IUserByCustomer }> {
|
||||||
const { user } = await lastValueFrom(
|
const { user } = await lastValueFrom(
|
||||||
this.usersClientService.UserFindOneById({ id }),
|
this.usersClientService.UserFindOneById({ id }),
|
||||||
);
|
);
|
||||||
return { user: this.adjustUsersPayload([user])[0] };
|
const res: { user: IUserByCustomer } = {
|
||||||
|
user: this.adjustUsersPayload([user])[0],
|
||||||
|
};
|
||||||
|
if (res.user.roles?.length) {
|
||||||
|
const allPermissions = res.user.roles.flatMap((r) => r.permissions);
|
||||||
|
const distinctPermissions = Array.from(
|
||||||
|
new Set(allPermissions.map((p) => p.claim)),
|
||||||
|
);
|
||||||
|
res.user.permissions = distinctPermissions;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createUser(req: CreateUserReq, meta?: Metadata) {
|
async createUser(req: CreateUserReq, meta?: Metadata) {
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user