mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: hide promote/archive buttons for template versions from users without permission (#10555)
This commit is contained in:
@@ -33,6 +33,7 @@ export const VersionRow: React.FC<VersionRowProps> = ({
|
||||
});
|
||||
|
||||
const jobStatus = version.job.status;
|
||||
const showActions = onPromoteClick || onArchiveClick;
|
||||
|
||||
return (
|
||||
<TimelineEntry
|
||||
@@ -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…</>} type="warning" lightBorder />
|
||||
)}
|
||||
@@ -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…
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
css={styles.promoteButton}
|
||||
disabled={isActive || jobStatus !== "succeeded"}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (onPromoteClick) {
|
||||
onPromoteClick(version.id);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Promote…
|
||||
</Button>
|
||||
|
||||
{showActions && (
|
||||
<>
|
||||
{jobStatus === "failed" ? (
|
||||
<Button
|
||||
css={styles.promoteButton}
|
||||
disabled={isActive || version.archived}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
onArchiveClick?.(version.id);
|
||||
}}
|
||||
>
|
||||
Archive…
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
css={styles.promoteButton}
|
||||
disabled={isActive || jobStatus !== "succeeded"}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
onPromoteClick?.(version.id);
|
||||
}}
|
||||
>
|
||||
Promote…
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Stack>
|
||||
</Stack>
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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: [],
|
||||
|
||||
Reference in New Issue
Block a user