İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?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;
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user