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

Add "Create User" button to admin dashboard #736

Merged
merged 45 commits into from
May 24, 2024

Conversation

rmunn
Copy link
Contributor

@rmunn rmunn commented Apr 18, 2024

Fixes #666.

Extracted the relevant parts of the register page into a component and put it in an admin-only "Create User" modal. Help text at the top of the modal links to the relevant parts of the (new-ish) Scribe documentation.

Help needed

Need to find the right CSS classes to format the text at the top of the modal so it looks good. Right now it's ugly: there's no blank space between the two paragraphs, for example.

Screenshots

UI design on large screens:

image

UI design on small screens:

image

This is basically exactly the same as how the Projects tab and its "Create Project" button are presented.

Modal design:

image

Doesn't do anything... yet.
Copy link

github-actions bot commented Apr 18, 2024

UI unit Tests

11 tests   11 ✅  0s ⏱️
 3 suites   0 💤
 1 files     0 ❌

Results for commit f2d011a.

♻️ This comment has been updated with latest results.

Currently the "sign out and sign back in" behavior of the register page
still works as it used to, which is not what we want when an admin is
creating the user. We'll change that next.
@myieye
Copy link
Contributor

myieye commented Apr 18, 2024

@rmunn That button looks good 👍

But before you extract the register page!

EDIT...looks like you already did. Unfortunately, this still applied:

There has been some discussion on this idea in our agenda doc.
I've copied it to the issue you're working on. Please take a look!

It sounds like we don't actually want to extract/use the register page 😬. Feel free to weigh in.

@rmunn
Copy link
Contributor Author

rmunn commented Apr 18, 2024

Extracting the register page turned out to be so easy to do, it's not like I wasted all that much time on this if we end up confirming our earlier decision. But I'm starting to feel that our earlier decision was wrong, and we do want a create-user modal on the admin dashboard. Let's discuss it on the issue so we're not discussing it in two places at once.

@rmunn rmunn self-assigned this Apr 19, 2024
rmunn added 5 commits May 13, 2024 11:15
Fixes merge conflicts in admin and register pages
When clicking on "Create User" in admin dashboard, we don't want the
modal to change the browser title; that should be reserved for the
dedicated Register page.
Pushed as a separate commit from the previous one so that the whitespace
changes are isolated in their own commit, which should help a little bit
with avoiding merge conflicts later.
If an admin is logged in and creating a user on the register page, we
set that user's CreatedById to the admin, so that the user will count as
a "guest user", just as if their account was created through the bulk
add/create users tool.
Copy link

github-actions bot commented May 13, 2024

C# Unit Tests

35 tests  ±0   35 ✅ ±0   5s ⏱️ ±0s
 8 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit f2d011a. ± Comparison against base commit d0f3381.

♻️ This comment has been updated with latest results.

rmunn added 3 commits May 13, 2024 13:05
Implements the TODO comment I had added earlier.
That info is now in the Create Users modal, so we don't need it here.
Now that we've removed the "Register" title from the modal, we should
give it a proper title.
@rmunn
Copy link
Contributor Author

rmunn commented May 13, 2024

After discussion with Kevin and Tim, implemented this as a way for admins to create a single guest user (will have the CreatedById field set to the admin's ID). That fits with the design I think Kevin was thinking of in #666 (comment).

Other than a little help needed with the CSS classes for the instructions (see PR description), I think this is ready. Marking as ready for review.

@rmunn rmunn marked this pull request as ready for review May 13, 2024 06:22
@rmunn rmunn requested a review from myieye May 13, 2024 06:22
Copy link
Contributor

@myieye myieye left a comment

Choose a reason for hiding this comment

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

Nice work 🙂 👍
I pushed a commit where I played with the styles and wording.
I also fixed a bug that was already in the code.

Here's what it looks like now:
image
image

backend/LexBoxApi/Controllers/UserController.cs Outdated Show resolved Hide resolved
frontend/src/lib/i18n/locales/en.json Outdated Show resolved Hide resolved
@hahn-kev

This comment was marked as duplicate.

@rmunn
Copy link
Contributor Author

rmunn commented May 17, 2024

Okay, finished addressing all of Tim's review comments. Implemented UI for allowing usernames. I currently do not validate usernames because we haven't yet decided on a rule; I could say "only lowercase alphanumeric plus underscore", but that might be too restrictive. We might want to allow hyphens and/or dots, for example, and we might want to allow uppercase (though I'd rather not, so that we don't have to worry about case collisions between rmunn and Rmunn and RMunn). Anyway, this is ready to review now, even though the usernames aren't validating yet, because validating them is going to be a very minor change.

@hahn-kev - Want to give this a re-review?

@myieye
Copy link
Contributor

myieye commented May 17, 2024

Regarding login validation...

  1. We actually do already have login validation in the bulk-create tool. We're using: /^[a-zA-Z0-9_]+$/.
  2. The Username collumn uses a case-insensitive collation, so we can allow capitalization without getting duplicates
  3. It sounds like this is what Redmine has: /^[a-z0-9_\-@\.]*$/. So funnily enough, they allow email addresses. Well, we're not going to do that 😆. It also means that users of LD-Redmine survived only being allowed to use latin characters. That's what our admins are used to.

So, I think it would be fine to just continue to use the pattern we alrady use for bulk-create.

Copy link
Contributor

@myieye myieye left a comment

Choose a reason for hiding this comment

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

I really appreciate having 3 endpoints. Thank you.
It's weird....so much more code, but it's all simpler code.

frontend/src/lib/components/Users/CreateUser.svelte Outdated Show resolved Hide resolved
frontend/src/lib/components/Users/CreateUser.svelte Outdated Show resolved Hide resolved
backend/LexBoxApi/GraphQL/ProjectMutations.cs Show resolved Hide resolved
backend/LexBoxApi/GraphQL/UserMutations.cs Outdated Show resolved Hide resolved
backend/LexBoxApi/GraphQL/UserMutations.cs Outdated Show resolved Hide resolved
frontend/src/lib/components/Users/CreateUser.svelte Outdated Show resolved Hide resolved
frontend/src/lib/components/Users/CreateUser.svelte Outdated Show resolved Hide resolved
frontend/src/lib/components/Users/CreateUserModal.svelte Outdated Show resolved Hide resolved
rmunn added 10 commits May 20, 2024 09:21
As long as we don't add @ to the usernameRe check, the check for
`value.contains('@')` is redundant, so let's get rid of it. We'll also
rearrange the check to have `isEmail` first as that's easier to read.
The comment mentions errors.username, but we decided not to have a
separate field called username. We kept the field called email since
that's its primary purpose, but the error message has been adjusted to
mention usernames *or* email addresses.
This lets us get rid of the autoLogin prop as well, as if you don't want
autoLogin you just don't implement an on:submitted handler.
If you're logged in as an admin, we trust you and don't expect you to be
participating in DDOS attacks or anything else that would require a
turnstile token.
Instaed of passing the name of the endpoint to handle into CreateUser,
we will now pass in the function responsible for submitting the data to
the endpoint. This will make it easier to expand the list of endpoints
in the future should we decide to.
@rmunn rmunn requested a review from myieye May 20, 2024 11:38
Copy link
Contributor

@myieye myieye left a comment

Choose a reason for hiding this comment

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

I think there's just one missing piece.

EDIT: oh man, somehow my comment got lost...here it comes...

Copy link
Collaborator

@hahn-kev hahn-kev left a comment

Choose a reason for hiding this comment

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

nice job Robin! I was able to test it all out and didn't find any issues. I left some minor feedback.

Sorry it's taken me so long to get around to reviewing this PR for you.

backend/LexBoxApi/GraphQL/UserMutations.cs Show resolved Hide resolved
frontend/src/lib/user.ts Outdated Show resolved Hide resolved
frontend/src/lib/user.ts Outdated Show resolved Hide resolved
frontend/src/lib/user.ts Show resolved Hide resolved
frontend/src/lib/user.ts Outdated Show resolved Hide resolved
frontend/src/routes/(authenticated)/admin/+page.svelte Outdated Show resolved Hide resolved
frontend/tests/pages/acceptInvitationPage.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@hahn-kev hahn-kev left a comment

Choose a reason for hiding this comment

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

Looks good to me, though it looks like we're still pending @myieye

@rmunn
Copy link
Contributor Author

rmunn commented May 23, 2024

@myieye - Commit f027c6b should address your review comments. I left that conversation open in case what I did wasn't what you had in mind. Let me know. Also, I merged develop into this branch to fix the merge conflict in en.json resulting from that last change.

Once you're happy with the error message, I'm looking forward to finally getting this merged.

Copy link
Contributor

@myieye myieye left a comment

Choose a reason for hiding this comment

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

Well that was an adventure 😬.
Good work hanging in there @rmunn! 👏 🚀

@rmunn rmunn merged commit 5c40148 into develop May 24, 2024
14 checks passed
@myieye myieye deleted the feat/admins-can-create-users branch June 18, 2024 10:02
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.

It should be more obvious to admins how to create users
3 participants