Skip to content

fix(server): let a workspace whose plan has ended delete a brand - #1630

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/read-only-brand-delete
Oct 28, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/read-only-brand-delete

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

A workspace whose plan has ended may delete a brand without buying first. This is the product call left open in your #1589 follow-up 3. Ansvisor decided on 2026-10-27 that deleting a brand only removes what the person gave us, so leaving needs no purchase.

  • DELETE /brands/:id joins a new DATA_REMOVAL list in requireActiveSubscription, open whatever the plan. Only admins can delete, as before.
  • Every other brand write stays closed: POST /brands, PUT and PATCH /brands/:id, and any DELETE under a brand (for example /brands/b1/domains/d1).

This commit was meant for #1611. I pushed it a few minutes after you merged #1611, so it never reached main. It's a cherry-pick of that commit (6cc1c99) onto today's main. The web side is in #1612 (the Delete button stays open while read-only) and #1613 (deleteBrand stays in the coverage test's open list). Until this lands, that button answers 402.

Related issue

None. Follows #1589 and #1611 (your follow-up 3), and Ansvisor's product decision (2026-10-27).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd server && npx vitest run src/middleware/subscription.test.js
  2. On a cloud set-up, give an organization subscription_status = canceled:
    • an admin's DELETE /api/brands/:id deletes the brand;
    • POST /api/brands and PATCH /api/brands/:id still answer 402.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) — no web change
  • yarn typecheck passes (run from web/) — no web change
  • yarn format:check passes (run from web/) — no web change
  • Changes are focused — one concern per PR

Also run in server/: npm run format, npm run lint and npm test (3,339 tests).

🤖 Generated with Claude Code

Ansvisor's decision (2026-10-27), the product call on ansvisor#1589's follow-up
3: DELETE /brands/:id only removes what the person gave us, so it joins a
new DATA_REMOVAL list, open whatever the plan. Admins only, as before;
every other brand write stays closed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

What I checked:

  • What opens. DATA_REMOVAL has one entry, DELETE /brands/:id (with or without a trailing slash). isOpen is read only after decodeToken, as for COST_STOPPING, so a request with no signed-in person is still refused. The regex is case-sensitive and Express routing isn't, so DELETE /Brands/x still gets the 402. That's the safe way round. The test also covers POST /brands, PUT/PATCH /brands/:id, DELETE /brands/b1/domains/d1 and DELETE /brands, which all still get the 402.
  • Still admins only, still the person's own brand. The route itself hasn't changed. It checks assertBrandAccess (brand in the caller's organization, 404/403 otherwise), then profiles.role === 'admin' (403 otherwise). The middleware was the only thing standing between an ended workspace and that check, so the rules for who may delete stay the same.
  • No paid work. deleteBrand deletes in batches (delete_brand_results_batch), then deletes the brand row. Nothing calls a model, Cloro, Scrape.do, DataForSEO or a store. The triggers the cascade fires are database-only: the usage counters, the catalog_sources_forget product cleanup, and the citation-rollup queue, which skips a brand that no longer exists. A second click joins the run already going (inProgress).
  • Tests. On this branch, subscription.test.js passes (25 tests). With main's subscription.js under the same tests, the new test fails.
  • Merge. Clean on main 3f6a4d4. Also clean with #1612 and #1613, the web halves.

Before and after the API deploy: server only, so merging changes nothing until the API is deployed. The API in production predates #1589, so brand deletion works there today. Deploy this with #1589, not after it: an API with #1589 and without this answers 402 to an ended workspace's Delete brand.

@gkhngyk
gkhngyk merged commit 22c0591 into ansvisor:main Oct 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants