Skip to content

Commit

Permalink
Working example
Browse files Browse the repository at this point in the history
  • Loading branch information
wcalderipe committed Feb 7, 2024
1 parent 8cb4862 commit c64b1c2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
3 changes: 2 additions & 1 deletion apps/authz/src/app/__test__/e2e/admin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,14 +459,15 @@ describe('Admin Endpoints', () => {
],
request: {
action: 'setPolicyRules',
nonce: 'random-nonce',
data: [
{
then: 'permit',
name: 'examplePermitPolicy',
when: [
{
criterion: 'checkAction',
args: ['fooo']
args: ['signTransaction']
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class SetPolicyRulesDto extends BaseActionDto {
export class SetPolicyRulesRequestDto extends BaseAdminRequestPayloadDto {
@IsDefined()
@ValidateNested()
@Type(() => SetPolicyRulesDto)
@ApiProperty()
request: SetPolicyRulesDto
}
22 changes: 3 additions & 19 deletions packages/authz-shared/src/lib/type/policy-builder.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { Intents } from '@narval/transaction-request-intent'
import { ApiExtraModels, ApiProperty, getSchemaPath } from '@nestjs/swagger'
import { Type } from 'class-transformer'
import { IsDefined, IsEnum, IsIn, IsString } from 'class-validator'
import { IsDefined, IsEnum, IsIn, IsString, ValidateNested } from 'class-validator'

export const Then = {
PERMIT: 'permit',
Expand Down Expand Up @@ -129,10 +129,8 @@ class ActionCriterion extends BaseCriterion {
})
criterion: typeof Criterion.CHECK_ACTION

// TODO (@sam, 07/02/24): Check how to validate an array of enums.
@IsDefined()
// @IsIn(Object.values(Action))
@IsEnum(Object.values(Action), {
@IsEnum(Action, {
each: true
})
@ApiProperty({
Expand Down Expand Up @@ -387,27 +385,13 @@ export class Policy {
@ApiProperty()
name: string

// @ValidateNested({ each: true })
@ValidateNested({ each: true })
// @Type(() => BaseCriterion, {
// discriminator: {
// property: 'criterion',
// subTypes: [{ value: ActionCriterion, name: Criterion.CHECK_ACTION }]
// }
// })
// @Type((opts) => {
// const foo = opts?.object.when.map((item: PolicyCriterion) => {
// switch (item.criterion) {
// case Criterion.CHECK_ACTION:
// return ActionCriterion
// default:
// return BaseCriterion
// }
// })

// console.log(foo)

// return foo
// })
@Type(() => ActionCriterion)
@ApiProperty({
oneOf: SUPPORTED_CRITERION.map((entity) => ({
Expand Down

0 comments on commit c64b1c2

Please sign in to comment.