Skip to content

Commit 04d397e

Browse files
committed
Make granting actor optional
1 parent 29aa89f commit 04d397e

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

packages/core/core-flows/src/rbac/workflows/assign-roles.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
WorkflowResponse,
55
createWorkflow,
66
transform,
7+
when,
78
} from "@medusajs/framework/workflows-sdk"
89
import { createRoleAssignmentsStep } from "../steps/create-role-assignments"
910
import { validateActorRolePermissionsStep } from "../steps/validate-actor-role-permissions"
@@ -17,8 +18,8 @@ export type AssignRolesWorkflowInput = {
1718
reference: string
1819
reference_id: string | string[]
1920
role_id: string | string[]
20-
granting_actor_id: string
21-
granting_actor: string
21+
granting_actor_id?: string
22+
granting_actor?: string
2223
/**
2324
* Server-derived scope context the grant happens within. When provided, the
2425
* granting actor's privileges are evaluated strictly within it; omitted =
@@ -60,11 +61,16 @@ export const assignRolesWorkflow = createWorkflow(
6061

6162
validateRolesExistStep(normalizedInput.roleIds)
6263

63-
validateActorRolePermissionsStep({
64-
actor_id: normalizedInput.grantingActorId,
65-
actor: normalizedInput.grantingActor,
66-
role_ids: normalizedInput.roleIds,
67-
scope: input.scope,
64+
when(
65+
{ normalizedInput },
66+
({ normalizedInput }) => !!normalizedInput.grantingActorId
67+
).then(() => {
68+
validateActorRolePermissionsStep({
69+
actor_id: normalizedInput.grantingActorId!,
70+
actor: normalizedInput.grantingActor,
71+
role_ids: normalizedInput.roleIds,
72+
scope: input.scope,
73+
})
6874
})
6975

7076
const assignments = transform(

packages/core/core-flows/src/rbac/workflows/unassign-roles.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
WorkflowResponse,
55
createWorkflow,
66
transform,
7+
when,
78
} from "@medusajs/framework/workflows-sdk"
89
import { deleteRoleAssignmentsStep } from "../steps/delete-role-assignments"
910
import { validateActorRolePermissionsStep } from "../steps/validate-actor-role-permissions"
@@ -16,8 +17,8 @@ export type UnassignRolesWorkflowInput = {
1617
reference: string
1718
reference_id: string | string[]
1819
role_id: string | string[]
19-
granting_actor_id: string
20-
granting_actor: string
20+
granting_actor_id?: string
21+
granting_actor?: string
2122
/**
2223
* Server-derived scope context the grant happens within. When provided, the
2324
* granting actor's privileges are evaluated strictly within it; omitted =
@@ -57,11 +58,16 @@ export const unassignRolesWorkflow = createWorkflow(
5758
}
5859
})
5960

60-
validateActorRolePermissionsStep({
61-
actor_id: normalizedInput.grantingActorId,
62-
actor: normalizedInput.grantingActor,
63-
role_ids: normalizedInput.roleIds,
64-
scope: input.scope,
61+
when(
62+
{ normalizedInput },
63+
({ normalizedInput }) => !!normalizedInput.grantingActorId
64+
).then(() => {
65+
validateActorRolePermissionsStep({
66+
actor_id: normalizedInput.grantingActorId!,
67+
actor: normalizedInput.grantingActor,
68+
role_ids: normalizedInput.roleIds,
69+
scope: input.scope,
70+
})
6571
})
6672

6773
const deleteInput = transform(

0 commit comments

Comments
 (0)