Merge pull request #33 from jyiL/patch-4

fixed permission
This commit is contained in:
刀刀
2020-10-28 19:13:30 +08:00
committed by GitHub
2 changed files with 30 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ namespace HyperfAdmin\Admin\Controller;
use Hyperf\Utils\Str;
use HyperfAdmin\Admin\Model\FrontRoutes;
use HyperfAdmin\Admin\Service\CommonConfig;
use HyperfAdmin\Admin\Service\Menu;
use HyperfAdmin\Admin\Service\ModuleProxy;
use HyperfAdmin\BaseUtils\Constants\ErrorCode;
use HyperfAdmin\BaseUtils\Guzzle;
@@ -25,6 +26,21 @@ class SystemController extends AdminAbstractController
'open_export' => false,
'navbar_notice' => '',
]);
if (isset($config['system_module']) && !$this->auth_service->isSupperAdmin()) {
$user_id = $this->auth_service->get('id');
$role_ids = $this->permission_service->getUserRoleIds($user_id);
$router_ids = $this->permission_service->getRoleMenuIds($role_ids);
$modules = array_unique($this->permission_service->getModules($router_ids));
foreach ($config['system_module'] as $module_key => $module_value) {
if(!in_array($module_value['name'], $modules))
unset($config['system_module'][$module_key]);
}
}
return $this->success($config);
}

View File

@@ -388,4 +388,18 @@ class PermissionService
}
throw new \RuntimeException('Handler not exist.');
}
public function getModules($router_ids)
{
if(!$router_ids) {
return [];
}
return FrontRoutes::query()
->select(['module'])
->whereIn('id', $router_ids)
->get()
->pluck('module')
->toArray();
}
}