mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-02-02 08:35:08 +08:00
feat: support admin assign superuser in admin ui (#12798)
### What problem does this PR solve? Allow superuser(admin) to grant or revoke other superuser. ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -1,7 +1,55 @@
|
||||
import { createContext, Dispatch, SetStateAction, useState } from 'react';
|
||||
import { Outlet } from 'react-router';
|
||||
|
||||
import type { IUserInfo } from '@/interfaces/database/user-setting';
|
||||
import authorizationUtil from '@/utils/authorization-util';
|
||||
|
||||
type LocalStoragePersistedUserInfo = {
|
||||
avatar: unknown;
|
||||
name: string;
|
||||
email: string;
|
||||
};
|
||||
|
||||
export type CurrentUserInfo =
|
||||
| {
|
||||
userInfo: null;
|
||||
source: null;
|
||||
}
|
||||
| {
|
||||
userInfo: AdminService.LoginData | IUserInfo;
|
||||
source: 'serverRequest';
|
||||
}
|
||||
| {
|
||||
userInfo: LocalStoragePersistedUserInfo;
|
||||
source: 'localStorage';
|
||||
};
|
||||
|
||||
const getLocalStorageUserInfo = (): CurrentUserInfo => {
|
||||
const userInfo = authorizationUtil.getUserInfoObject();
|
||||
|
||||
return userInfo
|
||||
? {
|
||||
userInfo: userInfo,
|
||||
source: 'localStorage',
|
||||
}
|
||||
: {
|
||||
userInfo: null,
|
||||
source: null,
|
||||
};
|
||||
};
|
||||
|
||||
export const CurrentUserInfoContext = createContext<
|
||||
[CurrentUserInfo, Dispatch<SetStateAction<CurrentUserInfo>>]
|
||||
>([getLocalStorageUserInfo(), () => {}]);
|
||||
|
||||
const AdminRootLayout = () => {
|
||||
return <Outlet />;
|
||||
const userInfoCtx = useState<CurrentUserInfo>(getLocalStorageUserInfo());
|
||||
|
||||
return (
|
||||
<CurrentUserInfoContext.Provider value={userInfoCtx}>
|
||||
<Outlet context={userInfoCtx} />
|
||||
</CurrentUserInfoContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default AdminRootLayout;
|
||||
|
||||
Reference in New Issue
Block a user