Skip to content

Commit 428d4c4

Browse files
committed
removed unwanted comments and updated unautorized response
1 parent c37cf00 commit 428d4c4

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

extensions/m8flow-backend/src/m8flow_backend/api.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ paths:
276276

277277
put:
278278
summary: Update tenant display name
279-
description: Updates the tenant's human-readable name in both the local database and the Keycloak realm (displayName). Restricted to 'super-admin' role. The slug and ID are immutable and cannot be changed.
279+
description: Updates the tenant's human-readable name in both the local database and the Keycloak realm (displayName). The slug and ID are immutable and cannot be changed.
280280
operationId: m8flow_backend.routes.keycloak_controller.update_tenant_name
281281
tags:
282282
- Tenant

extensions/m8flow-backend/src/m8flow_backend/routes/keycloak_controller.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,11 @@ def delete_tenant_realm(realm_id: str) -> tuple[dict, int]:
197197

198198
@handle_api_errors
199199
def update_tenant_name(tenant_id: str, body: dict) -> tuple[dict, int]:
200-
"""Update a tenant's name in both Keycloak (displayName) and Postgres.
201-
Restricted to super-admin role. Uses internal master admin token.
202-
"""
200+
"""Update a tenant's display name. Requires appropriate permissions."""
203201
user = getattr(g, 'user', None)
204202
if not user:
205203
raise ApiError(error_code="not_authenticated", message="User not authenticated", status_code=401)
206204

207-
# Check for super-admin permission via m8flow.yml configuration
208205
is_authorized = AuthorizationService.user_has_permission(user, "update", request.path)
209206

210207
if not is_authorized:
@@ -214,7 +211,7 @@ def update_tenant_name(tenant_id: str, body: dict) -> tuple[dict, int]:
214211
[getattr(g, 'identifier', g.name) for g in getattr(user, 'groups', [])],
215212
tenant_id
216213
)
217-
raise ApiError(error_code="forbidden", message="Only super-admin can update tenant name", status_code=403)
214+
raise ApiError(error_code="forbidden", message="Not authorized to update the tenant name.", status_code=403)
218215

219216
new_name = body.get("name")
220217
if not new_name or not str(new_name).strip():
@@ -230,13 +227,9 @@ def update_tenant_name(tenant_id: str, body: dict) -> tuple[dict, int]:
230227
if not tenant:
231228
return {"detail": "Tenant not found"}, 404
232229

233-
# Fetch Keycloak admin token internally
234230
admin_token = get_master_admin_token()
235231

236-
# Update Keycloak realm displayName
237232
update_realm(tenant.slug, display_name=new_name, admin_token=admin_token)
238-
239-
# Update Postgres tenant name
240233
tenant.name = new_name
241234
db.session.commit()
242235
logger.info("Updated tenant name: id=%s slug=%s to name=%s (updated by %s)",

0 commit comments

Comments
 (0)