Skip to content
/ loom Public

Commit 2b6a19d

Browse files
ghuntleyclaude
andcommitted
Use personal org for personal clips instead of display_name
Personal clips now properly belong to the user's personal org: - Uses ensure_personal_org() to get or create user's personal org - All clips now have a proper org_id (no more None) - Clip owner is the org's slug (personal-{user_id} for personal orgs) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f4cca72 commit 2b6a19d

File tree

1 file changed

+22
-8
lines changed
  • crates/loom-server/src/routes/clips

1 file changed

+22
-8
lines changed

crates/loom-server/src/routes/clips/crud.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ pub async fn create_clip(
8787
.into_response();
8888
}
8989

90-
// Determine owner: org slug if org_id provided, otherwise user's display_name
91-
let (owner_slug, org_id_for_record) = if let Some(org_uuid) = payload.org_id {
90+
// Determine owner org: use provided org_id or user's personal org
91+
let org = if let Some(org_uuid) = payload.org_id {
9292
// Check org membership
9393
let org_id = OrgId::new(org_uuid);
9494
let _membership = match state
@@ -121,7 +121,7 @@ pub async fn create_clip(
121121
};
122122

123123
// Get org for the owner name
124-
let org = match state.org_repo.get_org_by_id(&org_id).await {
124+
match state.org_repo.get_org_by_id(&org_id).await {
125125
Ok(Some(o)) => o,
126126
Ok(None) => {
127127
return (
@@ -144,14 +144,28 @@ pub async fn create_clip(
144144
)
145145
.into_response();
146146
}
147-
};
148-
149-
(org.slug, Some(org_uuid))
147+
}
150148
} else {
151-
// Personal clip - use user's display name as owner
152-
(current_user.user.display_name.clone(), None)
149+
// Personal clip - get or create user's personal org
150+
match state.org_repo.ensure_personal_org(&current_user.user.id).await {
151+
Ok(o) => o,
152+
Err(e) => {
153+
tracing::error!(error = %e, "Failed to ensure personal org");
154+
return (
155+
StatusCode::INTERNAL_SERVER_ERROR,
156+
Json(ClipsErrorResponse {
157+
error: "internal_error".to_string(),
158+
message: t(locale, "server.api.error.internal").to_string(),
159+
}),
160+
)
161+
.into_response();
162+
}
163+
}
153164
};
154165

166+
let owner_slug = org.slug.clone();
167+
let org_id_for_record = Some(org.id.into_inner());
168+
155169
// Check if clip name already exists for this owner
156170
if let Ok(true) = clips_repo.clip_name_exists(&owner_slug, &payload.name).await {
157171
return (

0 commit comments

Comments
 (0)