From ef4bec25e27211ee339f507c56588a4597fe8d27 Mon Sep 17 00:00:00 2001 From: psiddharthdesign <107192927+psiddharthdesign@users.noreply.github.com> Date: Wed, 7 Aug 2024 02:53:42 +0530 Subject: [PATCH] fix : only org admin can approve / disapprove --- .../runs/[runId]/ProjectRunDetails.tsx | 19 ++++++++++--------- .../[projectSlug]/runs/[runId]/page.tsx | 9 ++++++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/ProjectRunDetails.tsx b/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/ProjectRunDetails.tsx index d1c763ba..8976abf2 100644 --- a/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/ProjectRunDetails.tsx +++ b/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/ProjectRunDetails.tsx @@ -117,6 +117,7 @@ function RenderContent({ export const ProjectRunDetails: React.FC<{ run: Table<'digger_runs'>, loggedInUser: Table<'user_profiles'> + approverUser: Table<'user_profiles'> | null isUserOrgAdmin: boolean tfOutput: string | null, workflowRunUrl: string | null, @@ -125,7 +126,7 @@ export const ProjectRunDetails: React.FC<{ fullRepoName: string | null planBatchId: string | null applyBatchId: string | null -}> = ({ run: initialRun, loggedInUser, isUserOrgAdmin, tfOutput: initialTfOutput, +}> = ({ run: initialRun, loggedInUser, approverUser, isUserOrgAdmin, tfOutput: initialTfOutput, workflowRunUrl: initialWorkflowRunUrl, applyTerraformOutput: initialApplyTerraformOutput, applyWorkflowRunUrl: initialApplyWorkflowRunUrl, @@ -315,13 +316,13 @@ export const ProjectRunDetails: React.FC<{ )} - {['approved', 'pending_apply', 'running_apply', 'succeeded'].includes(ToSnakeCase(run.status)) && ( + {run.is_approved === true && ( Approved by: )} - {run.status === ToTitleCase('discarded') && ( + {run.is_approved === false && ( Discarded by: )} - {!(["queued", "pending_plan", "running_plan", "pending_approval", 'failed'].includes(ToSnakeCase(run.status))) && ( + {run.is_approved !== null && (
- {loggedInUser.avatar_url ? ( + {approverUser?.avatar_url ? ( {loggedInUser.full_name ) : (
- {loggedInUser.full_name?.charAt(0).toUpperCase() || 'A'} + {approverUser?.full_name?.charAt(0).toUpperCase() || 'A'}
)}
-

{loggedInUser.full_name}

+

{approverUser?.full_name}

{isUserOrgAdmin ? 'Organization Admin' : 'Member'}

diff --git a/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/page.tsx b/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/page.tsx index d8a753de..050ed0cc 100644 --- a/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/page.tsx +++ b/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/runs/[runId]/page.tsx @@ -37,6 +37,7 @@ type ProjectRunDetailsProps = { fullRepoName: string | null planBatchId: string | null applyBatchId: string | null + approverUser: Table<'user_profiles'> | null } @@ -65,9 +66,14 @@ export default async function RunDetailPage({ const [project, userProfile, repoDetails] = await Promise.all([ getSlimProjectById(project_id), getUserProfile(user.id), - getRepoDetails(run.repo_id) + getRepoDetails(run.repo_id), ]); + let approverUserProfile + if (run.approver_user_id) { + approverUserProfile = await getUserProfile(run.approver_user_id); + } + // Fetch organization role and batch IDs in parallel const [organizationRole, planBatchId, applyBatchId] = await Promise.all([ getLoggedInUserOrganizationRole(project.organization_id), @@ -101,6 +107,7 @@ export default async function RunDetailPage({ >