Skip to content

fix: hide promote/archive buttons for template versions from users without permission #10555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions site/src/pages/TemplatePage/TemplateVersionsPage/VersionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const VersionRow: React.FC<VersionRowProps> = ({
});

const jobStatus = version.job.status;
const showActions = onPromoteClick || onArchiveClick;

return (
<TimelineEntry
Expand Down Expand Up @@ -77,6 +78,7 @@ export const VersionRow: React.FC<VersionRowProps> = ({
<Stack direction="row" alignItems="center" spacing={2}>
{isActive && <Pill text="Active" type="success" />}
{isLatest && <Pill text="Newest" type="info" />}

{jobStatus === "pending" && (
<Pill text={<>Pending&hellip;</>} type="warning" lightBorder />
)}
Expand All @@ -87,34 +89,35 @@ export const VersionRow: React.FC<VersionRowProps> = ({
<Pill text="Canceled" type="neutral" lightBorder />
)}
{jobStatus === "failed" && <Pill text="Failed" type="error" />}
{jobStatus === "failed" ? (
<Button
css={styles.promoteButton}
disabled={isActive || version.archived}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
if (onArchiveClick) {
onArchiveClick(version.id);
}
}}
>
Archive&hellip;
</Button>
) : (
<Button
css={styles.promoteButton}
disabled={isActive || jobStatus !== "succeeded"}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
if (onPromoteClick) {
onPromoteClick(version.id);
}
}}
>
Promote&hellip;
</Button>

{showActions && (
<>
{jobStatus === "failed" ? (
<Button
css={styles.promoteButton}
disabled={isActive || version.archived}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onArchiveClick?.(version.id);
}}
>
Archive&hellip;
</Button>
) : (
<Button
css={styles.promoteButton}
disabled={isActive || jobStatus !== "succeeded"}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onPromoteClick?.(version.id);
}}
>
Promote&hellip;
</Button>
)}
</>
)}
</Stack>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,14 @@ export const Example: Story = {
},
MockTemplateVersion,
],
onPromoteClick: undefined,
},
};

export const CanPromote: Story = {
export const NoEditPermission: Story = {
args: {
activeVersionId: MockTemplateVersion.id,
onPromoteClick: action("onPromoteClick"),
versions: [
{
...MockTemplateVersion,
id: "2",
name: "test-template-version-2",
created_at: "2022-05-18T18:39:01.382927298Z",
},
MockTemplateVersion,
],
...Example.args,
onPromoteClick: undefined,
onArchiveClick: undefined,
},
};

Expand Down Expand Up @@ -95,6 +86,14 @@ export const BuildStatuses: Story = {
},
};

export const BuildStatusesNoEditPermission: Story = {
args: {
...BuildStatuses.args,
onPromoteClick: undefined,
onArchiveClick: undefined,
},
};

export const Empty: Story = {
args: {
versions: [],
Expand Down