mirror of
https://github.com/rustfs/console.git
synced 2026-08-29 03:52:28 +08:00
fix(ui): show Change Password only for users with consoleAdmin (#68)
This commit is contained in:
@@ -18,7 +18,7 @@ export function UserDropdown() {
|
||||
const { t } = useTranslation()
|
||||
const router = useRouter()
|
||||
const { logout, isAdmin, setIsAdmin } = useAuth()
|
||||
const { userInfo } = usePermissions()
|
||||
const { userInfo, canChangePassword } = usePermissions()
|
||||
const { isAdminUser } = useUsers()
|
||||
const { state } = useSidebar()
|
||||
const isCollapsed = state === "collapsed"
|
||||
@@ -68,7 +68,7 @@ export function UserDropdown() {
|
||||
<span>{(userInfo as { account_name?: string })?.account_name ?? (isAdmin ? "rustfsAdmin" : "")}</span>
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
{!isAdmin && (
|
||||
{canChangePassword && (
|
||||
<DropdownMenuItem onSelect={handleChangePassword}>
|
||||
<RiLockPasswordLine className="h-4 w-4" />
|
||||
<span>{t("Change Password")}</span>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { createContext, useContext, useState, useCallback, useEffect, useMemo } from "react"
|
||||
import { hasConsoleScopes, type ConsolePolicy } from "@/lib/console-policy-parser"
|
||||
import { PAGE_PERMISSIONS } from "@/lib/console-permissions"
|
||||
import { CONSOLE_SCOPES, PAGE_PERMISSIONS } from "@/lib/console-permissions"
|
||||
import { useAuth } from "@/contexts/auth-context"
|
||||
import { useApiOptional } from "@/contexts/api-context"
|
||||
|
||||
@@ -15,6 +15,8 @@ interface PermissionsContextValue {
|
||||
hasPermission: (action: string | string[], matchAll?: boolean) => boolean
|
||||
canAccessPath: (path: string) => boolean
|
||||
isAdmin: boolean
|
||||
/** True when user has consoleAdmin (or is admin). Only these users can change password per RustFS backend. */
|
||||
canChangePassword: boolean
|
||||
}
|
||||
|
||||
const PermissionsContext = createContext<PermissionsContextValue | null>(null)
|
||||
@@ -92,6 +94,8 @@ export function PermissionsProvider({ children }: { children: React.ReactNode })
|
||||
}
|
||||
}, [api, isAuthenticated, isAdmin, hasFetchedPolicy, isLoading, fetchUserPolicy])
|
||||
|
||||
const canChangePassword = isAdmin || hasPermission(CONSOLE_SCOPES.CONSOLE_ADMIN)
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
userPolicy,
|
||||
@@ -102,8 +106,9 @@ export function PermissionsProvider({ children }: { children: React.ReactNode })
|
||||
hasPermission,
|
||||
canAccessPath,
|
||||
isAdmin,
|
||||
canChangePassword,
|
||||
}),
|
||||
[userPolicy, userInfo, isLoading, hasFetchedPolicy, fetchUserPolicy, hasPermission, canAccessPath, isAdmin],
|
||||
[userPolicy, userInfo, isLoading, hasFetchedPolicy, fetchUserPolicy, hasPermission, canAccessPath, isAdmin, canChangePassword],
|
||||
)
|
||||
|
||||
return <PermissionsContext.Provider value={value}>{children}</PermissionsContext.Provider>
|
||||
|
||||
Reference in New Issue
Block a user