Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve] User cannot delete themselves #268

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.seatunnel.app.service.IRoleService;
import org.apache.seatunnel.app.service.IUserService;
import org.apache.seatunnel.app.utils.PasswordUtils;
import org.apache.seatunnel.app.utils.ServletUtils;
import org.apache.seatunnel.server.common.PageData;
import org.apache.seatunnel.server.common.SeatunnelErrorEnum;
import org.apache.seatunnel.server.common.SeatunnelException;
Expand Down Expand Up @@ -135,6 +136,11 @@ public void update(UpdateUserReq updateReq) {
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(int id) {
// can't delete yourself
if (ServletUtils.getCurrentUserId() == id) {
throw new SeatunnelException(
SeatunnelErrorEnum.INVALID_OPERATION, "Can't delete yourself");
}
userDaoImpl.delete(id);
roleServiceImpl.deleteByUserId(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public enum SeatunnelErrorEnum {
40005, "load engine metrics error", "load engine metrics error. error msg is [%s]"),
JOB_NO_VALUE_FOUND_FOR_PLACEHOLDER(
40006, "No value found for placeholder", "No value found for placeholder: [%s]"),
INVALID_OPERATION(40007, "invalid operation", "invalid operation [%s]"),

JOB_RUN_GENERATE_UUID_ERROR(50001, "generate uuid error", "generate uuid error"),
/* datasource and virtual table */
Expand Down
22 changes: 17 additions & 5 deletions seatunnel-ui/src/views/user-manage/list/use-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

import { reactive, ref, h } from 'vue'
import { useI18n } from 'vue-i18n'
import { NSpace, NButton } from 'naive-ui'
import { NSpace, NButton, NTooltip } from 'naive-ui'
import { userList, userDelete, userEnable, userDisable } from '@/service/user'
import { getTableColumn } from '@/common/table'
import type { ResponseTable } from '@/service/types'
import type { UserDetail } from '@/service/user/types'
import { useUserStore } from '@/store/user'

export function useTable() {
const { t } = useI18n()
const userStore = useUserStore()
const state = reactive({
columns: [],
tableData: [],
Expand Down Expand Up @@ -56,8 +58,11 @@ export function useTable() {
{
title: t('user_manage.operation'),
key: 'operation',
render: (row: UserDetail) =>
h(NSpace, null, {
render: (row: UserDetail) => {
const currentUser = userStore.getUserInfo as UserDetail
const isCurrentUser = Boolean(currentUser?.id && row?.id && currentUser.id === row.id)

return h(NSpace, null, {
default: () => [
h(
NButton,
Expand All @@ -76,11 +81,18 @@ export function useTable() {
),
h(
NButton,
{ text: true, onClick: () => handleDelete(row) },
{ default: () => t('user_manage.delete') }
{
text: true,
disabled: isCurrentUser,
onClick: () => handleDelete(row)
},
{
default: () => t('user_manage.delete')
}
)
]
})
}
}
]
}
Expand Down