Ana içeriğe geç

Kullanıcıya Rol Ata

Kullanıcıya rol atar.

Endpoint

POST /api/v1/users/assign-role

Authentication

Bu endpoint authentication gerektirir.

Header: Authorization: Bearer \{token\}

Permission

  • admin.manage - Admin yönetim işlemleri
  • roles.assign - Rol atama

Request

Headers

HeaderDeğerZorunlu
AuthorizationBearer \{token\}Evet
Content-Typeapplication/jsonEvet

Request Body

ParametreTipZorunluAçıklama
user_idintegerEvet*Kullanıcı ID'si
user_uuidstringEvet*Kullanıcı UUID'si
role_idintegerEvet*Rol ID'si
role_slugstringEvet*Rol slug'ı
secretstringHayırSistem rolleri için gizli anahtar

* user_id veya user_uuid'den biri, role_id veya role_slug'dan biri zorunludur.

Example Request

{
"user_uuid": "550e8400-e29b-41d4-a716-446655440000",
"role_slug": "mgmt.editor"
}

Response

Success Response (200 OK)

{
"id": 1,
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"email": "user@example.com",
"roles": [
{
"id": 5,
"name": "Editor",
"slug": "mgmt.editor",
"permissions": [...]
}
]
}

Error Responses

403 Forbidden

{
"message": "Rol atama yetkiniz yok"
}

403 Forbidden (Sistem Rolleri)

{
"message": "Forbidden role assignment"
}

403 Forbidden (Hiyerarşi Kontrolü)

{
"message": "You do not have permission to assign this role to this user",
"role_priority": 10,
"target_user_highest_priority": 20,
"your_priority": 30
}

Code Examples

cURL

curl -X POST https://api.example.com/api/v1/users/assign-role \
-H "Authorization: Bearer \{token\}" \
-H "Content-Type: application/json" \
-d '{
"user_uuid": "550e8400-e29b-41d4-a716-446655440000",
"role_slug": "mgmt.editor"
}'

Notes

  • Sistem rolleri (system.toor, server.root) için X-Role-Secret header'ı veya secret parametresi gereklidir
  • Kullanıcı sadece kendi seviyesinden düşük seviyeli rolleri atayabilir
  • User ID veya UUID, role ID veya slug kullanılabilir