Skip to content

Commit

Permalink
Merge pull request #185 from Pixilib/read-all-label-for-content-permi…
Browse files Browse the repository at this point in the history
…ssion

Read all label for content permission
  • Loading branch information
salimkanoun authored Oct 12, 2024
2 parents 0f9aa09 + b5ddb15 commit 950447b
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions GaelO-Flow/src/autorouting/autorouting.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class AutoroutingHandler {
break;
case DestinationType.TMTVJOB:
if (level !== LevelType.STUDIES) {
console.error('TMTVJob can only be sent to series');
console.error('TMTV Jobs can only be sent to series');
return;
}

Expand Down Expand Up @@ -175,7 +175,7 @@ export class AutoroutingHandler {

const jobId = await this.processingQueueService.addJob(null, {
JobType: ProcessingJobType.TMTV,
TmtvJob: {
Payload: {
PtOrthancSeriesId: ptSeriesID,
CtOrthancSeriesId: ctSeriesID,
SendMaskToOrthancAs: [ProcessingMask.RTSS, ProcessingMask.SEG],
Expand Down
11 changes: 7 additions & 4 deletions GaelO-Flow/src/labels/labels.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import { LabelsService } from './labels.service';
import { LabelsController } from './labels.controller';
import { LabelDto } from './labels.dto';
import { AdminGuard, ReadAllGuard } from '../guards/roles.guard';

describe('LabelsController', () => {
let labelsController: LabelsController;
Expand Down Expand Up @@ -31,15 +32,17 @@ describe('LabelsController', () => {
});

describe('findAll', () => {
it('check if findAll has adminGuard', async () => {
it('check if findAll labels has OrGuard admin or Readall', async () => {

const guards = Reflect.getMetadata(
'__guards__',
LabelsController.prototype.findAll,
);
const guardNames = guards.map((guard: any) => guard.name);

expect(guardNames.length).toBe(1);
expect(guardNames).toContain('AdminGuard');
const orGuards = new guards[0]().__getGuards();
expect(orGuards.length).toBe(2);
expect(orGuards[0]).toBe(AdminGuard);
expect(orGuards[1]).toBe(ReadAllGuard);
});

it('checks if findAll of the controller calls findAll of the service', async () => {
Expand Down
5 changes: 3 additions & 2 deletions GaelO-Flow/src/labels/labels.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {
import { ApiBearerAuth, ApiResponse, ApiTags } from '@nestjs/swagger';

import { LabelsService } from './labels.service';
import { AdminGuard } from '../guards/roles.guard';
import { AdminGuard, ReadAllGuard } from '../guards/roles.guard';
import { LabelDto } from './labels.dto';
import { OrGuard } from '../guards/or.guard';

/**
* Controller for the labels related APIs.
Expand All @@ -25,7 +26,7 @@ export class LabelsController {
@ApiBearerAuth('access-token')
@ApiResponse({ status: 200, description: 'Get all labels', type: [String] })
@ApiResponse({ status: 401, description: 'Unauthorized' })
@UseGuards(AdminGuard)
@UseGuards(OrGuard([AdminGuard, ReadAllGuard]))
@Get()
async findAll(): Promise<string[]> {
const allLabels = await this.LabelsService.findAll();
Expand Down
2 changes: 1 addition & 1 deletion GaelO-Flow/src/processing/processing-job.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export class ProcessingJobDto {

@ApiProperty({ required: false })
@IsObject()
TmtvJob: TmtvJobDto;
Payload: TmtvJobDto;
}
2 changes: 1 addition & 1 deletion GaelO-Flow/src/processing/processing.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ describe('ProcessingController', () => {
const request = { user: { userId: 1 } };
const processingJobDto: ProcessingJobDto = {
JobType: ProcessingJobType.TMTV,
TmtvJob: {
Payload: {
CtOrthancSeriesId: 'CtOrthancSeriesId',
PtOrthancSeriesId: 'PtOrthancSeriesId',
SendMaskToOrthancAs: [ProcessingMask.SEG],
Expand Down
2 changes: 1 addition & 1 deletion GaelO-Flow/src/processing/processing.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function tmtvJob(
orthancClient: OrthancClient,
processingClient: ProcessingClient,
) {
const jobData: TmtvJobDto = job.data.TmtvJob;
const jobData: TmtvJobDto = job.data.Payload;

const tmtvService = new TmtvService(orthancClient, processingClient);
const ctOrthancSeriesId: string = jobData.CtOrthancSeriesId;
Expand Down
14 changes: 12 additions & 2 deletions GaelO-Flow/test/label.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Test, TestingModule } from '@nestjs/testing';
import * as request from 'supertest';

import { AppModule } from '../src/app.module';
import { loginAsAdmin, loginAsUser } from './login';
import { createCustomJwt, loginAsAdmin, loginAsUser } from './login';

describe('Labels (e2e)', () => {
let app: INestApplication;
Expand Down Expand Up @@ -89,9 +89,19 @@ describe('Labels (e2e)', () => {
});

it('/labels (GET)', async () => {
const readAllToken = await createCustomJwt(app, { ReadAll: true });
const response = await request(server)
.get('/labels')
.set('Authorization', `Bearer ${userToken}`);
.set('Authorization', `Bearer ${readAllToken}`);

expect(response.status).toBe(200);
});

it('/labels (GET)', async () => {
const importToken = await createCustomJwt(app, { Import: true });
const response = await request(server)
.get('/labels')
.set('Authorization', `Bearer ${importToken}`);

expect(response.status).toBe(403);
});
Expand Down
4 changes: 2 additions & 2 deletions GaelO-Flow/test/processing.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('Processing (e2e)', () => {
.set('Authorization', `Bearer ${adminToken}`)
.send({
JobType: 'tmtv',
TmtvJob: {
Payload: {
CtOrthancSeriesId: '123',
PtOrthancSeriesId: '456',
SendMaskToOrthancAs: ['MASK'],
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('Processing (e2e)', () => {
.set('Authorization', `Bearer ${token}`)
.send({
JobType: 'tmtv',
TmtvJob: {
Payload: {
CtOrthancSeriesId: '123',
PtOrthancSeriesId: '456',
SendMaskToOrthancAs: ['MASK'],
Expand Down

0 comments on commit 950447b

Please sign in to comment.