Skip to content

Commit

Permalink
fix : only org admin can approve / disapprove
Browse files Browse the repository at this point in the history
  • Loading branch information
psiddharthdesign committed Aug 6, 2024
1 parent 5b0e814 commit ef4bec2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -315,36 +316,36 @@ export const ProjectRunDetails: React.FC<{
)}

</div>
{['approved', 'pending_apply', 'running_apply', 'succeeded'].includes(ToSnakeCase(run.status)) && (
{run.is_approved === true && (
<T.Small className="flex items-center"><CheckCircle2 className="size-5 text-green-500 mr-2" /> Approved by: </T.Small>
)}
{run.status === ToTitleCase('discarded') && (
{run.is_approved === false && (
<T.Small className="flex items-center"><XCircle className="text-red-500 mr-2" /> Discarded by: </T.Small>
)}
{!(["queued", "pending_plan", "running_plan", "pending_approval", 'failed'].includes(ToSnakeCase(run.status))) && (
{run.is_approved !== null && (
<motion.div
className="pt-4 mt-auto"
initial={{ opacity: 0, y: 50 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.5, delay: 0.2 }}
>
<div className="flex items-center mb-4">
{loggedInUser.avatar_url ? (
{approverUser?.avatar_url ? (
<Image
src={loggedInUser.avatar_url}
alt={loggedInUser.full_name || 'User Avatar'}
src={approverUser.avatar_url}
alt={approverUser.full_name || 'User Avatar'}
width={40}
height={40}
className="rounded-full mr-3"
/>
) : (
<div className="w-10 h-10 rounded-full bg-primary text-primary-foreground flex items-center justify-center mr-3">
{loggedInUser.full_name?.charAt(0).toUpperCase() || 'A'}
{approverUser?.full_name?.charAt(0).toUpperCase() || 'A'}
</div>
)}

<div>
<p className="font-medium">{loggedInUser.full_name}</p>
<p className="font-medium">{approverUser?.full_name}</p>
<p className="text-sm text-muted-foreground">
{isUserOrgAdmin ? 'Organization Admin' : 'Member'}
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type ProjectRunDetailsProps = {
fullRepoName: string | null
planBatchId: string | null
applyBatchId: string | null
approverUser: Table<'user_profiles'> | null
}


Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -101,6 +107,7 @@ export default async function RunDetailPage({
>
<DynamicProjectRunDetails run={run}
loggedInUser={userProfile}
approverUser={approverUserProfile}
isUserOrgAdmin={isOrganizationAdmin}
tfOutput={planData.terraform_output}
workflowRunUrl={planData.workflow_run_url}
Expand Down

0 comments on commit ef4bec2

Please sign in to comment.