Files
citrus-cms/app/Functions/specific-permission.php
2026-04-28 21:14:25 +03:00

74 lines
2.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
function isSpecificPermission($permission, $user = null, $typeId = null) {
if($user == null) {
$user = u();
}
// Eğer kullanıcı admin ise her şeye yetkisi vardır
if(isAdmin($user)) {
return true;
}
// Kullanıcının level indexini bul
$userLevelIndex = getLevelIndex($user->level);
// 1. Module Specific Permission Kontrolü
if (!$typeId) {
// Otomatik modül tespiti
// URL: /admin/types/{slug}
$slug = request()->segment(3);
if ($slug) {
$type = \App\Types::where('slug', $slug)->first();
if($type) {
$typeId = $type->id;
}
}
}
if ($typeId) {
$key = "type_{$typeId}_specific_permissions";
$moduleSettings = j(setting($key));
// Eğer permission bu modül için tanımlıysa
if (isset($moduleSettings[$permission])) {
$allowed = $moduleSettings[$permission];
if (!empty($allowed)) {
$allowedLevels = explode(',', $allowed);
// Trim whitespace from values
$allowedLevels = array_map('trim', $allowedLevels);
// Modül ayarları level indexlerini (1, 2, 3) kullanıyor
if (in_array($userLevelIndex, $allowedLevels)) {
return true;
}
}
// Modülde ayar var ama boş veya kullanıcı uymuyorsa reddet (Global'e düşmez)
return false;
}
}
// 2. Global Specific Permission Kontrolü
// Global ayarlar level isimlerini (Manager, User vb.) kullanıyor
$globalSetting = setting($permission);
if($globalSetting) {
$allowedGlobal = j($globalSetting);
if(!is_array($allowedGlobal)) {
$allowedGlobal = explode(',', $globalSetting);
}
if(!empty($allowedGlobal)) {
if (in_array($user->level, $allowedGlobal)) {
return true;
}
}
}
// 3. Hiçbir ayar bulunamadıysa veya eşleşme olmadıysa varsayılan olarak reddet
return false;
}
?>