Skip to content
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

Validate user account value #47

Merged
merged 5 commits into from
Nov 24, 2023

Conversation

rvykydal
Copy link
Contributor

The PR was originally open on anaconda repository and has some history and discussion there: rhinstaller/anaconda#5305

@rvykydal rvykydal marked this pull request as ready for review November 20, 2023 10:42
@rvykydal
Copy link
Contributor Author

rvykydal commented Nov 20, 2023

@garrett please see rhinstaller/anaconda#5305 (review)

@rvykydal rvykydal force-pushed the validate-user-account-value branch 2 times, most recently from 984388b to b002be4 Compare November 20, 2023 14:08
Copy link
Contributor

@garrett garrett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a bunch of suggestions.

valid = null;
} else if (userAccount.length > 32) {
valid = false;
setUserAccountInvalidHint(_("The user name is too long"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order of preference for the account name is:

  1. Account name (doesn't use "user"; this is good, as "user" is bad to show in interfaces)
  2. Username (the actual word, according to English dictionaries)
  3. User name (an uncommon variant, according to English dictionaries)

As both GNOME and KDE talk about "user" accounts and have a "name" field, I guess keeping with "User name" is probably OK enough for consistency, even if it's not ideal.

Therefore, this is fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, it would be good to mention what the cutoff is.

Suggested change
setUserAccountInvalidHint(_("The user name is too long"));
setUserAccountInvalidHint(_("User names must contain fewer than 33 characters"));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

setUserAccountInvalidHint(_("The user name is too long"));
} else if (reservedNames.includes(userAccount)) {
valid = false;
setUserAccountInvalidHint(_("Sorry, that user name is not available. Please try another."));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is blocked exclusively because it is reserved word, it might be nice to say that specifically here.

Suggested change
setUserAccountInvalidHint(_("Sorry, that user name is not available. Please try another."));
setUserAccountInvalidHint(_("This is a reserved word; please try another user name"));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

setUserAccountInvalidHint(_("Sorry, that user name is not available. Please try another."));
} else if (isUserAccountWithInvalidCharacters(userAccount)) {
valid = false;
setUserAccountInvalidHint(cockpit.format(_("The user name should usually only consist of lower case letters from a-z, digits and the following characters: $0"), "-_"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few improvements:

  • Rewording
  • "lowercase" is one word
  • Oxford comma for an inline list
Suggested change
setUserAccountInvalidHint(cockpit.format(_("The user name should usually only consist of lower case letters from a-z, digits and the following characters: $0"), "-_"));
setUserAccountInvalidHint(cockpit.format(_("User names may only contain lowercase letters from a-z, digits, and the following characters: $0"), "-_"));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@garrett
Copy link
Contributor

garrett commented Nov 20, 2023

⚠️ Also, in the future, when you're tagging me on GitHub, please use my name without typos. When you make typos, it makes other people upset... and I also won't see the ping.

(My name has two Rs and two Ts.)

@rvykydal
Copy link
Contributor Author

⚠️ Also, in the future, when you're tagging me on GitHub, please use my name without typos. When you make typos, it makes other people upset... and I also won't see the ping.

(My name has two Rs and two Ts.)

Sorry for that, relying on auto-completion makes me ignorant, now I'll remember :)

@rvykydal
Copy link
Contributor Author

Screenshot from 2023-11-21 14-40-50
Screenshot from 2023-11-21 14-41-12
Screenshot from 2023-11-21 14-42-47

Copy link
Contributor

@garrett garrett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the screenshots!

I'm looking at this all again, in context now, with a clearer head (less of a post-COVID headache today), and I have another round of suggestions. Apologies!

This time around, I'll show high fidelity mockups and explain it:

Create account, error long

  • Since we're talking about "user names", we should be consistent with the label.
  • This is using PatternFly recommendations for errors in the forms, with the red helper text .
  • I shortened the text to "User name must be shorter than 33 characters"
  • Like the original mockups, the user name field is shorter, to show the limit visually. (It should roughly fit 33 wide characters, like 33 "w"s side by side, plus a little padding for the error icon.)

Create account, error reserved

  • We don't need to say "please change" as that's implied
  • I changed the text to be a little clearer
  • I've added a (?) icon for a popover to explain it
  • The popover shows the reserved words
  • This icon and popover is a "nice to have" and should be a follow-up... do not block this PR for it 😉

Create account, error character type

  • I changed the text to be shorter for the description and made it more consistent with the details (with the word first, then symbols after)

Again: Apologies for another review with different changes after you already addressed what I said yesterday. Thanks in advance!

I've also attached the changes as suggestions here, so I hope that makes it easier to apply. I did not see where the "User account" label is in this PR (so I could change it to "User name", to make it more consistent with the rest of the writing as well as with GNOME, KDE, and probably other desktops.)

valid = null;
} else if (userAccount.length > 32) {
valid = false;
setUserAccountInvalidHint(_("User names must contain fewer than 33 characters"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setUserAccountInvalidHint(_("User names must contain fewer than 33 characters"));
setUserAccountInvalidHint(_("User name must be shorter than 33 characters"));

setUserAccountInvalidHint(_("User names must contain fewer than 33 characters"));
} else if (reservedNames.includes(userAccount)) {
valid = false;
setUserAccountInvalidHint(_("This is a reserved word; please try another user name"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setUserAccountInvalidHint(_("This is a reserved word; please try another user name"));
setUserAccountInvalidHint(_("User name must not be a reserved word"));

setUserAccountInvalidHint(_("This is a reserved word; please try another user name"));
} else if (isUserAccountWithInvalidCharacters(userAccount)) {
valid = false;
setUserAccountInvalidHint(cockpit.format(_("User names may only contain lowercase letters from a-z, digits, and the following characters: $0"), "-._"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setUserAccountInvalidHint(cockpit.format(_("User names may only contain lowercase letters from a-z, digits, and the following characters: $0"), "-._"));
setUserAccountInvalidHint(cockpit.format(_("User name may only contain: letters from a-z, digits 0-9, dash -, period ., and underscore _")));

@rvykydal rvykydal force-pushed the validate-user-account-value branch 2 times, most recently from 1fb49ea to da5daf8 Compare November 23, 2023 11:07
@rvykydal
Copy link
Contributor Author

* Since we're talking about "user names", we should be consistent with the label.

* This is using PatternFly recommendations for errors in the forms, with the red helper text .

* I shortened the text to "User name must be shorter than 33 characters"

* Like the original mockups, the user name field is shorter, to show the limit visually. (It should roughly fit 33 wide characters, like 33 "w"s side by side, plus a little padding for the error icon.)

Modified. 33 "w"s seems maybe too wide to me (too close to the width of the other entries) but I am ok with it:

Screenshot from 2023-11-22 17-15-33

Screenshot from 2023-11-22 17-16-05

* We don't need to say "please change" as that's implied

* I changed the text to be a little clearer

Updated

* I've added a (?) icon for a popover to explain it

* The popover shows the reserved words

* This icon and popover is a "nice to have" and should be a follow-up... do not block this PR for it 😉

I'd leave it as eventual follow-up.
(Personally I don't find the list very useful, IMO the change you hit the reserved name is quite low. Also there is a plan to move the validation to the backend so the backend would need to provide the list)

Screenshot from 2023-11-22 17-16-17

* I changed the text to be shorter for the description and made it more consistent with the details (with the word first, then symbols after)

Updated.
Just a note - some rejected names falling under this message are not really consistent with the message (same as in gnome users where the original message comes from) but I think it is acceptable given they are pretty rare (maybe except for numbers-only). (https://github.com/rvykydal/anaconda-webui/blob/da5daf8533c5b030f8a78d36a0c1c8ec099aead7/src/components/users/Accounts.jsx#L81, https://github.com/rvykydal/anaconda-webui/blob/da5daf8533c5b030f8a78d36a0c1c8ec099aead7/test/check-users#L125)

Screenshot from 2023-11-22 17-15-48

@garrett
Copy link
Contributor

garrett commented Nov 23, 2023

Thanks for the changes!

Modified. 33 "w"s seems maybe too wide to me (too close to the width of the other entries) but I am ok with it:

Yeah, that does seem wide. I guess on a larger resolution screen, there might be more of a difference?

I'd leave it as eventual follow-up.
(Personally I don't find the list very useful, IMO the change you hit the reserved name is quite low. Also there is a plan to move the validation to the backend so the backend would need to provide the list)

Yeah, agreed on both points. It's pretty unlikely someone will hit multiples of the reserved words. Having it be a follow-up is totally fine. Forgetting to follow-up is probably OK too, as it's pretty unlikely.

rejected names falling under this message are not really consistent with the message (same as in gnome users where the original message comes from) but I think it is acceptable given they are pretty rare (maybe except for numbers-only)

Should we have an error for numbers only then?

"User names must contain at least one letter from a-z."

Although I guess you could have a username of $, right? 🤔

@@ -55,6 +58,33 @@ export const accountsToDbusUsers = (accounts) => {
}];
};

const reservedNames = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code now is duplicated pyanaconda/core/users.py

I will create an issue to expose it via an API and remove the duplication.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rvykydal
Copy link
Contributor Author

rvykydal commented Nov 23, 2023

Thanks for the changes!

Modified. 33 "w"s seems maybe too wide to me (too close to the width of the other entries) but I am ok with it:

Yeah, that does seem wide. I guess on a larger resolution screen, there might be more of a difference?

I don't think so, actually the width of other entries is already limited by limiting the form width: https://github.com/rvykydal/anaconda-webui/blob/da5daf8533c5b030f8a78d36a0c1c8ec099aead7/src/components/users/Accounts.scss#L3.

rejected names falling under this message are not really consistent with the message (same as in gnome users where the original message comes from) but I think it is acceptable given they are pretty rare (maybe except for numbers-only)

Should we have an error for numbers only then?

"User names must contain at least one letter from a-z."

Although I guess you could have a username of $, right? 🤔

If anything, I'd say something like "numbers-only user name is not allowed" because for example these are valid: 3.4, 4$. (But I am fine with the current PR state)

@rvykydal rvykydal merged commit eaac83c into rhinstaller:main Nov 24, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants