Project configuration view: manage a project's statuses
New /projects/:id/configure view, linked from a new 'Configure' item on
the project view's Manage menu.
Backend:
- CardStatusRepository/CardStatusController gain full CRUD: create
(appended at the end), reorder (dense positions, like card
ordering), and delete.
- Deleting a status with cards attached is rejected with 409 and
error.details.card_count, rather than hitting the existing FK
RESTRICT constraint -- retrying with { reassign_to: <status id> }
moves those cards to that status first (CardRepository::
reassignStatus, appended after the destination's existing cards)
and deletes in one transaction (CardStatusRepository::transaction,
shared PDO connection across repositories).
- The last status in a project can't be deleted, since a project card
is required to have one.
- Routes: POST/DELETE .../statuses(/:id), PUT .../statuses/order.
- 14 new CardStatusTest cases covering all of the above.
Frontend:
- ProjectConfigureView.vue: header (title, back-to-project link, the
shared Manage menu) + a vuedraggable status list (reorder persists
the whole new order) with a delete button per row and an add-status
form. A row's plain delete either succeeds immediately or, on 409,
opens a modal to choose a different status before retrying the
delete with reassign_to.
- Extracted ProjectManageMenu.vue (the Manage dropdown + delete-project
modal) out of ProjectView so both views share it; it now also has a
Configure link (hidden on the configure page itself).
- ApiError gains a cardCount getter (details.card_count), mirroring
the existing retryAfter getter.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+187
-5
@@ -80,21 +80,203 @@ final class CardStatusTest extends ApiTestCase
|
||||
self::assertSame($projectId, $card['project_id']);
|
||||
}
|
||||
|
||||
public function test_a_referenced_status_cannot_be_deleted(): void
|
||||
public function test_a_referenced_status_cannot_be_deleted_at_the_database_level(): 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.
|
||||
// The DELETE /statuses/{id} endpoint reassigns cards away before
|
||||
// deleting (see below); this is the lower-level guarantee it relies
|
||||
// on. 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);
|
||||
$statusId = $this->statuses($projectId, $auth)[0]['id'];
|
||||
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => 'x'], $auth);
|
||||
|
||||
$this->db()->exec('PRAGMA foreign_keys = ON');
|
||||
$this->expectException(PDOException::class);
|
||||
$this->db()->prepare('DELETE FROM card_statuses WHERE id = ?')->execute([$statusId]);
|
||||
}
|
||||
|
||||
public function test_a_status_can_be_added(): void
|
||||
{
|
||||
$auth = $this->authHeader();
|
||||
$projectId = $this->newProject($auth);
|
||||
|
||||
$response = $this->request('POST', "/api/projects/{$projectId}/statuses", ['name' => 'Blocked'], $auth);
|
||||
|
||||
self::assertSame(201, $response->getStatusCode());
|
||||
$status = $this->decode($response)['status'];
|
||||
self::assertSame('Blocked', $status['name']);
|
||||
self::assertSame(3, $status['position']);
|
||||
self::assertSame(['To do', 'Doing', 'Done', 'Blocked'], array_column($this->statuses($projectId, $auth), 'name'));
|
||||
}
|
||||
|
||||
public function test_adding_a_status_requires_a_name(): void
|
||||
{
|
||||
$auth = $this->authHeader();
|
||||
$projectId = $this->newProject($auth);
|
||||
|
||||
$response = $this->request('POST', "/api/projects/{$projectId}/statuses", ['name' => ''], $auth);
|
||||
|
||||
self::assertSame(422, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function test_a_status_cannot_be_added_to_another_owners_project(): void
|
||||
{
|
||||
$owner = $this->authHeader('owner@example.com');
|
||||
$other = $this->authHeader('other@example.com');
|
||||
$projectId = $this->newProject($owner, 'Private');
|
||||
|
||||
$response = $this->request('POST', "/api/projects/{$projectId}/statuses", ['name' => 'x'], $other);
|
||||
|
||||
self::assertSame(404, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function test_statuses_can_be_reordered(): void
|
||||
{
|
||||
$auth = $this->authHeader();
|
||||
$projectId = $this->newProject($auth);
|
||||
$ids = array_column($this->statuses($projectId, $auth), 'id');
|
||||
$reversed = array_reverse($ids);
|
||||
|
||||
$response = $this->request(
|
||||
'PUT',
|
||||
"/api/projects/{$projectId}/statuses/order",
|
||||
['status_ids' => $reversed],
|
||||
$auth,
|
||||
);
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
$statuses = $this->decode($response)['statuses'];
|
||||
self::assertSame($reversed, array_column($statuses, 'id'));
|
||||
self::assertSame([0, 1, 2], array_column($statuses, 'position'));
|
||||
}
|
||||
|
||||
public function test_reordering_statuses_requires_every_status_exactly_once(): void
|
||||
{
|
||||
$auth = $this->authHeader();
|
||||
$projectId = $this->newProject($auth);
|
||||
$ids = array_column($this->statuses($projectId, $auth), 'id');
|
||||
|
||||
$missing = $this->request(
|
||||
'PUT',
|
||||
"/api/projects/{$projectId}/statuses/order",
|
||||
['status_ids' => array_slice($ids, 0, 2)],
|
||||
$auth,
|
||||
);
|
||||
self::assertSame(422, $missing->getStatusCode());
|
||||
|
||||
$foreign = $this->request(
|
||||
'PUT',
|
||||
"/api/projects/{$projectId}/statuses/order",
|
||||
['status_ids' => [...$ids, 999999]],
|
||||
$auth,
|
||||
);
|
||||
self::assertSame(422, $foreign->getStatusCode());
|
||||
}
|
||||
|
||||
public function test_an_empty_status_can_be_deleted_directly(): void
|
||||
{
|
||||
$auth = $this->authHeader();
|
||||
$projectId = $this->newProject($auth);
|
||||
$statusId = $this->statuses($projectId, $auth)[0]['id'];
|
||||
|
||||
$response = $this->request('DELETE', "/api/projects/{$projectId}/statuses/{$statusId}", null, $auth);
|
||||
|
||||
self::assertSame(204, $response->getStatusCode());
|
||||
self::assertSame(['Doing', 'Done'], array_column($this->statuses($projectId, $auth), 'name'));
|
||||
self::assertSame([0, 1], array_column($this->statuses($projectId, $auth), 'position'));
|
||||
}
|
||||
|
||||
public function test_deleting_a_status_with_cards_requires_reassignment(): void
|
||||
{
|
||||
$auth = $this->authHeader();
|
||||
$projectId = $this->newProject($auth);
|
||||
$statusId = $this->statuses($projectId, $auth)[0]['id'];
|
||||
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => 'x'], $auth);
|
||||
|
||||
$response = $this->request('DELETE', "/api/projects/{$projectId}/statuses/{$statusId}", null, $auth);
|
||||
|
||||
self::assertSame(409, $response->getStatusCode());
|
||||
self::assertSame(1, $this->decode($response)['error']['details']['card_count']);
|
||||
// Still there -- the delete was rejected, not partially applied.
|
||||
self::assertSame(['To do', 'Doing', 'Done'], array_column($this->statuses($projectId, $auth), 'name'));
|
||||
}
|
||||
|
||||
public function test_deleting_a_status_reassigns_its_cards(): void
|
||||
{
|
||||
$auth = $this->authHeader();
|
||||
$projectId = $this->newProject($auth);
|
||||
[$toDo, $doing] = $this->statuses($projectId, $auth);
|
||||
$card = $this->decode(
|
||||
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => 'x'], $auth),
|
||||
)['card'];
|
||||
self::assertSame($toDo['id'], $card['status_id']);
|
||||
|
||||
$response = $this->request(
|
||||
'DELETE',
|
||||
"/api/projects/{$projectId}/statuses/{$toDo['id']}",
|
||||
['reassign_to' => $doing['id']],
|
||||
$auth,
|
||||
);
|
||||
|
||||
self::assertSame(204, $response->getStatusCode());
|
||||
self::assertSame(['Doing', 'Done'], array_column($this->statuses($projectId, $auth), 'name'));
|
||||
|
||||
$moved = $this->decode($this->request('GET', "/api/cards/{$card['id']}", null, $auth))['card'];
|
||||
self::assertSame($doing['id'], $moved['status_id']);
|
||||
}
|
||||
|
||||
public function test_reassign_to_must_be_a_different_status_in_the_same_project(): void
|
||||
{
|
||||
$auth = $this->authHeader();
|
||||
$projectId = $this->newProject($auth);
|
||||
$other = $this->newProject($auth, 'Other');
|
||||
$toDo = $this->statuses($projectId, $auth)[0];
|
||||
$otherStatus = $this->statuses($other, $auth)[0];
|
||||
$this->request('POST', "/api/projects/{$projectId}/cards", ['text' => 'x'], $auth);
|
||||
|
||||
$sameStatus = $this->request(
|
||||
'DELETE',
|
||||
"/api/projects/{$projectId}/statuses/{$toDo['id']}",
|
||||
['reassign_to' => $toDo['id']],
|
||||
$auth,
|
||||
);
|
||||
self::assertSame(422, $sameStatus->getStatusCode());
|
||||
|
||||
$foreignStatus = $this->request(
|
||||
'DELETE',
|
||||
"/api/projects/{$projectId}/statuses/{$toDo['id']}",
|
||||
['reassign_to' => $otherStatus['id']],
|
||||
$auth,
|
||||
);
|
||||
self::assertSame(422, $foreignStatus->getStatusCode());
|
||||
}
|
||||
|
||||
public function test_the_last_status_in_a_project_cannot_be_deleted(): void
|
||||
{
|
||||
$auth = $this->authHeader();
|
||||
$projectId = $this->newProject($auth);
|
||||
$ids = array_column($this->statuses($projectId, $auth), 'id');
|
||||
|
||||
$this->request('DELETE', "/api/projects/{$projectId}/statuses/{$ids[0]}", null, $auth);
|
||||
$this->request('DELETE', "/api/projects/{$projectId}/statuses/{$ids[1]}", null, $auth);
|
||||
$response = $this->request('DELETE', "/api/projects/{$projectId}/statuses/{$ids[2]}", null, $auth);
|
||||
|
||||
self::assertSame(409, $response->getStatusCode());
|
||||
self::assertSame(1, count($this->statuses($projectId, $auth)));
|
||||
}
|
||||
|
||||
public function test_a_status_cannot_be_deleted_from_another_owners_project(): void
|
||||
{
|
||||
$owner = $this->authHeader('owner@example.com');
|
||||
$other = $this->authHeader('other@example.com');
|
||||
$projectId = $this->newProject($owner, 'Private');
|
||||
$statusId = $this->statuses($projectId, $owner)[0]['id'];
|
||||
|
||||
$response = $this->request('DELETE', "/api/projects/{$projectId}/statuses/{$statusId}", null, $other);
|
||||
|
||||
self::assertSame(404, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function test_deleting_a_project_cascades_to_its_statuses(): void
|
||||
{
|
||||
$auth = $this->authHeader();
|
||||
|
||||
Reference in New Issue
Block a user