Make the inbox global instead of per-project

A card either sits in its owner's inbox (project_id AND status_id both NULL)
or belongs to exactly one project with a status in it (both set) -- enforced
by a CHECK constraint, never one without the other. The inbox is global to a
user now, not per-project: cards can move from a project into the inbox and
back into any status column of any project.

Backend
- migrations/009: rebuilds `cards` (SQLite can't relax NOT NULL / add a CHECK
  in place) with a nullable project_id, a new owner_id (cards need direct
  ownership once they can have no project), and the CHECK constraint. Cards
  that had no status (the old per-project inbox) move to the new global inbox.
  status_id's FK is now ON DELETE RESTRICT, not SET NULL -- nulling it alone
  would violate the invariant, and there's no status-delete endpoint anyway.
- CardRepository: "column" is now (owner_id, project_id, status_id); every
  method that dealt with a project's columns is generalised to also cover the
  inbox and cross-project moves (orderColumn, idsInColumn, repack, ...).
- CardController/routes: single-card and ordering routes move to global,
  since a card may have no project to nest them under --
  GET/PATCH/DELETE /api/cards/{id}, PUT /api/cards/order (body now takes
  project_id + status_id, both null for the inbox). New GET/POST
  /api/inbox/cards. PATCH no longer accepts status_id -- moving a card, in or
  out of a project, is exclusively PUT /api/cards/order now. A card created
  directly in a project (POST /api/projects/{id}/cards) lands in its first
  status, since a project card can't have no status.
- Tests: ProjectTest/CardStatusTest updated for the new routes; CardOrderTest
  rewritten with full inbox/cross-project coverage. 57 tests pass.

Frontend
- New stores/inbox.ts (the global inbox) and lib/cardOrder.ts (the shared
  PUT /api/cards/order call, used by both the sidebar and a project's board).
- AppSidebar: an Inbox section under the project list -- a vuedraggable list
  in the same "kanban" drag group as every project's kanban columns, so a
  card drags straight from the sidebar into whichever project is open, or
  back out. (The empty-inbox state needed a real bugfix: it wasn't rendering
  a <draggable> at all, so there was nowhere to drop a card back into an
  empty inbox.) A drop reloads the inbox and, if a project is open, its cards.
- ProjectView's kanban board drops its synthetic Inbox column -- just the
  real statuses now.
- DashboardView simplified to a plain grid of project tiles (name + card
  count); its per-project "New" section is gone, since a project card can no
  longer have no status.
- stores/cards.ts: patch/remove move to the global /api/cards/{id} routes.

Verified end-to-end against the rebuilt container (existing per-project-inbox
cards correctly migrated to the global inbox, 0 invariant violations) and the
dev server via headless Chrome: sidebar inbox -> project A "To do" -> back to
inbox -> project B "Done", full journey confirmed via the API at each step.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-04 15:22:33 +01:00
co-authored by Claude Sonnet 5
parent c82bdbbf0e
commit 4ee0f24078
19 changed files with 957 additions and 674 deletions
+13 -70
View File
@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Tests;
use PDOException;
final class CardStatusTest extends ApiTestCase
{
/** Create a project and return its id. */
@@ -63,93 +65,34 @@ final class CardStatusTest extends ApiTestCase
self::assertSame(404, $this->request('GET', "/api/projects/{$projectId}/statuses", null, $other)->getStatusCode());
}
public function test_a_new_card_has_no_status(): void
public function test_a_card_created_directly_in_a_project_starts_in_its_first_status(): void
{
$auth = $this->authHeader();
$projectId = $this->newProject($auth);
$firstStatus = $this->statuses($projectId, $auth)[0];
$card = $this->decode(
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => 'First'], $auth),
)['card'];
// New cards sit in the "inbox" — no status until the user assigns one.
self::assertArrayHasKey('status_id', $card);
self::assertNull($card['status_id']);
self::assertNull($card['status']);
self::assertSame($firstStatus['id'], $card['status_id']);
self::assertSame('To do', $card['status']['name']);
self::assertSame($projectId, $card['project_id']);
}
public function test_a_card_can_be_moved_between_statuses_and_back_to_the_inbox(): void
public function test_a_referenced_status_cannot_be_deleted(): void
{
// There's no delete-status endpoint; this exercises the FK directly.
// A card with a project must have a status (the CHECK constraint), so
// the FK is ON DELETE RESTRICT rather than SET NULL.
$auth = $this->authHeader();
$projectId = $this->newProject($auth);
$statuses = $this->statuses($projectId, $auth);
$cardId = $this->decode(
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => 'Move me'], $auth),
)['card']['id'];
$doing = $this->decode(
$this->request('PATCH', "/api/projects/{$projectId}/cards/{$cardId}", ['status_id' => $statuses[1]['id']], $auth),
)['card'];
self::assertSame($statuses[1]['id'], $doing['status_id']);
self::assertSame('Doing', $doing['status']['name']);
$backToInbox = $this->decode(
$this->request('PATCH', "/api/projects/{$projectId}/cards/{$cardId}", ['status_id' => null], $auth),
)['card'];
self::assertNull($backToInbox['status_id']);
self::assertNull($backToInbox['status']);
}
public function test_a_card_rejects_a_status_from_another_project(): void
{
$auth = $this->authHeader();
$mine = $this->newProject($auth, 'Mine');
$other = $this->newProject($auth, 'Other');
$foreignStatusId = $this->statuses($other, $auth)[0]['id'];
$cardId = $this->decode(
$this->request('POST', "/api/projects/{$mine}/cards", ['text' => 'x'], $auth),
)['card']['id'];
$response = $this->request('PATCH', "/api/projects/{$mine}/cards/{$cardId}", ['status_id' => $foreignStatusId], $auth);
self::assertSame(422, $response->getStatusCode());
self::assertArrayHasKey('status_id', $this->decode($response)['error']['details']);
}
public function test_a_card_rejects_an_unknown_status(): void
{
$auth = $this->authHeader();
$projectId = $this->newProject($auth);
$cardId = $this->decode(
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => 'x'], $auth),
)['card']['id'];
$response = $this->request('PATCH', "/api/projects/{$projectId}/cards/{$cardId}", ['status_id' => 999999], $auth);
self::assertSame(422, $response->getStatusCode());
}
public function test_deleting_a_status_clears_it_from_its_cards(): void
{
$auth = $this->authHeader();
$projectId = $this->newProject($auth);
$cardId = $this->decode(
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => 'Orphan me'], $auth),
)['card']['id'];
$statusId = $this->statuses($projectId, $auth)[0]['id'];
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => 'x'], $auth);
$this->request('PATCH', "/api/projects/{$projectId}/cards/{$cardId}", ['status_id' => $statusId], $auth);
// No delete endpoint for statuses yet — remove the row directly to
// exercise ON DELETE SET NULL.
$this->db()->exec('PRAGMA foreign_keys = ON');
$this->expectException(PDOException::class);
$this->db()->prepare('DELETE FROM card_statuses WHERE id = ?')->execute([$statusId]);
$reread = $this->decode(
$this->request('GET', "/api/projects/{$projectId}/cards/{$cardId}", null, $auth),
)['card'];
self::assertNull($reread['status_id']);
self::assertNull($reread['status']);
}
public function test_deleting_a_project_cascades_to_its_statuses(): void