aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/api
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/api')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/api/groups.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/api/groups.py b/packages/meshbay-hub/src/meshbay_hub/api/groups.py
index 43d72c3..83feeb4 100644
--- a/packages/meshbay-hub/src/meshbay_hub/api/groups.py
+++ b/packages/meshbay-hub/src/meshbay_hub/api/groups.py
@@ -276,6 +276,38 @@ async def create_group(
return {"group_id": group.id, "name": group.name}
+class GroupUpdateRequest(BaseModel):
+ description: str | None = None
+
+
+@router.patch("/{group_id}")
+async def update_group(
+ group_id: str,
+ body: GroupUpdateRequest,
+ current_user: User = Depends(require_user_scope),
+ db: AsyncSession = Depends(get_db),
+):
+ """
+ Change the group's description. Owner only.
+
+ Only the description: name, visibility and join policy are what members
+ joined on the strength of, and a group that can quietly become public is a
+ different thing from the one they agreed to. Those need a decision about who
+ is told, not a PATCH.
+ """
+ group = await db.get(Group, group_id)
+ if not group:
+ raise HTTPException(status_code=404, detail="Group not found")
+ if group.admin_id != current_user.id:
+ raise HTTPException(status_code=403, detail="Only the group owner can edit it")
+
+ if body.description is not None:
+ desc = body.description.strip()[:512]
+ group.description = desc or None
+ await db.commit()
+ return {"group_id": group.id, "description": group.description or ""}
+
+
@router.post("/{group_id}/members/{username}", status_code=201)
async def add_group_member(
group_id: str,