Skip to content

Commit

Permalink
refactor - Refactor authority check functions in API 180
Browse files Browse the repository at this point in the history
  • Loading branch information
szabodaniel995 committed Apr 21, 2024
1 parent dc0caa2 commit 2935c5b
Show file tree
Hide file tree
Showing 37 changed files with 796 additions and 669 deletions.
4 changes: 3 additions & 1 deletion apps/api/src/approval/controller/approval.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { REDIS_CLIENT } from '../../provider/redis.provider'
import { RedisClientType } from 'redis'
import { mockDeep } from 'jest-mock-extended'
import { ProviderModule } from '../../provider/provider.module'
import { AuthorityCheckerService } from '../../common/authority-checker.service'

describe('ApprovalController', () => {
let controller: ApprovalController
Expand All @@ -34,7 +35,8 @@ describe('ApprovalController', () => {
{
provide: MAIL_SERVICE,
useClass: MockMailService
}
},
AuthorityCheckerService
]
})
.overrideProvider(REDIS_CLIENT)
Expand Down
4 changes: 3 additions & 1 deletion apps/api/src/approval/service/approval.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { REDIS_CLIENT } from '../../provider/redis.provider'
import { RedisClientType } from 'redis'
import { mockDeep } from 'jest-mock-extended'
import { ProviderModule } from '../../provider/provider.module'
import { AuthorityCheckerService } from '../../common/authority-checker.service'

describe('ApprovalService', () => {
let service: ApprovalService
Expand All @@ -32,7 +33,8 @@ describe('ApprovalService', () => {
{
provide: MAIL_SERVICE,
useClass: MockMailService
}
},
AuthorityCheckerService
]
})
.overrideProvider(REDIS_CLIENT)
Expand Down
30 changes: 16 additions & 14 deletions apps/api/src/approval/service/approval.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
UpdateVariableMetadata,
UpdateWorkspaceMetadata
} from '../approval.types'
import getWorkspaceWithAuthority from '../../common/get-workspace-with-authority'
import { AuthorityCheckerService } from '../../common/authority-checker.service'

@Injectable()
export class ApprovalService {
Expand All @@ -43,7 +43,8 @@ export class ApprovalService {
private readonly projectService: ProjectService,
private readonly environmentService: EnvironmentService,
private readonly secretService: SecretService,
private readonly variableService: VariableService
private readonly variableService: VariableService,
public authorityCheckerService: AuthorityCheckerService
) {}

async updateApproval(user: User, reason: string, approvalId: Approval['id']) {
Expand Down Expand Up @@ -453,12 +454,12 @@ export class ApprovalService {
actions: ApprovalAction[],
statuses: ApprovalStatus[]
) {
await getWorkspaceWithAuthority(
user.id,
workspaceId,
Authority.MANAGE_APPROVALS,
this.prisma
)
await this.authorityCheckerService.checkAuthorityOverWorkspace({
userId: user.id,
entity: { id: workspaceId },
authority: Authority.MANAGE_APPROVALS,
prisma: this.prisma
})

return await this.prisma.approval.findMany({
where: {
Expand Down Expand Up @@ -493,12 +494,13 @@ export class ApprovalService {
actions: ApprovalAction[],
statuses: ApprovalStatus[]
) {
await getWorkspaceWithAuthority(
user.id,
workspaceId,
Authority.READ_WORKSPACE,
this.prisma
)
await this.authorityCheckerService.checkAuthorityOverWorkspace({
userId: user.id,
entity: { id: workspaceId },
authority: Authority.READ_WORKSPACE,

prisma: this.prisma
})

return this.prisma.approval.findMany({
where: {
Expand Down
Loading

0 comments on commit 2935c5b

Please sign in to comment.