Skip import password prompt for OIDC users
This commit is contained in:
@@ -44,6 +44,7 @@ import {
|
|||||||
makeUserAdmin,
|
makeUserAdmin,
|
||||||
removeAdminStatus,
|
removeAdminStatus,
|
||||||
deleteUser,
|
deleteUser,
|
||||||
|
getUserInfo,
|
||||||
getCookie,
|
getCookie,
|
||||||
isElectron,
|
isElectron,
|
||||||
} from "@/ui/main-axios.ts";
|
} from "@/ui/main-axios.ts";
|
||||||
@@ -92,6 +93,12 @@ export function AdminSettings({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const [securityInitialized, setSecurityInitialized] = React.useState(true);
|
const [securityInitialized, setSecurityInitialized] = React.useState(true);
|
||||||
|
const [currentUser, setCurrentUser] = React.useState<{
|
||||||
|
id: string;
|
||||||
|
username: string;
|
||||||
|
is_admin: boolean;
|
||||||
|
is_oidc: boolean;
|
||||||
|
} | null>(null);
|
||||||
|
|
||||||
const [exportLoading, setExportLoading] = React.useState(false);
|
const [exportLoading, setExportLoading] = React.useState(false);
|
||||||
const [importLoading, setImportLoading] = React.useState(false);
|
const [importLoading, setImportLoading] = React.useState(false);
|
||||||
@@ -100,6 +107,11 @@ export function AdminSettings({
|
|||||||
const [showPasswordInput, setShowPasswordInput] = React.useState(false);
|
const [showPasswordInput, setShowPasswordInput] = React.useState(false);
|
||||||
const [importPassword, setImportPassword] = React.useState("");
|
const [importPassword, setImportPassword] = React.useState("");
|
||||||
|
|
||||||
|
const requiresImportPassword = React.useMemo(
|
||||||
|
() => !currentUser?.is_oidc,
|
||||||
|
[currentUser?.is_oidc],
|
||||||
|
);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (isElectron()) {
|
if (isElectron()) {
|
||||||
const serverUrl = (window as any).configuredServerUrl;
|
const serverUrl = (window as any).configuredServerUrl;
|
||||||
@@ -117,6 +129,22 @@ export function AdminSettings({
|
|||||||
toast.error(t("admin.failedToFetchOidcConfig"));
|
toast.error(t("admin.failedToFetchOidcConfig"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
getUserInfo()
|
||||||
|
.then((info) => {
|
||||||
|
if (info) {
|
||||||
|
setCurrentUser({
|
||||||
|
id: info.userId,
|
||||||
|
username: info.username,
|
||||||
|
is_admin: info.is_admin,
|
||||||
|
is_oidc: info.is_oidc,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
if (!err?.message?.includes("No server configured")) {
|
||||||
|
console.warn("Failed to fetch current user info", err);
|
||||||
|
}
|
||||||
|
});
|
||||||
fetchUsers();
|
fetchUsers();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -334,7 +362,7 @@ export function AdminSettings({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!importPassword.trim()) {
|
if (requiresImportPassword && !importPassword.trim()) {
|
||||||
toast.error(t("admin.passwordRequired"));
|
toast.error(t("admin.passwordRequired"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -357,7 +385,9 @@ export function AdminSettings({
|
|||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file", importFile);
|
formData.append("file", importFile);
|
||||||
|
if (requiresImportPassword) {
|
||||||
formData.append("password", importPassword);
|
formData.append("password", importPassword);
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(apiUrl, {
|
const response = await fetch(apiUrl, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -966,7 +996,7 @@ export function AdminSettings({
|
|||||||
</span>
|
</span>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
{importFile && (
|
{importFile && requiresImportPassword && (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="import-password">Password</Label>
|
<Label htmlFor="import-password">Password</Label>
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
@@ -985,7 +1015,9 @@ export function AdminSettings({
|
|||||||
<Button
|
<Button
|
||||||
onClick={handleImportDatabase}
|
onClick={handleImportDatabase}
|
||||||
disabled={
|
disabled={
|
||||||
importLoading || !importFile || !importPassword.trim()
|
importLoading ||
|
||||||
|
!importFile ||
|
||||||
|
(requiresImportPassword && !importPassword.trim())
|
||||||
}
|
}
|
||||||
className="w-full"
|
className="w-full"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user