Skip to content

Commit 9f35c19

Browse files
committed
fix:Admin not allow change password
1 parent c30bbf0 commit 9f35c19

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

components/user/change-password.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ export function ChangePassword({ visible, onVisibleChange }: ChangePasswordProps
7676
accessKey: userInfo?.account_name ?? "",
7777
secretKey: newSecretKey,
7878
status: "enabled",
79-
})
79+
}, { suppress403Redirect: true })
8080
message.success(t("Updated successfully"))
8181
closeModal()
8282
} catch (error) {
8383
console.error(error)
84-
message.error(t("Update failed"))
84+
message.error((error as Error)?.message || t("Update failed"))
8585
} finally {
8686
setSubmitting(false)
8787
}

components/user/dropdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function UserDropdown() {
6868
<span>{(userInfo as { account_name?: string })?.account_name ?? (isAdmin ? "rustfsAdmin" : "")}</span>
6969
</div>
7070
</DropdownMenuItem>
71-
{canChangePassword && (
71+
{!isAdmin && (
7272
<DropdownMenuItem onSelect={handleChangePassword}>
7373
<RiLockPasswordLine className="h-4 w-4" />
7474
<span>{t("Change Password")}</span>

hooks/use-users.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@ import { useApiOptional } from "@/contexts/api-context"
66
export function useUsers() {
77
const api = useApiOptional()
88

9+
type UserRequestOptions = {
10+
suppress403Redirect?: boolean
11+
}
12+
913
const listUsers = useCallback(async () => {
1014
if (!api) return null
1115
return api.get("/list-users")
1216
}, [api])
1317

1418
const createUser = useCallback(
15-
async (data: Record<string, unknown>) => {
19+
async (data: Record<string, unknown>, options?: UserRequestOptions) => {
1620
if (!api) return null
1721
const { accessKey, ...rest } = data
18-
return api.put(`/add-user?accessKey=${encodeURIComponent(accessKey as string)}`, rest)
22+
return api.put(`/add-user?accessKey=${encodeURIComponent(accessKey as string)}`, rest, options)
1923
},
2024
[api],
2125
)

0 commit comments

Comments
 (0)