feat: RBAC
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import request from '@/utils/request';
|
||||
|
||||
export function grantPermission(id: string, menuIds: string[]) {
|
||||
return request.put(`/permission/roles/${id}/menus`, { menuIds });
|
||||
return request.put(`/permission/roles/${id}/resources`, { menuIds });
|
||||
}
|
||||
|
||||
export function getRoleMenuIds(id: string) {
|
||||
return request.get(`/permission/roles/${id}/menus`);
|
||||
return request.get(`/permission/roles/${id}/resources`);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ const {Text} = Typography;
|
||||
export const enum TableOptions {
|
||||
EDIT = 'edit',
|
||||
DELETE = 'delete',
|
||||
ASSIGN_PERMISSION = 'assign_permission',
|
||||
ASSIGN_MENUS = 'assign_menus',
|
||||
ASSIGN_RESOURCES = 'assign_resources',
|
||||
}
|
||||
|
||||
export function getColumns(callback: (type: TableOptions, record: any) => Promise<void>): TableColumnProps[] {
|
||||
@@ -61,8 +62,10 @@ export function getColumns(callback: (type: TableOptions, record: any) => Promis
|
||||
<Space>
|
||||
<Button size='small' onClick={() => callback(TableOptions.EDIT, record)} type="text"
|
||||
status="default">更新</Button>
|
||||
<Button size='small' onClick={() => callback(TableOptions.ASSIGN_PERMISSION, record)} type="text"
|
||||
status="default">分配权限</Button>
|
||||
<Button size='small' onClick={() => callback(TableOptions.ASSIGN_MENUS, record)} type="text"
|
||||
status="default">分配菜单</Button>
|
||||
<Button size='small' onClick={() => callback(TableOptions.ASSIGN_RESOURCES, record)} type="text"
|
||||
status="default">分配数据</Button>
|
||||
<Popconfirm
|
||||
focusLock
|
||||
title="删除数据"
|
||||
|
||||
@@ -64,7 +64,7 @@ function UserManage() {
|
||||
case TableOptions.DELETE:
|
||||
await onDelete(record);
|
||||
break
|
||||
case TableOptions.ASSIGN_PERMISSION:
|
||||
case TableOptions.ASSIGN_MENUS:
|
||||
showAssignRolesModal(record);
|
||||
break
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ import { GrantMenuDto } from './dto/grant-menu.dto';
|
||||
export class PermissionController {
|
||||
constructor(private readonly permissionService: PermissionService) {}
|
||||
|
||||
@Get('/roles/:roleId/menus')
|
||||
@Get('/roles/:roleId/resources')
|
||||
getRoleMenus(@Param('roleId') roleId: string) {
|
||||
return this.permissionService.getRoleMenus(roleId);
|
||||
}
|
||||
|
||||
@Put('/roles/:roleId/menus')
|
||||
@Put('/roles/:roleId/resources')
|
||||
assignMenus(@Param('roleId') roleId: string, @Body() dto: GrantMenuDto) {
|
||||
return this.permissionService.assignMenus(roleId, dto);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user