feat: improve anonymous
This commit is contained in:
parent
6b2d8fdd4a
commit
bb3b783006
@ -2,23 +2,26 @@ import { useCookieState } from 'ahooks';
|
||||
import { Menu, Select } from 'antd';
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useACLRoleContext } from '../acl';
|
||||
import { useAPIClient } from '../api-client';
|
||||
import { useCurrentUserContext } from './CurrentUserProvider';
|
||||
|
||||
const useCurrentRoles = () => {
|
||||
const { allowAnonymous } = useACLRoleContext();
|
||||
const { data } = useCurrentUserContext();
|
||||
return [
|
||||
...(data?.data?.roles || []).map(item => {
|
||||
const options = (data?.data?.roles || []).map((item) => {
|
||||
return {
|
||||
title: item.title,
|
||||
name: item.name,
|
||||
}
|
||||
}),
|
||||
{
|
||||
};
|
||||
});
|
||||
if (allowAnonymous) {
|
||||
options.push({
|
||||
title: 'Anonymous',
|
||||
name: 'anonymous',
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
return options;
|
||||
};
|
||||
|
||||
export const SwitchRole = () => {
|
||||
|
@ -16,6 +16,12 @@ export async function checkAction(ctx, next) {
|
||||
appends: ['menuUiSchemas'],
|
||||
});
|
||||
|
||||
const anonymous = await ctx.db.getRepository('roles').findOne({
|
||||
filter: {
|
||||
name: 'anonymous',
|
||||
},
|
||||
});
|
||||
|
||||
const role = ctx.app.acl.getRole(currentRole);
|
||||
|
||||
ctx.body = {
|
||||
@ -25,6 +31,7 @@ export async function checkAction(ctx, next) {
|
||||
allowAll: currentRole === 'root',
|
||||
allowConfigure: roleInstance.get('allowConfigure'),
|
||||
allowMenuItemIds: roleInstance.get('menuUiSchemas').map((uiSchema) => uiSchema.get('x-uid')),
|
||||
allowAnonymous: !!anonymous,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ export default {
|
||||
model: 'RoleModel',
|
||||
filterTargetKey: 'name',
|
||||
// targetKey: 'name',
|
||||
sortable: true,
|
||||
fields: [
|
||||
{
|
||||
type: 'uid',
|
||||
|
Loading…
Reference in New Issue
Block a user