diff --git a/backend/src/main/java/run/webup/platform/DeploymentWorker.java b/backend/src/main/java/run/webup/platform/DeploymentWorker.java index fe07501..7f715b9 100644 --- a/backend/src/main/java/run/webup/platform/DeploymentWorker.java +++ b/backend/src/main/java/run/webup/platform/DeploymentWorker.java @@ -43,6 +43,8 @@ public class DeploymentWorker { UUID id = UUID.fromString(op.get("id").toString()); String lease = op.get("lease_token").toString(); try { + if ("RESUME".equals(op.get("action"))) + operations.checkAllowed(UUID.fromString(op.get("project_id").toString())); gateway.request( "/runtime/projects/" + op.get("project_id") + "/state", Map.of("action", op.get("action"), "operationId", id.toString())); diff --git a/backend/src/main/java/run/webup/platform/HostingService.java b/backend/src/main/java/run/webup/platform/HostingService.java index 0719367..97fec5d 100644 --- a/backend/src/main/java/run/webup/platform/HostingService.java +++ b/backend/src/main/java/run/webup/platform/HostingService.java @@ -282,8 +282,7 @@ public class HostingService { } Map beforeSourceSnapshot(UUID user, UUID project, String key) { - if ("ARCHIVED".equals(own(user, project).get("status"))) - throw new ApiError.Failure(409, "归档项目不能发布"); + own(user, project); operations.checkAllowed(project); var replay = deploymentReplay(project, key); if (replay != null) return replay; diff --git a/backend/src/main/java/run/webup/platform/RuntimeOperationService.java b/backend/src/main/java/run/webup/platform/RuntimeOperationService.java index 1a970e5..071e2b3 100644 --- a/backend/src/main/java/run/webup/platform/RuntimeOperationService.java +++ b/backend/src/main/java/run/webup/platform/RuntimeOperationService.java @@ -28,6 +28,7 @@ public class RuntimeOperationService { return UUID.fromString(p.get("id").toString()); } if (action.equals("RESUME")) { + checkNotArchived(project); var allowed = db.queryForList("SELECT status FROM project_moderation WHERE project_id=?", project); if (allowed.isEmpty() || !"APPROVED".equals(allowed.getFirst().get("status"))) @@ -98,6 +99,7 @@ public class RuntimeOperationService { } public void checkAllowed(UUID project) { + checkNotArchived(project); String message = switch (reviewStatus(project)) { case "APPROVED" -> null; @@ -107,4 +109,12 @@ public class RuntimeOperationService { }; if (message != null) throw new ApiError.Failure(403, message); } + + private void checkNotArchived(UUID project) { + if (db.queryForObject( + "SELECT COUNT(*) FROM projects WHERE id=? AND status='ARCHIVED'", + Integer.class, + project) + != 0) throw new ApiError.Failure(409, "归档项目不能执行运行操作"); + } } diff --git a/backend/src/test/java/run/webup/platform/HostingIntegrationTest.java b/backend/src/test/java/run/webup/platform/HostingIntegrationTest.java index a5123e6..9618807 100644 --- a/backend/src/test/java/run/webup/platform/HostingIntegrationTest.java +++ b/backend/src/test/java/run/webup/platform/HostingIntegrationTest.java @@ -18,6 +18,7 @@ class HostingIntegrationTest { @Autowired WalletService wallets; @Autowired HostingService hosting; @Autowired DeploymentCoordinator deployments; + @Autowired RuntimeOperationService operations; @Autowired ObjectMapper json; @MockitoBean EphemeralStore store; UUID user, project, plan; @@ -136,6 +137,41 @@ class HostingIntegrationTest { rollback.path("services").get(0).path("environment").path("ADMIN_PASSWORD").asText()); } + @Test + void archivedProjectCannotQueueOrApplyReleasesOrResumeRuntime() { + hosting.subscribe(user, project, plan, "archived-plan"); + hosting.service(user, project, null, spec(200)); + hosting.deploy(user, project, "before-archive", null); + users.db().update("UPDATE projects SET status='ARCHIVED' WHERE id=?", project); + assertEquals( + 409, + assertThrows( + ApiError.Failure.class, () -> hosting.deploy(user, project, "after-archive", null)) + .status); + assertEquals( + 409, + assertThrows( + ApiError.Failure.class, + () -> hosting.deploy(user, project, "rollback", UUID.randomUUID())) + .status); + assertEquals( + 409, + assertThrows( + ApiError.Failure.class, () -> hosting.beforeSourceSnapshot(user, project, "source")) + .status); + assertEquals( + 409, + assertThrows( + ApiError.Failure.class, + () -> operations.enqueue(project, user, "RESUME", "test", "archived-resume")) + .status); + var queued = deployments.claim(); + assertNotNull(queued); + assertEquals( + 409, assertThrows(ApiError.Failure.class, () -> deployments.payload(queued)).status); + assertNotNull(operations.enqueue(project, user, "SUSPEND", "test", "archived-suspend")); + } + @Test void purchaseIsIdempotentAndSnapshotsPlan() { hosting.subscribe(user, project, plan, "first");