Feat: Request access

This commit is contained in:
Daniel Hougaard
2024-04-03 16:38:52 -07:00
parent 7e29a6a656
commit eca36f1993

View File

@@ -0,0 +1,37 @@
import { ForbiddenError, subject } from "@casl/ability";
import { BadRequestError } from "@app/lib/errors";
import { ActorType } from "@app/services/auth/auth-type";
import { ProjectPermissionActions, ProjectPermissionSub } from "../permission/project-permission";
import { TVerifyApprovers } from "./access-approval-policy-types";
export const verifyApprovers = async ({
approverProjectMemberships,
projectId,
orgId,
envSlug,
actorAuthMethod,
secretPath,
permissionService
}: TVerifyApprovers) => {
for (const approver of approverProjectMemberships) {
try {
// eslint-disable-next-line no-await-in-loop
const { permission: approverPermission } = await permissionService.getProjectPermission(
ActorType.USER,
approver.userId,
projectId,
actorAuthMethod,
orgId
);
ForbiddenError.from(approverPermission).throwUnlessCan(
ProjectPermissionActions.Create,
subject(ProjectPermissionSub.Secrets, { environment: envSlug, secretPath })
);
} catch (err) {
throw new BadRequestError({ message: "One or more approvers doesn't have access to be specified secret path" });
}
}
};