fix: Allow deleting failed and canceled imports (#12379)

* fix: Allow deleting failed and canceled imports

The delete policy only permitted imports in the Completed state, so the
overflow menu for Errored or Canceled imports rendered with no items.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* test: Cover Errored and Canceled in imports.delete

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Tom Moor
2026-05-18 21:37:16 -04:00
committed by GitHub
parent 4a6e94be3f
commit 597b6d801c
2 changed files with 26 additions and 17 deletions
+7 -1
View File
@@ -3,6 +3,12 @@ import { User, Team, Import } from "@server/models";
import { allow, can } from "./cancan";
import { and, isTeamAdmin, isTeamMutable, or } from "./utils";
const TerminalStates = [
ImportState.Completed,
ImportState.Errored,
ImportState.Canceled,
];
allow(User, ["createImport", "listImports"], Team, (actor, team) =>
and(isTeamAdmin(actor, team), isTeamMutable(actor))
);
@@ -14,7 +20,7 @@ allow(User, "read", Import, (actor, importModel) =>
allow(User, "delete", Import, (actor, importModel) =>
and(
can(actor, "read", importModel),
importModel?.state === ImportState.Completed
!!importModel && TerminalStates.includes(importModel.state)
)
);
+6 -3
View File
@@ -177,10 +177,12 @@ describe("#imports.info", () => {
});
describe("#imports.delete", () => {
it("should delete the import", async () => {
it.each([ImportState.Completed, ImportState.Errored, ImportState.Canceled])(
"should delete the import when in %s state",
async (state) => {
const admin = await buildAdmin();
const importModel = await buildImport({
state: ImportState.Completed,
state,
createdById: admin.id,
teamId: admin.teamId,
});
@@ -194,7 +196,8 @@ describe("#imports.delete", () => {
expect(res.status).toEqual(200);
expect(body.success).toEqual(true);
});
}
);
it("should throw error when import is not in deletable state", async () => {
const admin = await buildAdmin();