Код: Выделить всё
public function GetRoles($id = 'new', $module = null) {
$json = [];
$groups = array_merge((array) ($this->auth['payload']['group'] ?? null), (array) ($this->auth['payload']['additionalGroup'] ?? null));
$access = GetAccess($module ?? $this->module, $groups);
$json['insert'] = ($id === 'new' && in_array('insert', $access)) ? true : null;
$json['view'] = ($id === 'view' && in_array('view', $access)) ? true : null;
$json['update'] = ($id !== 'new' && in_array('update', $access)) ? true : null;
$json['delete'] = ($id !== 'new' && in_array('delete', $access)) ? true : null;
$json['upload'] = ($id !== 'new' && in_array('upload', $access)) ? true : null;
$json['remove'] = ($id !== 'new' && in_array('remove', $access)) ? true : null;
$json['inactive'] = ($id !== 'new' && in_array('inactive', $access)) ? true : null;
$json['approve'] = ($id !== 'new' && in_array('approve', $access)) ? true : null;
$json['cancel'] = ($id !== 'new' && in_array('cancel', $access)) ? true : null;
$json['reopen'] = ($id !== 'new' && in_array('reopen', $access)) ? true : null;
return $json;
}
Код: Выделить всё
function GetAccess($module, $groups, $role = null) {
global $config;
$rules = [];
$modules = ModuleMerge($config['modules']);
if (isset($config['access'][$module])) {
foreach ($config['access'][$module] ?? [] as $key => $value) {
if (in_array($key, $groups)) {
$rules = array_unique(array_merge($rules, $value));
}
}
} else if (in_array($module, ['main', 'login', 'login_google', 'register', 'reset', 'newpassword', 'validate', 'contact_us', 'disclaimer', 'privacy_policy', 'security_policy', 'terms_condition', 'help'])) {
$rules = ['view', 'insert', 'update'];
} else {
$rules = $modules[$module];
}
if ($role) {
$rules = in_array($role, $rules);
}
return $rules;
}
Код: Выделить всё
function ModuleMerge($array) {
$result = [];
for ($i = 0; $i < count($array); $i++) {
$moduleKey = $array[$i]['module'] ?? null;
if (!isset($result[$moduleKey])) {
$result[$moduleKey] = [];
}
$result[$moduleKey] = $result[$moduleKey]
? array_unique(array_merge($result[$moduleKey], $array[$i]['roles'] ?? []))
: ($array[$i]['roles'] ?? []);
if (is_array($array[$i]['children'] ?? null)) {
$result = array_merge($result, ModuleMerge($array[$i]['children']));
}
}
return $result;
}
Основная группа -> ['Сотрудники']
Дополнительная группа -> ['Администратор магазина', 'Товары' ', 'Инвентарь SV']
Роли сотрудников группы -> ['Просмотр главной панели управления', 'редактировать профиль', 'загрузить изображение профиля']
Группа Роли администратора магазина -> ['Просмотреть страницу модуля магазина', 'добавить товар в магазине', 'обновить товар в магазине', 'удалить товар в магазине', 'одобрить товар в магазине']
Группировать роли товаров -> ['Просмотреть наличие товара ', 'вставить получателя товара']
На данный момент пользователь 1 имеет доступ только к основной группе, доступ к всплывающему окну дополнительной группы запрещен!
Я жду Дэна Пользователь 1 также может иметь доступ к дополнительным ролям группы
Подробнее здесь: https://stackoverflow.com/questions/791 ... r-multiple