forge
Explore
Log in

Don't you dare go Hollow

A project with cards on it is not something you delete

Browse files at this commit

faea59ea60db7b81651ad1c8607e9700e88a7345Ahmet Kaan GümüşParent: 3019970
  • fix
    • a project with cards on it is not something you delete
Show full message
🐛 fix(tags): a project with cards on it is not something you delete

Deleting a tag moved every card on it to the default and took the tag away.
One click on a row with no confirmation behind it re-filed somebody's whole
project, and nothing on the screen said how much work was about to move.

A tag with live cards is refused now — `Conflict("tag_in_use")`, which the
page shows as "This tag still has cards" rather than "something went wrong"
— and its row ships no delete control, the same rule the default tag has
always had. The row carries the card count in the board's own count chip, so
a missing delete is a number the admin can already read instead of a control
that mysteriously is not there. Emptying the tag is what makes it deletable,
and that is a decision made one card at a time.

Cards already thrown away are the exception: a soft-deleted card is nobody's
work any more, it does not count, and its tag reference moves to the default
as the tag goes — so nothing is ever left pointing at a project that is not
there. `PRAGMA foreign_key_check` is part of the test that says so.

Two other things this hunt turned up, both the same defect class as the
avatar sizes — a skin rule in a `[data-ui]` scope outweighing a modifier
class on the same node:

`.quiet-danger` lost to `[data-ui=ledger] .quiet`, so on the Ledger skin a
delete button had no red border and lost its red text on hover. Written
`.quiet.quiet-danger` now.

And `hold_batch` could pull a mail *back*: a delivery pass writes its lease
into `next_attempt_at`, the same column the batch debounce postpones, so a
new trigger with a one-minute window could make a row a pass was already
composing due again — and the reader would get that mail twice. It only ever
postpones now, in the read and in the `UPDATE`'s own `WHERE`, with a test
that leases a row and then holds it.
crates/izlek-core/src/store/mod.rsmodified+15 -0
@@ -1088,6 +1088,11 @@ pub trait Store: BoardReads + DetailReads + 'static {
10881088 /// Every tag on the board, in the admin's hand-set order.
10891089 async fn tags(&self, board_id: &str) -> Result<Vec<Tag>>;
10901090
1091+ /// How many live cards wear each of the board's tags, keyed by tag id. A
1092+ /// tag nobody uses is absent rather than zero — the caller reads a
1093+ /// missing key as none, which is what a fresh tag is.
1094+ async fn tag_task_counts(&self, board_id: &str) -> Result<Vec<(String, u32)>>;
1095+
10911096 /// Appends a tag at the end of the board's order. The name is unique per
10921097 /// board: two tags with one name are one project spelled twice.
10931098 async fn create_tag(&self, board_id: &str, name: &str, at: OffsetDateTime) -> Result<Tag>;
@@ -1096,6 +1101,11 @@ pub trait Store: BoardReads + DetailReads + 'static {
10961101
10971102 /// Deletes a tag. Its tasks move to the board's default tag; the default
10981103 /// itself is refused — it is where they would go.
1104+ /// Retires a tag. A tag with cards on it is refused with
1105+ /// [`StoreError::Conflict`] — the cards are the reason it exists, and
1106+ /// moving somebody's whole project onto the default because one menu item
1107+ /// was clicked is not a deletion the admin asked for. The default tag is
1108+ /// refused as well: it is where a card with no project of its own lives.
10991109 async fn delete_tag(&self, tag_id: &str) -> Result<()>;
11001110
11011111 /// Swaps a tag with its neighbour in the order. A tag already at that end
@@ -1322,6 +1332,11 @@ pub trait Store: BoardReads + DetailReads + 'static {
13221332 /// settled. Only rows that are still pending and have never been
13231333 /// attempted move — a mail already refused is on its own retry clock, and
13241334 /// a batch must not drag it back.
1335+ ///
1336+ /// It only ever postpones. A delivery pass writes its lease into the same
1337+ /// column, so a hold that moved a row *earlier* would hand the mail a
1338+ /// second pass is composing to a third one, and the reader would get it
1339+ /// twice.
13251340 async fn hold_batch(
13261341 &self,
13271342 task_id: &str,
crates/izlek-core/src/store/turso_store.rsmodified+51 -6
@@ -3733,7 +3733,7 @@ impl Store for TursoStore {
37333733 // date-format trick rather than a calculation.
37343734 let mut rows = conn
37353735 .query(
3736- "SELECT id, claimed_at FROM mail_send \
3736+ "SELECT id, claimed_at, next_attempt_at FROM mail_send \
37373737 WHERE task_id = ?1 AND recipient = ?2 AND kind = 'rule' \
37383738 AND state = 'pending' AND attempts = 0 \
37393739 AND next_attempt_at IS NOT NULL",
@@ -3745,15 +3745,25 @@ impl Store for TursoStore {
37453745 while let Some(row) = rows.next().await.map_err(backend)? {
37463746 let id = text(&row, 0)?;
37473747 let born = parse_stamp(&text(&row, 1)?)?;
3748- held.push((id, born));
3748+ let due = parse_stamp(&text(&row, 2)?)?;
3749+ held.push((id, born, due));
37493750 }
37503751 drop(rows);
3751- for (id, born) in held {
3752+ for (id, born, due) in held {
37523753 let ceiling = born + cap;
37533754 let when = if until > ceiling { ceiling } else { until };
3755+ // Only ever later. A row a delivery pass is holding — its lease is
3756+ // written in this same column — must not be pulled back under the
3757+ // pass that took it, or the mail it is composing right now becomes
3758+ // due for a second pass and goes out twice. The `<` in the update
3759+ // is the guard, not the read above it: the two are one statement.
3760+ if when <= due {
3761+ continue;
3762+ }
37543763 conn.execute(
37553764 "UPDATE mail_send SET next_attempt_at = ?1 \
3756- WHERE id = ?2 AND state = 'pending' AND attempts = 0",
3765+ WHERE id = ?2 AND state = 'pending' AND attempts = 0 \
3766+ AND next_attempt_at < ?1",
37573767 params![stamp(when)?, id],
37583768 )
37593769 .await
@@ -3816,6 +3826,23 @@ impl Store for TursoStore {
38163826 Ok(out)
38173827 }
38183828
3829+ async fn tag_task_counts(&self, board_id: &str) -> Result<Vec<(String, u32)>> {
3830+ let conn = self.conn.lock().await;
3831+ let mut rows = conn
3832+ .query(
3833+ "SELECT tag_id, COUNT(*) FROM task \
3834+ WHERE board_id = ?1 AND deleted_at IS NULL GROUP BY tag_id",
3835+ params![board_id],
3836+ )
3837+ .await
3838+ .map_err(backend)?;
3839+ let mut out = Vec::new();
3840+ while let Some(row) = rows.next().await.map_err(backend)? {
3841+ out.push((text(&row, 0)?, row.get::<i64>(1).map_err(backend)? as u32));
3842+ }
3843+ Ok(out)
3844+ }
3845+
38193846 async fn create_tag(&self, board_id: &str, name: &str, at: OffsetDateTime) -> Result<Tag> {
38203847 let id = Ulid::new().to_string();
38213848 let now = stamp(at)?;
@@ -3903,8 +3930,12 @@ impl Store for TursoStore {
39033930 .map_err(backend)?;
39043931 // The default is the board's fallback, not a project anyone can
39053932 // retire: deleting it would leave its board's tasks nowhere to go.
3906- // Any other tag's tasks move to that default, in the one write set:
3907- // no task is ever seen pointing at a project that is not there.
3933+ // Any other tag is deletable only while it is empty — a tag with
3934+ // cards on it is a project somebody is working in, and a delete that
3935+ // quietly re-files that work is not a delete they asked for. Cards
3936+ // already thrown away are the exception: they are nobody's work any
3937+ // more, and they move to the default so the reference they still hold
3938+ // points at something.
39083939 let deleted = async {
39093940 let mut rows = tx
39103941 .query(
@@ -3921,6 +3952,20 @@ impl Store for TursoStore {
39213952 if is_default != 0 {
39223953 return Ok(Err(StoreError::Conflict("default_tag")));
39233954 }
3955+ let mut rows = tx
3956+ .query(
3957+ "SELECT COUNT(*) FROM task WHERE tag_id = ?1 AND deleted_at IS NULL",
3958+ params![tag_id],
3959+ )
3960+ .await?;
3961+ let live: i64 = match rows.next().await? {
3962+ Some(row) => row.get(0)?,
3963+ None => 0,
3964+ };
3965+ drop(rows);
3966+ if live > 0 {
3967+ return Ok(Err(StoreError::Conflict("tag_in_use")));
3968+ }
39243969 tx.execute(
39253970 "UPDATE task SET tag_id = \
39263971 (SELECT id FROM tag WHERE board_id = ?1 AND is_default = 1) \
crates/izlek-core/tests/store.rsmodified+138 -5
@@ -2905,7 +2905,7 @@ fn card_of<'a>(
29052905 }
29062906
29072907 #[tokio::test]
2908-async fn deleting_a_tag_moves_its_tasks_to_the_default_and_a_foreign_tag_is_not_found() {
2908+async fn a_tag_is_worn_a_foreign_one_is_not_found_and_a_worn_one_is_not_deletable() {
29092909 let (scratch, workspace, admin) = workspace_with_admin().await;
29102910 let store = &scratch.store;
29112911 let board = store.board(&workspace).await.unwrap().unwrap();
@@ -2956,14 +2956,88 @@ async fn deleting_a_tag_moves_its_tasks_to_the_default_and_a_foreign_tag_is_not_
29562956 Err(StoreError::NotFound)
29572957 ));
29582958
2959- // Deleting a worn tag leaves the task on the board's default, and the
2960- // task survives.
2961- store.delete_tag(&tag.id).await.unwrap();
2959+ // A tag with a card on it is not deletable: the card is the reason the
2960+ // project exists, and nothing about it moves.
2961+ assert!(matches!(
2962+ store.delete_tag(&tag.id).await,
2963+ Err(StoreError::Conflict("tag_in_use"))
2964+ ));
29622965 let view = board_of(store, &workspace).await;
29632966 assert_eq!(
29642967 card_of(&view, &task).tag.as_ref().map(|t| t.name.as_str()),
2965- Some("General")
2968+ Some("ops"),
2969+ "the refused delete moved the card anyway"
29662970 );
2971+ assert_eq!(store.tags(&board.id).await.unwrap().len(), 2);
2972+
2973+ // Emptied, it goes.
2974+ let default = store
2975+ .tags(&board.id)
2976+ .await
2977+ .unwrap()
2978+ .into_iter()
2979+ .find(|t| t.is_default)
2980+ .unwrap();
2981+ store.set_task_tag(&task, &default.id).await.unwrap();
2982+ store.delete_tag(&tag.id).await.unwrap();
2983+ assert_eq!(store.tags(&board.id).await.unwrap().len(), 1);
2984+}
2985+
2986+/// The counts the tags screen draws, and the one card that stops counting.
2987+#[tokio::test]
2988+async fn tag_counts_hold_the_live_cards_and_a_thrown_away_card_stops_blocking() {
2989+ let (scratch, workspace, admin) = workspace_with_admin().await;
2990+ let store = &scratch.store;
2991+ let board = store.board(&workspace).await.unwrap().unwrap();
2992+ let tag = store
2993+ .create_tag(&board.id, "ops", OffsetDateTime::now_utc())
2994+ .await
2995+ .unwrap();
2996+ let first = add_task(store, &workspace, "Backlog", "one", None, &admin).await;
2997+ let second = add_task(store, &workspace, "Backlog", "two", None, &admin).await;
2998+ store.set_task_tag(&first, &tag.id).await.unwrap();
2999+ store.set_task_tag(&second, &tag.id).await.unwrap();
3000+
3001+ let counts = store.tag_task_counts(&board.id).await.unwrap();
3002+ assert_eq!(
3003+ counts.iter().find(|(id, _)| id == &tag.id).map(|(_, n)| *n),
3004+ Some(2)
3005+ );
3006+
3007+ // A card thrown away is nobody's work any more: it stops counting, and
3008+ // once the last live one is gone the tag can be retired — the deleted
3009+ // card's own reference moves to the default rather than dangling.
3010+ store
3011+ .delete_task(&first, &admin, OffsetDateTime::now_utc())
3012+ .await
3013+ .unwrap();
3014+ assert!(matches!(
3015+ store.delete_tag(&tag.id).await,
3016+ Err(StoreError::Conflict("tag_in_use")),
3017+ ));
3018+ store
3019+ .delete_task(&second, &admin, OffsetDateTime::now_utc())
3020+ .await
3021+ .unwrap();
3022+ assert_eq!(
3023+ store
3024+ .tag_task_counts(&board.id)
3025+ .await
3026+ .unwrap()
3027+ .iter()
3028+ .find(|(id, _)| id == &tag.id),
3029+ None,
3030+ "a tag nobody wears is absent, not zero"
3031+ );
3032+ store.delete_tag(&tag.id).await.unwrap();
3033+
3034+ // Nothing points at a tag that is not there.
3035+ let mut broken = raw_conn(&scratch)
3036+ .await
3037+ .query("PRAGMA foreign_key_check", ())
3038+ .await
3039+ .unwrap();
3040+ assert!(broken.next().await.unwrap().is_none());
29673041 }
29683042
29693043 #[tokio::test]
@@ -7503,6 +7577,65 @@ async fn the_hold_has_a_ceiling_measured_from_the_oldest_mail() {
75037577 let _ = std::fs::remove_dir_all(&dir);
75047578 }
75057579
7580+/// A hold only ever postpones. The delivery pass writes its lease into the
7581+/// same column, so a hold that pulled a leased row back would make the mail
7582+/// one pass is composing due for another — and the reader would get it twice.
7583+#[tokio::test]
7584+async fn a_hold_never_pulls_a_leased_row_back_under_the_pass_that_took_it() {
7585+ let (dir, store, workspace, admin) = waiting(1).await;
7586+ let mate = member(&store, &workspace, "emre@izlek.sh", "Emre").await;
7587+ let task = add_task(&store, &workspace, "Backlog", "Ship it", None, &admin).await;
7588+ store.assign_task(&task, &mate).await.unwrap();
7589+ let rule = a_rule(&store, &workspace, "Done", "Card is done").await;
7590+
7591+ let now = OffsetDateTime::now_utc();
7592+ store
7593+ .claim_send(&rule.id, "event-1", &task, "emre@izlek.sh", now, now)
7594+ .await
7595+ .unwrap()
7596+ .expect("a fresh row is claimed");
7597+ // A delivery pass takes it: the lease is five minutes out.
7598+ let taken = store
7599+ .claim_sends_owed(now + Duration::seconds(1), now + izlek_core::mail::LEASE, 10)
7600+ .await
7601+ .unwrap();
7602+ assert_eq!(taken.len(), 1, "the pass did not take the row");
7603+ let leased = the_one_row(&store).await.next_attempt_at.unwrap();
7604+
7605+ // A new trigger on the same card, one quiet minute out: earlier than the
7606+ // lease, so it must change nothing.
7607+ store
7608+ .hold_batch(
7609+ &task,
7610+ "emre@izlek.sh",
7611+ now + Duration::minutes(1),
7612+ Duration::minutes(4),
7613+ )
7614+ .await
7615+ .unwrap();
7616+ assert_eq!(
7617+ the_one_row(&store).await.next_attempt_at.unwrap(),
7618+ leased,
7619+ "the hold pulled a row out from under the pass holding it"
7620+ );
7621+
7622+ // A hold past the lease is a postponement, and does apply.
7623+ store
7624+ .hold_batch(
7625+ &task,
7626+ "emre@izlek.sh",
7627+ now + Duration::minutes(30),
7628+ Duration::hours(2),
7629+ )
7630+ .await
7631+ .unwrap();
7632+ assert!(
7633+ the_one_row(&store).await.next_attempt_at.unwrap() > leased,
7634+ "a real postponement was refused too"
7635+ );
7636+ let _ = std::fs::remove_dir_all(&dir);
7637+}
7638+
75067639 /// A workspace with no window is İzlek as it was: a trigger is a mail, sent
75077640 /// the moment it is owed.
75087641 #[tokio::test]
crates/izlek-web/src/server.rsmodified+8 -0
@@ -359,6 +359,9 @@ pub enum Refusal {
359359 EmptySubject,
360360 /// A tag with no name is not a tag the board can show.
361361 EmptyTag,
362+ /// A tag with cards on it stays. Emptying it is the admin's job, and it
363+ /// is one they can see the size of.
364+ TagInUse,
362365 /// A message with no body: there is nothing for the recipient to read.
363366 EmptyBody,
364367 /// The date field did not hold a date.
@@ -422,6 +425,7 @@ impl Refusal {
422425 Refusal::NotAnImage => "That is not an image.".to_string(),
423426 Refusal::EmptySubject => "Give the rule a subject line.".to_string(),
424427 Refusal::EmptyTag => "Give the tag a name.".to_string(),
428+ Refusal::TagInUse => "This tag still has cards.".to_string(),
425429 Refusal::EmptyBody => "Write something first.".to_string(),
426430 Refusal::BadDeadline => "That is not a date.".to_string(),
427431 Refusal::Cycle => "That link would put this task behind itself.".to_string(),
@@ -481,6 +485,7 @@ impl Refusal {
481485 Refusal::BadSender(_) => self.message(),
482486 Refusal::EmptySubject => "Kurala bir konu ver.".to_string(),
483487 Refusal::EmptyTag => "Etikete bir ad ver.".to_string(),
488+ Refusal::TagInUse => "Bu etikette kartlar var.".to_string(),
484489 Refusal::EmptyBody => "Önce bir şey yaz.".to_string(),
485490 Refusal::Rejected => "Bu işe yaramadı.".to_string(),
486491 Refusal::RateLimited => {
@@ -531,6 +536,7 @@ impl Refusal {
531536 "not-an-image" => Refusal::NotAnImage,
532537 "empty-subject" => Refusal::EmptySubject,
533538 "empty-tag" => Refusal::EmptyTag,
539+ "tag-in-use" => Refusal::TagInUse,
534540 "empty-body" => Refusal::EmptyBody,
535541 "bad-deadline" => Refusal::BadDeadline,
536542 "cycle" => Refusal::Cycle,
@@ -587,6 +593,7 @@ impl Refusal {
587593 Refusal::NotAnImage => "not-an-image",
588594 Refusal::EmptySubject => "empty-subject",
589595 Refusal::EmptyTag => "empty-tag",
596+ Refusal::TagInUse => "tag-in-use",
590597 Refusal::EmptyBody => "empty-body",
591598 Refusal::BadDeadline => "bad-deadline",
592599 Refusal::Cycle => "cycle",
@@ -874,6 +881,7 @@ mod refusal_message_tests {
874881 Refusal::NotNestable,
875882 Refusal::NotFound,
876883 Refusal::NoSuchMember,
884+ Refusal::TagInUse,
877885 Refusal::Unavailable,
878886 ];
879887 for refusal in all {
crates/izlek-web/src/tags.rsmodified+29 -9
@@ -39,6 +39,9 @@ struct TagLine {
3939 name: String,
4040 position: i64,
4141 is_default: bool,
42+ /// Cards wearing this tag. A tag with any is not deletable, and the row
43+ /// says how many rather than leaving the admin to guess why.
44+ tasks: u32,
4245 }
4346
4447 /// Every tag on the workspace's own board, in the admin's hand-set order.
@@ -53,12 +56,21 @@ async fn tags_of(
5356 else {
5457 return Err(Refusal::Unavailable);
5558 };
59+ let counts = store
60+ .tag_task_counts(&board.id)
61+ .await
62+ .map_err(|_| Refusal::Unavailable)?;
5663 Ok(store
5764 .tags(&board.id)
5865 .await
5966 .map_err(|_| Refusal::Unavailable)?
6067 .into_iter()
6168 .map(|tag| TagLine {
69+ tasks: counts
70+ .iter()
71+ .find(|(id, _)| id == &tag.id)
72+ .map(|(_, count)| *count)
73+ .unwrap_or(0),
6274 id: tag.id,
6375 name: tag.name,
6476 position: tag.position,
@@ -179,19 +191,24 @@ struct DeleteTagForm {
179191 tag_id: String,
180192 }
181193
182-/// Removes a tag. The store refuses to delete the default — every task
183-/// without a tag wears it — and that refusal lands here as "unavailable";
184-/// the row itself ships no delete control in the first place.
194+/// Removes a tag. The store refuses two of them: the default — every task
195+/// without a project of its own wears it — and any tag that still has cards,
196+/// which comes back named so the admin reads why rather than "something went
197+/// wrong". Neither row ships a delete control in the first place; this is
198+/// the same rule where it is actually enforced.
185199 #[route(POST "/api/delete_tag")]
186200 async fn delete_tag(cx: &Cx, Form(input): Form<DeleteTagForm>) -> Redirect {
187201 let (store, _, _) = match tag_of_this_workspace(cx, &input.tag_id).await {
188202 Ok(triple) => triple,
189203 Err(refusal) => return redirect(cx, Some(refusal)),
190204 };
191- if store.delete_tag(&input.tag_id).await.is_err() {
192- return redirect(cx, Some(Refusal::Unavailable));
205+ match store.delete_tag(&input.tag_id).await {
206+ Ok(()) => redirect(cx, None),
207+ Err(izlek_core::store::StoreError::Conflict("tag_in_use")) => {
208+ redirect(cx, Some(Refusal::TagInUse))
209+ }
210+ Err(_) => redirect(cx, Some(Refusal::Unavailable)),
193211 }
194- redirect(cx, None)
195212 }
196213
197214 #[derive(Deserialize)]
@@ -251,8 +268,10 @@ async fn composer(cx: &Cx, refusal: Option<&Refusal>, lang: Lang) -> Result {
251268 }
252269
253270 /// One tag's row: the rename form in place of it when `editing`, its display
254-/// otherwise. The default tag draws no delete form — the store would refuse
255-/// it, and a control that cannot act is not drawn.
271+/// otherwise. The default tag draws no delete form, and neither does a tag
272+/// with cards on it — the store would refuse both, and a control that cannot
273+/// act is not drawn. The card count sits on the row, so a missing delete is
274+/// a number the admin can already see rather than a control that vanished.
256275 async fn tag_row(cx: &Cx, tag: &TagLine, editing: bool, refusal: Option<&Refusal>, lang: Lang) -> Result {
257276 if editing {
258277 return view! {
@@ -280,6 +299,7 @@ async fn tag_row(cx: &Cx, tag: &TagLine, editing: bool, refusal: Option<&Refusal
280299 cx =>
281300 <div class="tag-row">
282301 <span class="tag-name">(tag.name.clone())</span>
302+ <span class="tag-count">(tag.tasks)</span>
283303
284304 <a class="quiet" href=(format!("/tags?edit={}", tag.id)) title=(t(lang, Key::EditThisTag))>(t(lang, Key::EditLabel))</a>
285305
@@ -294,7 +314,7 @@ async fn tag_row(cx: &Cx, tag: &TagLine, editing: bool, refusal: Option<&Refusal
294314 <button class="quiet" type="submit" title=(t(lang, Key::MoveTagDown)) aria-label=(t(lang, Key::MoveTagDown))>("\u{2193}")</button>
295315 </form>
296316
297- if !tag.is_default {
317+ if !tag.is_default && tag.tasks == 0 {
298318 <form method="post" action="/api/delete_tag">
299319 <input type="hidden" name="tag_id" value=(tag.id.clone())>
300320 <button class="quiet quiet-danger" type="submit" title=(t(lang, Key::DeleteThisTag))>(t(lang, Key::Delete))</button>
crates/izlek-web/tests/http.rsmodified+68 -0
@@ -7525,6 +7525,74 @@ async fn the_default_tag_cannot_be_deleted_and_ships_no_delete_button() {
75257525 assert!(page.contains("Aurora"), "the created tag is not listed: {page}");
75267526 }
75277527
7528+/// A tag with cards on it stays: no delete control on its row, and the call
7529+/// itself refused by name if somebody posts it anyway. Emptying it is what
7530+/// makes it deletable.
7531+#[tokio::test]
7532+async fn a_tag_with_cards_on_it_cannot_be_deleted() {
7533+ let app = App::open().await;
7534+ let admin_cookie = admin(&app).await;
7535+ let aurora = a_tag(&app, &admin_cookie, "Aurora").await;
7536+ let workspace_id = app.workspace_id().await;
7537+ let board = app.store.board(&workspace_id).await.unwrap().expect("no board");
7538+ let open = app.store.columns(&board.id).await.unwrap()[0].id.clone();
7539+ let admin_id = app
7540+ .store
7541+ .users(&workspace_id)
7542+ .await
7543+ .unwrap()
7544+ .into_iter()
7545+ .find(|user| user.role == Role::Admin)
7546+ .unwrap()
7547+ .id;
7548+ let task = a_task_by(&app, &board.id, &open, "Hold the door", &admin_id).await;
7549+ app.store.set_task_tag(&task, &aurora.id).await.unwrap();
7550+
7551+ let page = String::from_utf8(app.get("/tags", Some(&admin_cookie)).await.bytes).unwrap();
7552+ assert_eq!(
7553+ page.matches(r#"action="/api/delete_tag""#).count(),
7554+ 0,
7555+ "a tag with a card on it still offers a delete: {page}"
7556+ );
7557+ assert!(
7558+ page.contains(r#"<span class="tag-count">1</span>"#),
7559+ "the row does not say how many cards are on it: {page}"
7560+ );
7561+
7562+ let refused = app
7563+ .post("/api/delete_tag", Some(&admin_cookie), &[("tag_id", &aurora.id)])
7564+ .await;
7565+ assert!(
7566+ refused.body.contains("TagInUse"),
7567+ "the refusal does not name itself: {}",
7568+ refused.body
7569+ );
7570+ assert_eq!(
7571+ app.store.tags(&board.id).await.unwrap().len(),
7572+ 2,
7573+ "the tag went anyway"
7574+ );
7575+
7576+ // Moved off it, the tag is deletable again — control and call both.
7577+ let default_id = app
7578+ .store
7579+ .tags(&board.id)
7580+ .await
7581+ .unwrap()
7582+ .into_iter()
7583+ .find(|tag| tag.is_default)
7584+ .unwrap()
7585+ .id;
7586+ app.store.set_task_tag(&task, &default_id).await.unwrap();
7587+ let page = String::from_utf8(app.get("/tags", Some(&admin_cookie)).await.bytes).unwrap();
7588+ assert_eq!(page.matches(r#"action="/api/delete_tag""#).count(), 1);
7589+ let gone = app
7590+ .post("/api/delete_tag", Some(&admin_cookie), &[("tag_id", &aurora.id)])
7591+ .await;
7592+ assert!(!gone.body.contains("TagInUse"), "{}", gone.body);
7593+ assert_eq!(app.store.tags(&board.id).await.unwrap().len(), 1);
7594+}
7595+
75287596 /// An open live stream must not be something the shutdown has to wait out.
75297597 ///
75307598 /// The server stops accepting connections and then gives in-flight requests
style/main.scssmodified+19 -1
@@ -3134,7 +3134,11 @@ input[type="radio"] {
31343134 }
31353135
31363136 // Danger modifier for a `.quiet` button — the "Delete" action in a rule row.
3137-.quiet-danger {
3137+// Written `.quiet.quiet-danger` for the same reason the avatar sizes are:
3138+// the skins style `.quiet` from a `[data-ui]` scope, which outweighs a lone
3139+// modifier class — on the Ledger skin a delete button lost its red border,
3140+// and its red text on hover, to a rule about ordinary quiet buttons.
3141+.quiet.quiet-danger {
31383142 border-color: var(--danger-border);
31393143 color: var(--danger);
31403144
@@ -3524,6 +3528,20 @@ input[type="radio"] {
35243528 white-space: nowrap;
35253529 }
35263530
3531+// How many cards are on the project, in the same chip the board counts its
3532+// columns with. It is also the reason the delete control beside it is or is
3533+// not there.
3534+.tag-count {
3535+ flex: none;
3536+ font-family: var(--font-mono);
3537+ font-size: 11px;
3538+ font-variant-numeric: tabular-nums;
3539+ color: var(--muted-soft);
3540+ background: var(--panel-sunken);
3541+ border-radius: var(--radius);
3542+ padding: 1px 6px;
3543+}
3544+
35273545 .tag-new {
35283546 background: var(--surface);
35293547 border: 1px solid var(--border);