Skip to content

Commit cbd4886

Browse files
roman-dvorakclaude
andcommitted
API: add PATCH /v1/devices/{id}/label for device-authenticated label update
The observer display name (label) was settable only at registration/recovery. This endpoint lets the mobile app update it at any time using the device JWT. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c7e2faa commit cbd4886

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎backend/apps/devices/api.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
)
1414
from .models import ConsentRecord, Device, RecoveryPhrase
1515
from .schemas import (
16+
DeviceLabelIn,
1617
DeviceRecoverIn,
1718
DeviceRecoverOut,
1819
DeviceRegisterIn,
@@ -90,6 +91,20 @@ def recover_device(request, payload: DeviceRecoverIn):
9091
return 200, {"device_id": str(device.id)}
9192

9293

94+
@router.patch("/{device_id}/label", auth=device_auth, response={200: SimpleOk, 403: dict})
95+
def update_label(request, device_id: str, payload: DeviceLabelIn):
96+
"""Update the display name (label) of the calling device.
97+
98+
The label is shown publicly on the web as the observer name. It can be set
99+
on registration/recovery and changed at any time via this endpoint.
100+
"""
101+
if str(request.device.id) != device_id:
102+
return 403, {"detail": "Can only update your own label"}
103+
request.device.label = payload.label.strip()[:120]
104+
request.device.save(update_fields=["label"])
105+
return 200, SimpleOk()
106+
107+
93108
@router.post("/{device_id}/revoke", auth=device_auth, response={200: SimpleOk, 403: dict})
94109
def revoke_device(request, device_id: str):
95110
"""Revoke the calling device (must authenticate as itself)."""

‎backend/apps/devices/schemas.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,9 @@ class DeviceRecoverOut(Schema):
3232
device_id: str
3333

3434

35+
class DeviceLabelIn(Schema):
36+
label: str
37+
38+
3539
class SimpleOk(Schema):
3640
ok: bool = True

0 commit comments

Comments
 (0)