-
Notifications
You must be signed in to change notification settings - Fork 641
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
Support username casing change in Admin UI #9748
base: dev
Are you sure you want to change the base?
Conversation
Should this be the linked issue? https://github.com/NuGet/Engineering/issues/5057 |
0158a73
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.
Apart from updating the record, there is a previous step we perform when changing username casing. We check if the user have available packages (check the playbook for more context). I think this could be added by adding a column on the first form (Verify Account) to include if the user has available packages. And also, please update the playbook with this new changes.
src/NuGetGallery/Areas/Admin/Controllers/ChangeUsernameController.cs
Outdated
Show resolved
Hide resolved
Add checkbox to check owned packages
Add new param to ValidateNewUsername endpoint
@@ -83,14 +87,28 @@ public ActionResult VerifyAccount(string accountEmailOrUsername) | |||
} | |||
|
|||
[HttpGet] | |||
public ActionResult ValidateNewUsername(string newUsername) | |||
public ActionResult ValidateNewUsername(string newUsername, bool checkOwnedPackages, string oldUsername = "") |
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.
I don't see where we're passing true
for checkOwnedPackages
other than unit test. How we're passing value here?
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.
@RiadGahlouz
Have you looked into my question? After this I can approve this PR.
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.
It's coming from a form input:
<input type="checkbox" id="checkNonDeletedOwnedPackages" data-bind="checked: checkOwnedPackages" /> |
<input type="text" placeholder="New username" autocomplete="off" autofocus style="width: 200px;" rows="1" data-bind="value: newUsername" /> | ||
<input type="checkbox" id="checkNonDeletedOwnedPackages" data-bind="checked: checkOwnedPackages" /> | ||
<label for="checkNonDeletedOwnedPackages">Check Non-Deleted Owned Packages</label> |
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.
If setting this checkbox just adds a list of owned packages, how about changing it to "List ..."?
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.
Maybe even enable it automatically if new/old only differs by the case?
return new ValidateUsernameResult() | ||
{ | ||
IsFormatValid = UsernameValidationRegex.IsMatch(username), | ||
IsAvailable = foundUser == null || (requestor.Key == foundUser.Key && foundUser.Username != username) // The username check is in the event where we found a user in the DB but we're doing a cAsIng change |
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.
IsAvailable = foundUser == null || (requestor.Key == foundUser.Key && foundUser.Username != username) // The username check is in the event where we found a user in the DB but we're doing a cAsIng change | |
IsAvailable = foundUser == null || (requestor.Key == foundUser.Key && foundUser.Username != username) // The username check is in the event where we found a user in the DB but we're doing a casing change |
{ | ||
var oldUsername = IndividualAccount.Username; | ||
|
||
var result = await ChangeUsernameController.ChangeUsername(IndividualAccount.Username, IndividualAccount.Username.ToUpper()) as JsonResult; |
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.
@@ -83,14 +87,28 @@ public ActionResult VerifyAccount(string accountEmailOrUsername) | |||
} | |||
|
|||
[HttpGet] | |||
public ActionResult ValidateNewUsername(string newUsername) | |||
public ActionResult ValidateNewUsername(string newUsername, bool checkOwnedPackages, string oldUsername = "") |
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.
{ | ||
if (string.IsNullOrEmpty(newUsername)) | ||
{ | ||
return Json(HttpStatusCode.BadRequest, "Username cannot be null or empty.", JsonRequestBehavior.AllowGet); | ||
} | ||
|
||
var result = ValidateUsername(newUsername); | ||
var oldAccount = _userService.FindByUsername(oldUsername); |
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.
nit: oldAccount -> account
It may be better to use the same name for local variables under the same class. For example, line 130 uses "account". We can follow the same name convention and also the account itself is still the same but the name will be changed. Personally I think this is more readable and easier to maintain in the future.
@@ -116,39 +134,44 @@ public async Task<ActionResult> ChangeUsername(string oldUsername, string newUse | |||
return Json(HttpStatusCode.NotFound, "Old username account was not found.", JsonRequestBehavior.AllowGet); | |||
} | |||
|
|||
var newUsernameValidation = ValidateUsername(newUsername); | |||
var newUsernameValidation = ValidateUsernameChange(account, newUsername); |
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.
@RiadGahlouz |
Summary of the changes (in less than 80 characters):
This PR adds support for username casing change in the Admin UI. There are no UI changes, simply controller flow changes.
Addresses https://github.com/NuGet/Engineering/issues/5057