Feat: Request access

This commit is contained in:
Daniel Hougaard
2024-05-07 17:30:35 +02:00
parent 7a3a9ca9ea
commit 4326ce970a
6 changed files with 7 additions and 9 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ import knex from "knex";
import { writeFileSync } from "fs"; import { writeFileSync } from "fs";
dotenv.config({ dotenv.config({
path: path.join(__dirname, "../../.env.migration") path: path.join(__dirname, "../../.env")
}); });
const db = knex({ const db = knex({
@@ -34,6 +34,7 @@ export async function up(knex: Knex): Promise<void> {
export async function down(knex: Knex): Promise<void> { export async function down(knex: Knex): Promise<void> {
await knex.schema.dropTableIfExists(TableName.AccessApprovalPolicyApprover); await knex.schema.dropTableIfExists(TableName.AccessApprovalPolicyApprover);
await knex.schema.dropTableIfExists(TableName.AccessApprovalPolicy); await knex.schema.dropTableIfExists(TableName.AccessApprovalPolicy);
await dropOnUpdateTrigger(knex, TableName.AccessApprovalPolicy); await dropOnUpdateTrigger(knex, TableName.AccessApprovalPolicy);
await dropOnUpdateTrigger(knex, TableName.AccessApprovalPolicyApprover); await dropOnUpdateTrigger(knex, TableName.AccessApprovalPolicyApprover);
} }
@@ -155,7 +155,6 @@ export const accessApprovalPolicyServiceFactory = ({
actorAuthMethod, actorAuthMethod,
actorOrgId actorOrgId
); );
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.SecretApproval); ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.SecretApproval);
const updatedPolicy = await accessApprovalPolicyDAL.transaction(async (tx) => { const updatedPolicy = await accessApprovalPolicyDAL.transaction(async (tx) => {
@@ -179,7 +178,6 @@ export const accessApprovalPolicyServiceFactory = ({
); );
await verifyApprovers({ await verifyApprovers({
projectId: accessApprovalPolicy.projectId,
orgId: actorOrgId, orgId: actorOrgId,
envSlug: accessApprovalPolicy.environment.slug, envSlug: accessApprovalPolicy.environment.slug,
secretPath: doc.secretPath!, secretPath: doc.secretPath!,
@@ -189,8 +187,6 @@ export const accessApprovalPolicyServiceFactory = ({
}); });
if (secretApprovers.length !== approvers.length) if (secretApprovers.length !== approvers.length)
throw new BadRequestError({ message: "Approver not found in project" });
if (doc.approvals > secretApprovers.length)
throw new BadRequestError({ message: "Approvals cannot be greater than approvers" }); throw new BadRequestError({ message: "Approvals cannot be greater than approvers" });
await accessApprovalPolicyApproverDAL.delete({ policyId: doc.id }, tx); await accessApprovalPolicyApproverDAL.delete({ policyId: doc.id }, tx);
await accessApprovalPolicyApproverDAL.insertMany( await accessApprovalPolicyApproverDAL.insertMany(
@@ -67,6 +67,10 @@ export const SecretApprovalPage = () => {
<TabPanel value={TabSection.ResourcePolicies}> <TabPanel value={TabSection.ResourcePolicies}>
<AccessApprovalPolicyList workspaceId={projectId} /> <AccessApprovalPolicyList workspaceId={projectId} />
</TabPanel> </TabPanel>
<TabPanel value={TabSection.ResourcePolicies}>
<AccessApprovalPolicyList workspaceId={workspaceId} />
</TabPanel>
</Tabs> </Tabs>
</div> </div>
); );
@@ -83,7 +83,7 @@ export const AccessApprovalPolicyList = ({ workspaceId }: IProps) => {
return ( return (
<div> <div>
<div className="mb-6 flex justify-between items-end"> <div className="mb-6 flex items-end justify-between">
<div className="flex flex-col"> <div className="flex flex-col">
<span className="text-xl font-semibold text-mineshaft-100">Access Request Policies</span> <span className="text-xl font-semibold text-mineshaft-100">Access Request Policies</span>
<div className="mt-2 text-sm text-bunker-300"> <div className="mt-2 text-sm text-bunker-300">
@@ -177,7 +177,6 @@ export const AccessPolicyForm = ({
/> />
<Controller <Controller
control={control}
name="secretPath" name="secretPath"
render={({ field, fieldState: { error } }) => ( render={({ field, fieldState: { error } }) => (
<FormControl label="Secret Path" isError={Boolean(error)} errorText={error?.message}> <FormControl label="Secret Path" isError={Boolean(error)} errorText={error?.message}>
@@ -187,8 +186,6 @@ export const AccessPolicyForm = ({
/> />
<Controller <Controller
control={control}
name="approvers"
render={({ field: { value, onChange }, fieldState: { error } }) => ( render={({ field: { value, onChange }, fieldState: { error } }) => (
<FormControl <FormControl
label="Approvers Required" label="Approvers Required"