Skip to content

Commit

Permalink
Merge pull request #50 from Horizontal-org/1.2
Browse files Browse the repository at this point in the history
1.2
  • Loading branch information
juandans01 authored Mar 14, 2024
2 parents e8e69a8 + 8484adf commit 633b3bc
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/migrations/1710283666709-change_description_data_type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {MigrationInterface, QueryRunner} from "typeorm";

export class changeDescriptionDataType1710283666709 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
"ALTER TABLE report_entity MODIFY description TEXT NULL;"
)
}

public async down(queryRunner: QueryRunner): Promise<void> {
}

}
12 changes: 11 additions & 1 deletion src/modules/project/controllers/create.project.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { RolesUser } from 'modules/user/domain';

import { CreateProjectDto, ReadProjectDto } from '../dto';
import { ICreateProjectApplication, TYPES } from '../interfaces';
import { ReadUserDto } from 'modules/user/dto';
import { LoggedUser } from 'modules/auth/decorators';

@AuthController('project', [RolesUser.ADMIN, RolesUser.EDITOR], JwtTypes.WEB)
export class CreateProjectController {
Expand All @@ -18,7 +20,15 @@ export class CreateProjectController {

@ApiResponse({ type: ReadProjectDto })
@Post()
async handler(@Body() createProjectDto: CreateProjectDto): Promise<ReadProjectDto> {
async handler(
@Body() createProjectDto: CreateProjectDto,
@LoggedUser() { id, username, role }: ReadUserDto,
): Promise<ReadProjectDto> {
let projectDto = createProjectDto
if (role !== 'admin') {
projectDto.users = [id]
}

const project = await this.createProjectApplication.execute(createProjectDto);

return project;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CloseResourceDto } from '../dto';
import { RolesUser } from 'modules/user/domain';
import { JwtTypes } from 'modules/jwt/domain/jwt-types.auth.enum';

@AuthController('resource', [RolesUser.ADMIN, RolesUser.EDITOR, RolesUser.VIEWER, RolesUser.REPORTER], JwtTypes.WEB)
@AuthController('resource', [RolesUser.ADMIN], JwtTypes.WEB)

export class CheckNameResourceController {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CloseResourceDto } from '../dto';
import { RolesUser } from 'modules/user/domain';
import { JwtTypes } from 'modules/jwt/domain/jwt-types.auth.enum';

@AuthController('resource', [RolesUser.ADMIN, RolesUser.EDITOR, RolesUser.VIEWER, RolesUser.REPORTER], JwtTypes.WEB)
@AuthController('resource', [RolesUser.ADMIN], JwtTypes.WEB)

export class CloseResourceController {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RolesUser } from 'modules/user/domain';

import { IDeleteResourceService, TYPES } from '../interfaces';

@AuthController('resource', [RolesUser.ADMIN, RolesUser.EDITOR], JwtTypes.WEB)
@AuthController('resource', [RolesUser.ADMIN], JwtTypes.WEB)
export class DeleteResourceController {
constructor(
@Inject(TYPES.services.IDeleteResourceService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export class DownloadResourceController {
@Query('fileNames', new ParseArrayPipe()) fileNames = [],
@Res() res: Response,
) {
console.log("🚀 ~ file: download.resource.controller.ts:26 ~ DownloadResourceController ~ fileNames:", fileNames)
const zipStream = await this.downloadService.execute(fileNames);
zipStream.pipe(res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Inject,
Param,
Response,
UnauthorizedException,
} from '@nestjs/common';

import { AuthController } from 'common/decorators/auth-controller.decorator';
Expand All @@ -14,13 +15,16 @@ import { JwtTypes } from 'modules/jwt/domain/jwt-types.auth.enum';
import { IStorageFileHandler } from 'modules/file/interfaces';
import { ReadUserDto } from 'modules/user/dto';
import { LoggedUser } from 'modules/auth/decorators';
import { IUserHasResourceService } from '../interfaces/services/user-has.resource.service.interface';

// JWT IS ALL BECAUSE THIS IS BEING CONSUMED AS A COOKIE
@AuthController('resource', [RolesUser.ADMIN, RolesUser.EDITOR], JwtTypes.ALL)
@AuthController('resource', [RolesUser.ADMIN, RolesUser.EDITOR, RolesUser.VIEWER], JwtTypes.ALL)
export class GetAssetResourceController {
constructor(
@Inject(TYPES.handlers.IStorageFileHandler)
private readonly storageFileHandler: IStorageFileHandler,
@Inject(TYPES.services.IUserHasResourceService)
private readonly userHasResourceService: IUserHasResourceService,
) {}

@Get('asset/:fileName')
Expand All @@ -31,6 +35,16 @@ export class GetAssetResourceController {
@Headers() headers,
@Response() res,
) {

console.log("🚀 ~ GetAssetResourceController ~ role:", username, role)

if (role !== 'admin') {
const hasResource = await this.userHasResourceService.execute(id, fileName)
if (!hasResource) {
throw new UnauthorizedException()
}
}

const stream = await this.storageFileHandler.fetch({
bucket: 'resources',
fileName: fileName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { RolesUser } from 'modules/user/domain';
import { ReadResourceDto } from '../dto';
import { IListResourceService, TYPES } from '../interfaces';

@AuthController('resource', [RolesUser.ADMIN, RolesUser.EDITOR, RolesUser.VIEWER], JwtTypes.WEB)
@AuthController('resource', [RolesUser.ADMIN, RolesUser.EDITOR], JwtTypes.WEB)
@ApiExtraModels(PaginatedDto)
export class ListResourceController {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { TYPES, IUploadResourceService } from '../interfaces';
import { RolesUser } from 'modules/user/domain';
import { JwtTypes } from 'modules/jwt/domain/jwt-types.auth.enum';

@AuthController('resource', [RolesUser.ADMIN, RolesUser.EDITOR, RolesUser.VIEWER, RolesUser.REPORTER], JwtTypes.WEB)
@AuthController('resource', [RolesUser.ADMIN], JwtTypes.WEB)
export class UploadResourceController {
constructor(
@Inject(TYPES.services.IUploadResourceService)
Expand All @@ -23,7 +23,6 @@ export class UploadResourceController {
@Req() stream: Request,
@Param('fileName') fileName: string,
): Promise<ReadResourceDto> {
console.log("🚀 ~ file: upload.resource.controller.ts:26 ~ UploadResourceController ~ fileName:", fileName)

const file = await this.uploadResourceService.execute({
bucket: 'resources',
Expand Down
2 changes: 1 addition & 1 deletion src/modules/resource/services/user-has.resource.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class UserHasResourceService implements IUserHasResourceService {
.innerJoin('project.resources', 'resources')
.innerJoin('project.users', 'users')
.where('users.id = :userId', { userId: userId })
.where('resources.fileName = :fileName', { fileName: fileName })
.andWhere('resources.fileName = :fileName', { fileName: fileName })
.getCount()

return !!(query)
Expand Down

0 comments on commit 633b3bc

Please sign in to comment.