Ana içeriğe geç

Rol Güncelle

Rol bilgilerini günceller.

Endpoint

PUT /api/v1/roles/\{id\}
PATCH /api/v1/roles/\{id\}

Authentication

Bu endpoint authentication gerektirir.

Header: Authorization: Bearer \{token\}

Permission

  • admin.manage - Admin yönetim işlemleri
  • roles.update - Rol güncelleme

Request

Headers

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

Path Parameters

ParametreTipZorunluAçıklama
idintegerEvetRol ID'si

Request Body

ParametreTipZorunluAçıklama
namestringHayırRol adı (max: 191)
slugstringHayırRol slug'ı (unique, max: 191)
priorityintegerHayırRol önceliği (1-1000)
is_activebooleanHayırAktif durumu
secretstringHayırSistem rolleri için gizli anahtar
permission_idsarrayHayırPermission ID'leri
permission_slugsarrayHayırPermission slug'ları
permission_upgradebooleanHayırPermission ekleme/kaldırma (true: ekle, false: kaldır, varsayılan: true)

Example Request

{
"name": "Editor Updated",
"priority": 45,
"permission_ids": [1, 2, 3],
"permission_upgrade": true
}

Response

Success Response (200 OK)

{
"id": 5,
"name": "Editor Updated",
"slug": "mgmt.editor",
"priority": 45,
"is_active": true,
"created_at": "2025-11-20T12:00:00.000000Z",
"updated_at": "2025-11-20T12:00:00.000000Z",
"permissions": [
{
"id": 1,
"name": "Admin Yönetimi",
"slug": "admin.manage"
}
]
}

Error Responses

403 Forbidden

{
"message": "Rol güncelleme yetkiniz yok"
}

403 Forbidden (Hiyerarşi Kontrolü)

{
"message": "You cannot set a role priority equal to or higher than your own role level",
"your_priority": 20,
"requested_priority": 10
}

Code Examples

cURL

curl -X PATCH https://api.example.com/api/v1/roles/5 \
-H "Authorization: Bearer \{token\}" \
-H "Content-Type: application/json" \
-d '{
"name": "Editor Updated",
"priority": 45,
"permission_ids": [1, 2, 3]
}'

Notes

  • Kullanıcı sadece kendi seviyesinden düşük seviyeli rolleri güncelleyebilir
  • Sistem rolleri için X-Role-Secret header'ı veya secret parametresi gereklidir
  • permission_ids veya permission_slugs ile permission'lar eklenebilir veya kaldırılabilir
  • permission_upgrade=true permission'ları ekler, false kaldırır