fix(cc-config): one account is one profile, and rename it in place
Four defects, all from one design mistake: a profile's display name and its filename were the same string. - Saving the logged-in account made a SECOND profile of an account another profile already held. Both then reported themselves active, so there was nothing to switch between. `POST /profiles` now refuses `EDUPLICATE` and names the profile that already holds the account. Re-saving into the account's own profile stays allowed - that is the token-refresh path. - Worse, an accidental duplicate could not be cleaned up: two profiles of one account are both active, and the delete guard refused any active profile, so neither was ever deletable. The guard now blocks only the LAST saved copy of the live account, which is the actual credential-loss condition it exists for. The trash button had to follow, or the server would allow what the UI hid. - A name could not contain spaces or diacritics, because it had to be filename-safe. A profile now carries `name` (internal identifier, still the filename, still what every route takes) and `label` (what the user reads and edits: 1-60 free-form characters, control characters rejected, stored trimmed, unique case-insensitively). A label never touches a path, which is what makes "Tài khoản chính" a legal name. - Naming happened up front in a "save current account as" field. That field is gone. The server derives the identifier, the save button lives on the live account's card and appears only while it is unsaved, and the label is edited by clicking it (Enter saves, Escape cancels). Renaming rewrites the label in place and deliberately does NOT move `name`, so it cannot half-fail and leave a profile unreachable. Profiles written before labels existed report `label` equal to their `name`, so nothing needs migrating. Adds `PATCH /api/cc-config/profiles`; `POST` now takes an optional `name`. Verified: server 1431/1431 (11 new), client 459/459, tsc clean. Also exercised end to end against a COPY of the real profile store on this machine: the duplicate deleted, the last copy still refused, a Vietnamese label accepted, and the stored access/refresh tokens and 0600 mode intact after a rename.
This commit is contained in:
+19
-6
@@ -1517,13 +1517,23 @@ export const api = {
|
||||
profiles: () =>
|
||||
request<{ items: CcProfile[]; active: CcAccountIdentity | null }>("/cc-config/profiles"),
|
||||
/**
|
||||
* POST /api/cc-config/profiles - snapshot the logged-in account under
|
||||
* `name`, overwriting a profile of that name.
|
||||
* POST /api/cc-config/profiles - snapshot the logged-in account as a
|
||||
* profile. The identifier and initial label are derived from the account;
|
||||
* saving an account another profile already holds fails `EDUPLICATE`.
|
||||
*/
|
||||
saveProfile: (name: string) =>
|
||||
request<{ ok: true; name: string } & CcAccountIdentity>("/cc-config/profiles", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ name }),
|
||||
saveProfile: () =>
|
||||
request<{ ok: true; name: string; label: string } & CcAccountIdentity>(
|
||||
"/cc-config/profiles",
|
||||
{ method: "POST", body: JSON.stringify({}) }
|
||||
),
|
||||
/**
|
||||
* PATCH /api/cc-config/profiles - change a profile's display label. The
|
||||
* `name` identifier does not move; spaces and diacritics are allowed.
|
||||
*/
|
||||
renameProfile: (name: string, label: string) =>
|
||||
request<{ ok: true; name: string; label: string }>("/cc-config/profiles", {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({ name, label }),
|
||||
}),
|
||||
/**
|
||||
* POST /api/cc-config/profiles/activate - make a saved profile the account
|
||||
@@ -2310,7 +2320,10 @@ export interface CcAccountIdentity {
|
||||
|
||||
/** One saved auth profile from GET /api/cc-config/profiles. */
|
||||
export interface CcProfile extends CcAccountIdentity {
|
||||
/** Internal identifier (also its filename) — what the mutation routes take. */
|
||||
name: string;
|
||||
/** Display name the user edits; falls back to `name` for older profiles. */
|
||||
label: string;
|
||||
/** When the profile was last snapshotted, epoch ms. */
|
||||
savedAt: number | null;
|
||||
/** True when this profile's account is the one logged in right now. */
|
||||
|
||||
Reference in New Issue
Block a user