Repository navigation
fix: disabled delete admin user - #8208
Merged
Merged
Conversation
shaohuzhang1
commented
Nov 27, 2026
| > | ||
| <MkIcon name="icon_delete-trash_outlined" /> | ||
| </el-button> | ||
| </MkTooltip> |
Contributor
Author
There was a problem hiding this comment.
Review of the diff
- <el-button type="primary" :disabled="row.id === user.userInfo?.id" text @click.stop="deleteUser(row)">
+ <el-button
+ type="primary"
+ :disabled="row.role === ROLE_TYPE.ADMIN || row.id === user.userInfo?.id"
+ text
+ @click.stop="deleteUser(row)"
+ >The intent (block deletion of admin users) is reasonable, but there are several things worth checking.
1. Correctness of the rule
- Is
row.rolea single value or an array? If the backend returnsroles: ['ADMIN', ...]or aroleCode,row.role === ROLE_TYPE.ADMINwill silently befalseand the guard won't work. Verify the actual field name/shape of the user DTO. - Other privileged roles. If you have
SUPER_ADMIN,OPERATOR, tenant-owner, etc., they also need protection. Prefer a set-based check:const PROTECTED_ROLES = new Set([ROLE_TYPE.ADMIN, ROLE_TYPE.SUPER_ADMIN])
- Type mismatch. Ensure
ROLE_TYPE.ADMIN(string vs. number enum) matches the runtime type ofrow.role; a strict===against a mismatched type fails silently. - Last-admin rule. Even if the role check passes, the backend should refuse deleting the last remaining admin of a tenant/system.
- Is
ROLE_TYPEimported? In<script setup>templates this resolves fine only if it's imported / exposed. If it isn't, you'll get a runtime "property of undefined" error rather than a compile error — double-check the import.
2. Front-end checks are UX only
Disabling the button does not enforce anything. Anyone can call the delete API directly (devtools, curl). Make sure the same rule is enforced server-side and returns a clear 403/409 error. Ideally also handle that error in deleteUser() and re-sync the list.
3. Readability / maintainability
- Inline boolean logic inside a template is hard to reuse. Extract it:
const canDeleteUser = (row: SystemUser) => row.role !== ROLE_TYPE.ADMIN && row.id !== user.userInfo?.id
This also makes it unit-testable and reusable in batch-delete / context menus / detail pages, which otherwise tend to drift out of sync.:disabled="!canDeleteUser(row)"
- The condition mixes two concerns: permission (
perm.system.user.delete(), already used inv-if) and business rule (can't delete admins). Consider naming it accordingly (e.g.isProtectedUser(row)).
4. UX / accessibility
- A disabled Element Plus button does not emit mouse events, so the
MkTooltipwrapping it may not show. If users need to understand why it's disabled, wrap the button in a<span>(or useel-tooltipwith a wrapper) and set the tooltip content conditionally:<MkTooltip :content="isProtected(row) ? t('user.cannotDeleteAdmin') : t('common.actions.delete')" ...> <span><el-button ... /></span> </MkTooltip>
- Disabled
textbuttons can be nearly invisible against the background — verify contrast in both light/dark themes. @click.stopis harmless when disabled, but if you wrap in a span, keep it so clicks don't bubble to the row handler.
5. Minor style nits
- The multi-line attribute reflow is fine, but the rest of the file uses single-line attributes for short buttons; keep formatting consistent per project lint rules (
prettier/eslint-plugin-vue). - Consider putting
textbeforetypeonly if your lint order config demands it — otherwise irrelevant. - No trailing whitespace or indentation problems detected in the added lines.
6. Testing
Add a component test asserting the button is disabled for: (a) admin row, (b) the current user's own row, (c) enabled for a normal user. Also add an API-level test that the backend rejects deleting an admin.
Summary
The change is functional for the happy path, but:
- verify
row.roleshape/type and thatROLE_TYPEis imported; - cover all privileged roles, not just
ADMIN; - enforce the same rule on the backend;
- extract the predicate into a helper for reuse and testability;
- improve the disabled-state tooltip/contrast so the reason is discoverable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
【【用户管理】用户可以把自己的账号和admin的账号删除】
https://www.tapd.cn/tapd_fe/45245355/bug/detail/1145245355001079271