Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/user/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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>
Expand Down
9 changes: 7 additions & 2 deletions hooks/use-permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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>
Expand Down