Skip to content

Commit

Permalink
webui: rename "User account" to "User name".
Browse files Browse the repository at this point in the history
For better consistency with system tools.
  • Loading branch information
rvykydal committed Nov 23, 2023
1 parent d96a7ec commit 50ecb8c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/components/review/ReviewConfiguration.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const ReviewConfiguration = ({ deviceData, diskSelection, language, local
{_("Account")}
</DescriptionListTerm>
<DescriptionListDescription id={idPrefix + "-target-system-account"}>
{accounts.fullName ? `${accounts.fullName} (${accounts.userAccount})` : accounts.userAccount}
{accounts.fullName ? `${accounts.fullName} (${accounts.userName})` : accounts.userName}
</DescriptionListDescription>
</DescriptionListGroup>
</ReviewDescriptionList>
Expand Down
78 changes: 39 additions & 39 deletions src/components/users/Accounts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ const _ = cockpit.gettext;

export function getAccountsState (
fullName = "",
userAccount = "",
userName = "",
password = "",
confirmPassword = "",
) {
return {
fullName,
userAccount,
userName,
password,
confirmPassword,
};
}

export const accountsToDbusUsers = (accounts) => {
return [{
name: cockpit.variant("s", accounts.userAccount || ""),
name: cockpit.variant("s", accounts.userName || ""),
gecos: cockpit.variant("s", accounts.fullName || ""),
password: cockpit.variant("s", accounts.password || ""),
"is-crypted": cockpit.variant("b", false),
Expand All @@ -78,12 +78,12 @@ const reservedNames = [
"system",
];

const isUserAccountWithInvalidCharacters = (userAccount) => {
const isUserNameWithInvalidCharacters = (userName) => {
return (
userAccount === "." ||
userAccount === ".." ||
userAccount.match(/^[0-9]+$/) ||
!userAccount.match(/^[A-Za-z0-9._][A-Za-z0-9._-]{0,30}([A-Za-z0-9._-]|\$)?$/)
userName === "." ||
userName === ".." ||
userName.match(/^[0-9]+$/) ||
!userName.match(/^[A-Za-z0-9._][A-Za-z0-9._-]{0,30}([A-Za-z0-9._-]|\$)?$/)
);
};

Expand All @@ -95,39 +95,39 @@ const CreateAccount = ({
setAccounts,
}) => {
const [fullName, setFullName] = useState(accounts.fullName);
const [_userAccount, _setUserAccount] = useState(accounts.userAccount);
const [userAccount, setUserAccount] = useState(accounts.userAccount);
const [userAccountInvalidHint, setUserAccountInvalidHint] = useState("");
const [isUserAccountValid, setIsUserAccountValid] = useState(null);
const [_userName, _setUserName] = useState(accounts.userName);
const [userName, setUserName] = useState(accounts.userName);
const [userNameInvalidHint, setUserNameInvalidHint] = useState("");
const [isUserNameValid, setIsUserNameValid] = useState(null);
const [password, setPassword] = useState(accounts.password);
const [confirmPassword, setConfirmPassword] = useState(accounts.confirmPassword);
const [isPasswordValid, setIsPasswordValid] = useState(false);

useEffect(() => {
debounce(300, () => setUserAccount(_userAccount))();
}, [_userAccount, setUserAccount]);
debounce(300, () => setUserName(_userName))();
}, [_userName, setUserName]);

useEffect(() => {
setIsUserValid(isPasswordValid && isUserAccountValid);
}, [setIsUserValid, isPasswordValid, isUserAccountValid]);
setIsUserValid(isPasswordValid && isUserNameValid);
}, [setIsUserValid, isPasswordValid, isUserNameValid]);

useEffect(() => {
let valid = true;
setUserAccountInvalidHint("");
if (userAccount.length === 0) {
setUserNameInvalidHint("");
if (userName.length === 0) {
valid = null;
} else if (userAccount.length > 32) {
} else if (userName.length > 32) {
valid = false;
setUserAccountInvalidHint(_("User names must be shorter than 33 characters"));
} else if (reservedNames.includes(userAccount)) {
setUserNameInvalidHint(_("User names must be shorter than 33 characters"));
} else if (reservedNames.includes(userName)) {
valid = false;
setUserAccountInvalidHint(_("User name must not be a reserved word"));
} else if (isUserAccountWithInvalidCharacters(userAccount)) {
setUserNameInvalidHint(_("User name must not be a reserved word"));
} else if (isUserNameWithInvalidCharacters(userName)) {
valid = false;
setUserAccountInvalidHint(cockpit.format(_("User name may only contain: letters from a-z, digits 0-9, dash $0, period $1, underscore $2"), "-", ".", "_"));
setUserNameInvalidHint(cockpit.format(_("User name may only contain: letters from a-z, digits 0-9, dash $0, period $1, underscore $2"), "-", ".", "_"));
}
setIsUserAccountValid(valid);
}, [userAccount]);
setIsUserNameValid(valid);
}, [userName]);

const passphraseForm = (
<PasswordFormFields
Expand All @@ -145,10 +145,10 @@ const CreateAccount = ({
);

useEffect(() => {
setAccounts(ac => ({ ...ac, fullName, userAccount, password, confirmPassword }));
}, [setAccounts, fullName, userAccount, password, confirmPassword]);
setAccounts(ac => ({ ...ac, fullName, userName, password, confirmPassword }));
}, [setAccounts, fullName, userName, password, confirmPassword]);

const userAccountValidated = isUserAccountValid === null ? "default" : isUserAccountValid ? "success" : "error";
const userNameValidated = isUserNameValid === null ? "default" : isUserNameValid ? "success" : "error";

return (
<Form
Expand All @@ -173,22 +173,22 @@ const CreateAccount = ({
/>
</FormGroup>
<FormGroup
label={_("User account")}
fieldId={idPrefix + "-user-account"}
label={_("User name")}
fieldId={idPrefix + "-user-name"}
>
<InputGroup id={idPrefix + "-user-account-input-group"}>
<InputGroup id={idPrefix + "-user-name-input-group"}>
<TextInput
id={idPrefix + "-user-account"}
value={_userAccount}
onChange={(_event, val) => _setUserAccount(val)}
validated={userAccountValidated}
id={idPrefix + "-user-name"}
value={_userName}
onChange={(_event, val) => _setUserName(val)}
validated={userNameValidated}
/>
</InputGroup>
{userAccountValidated === "error" &&
{userNameValidated === "error" &&
<FormHelperText>
<HelperText>
<HelperTextItem variant={userAccountValidated}>
{userAccountInvalidHint}
<HelperTextItem variant={userNameValidated}>
{userNameInvalidHint}
</HelperTextItem>
</HelperText>
</FormHelperText>}
Expand Down
2 changes: 1 addition & 1 deletion src/components/users/Accounts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
align-items: flex-start;
}

#accounts-create-account-user-account-input-group {
#accounts-create-account-user-name-input-group {
width: min(39ch, 100%);
}
28 changes: 14 additions & 14 deletions test/check-users
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TestUsers(anacondalib.VirtInstallMachineCase):
self.assertIn('"password" s "password"', users)

@staticmethod
def _test_user_account(user, installer, valid, invalid):
def _test_user_name(user, installer, valid, invalid):
installer.check_next_disabled(disabled=False)

n_valid = len(valid) - 1
Expand All @@ -62,9 +62,9 @@ class TestUsers(anacondalib.VirtInstallMachineCase):
for i in range(max(n_valid, n_invalid)):
i_valid = min(i, n_valid)
i_invalid = min(i, n_invalid)
user.set_user_account(invalid[i_invalid])
user.set_user_name(invalid[i_invalid])
installer.check_next_disabled()
user.set_user_account(valid[i_valid])
user.set_user_name(valid[i_valid])
installer.check_next_disabled(disabled=False)

def testAccessAndValidation(self):
Expand All @@ -82,17 +82,17 @@ class TestUsers(anacondalib.VirtInstallMachineCase):
# Fill in valid values
password = "password"
full_name = "Full Tester"
user_account = "tester"
user_name = "tester"

p.set_password(password)
p.set_password_confirm(password)
u.set_full_name(full_name)
u.set_user_account(user_account)
u.set_user_name(user_name)

p.check_password(password)
p.check_password_confirm(password)
u.check_full_name(full_name)
u.check_user_account(user_account)
u.check_user_name(user_name)
i.check_next_disabled(disabled=False)

# Test that you can move forward and going back keeps values
Expand All @@ -101,15 +101,15 @@ class TestUsers(anacondalib.VirtInstallMachineCase):
p.check_password(password)
p.check_password_confirm(password)
u.check_full_name(full_name)
u.check_user_account(user_account)
u.check_user_name(user_name)

# Test that moving back and forward keeps values
i.back()
i.next()
p.check_password(password)
p.check_password_confirm(password)
u.check_full_name(full_name)
u.check_user_account(user_account)
u.check_user_name(user_name)

# Test full name validation
u.set_full_name("")
Expand All @@ -118,7 +118,7 @@ class TestUsers(anacondalib.VirtInstallMachineCase):

# Test account validation
# FIXME this should be tested by unit tests?
invalid_user_accounts = [
invalid_user_names = [
"",
# reserved
"root", "system", "daemon", "home",
Expand All @@ -132,7 +132,7 @@ class TestUsers(anacondalib.VirtInstallMachineCase):
"tester?",
"longer_than_32_characteeeeeeeeeeeeeeeeeeers",
]
valid_user_accounts = [
valid_user_names = [
"tester-",
"...",
"12.3",
Expand All @@ -145,8 +145,8 @@ class TestUsers(anacondalib.VirtInstallMachineCase):
".tester",
"_",
]
self._test_user_account(u, i, valid_user_accounts, invalid_user_accounts)
u.set_user_account(user_account)
self._test_user_name(u, i, valid_user_names, invalid_user_names)
u.set_user_name(user_name)

# Test password validation
# No password set
Expand Down Expand Up @@ -185,10 +185,10 @@ class TestUsers(anacondalib.VirtInstallMachineCase):
p.set_password(password)
p.set_password_confirm(password)
u.set_full_name(full_name)
u.set_user_account(user_account)
u.set_user_name(user_name)
r = Review(b)
i.reach(i.steps.REVIEW)
r.check_account(f"{full_name} ({user_account})")
r.check_account(f"{full_name} ({user_name})")


if __name__ == '__main__':
Expand Down
14 changes: 7 additions & 7 deletions test/helpers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ def __init__(self, browser, machine):
UsersDBus.__init__(self, machine)

@log_step(snapshot_before=True)
def set_user_account(self, user_account, append=False, value_check=True):
sel = "#accounts-create-account-user-account"
self.browser.set_input_text(sel, user_account, append=append, value_check=value_check)
def set_user_name(self, user_name, append=False, value_check=True):
sel = "#accounts-create-account-user-name"
self.browser.set_input_text(sel, user_name, append=append, value_check=value_check)

@log_step(snapshot_before=True)
def check_user_account(self, user_account):
sel = "#accounts-create-account-user-account"
self.browser.wait_val(sel, user_account)
def check_user_name(self, user_name):
sel = "#accounts-create-account-user-name"
self.browser.wait_val(sel, user_name)

@log_step(snapshot_before=True)
def set_full_name(self, full_name, append=False, value_check=True):
Expand All @@ -88,7 +88,7 @@ def create_user(browser, machine):
password = "password"
p.set_password(password)
p.set_password_confirm(password)
u.set_user_account("tester")
u.set_user_name("tester")


def dbus_reset_users(machine):
Expand Down

0 comments on commit 50ecb8c

Please sign in to comment.