-
Notifications
You must be signed in to change notification settings - Fork 74
Adapt the "authentication" section of the web UI to the new API #3007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a312218
741838e
d8b2faf
8a26924
05c9b39
22030f7
018aed0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * Copyright (c) [2026] SUSE LLC | ||
| * | ||
| * All Rights Reserved. | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License as published by the Free | ||
| * Software Foundation; either version 2 of the License, or (at your option) | ||
| * any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| * more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License along | ||
| * with this program; if not, contact SUSE LLC. | ||
| * | ||
| * To contact SUSE LLC about this file by physical or electronic mail, you may | ||
| * find current contact information at www.suse.com. | ||
| */ | ||
|
|
||
| import React from "react"; | ||
| import { sprintf } from "sprintf-js"; | ||
| import { useProgressTracking } from "~/hooks/use-progress-tracking"; | ||
| import { useConfig } from "~/hooks/model/config"; | ||
| import { useIssues } from "~/hooks/model/issue"; | ||
| import { USER } from "~/routes/paths"; | ||
| import { _ } from "~/i18n"; | ||
| import Summary from "~/components/core/Summary"; | ||
| import Link from "~/components/core/Link"; | ||
|
|
||
| const rootConfigured = (config) => { | ||
| if (!config.root) return false; | ||
|
|
||
| const { password, sshPublicKey } = config.root; | ||
| if (password && password !== "") return true; | ||
| if (sshPublicKey && sshPublicKey !== "") return true; | ||
|
|
||
| return false; | ||
| }; | ||
|
|
||
| const userConfigured = (config) => { | ||
| if (!config.user) return false; | ||
|
|
||
| const { userName, fullName, password } = config.user; | ||
| return userName !== "" && fullName !== "" && password !== ""; | ||
| }; | ||
|
|
||
| /** | ||
| * Renders a summary text describing the authentication configuration. | ||
| */ | ||
| const Value = () => { | ||
| const config = useConfig(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NP: this is fully ok, but I wanted to mention that I tend to get the config in the main component and pass down via prop. I do so just to save some observers at TanstackQuery layer and because in this kind of simple, one level nesting components looks like a good compromise. |
||
| const root = rootConfigured(config); | ||
| const user = userConfigured(config); | ||
|
|
||
| if (!root && !user) return _("Not configured yet"); | ||
| if (root && !user) return _("Configured for the root user"); | ||
|
|
||
| const userName = config.user.userName; | ||
| // TRANSLATORS: %s is a username like 'jdoe' | ||
| if (root) return sprintf(_("Configured for root and user '%s'"), userName); | ||
|
|
||
| // TRANSLATORS: %s is a username like 'jdoe' | ||
| return sprintf(_("Configured for user '%s'"), userName); | ||
| }; | ||
|
|
||
| /** | ||
| * Renders the estimated disk space required for the installation. | ||
| */ | ||
| const Description = () => { | ||
| const config = useConfig(); | ||
| if (!rootConfigured(config)) return; | ||
|
|
||
| const password = config.root.password || ""; | ||
| const sshKey = config.root.sshPublicKey || ""; | ||
|
|
||
| if (password !== "" && sshKey !== "") return _("Root login with password and SSH key"); | ||
| if (password !== "") return _("Root login with password"); | ||
| return _("Root login with SSH key"); | ||
| }; | ||
|
|
||
| /** | ||
| * A software installation summary. | ||
| */ | ||
| export default function UsersSummary() { | ||
| const { loading } = useProgressTracking("users"); | ||
| const hasIssues = !!useIssues("users").length; | ||
|
|
||
| return ( | ||
| <Summary | ||
| hasIssues={hasIssues} | ||
| icon="manage_accounts" | ||
| title={ | ||
| <Link to={USER.root} variant="link" isInline> | ||
| {_("Authentication")} | ||
| </Link> | ||
| } | ||
| value={<Value />} | ||
| description={<Description />} | ||
| isLoading={loading} | ||
| /> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,14 +33,23 @@ import { | |
| } from "@patternfly/react-core"; | ||
| import { Link, Page, SplitButton } from "~/components/core"; | ||
| import PasswordCheck from "~/components/users/PasswordCheck"; | ||
| import { useFirstUser, useFirstUserChanges, useRemoveFirstUserMutation } from "~/queries/users"; | ||
| // This should be based on the config, not on the proposal. As a temporary hack (introduced in a | ||
| // separate commit that should be easy to revert), we are using the proposal because the config | ||
| // does not emit an event on every change. | ||
| import { useProposal } from "~/hooks/model/proposal"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NP: not related specifically to your code here, but it is kind of a mess sometimes having ~/hooks/model/proposal/whatever and sometimes, like here, not. Hard to follow/understand. |
||
| import { useRemoveUser } from "~/hooks/model/config/user"; | ||
| import { PATHS } from "~/routes/users"; | ||
| import { isEmpty } from "radashi"; | ||
| import { _ } from "~/i18n"; | ||
|
|
||
| const useUser = () => { | ||
| const proposal = useProposal().users; | ||
| return proposal?.user; | ||
| }; | ||
|
|
||
| const UserActions = () => { | ||
| const user = useFirstUser(); | ||
| const { mutate: removeUser } = useRemoveFirstUserMutation(); | ||
| const user = useUser(); | ||
| const removeUser = useRemoveUser(); | ||
|
|
||
| if (isEmpty(user?.userName)) { | ||
| return ( | ||
|
|
@@ -60,7 +69,7 @@ const UserActions = () => { | |
| }; | ||
|
|
||
| const UserData = () => { | ||
| const user = useFirstUser(); | ||
| const user = useUser(); | ||
| const fullnameTermId = useId(); | ||
| const usernameTermId = useId(); | ||
|
|
||
|
|
@@ -94,8 +103,6 @@ const UserData = () => { | |
| }; | ||
|
|
||
| export default function FirstUser() { | ||
| useFirstUserChanges(); | ||
|
|
||
| return ( | ||
| <Page.Section | ||
| title={_("First user")} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 🙏