Various fixes: profilePicture / logo upload, imageIdentifiers (#6530)

In this PR:
- refactoring auth module to extract a jwt module that can be re-used
from other part of the app (avoiding circular dependencies file module
=> auth => file (file and auth both need jwt actually)
- activating imageIdentfier on person on workspace creation (this will
put back the images on people)
- fixing picture upload (we were missing some fileToken)
This commit is contained in:
Charles Bochet
2024-08-04 15:08:25 +02:00
committed by GitHub
parent e787215e15
commit c543716381
15 changed files with 143 additions and 91 deletions

View File

@ -1,15 +1,15 @@
import { forwardRef, Module } from '@nestjs/common';
import { Module } from '@nestjs/common';
import { AuthModule } from 'src/engine/core-modules/auth/auth.module';
import { FileUploadModule } from 'src/engine/core-modules/file/file-upload/file-upload.module';
import { FilePathGuard } from 'src/engine/core-modules/file/guards/file-path-guard';
import { JwtModule } from 'src/engine/core-modules/jwt/jwt.module';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
import { FileController } from './controllers/file.controller';
import { FileService } from './services/file.service';
@Module({
imports: [FileUploadModule, forwardRef(() => AuthModule)],
imports: [FileUploadModule, JwtModule],
providers: [FileService, EnvironmentService, FilePathGuard],
exports: [FileService],
controllers: [FileController],

View File

@ -6,13 +6,13 @@ import {
Injectable,
} from '@nestjs/common';
import { TokenService } from 'src/engine/core-modules/auth/services/token.service';
import { JwtWrapperService } from 'src/engine/core-modules/jwt/services/jwt-wrapper.service';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
@Injectable()
export class FilePathGuard implements CanActivate {
constructor(
private readonly tokenService: TokenService,
private readonly jwtWrapperService: JwtWrapperService,
private readonly environmentService: EnvironmentService,
) {}
@ -22,11 +22,11 @@ export class FilePathGuard implements CanActivate {
if (query && query['token']) {
const payloadToDecode = query['token'];
const decodedPayload = await this.tokenService.decodePayload(
const decodedPayload = await this.jwtWrapperService.decode(
payloadToDecode,
{
secret: this.environmentService.get('FILE_TOKEN_SECRET'),
},
} as any,
);
const expirationDate = decodedPayload?.['expiration_date'];

View File

@ -10,16 +10,16 @@ import {
FileStorageExceptionCode,
} from 'src/engine/integrations/file-storage/interfaces/file-storage-exception';
import { TokenService } from 'src/engine/core-modules/auth/services/token.service';
import { JwtWrapperService } from 'src/engine/core-modules/jwt/services/jwt-wrapper.service';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
import { FileStorageService } from 'src/engine/integrations/file-storage/file-storage.service';
@Injectable()
export class FileService {
constructor(
private readonly jwtWrapperService: JwtWrapperService,
private readonly fileStorageService: FileStorageService,
private readonly environmentService: EnvironmentService,
private readonly tokenService: TokenService,
) {}
async getFileStream(
@ -57,7 +57,7 @@ export class FileService {
const expirationDate = addMilliseconds(new Date(), ms(fileTokenExpiresIn));
const signedPayload = await this.tokenService.encodePayload(
const signedPayload = await this.jwtWrapperService.sign(
{
expiration_date: expirationDate,
...payloadToEncode,