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