feat(admin): 完善后台角色管理与权限同步,新增当前管理员信息接口
This commit is contained in:
39
app/Support/AdminAuthProfile.php
Normal file
39
app/Support/AdminAuthProfile.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\AdminUser;
|
||||
|
||||
final class AdminAuthProfile
|
||||
{
|
||||
/**
|
||||
* @return array{
|
||||
* id: int,
|
||||
* username: string,
|
||||
* nickname: string,
|
||||
* email: ?string,
|
||||
* permissions: list<string>,
|
||||
* navigation: list<array{
|
||||
* segment: string,
|
||||
* label: string,
|
||||
* href: string,
|
||||
* activeMatchPrefix?: string,
|
||||
* requiredAny?: list<string>
|
||||
* }>
|
||||
* }
|
||||
*/
|
||||
public static function fromAdmin(AdminUser $admin): array
|
||||
{
|
||||
$fresh = $admin->fresh();
|
||||
$permissionSlugs = $fresh->adminPermissionSlugs();
|
||||
|
||||
return [
|
||||
'id' => $fresh->id,
|
||||
'username' => $fresh->username,
|
||||
'nickname' => $fresh->name,
|
||||
'email' => $fresh->email,
|
||||
'permissions' => $permissionSlugs,
|
||||
'navigation' => AdminAuthorizationRegistry::visibleNavigationItems($permissionSlugs),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user