feat: improve anonymous

This commit is contained in:
chenos 2022-04-14 18:37:51 +08:00
parent 6b2d8fdd4a
commit bb3b783006
3 changed files with 21 additions and 10 deletions

View File

@ -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 = () => {

View File

@ -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,
};
}

View File

@ -7,6 +7,7 @@ export default {
model: 'RoleModel',
filterTargetKey: 'name',
// targetKey: 'name',
sortable: true,
fields: [
{
type: 'uid',