Skip to content

Commit

Permalink
Merge pull request #62 from ti-broish/protocols-statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
hkdobrev authored Jun 28, 2021
2 parents ae0c950 + 4bc4b8f commit 4b388bf
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/casl/casl-ability.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class CaslAbilityFactory {
// read access to everything
can(Action.Read, 'all');
can([Action.Manage], User);
can([Action.Manage], Protocol);
can([Action.Create, Action.Update, Action.Publish], Post);
// Delete only unpublished posts
can(Action.Delete, Post, { publishAt: { $eq: null } });
Expand Down
34 changes: 34 additions & 0 deletions src/protocols/api/protocols-statuses.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Ability } from '@casl/ability';
import {
Controller,
Get,
HttpCode,
UsePipes,
ValidationPipe,
UseGuards,
} from '@nestjs/common';
import { Action } from 'src/casl/action.enum';
import { CheckPolicies } from 'src/casl/check-policies.decorator';
import { PoliciesGuard } from 'src/casl/policies.guard';
import { Protocol, ProtocolStatus } from '../entities/protocol.entity';
import { ProtocolDto } from './protocol.dto';

@Controller('protocols/statuses')
export class ProtocolsStatusesController {
@Get()
@HttpCode(200)
@UseGuards(PoliciesGuard)
@CheckPolicies((ability: Ability) => ability.can(Action.Manage, Protocol))
@UsePipes(new ValidationPipe({ transform: true }))
index(): ProtocolDto[] {
const result: ProtocolDto[] = [];

Object.values(ProtocolStatus).forEach((status: ProtocolStatus) => {
const v = new ProtocolDto();
v.status = status;
result.push(v);
});

return result;
}
}
1 change: 0 additions & 1 deletion src/protocols/entities/protocol.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export enum ProtocolStatus {
REPLACED = 'replaced',
READY = 'ready',
APPROVED = 'approved',
PUBLISHING = 'publishing',
PUBLISHED = 'published',
}

Expand Down
4 changes: 0 additions & 4 deletions src/protocols/entities/protocols.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ export class ProtocolsRepository {
return qb.getMany();
}

async markProtocolsAsPublishing(protocols: Protocol[]): Promise<void> {
this.markProtocolsAs(ProtocolStatus.PUBLISHING, protocols);
}

async markProtocolsAsPublished(protocols: Protocol[]): Promise<void> {
this.markProtocolsAs(ProtocolStatus.PUBLISHED, protocols);
}
Expand Down
7 changes: 6 additions & 1 deletion src/protocols/protocols.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ProtocolsRepository } from './entities/protocols.repository';
import { Violation } from '../violations/entities/violation.entity';
import { ViolationsModule } from '../violations/violations.module';
import { SectionsModule } from 'src/sections/sections.module';
import { ProtocolsStatusesController } from './api/protocols-statuses.controller';

@Module({
imports: [
Expand All @@ -20,7 +21,11 @@ import { SectionsModule } from 'src/sections/sections.module';
SectionsModule,
ViolationsModule,
],
controllers: [ProtocolsController, ProtocolAssigneesController],
controllers: [
ProtocolsStatusesController,
ProtocolsController,
ProtocolAssigneesController,
],
providers: [ProtocolsRepository],
exports: [ProtocolsRepository],
})
Expand Down

0 comments on commit 4b388bf

Please sign in to comment.