Skip to content

fix: disabled delete admin user - #8208

Merged
fit2cloudwxx merged 1 commit into
v3from
pr@v3@fix_disabledDelAdminUser
Nov 27, 2026
Merged

fit2cloudwxx merged 1 commit into
v3from
pr@v3@fix_disabledDelAdminUser

Conversation

@shaohuzhang1

@shaohuzhang1 shaohuzhang1 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

【【用户管理】用户可以把自己的账号和admin的账号删除】
https://www.tapd.cn/tapd_fe/45245355/bug/detail/1145245355001079271

>
<MkIcon name="icon_delete-trash_outlined" />
</el-button>
</MkTooltip>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.role a single value or an array? If the backend returns roles: ['ADMIN', ...] or a roleCode, row.role === ROLE_TYPE.ADMIN will silently be false and 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 of row.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_TYPE imported? 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
    :disabled="!canDeleteUser(row)"
    This also makes it unit-testable and reusable in batch-delete / context menus / detail pages, which otherwise tend to drift out of sync.
  • The condition mixes two concerns: permission (perm.system.user.delete(), already used in v-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 MkTooltip wrapping it may not show. If users need to understand why it's disabled, wrap the button in a <span> (or use el-tooltip with 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 text buttons can be nearly invisible against the background — verify contrast in both light/dark themes.
  • @click.stop is 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 text before type only 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:

  1. verify row.role shape/type and that ROLE_TYPE is imported;
  2. cover all privileged roles, not just ADMIN;
  3. enforce the same rule on the backend;
  4. extract the predicate into a helper for reuse and testability;
  5. improve the disabled-state tooltip/contrast so the reason is discoverable.

@fit2cloudwxx
fit2cloudwxx merged commit 653acc3 into v3 Nov 27, 2026
3 of 4 checks passed
@fit2cloudwxx
fit2cloudwxx deleted the pr@v3@fix_disabledDelAdminUser branch November 27, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants