Repository navigation
fix: switch for the knowledge image list - #7892
Conversation
| :disabled="operationLoading || !canImage('edit')" | ||
| :before-change="() => handleChangeActive(row)" | ||
| /> | ||
|
|
There was a problem hiding this comment.
The change from && to || is a logic bug and likely incorrect.
Analysis of the original (&&):
- Switch is disabled only when data is loading AND the user lacks edit permission.
- If not loading, or if user has permission, the switch stays enabled.
- This allows a user with edit rights to toggle even during loading (which can be risky), but lets users see/toggle when idle.
Analysis of the new (||):
- Switch is disabled when data is loading OR user lacks edit permission.
- More importantly: if the user lacks edit permission, it's always disabled — good.
- But during loading, it's disabled for everyone — also reasonable.
- The real question is intent: does
canImage('edit')mean "user CAN edit"? If yes, then!canImage('edit')= "cannot edit" →||= "disabled if cannot edit OR loading" — this is arguably the more correct/intuitive behavior.
Potential issues to verify:
-
Semantics of
canImage('edit'): Confirm it returnstruewhen the user has permission. If it actually returns whether an image editing operation is allowed (naming is ambiguous), negating it may behave unexpectedly. -
operationLoadingscope: Is it per-row or global? If global, one row's save disables switches on all rows. Consider a per-row loading flag (e.g.,row._loading) for better UX. -
before-changevsdisabledredundancy:handleChangeActive(row)presumably performs the API call. With:disabled, the switch won't firebefore-changewhen disabled — so make sure permission checks inhandleChangeActiveare still present as defense-in-depth (server-side authorization must exist regardless). -
Read-only display: When disabled due to lack of permission, consider showing a tooltip explaining why (better UX than a silently inert control).
Optimization suggestion:
:disabled="isRowBusy(row) || !canImage('edit')"Create a helper isRowBusy(row) that tracks per-row operations rather than a shared operationLoading, avoiding cross-row lock-outs.
Verdict: The || change is defensible and probably intentional (fixing cases where unauthorized users could interact), but verify: (a) the meaning of canImage('edit'), and (b) whether operationLoading is global — if global, prefer per-row loading to avoid disabling unrelated rows.
fix: switch for the knowledge image list