新增对当前用户以及管理员用户的保护,不允许删除
This commit is contained in:
parent
8164fbc716
commit
284a247f5e
@ -7,7 +7,6 @@ import {
|
||||
addMenuListApi,
|
||||
putMenuListApi
|
||||
} from '@/api/vadmin/auth/menu'
|
||||
import { TableData } from '@/api/table/types'
|
||||
import { useTable } from '@/hooks/web/useTable'
|
||||
import { useI18n } from '@/hooks/web/useI18n'
|
||||
import { ElButton, ElSwitch } from 'element-plus'
|
||||
@ -30,7 +29,7 @@ const getOptions = async () => {
|
||||
|
||||
getOptions()
|
||||
|
||||
const { register, tableObject, methods } = useTable<TableData>({
|
||||
const { register, tableObject, methods } = useTable({
|
||||
getListApi: getMenuListApi,
|
||||
delListApi: delMenuListApi,
|
||||
response: {
|
||||
|
@ -116,10 +116,10 @@ getList()
|
||||
@register="register"
|
||||
>
|
||||
<template #action="{ row }">
|
||||
<ElButton type="primary" text size="small" @click="updateAction(row)">
|
||||
<ElButton type="primary" text size="small" @click="updateAction(row)" v-if="row.id !== 1">
|
||||
{{ t('exampleDemo.edit') }}
|
||||
</ElButton>
|
||||
<ElButton type="danger" text size="small" @click="delData(row)">
|
||||
<ElButton type="danger" text size="small" @click="delData(row)" v-if="row.id !== 1">
|
||||
{{ t('exampleDemo.del') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
|
@ -141,7 +141,13 @@ getList()
|
||||
<ElButton type="primary" text size="small" @click="updateAction(row)">
|
||||
{{ t('exampleDemo.edit') }}
|
||||
</ElButton>
|
||||
<ElButton type="danger" text size="small" @click="delData(row)">
|
||||
<ElButton
|
||||
type="danger"
|
||||
text
|
||||
size="small"
|
||||
@click="delData(row)"
|
||||
v-if="authStore.getUser.id !== row.id && row.id !== 1"
|
||||
>
|
||||
{{ t('exampleDemo.del') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
|
@ -33,6 +33,10 @@ async def create_user(data: schemas.UserIn, auth: Auth = Depends(login_auth)):
|
||||
|
||||
@app.delete("/users/", summary="批量删除用户")
|
||||
async def delete_users(ids: list = Depends(id_list), auth: Auth = Depends(login_auth)):
|
||||
if auth.user.id in ids:
|
||||
return ErrorResponse("不能删除当前登录用户")
|
||||
elif 1 in ids:
|
||||
return ErrorResponse("不能删除超级管理员用户")
|
||||
await crud.UserDal(auth.db).delete_datas(ids=ids)
|
||||
return SuccessResponse("删除成功")
|
||||
|
||||
@ -83,12 +87,16 @@ async def create_role(role: schemas.RoleIn, auth: Auth = Depends(login_auth)):
|
||||
|
||||
@app.delete("/roles/", summary="批量删除角色")
|
||||
async def delete_roles(ids: list = Depends(id_list), auth: Auth = Depends(login_auth)):
|
||||
if 1 in ids:
|
||||
return ErrorResponse("不能删除管理员角色")
|
||||
await crud.RoleDal(auth.db).delete_datas(ids)
|
||||
return SuccessResponse("删除成功")
|
||||
|
||||
|
||||
@app.put("/roles/{data_id}/", summary="更新角色信息")
|
||||
async def put_role(data_id: int, data: schemas.RoleIn, auth: Auth = Depends(login_auth)):
|
||||
if 1 == data_id:
|
||||
return ErrorResponse("不能修改管理员角色")
|
||||
return SuccessResponse(await crud.RoleDal(auth.db).put_data(data_id, data))
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user