From 2c8afc82181f5642f4b68d4a34b00d960141ece3 Mon Sep 17 00:00:00 2001 From: glwhappen <1597721684@qq.com> Date: Mon, 30 Nov 2026 13:59:31 +0800 Subject: [PATCH] Apply team API profile changes and tags in one revision --- src-tauri/src/api.rs | 59 ++++++++++++++++++++++++++++++++++-- src-tauri/src/space/write.rs | 5 ++- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/api.rs b/src-tauri/src/api.rs index 03cb375c8..6e007d84a 100644 --- a/src-tauri/src/api.rs +++ b/src-tauri/src/api.rs @@ -595,22 +595,28 @@ async fn edit_profile(Extension(t): Extension, Path(id): Path, J apply_refresh_rate(&mut stored.config, hz) .map_err(|e| err(StatusCode::BAD_REQUEST, e))?; } - // Checked before anything is saved: an unknown tag changes nothing. + // An unknown tag refuses the edit before the profile is saved. let tags = match body.tags.as_deref() { Some(wanted) => Some(resolve_tags(wanted)?), None => None, }; + // A team's profile carries its tags in the same write as its other settings. + let (team_tags, personal_tags) = if t.team().is_some() { (tags, None) } else { (None, tags) }; + let wrote_team_tags = team_tags.is_some(); // Without a rev, the one just read: a change made in between is not undone. let opts = space::profile::SaveOpts { sent_rev: Some(body.rev.unwrap_or(stored.meta.rev)), move_to: body.folder.clone(), + tag_ids: team_tags, inline_proxy, password: body.password.clone(), }; space::profile::save(door, &t, stored, opts).await.map_err(fail(StatusCode::INTERNAL_SERVER_ERROR))?; - if let Some(ids) = tags { + if let Some(ids) = personal_tags { assign_tags(&t, &id, ids).await?; + } else if wrote_team_tags { + crate::notify_store_changed("tags"); } let updated = space::profile::load_raw(&id).map_err(fail(StatusCode::INTERNAL_SERVER_ERROR))?; @@ -2329,6 +2335,55 @@ mod tests { drop(t.srv); } + #[tokio::test] + async fn a_team_patch_moves_and_tags_a_profile_with_one_revision() { + let mut grants = vec![ + allow(Scope::Team, Action::See), + allow(folder("Ads"), Action::Start), + allow(folder("Shops"), Action::Create), + ]; + let t = Team::new(&grants).await; + for f in ["Ads", "Shops"] { + t.folder(f).await; + } + for (id, name) in [("tag-secret-2", "Before"), ("review", "Needs review")] { + let body = json!({ "name": name, "data": b64(json!({ "color": "orange" })) }); + t.admin_call(Method::PUT, &format!("/items/tag/{id}"), Some(body)).await; + } + t.profile("p-1", "Ads", "First", json!({})).await; + t.enter().await; + + let path = "/profiles/p-1"; + let before = t.on_server("p-1").await; + assert_eq!(before["card"]["tags"], json!(["tag-secret-2"])); + let rev = before["revision"].as_u64().unwrap(); + let patch = json!({ + "rev": rev, "notes": "Ready for review", "folder": "Shops", + "tags": ["needs review", "review"] + }); + let (status, got) = t.call("PATCH", path, Some(patch.clone())).await; + assert_eq!((status, got["need"].as_str()), (StatusCode::FORBIDDEN, Some("edit")), "{got}"); + assert_eq!(t.on_server("p-1").await, before); + + // Edit where it is now, and Create where it goes. No Edit there. + grants.push(allow(folder("Ads"), Action::Edit)); + t.set_grants(&grants).await; + let mut bad_tag = patch.clone(); + bad_tag["tags"] = json!(["review", "unknown-tag"]); + let (status, got) = t.call("PATCH", path, Some(bad_tag)).await; + assert_eq!(status, StatusCode::BAD_REQUEST, "{got}"); + assert_eq!(t.on_server("p-1").await, before); + + let (status, got) = t.call("PATCH", path, Some(patch)).await; + assert_eq!(status, StatusCode::OK, "{got}"); + assert_eq!(got["tags"], json!(["review"])); + let after = t.on_server("p-1").await; + assert_eq!(after["folder"], "Shops"); + assert_eq!(after["card"]["notes"], "Ready for review"); + assert_eq!(after["card"]["tags"], json!(["review"])); + assert_eq!(after["revision"].as_u64(), Some(rev + 1)); + } + #[tokio::test] async fn a_member_with_the_rights_writes_each_kind_of_change_to_the_team() { let all = [Action::See, Action::Start, Action::Edit, Action::Create, Action::Delete]; diff --git a/src-tauri/src/space/write.rs b/src-tauri/src/space/write.rs index 82712bdb6..45441daf2 100644 --- a/src-tauri/src/space/write.rs +++ b/src-tauri/src/space/write.rs @@ -30,6 +30,8 @@ pub struct SaveOpts { pub sent_rev: Option, /// Where it goes; "" is no folder. None keeps it where it is; a new one takes the settings' own. pub move_to: Option, + /// Exact tag ids for an existing team profile. None keeps the current tags. + pub tag_ids: Option>, /// A proxy line came with it and was stored for it. pub inline_proxy: bool, /// A protected profile's password (#127): an edit of its sealed part needs it. @@ -134,7 +136,8 @@ pub async fn save_profile(door: Door, t: &Ticket, team: &str, stored: StoredProf doors::clear(door, team, &ask)?; let edit = perm::team_write::(team, On::Profile { id: id.clone(), folder: now.row.folder.clone() })?; let to = if moves { Some(perm::team_write::(team, On::Folder(dest.clone()))?) } else { None }; - let card = remote::card(&stored, now.row.card.tags.clone()); + let tags = opts.tag_ids.unwrap_or_else(|| now.row.card.tags.clone()); + let card = remote::card(&stored, tags); let data = remote::profile_data(&stored); let name = remote::name_of(&stored); let base = opts.sent_rev.unwrap_or(now.row.revision);