-
-
Notifications
You must be signed in to change notification settings - Fork 527
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
4503 super admin create users #5097
Open
Benjamin-Couey
wants to merge
19
commits into
rubyforgood:main
Choose a base branch
from
Benjamin-Couey:4503-super-admin-create-users
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
4503 super admin create users #5097
Benjamin-Couey
wants to merge
19
commits into
rubyforgood:main
from
Benjamin-Couey:4503-super-admin-create-users
+205
−27
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…esources should be available seems like it would come down to the user's permissions, which a controller should handle
…le type is selected
…der of role-resource and double-select controller action doesn't impact behavior
…s super admin, added comments explaining constraints
…sers in addition to org users
… user if only ORG_ADMIN role is specified
…checking for error messages on missing role type or resoruce id
…verify organizations are preloaded for the new user page as this is no longer the case
…sers, automatically add the ORG_USER role, and raise an error when no resource is provided
…e hidden if super admin role is selected
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #4503
Description
This PR modifies
app/controllers/admin/users_controller.rb
andapp/views/admin/users/new.html.erb
so that the super admin form for inviting a new user lets one select both the role the new user should have and the resource that role should be associated with if necessary. For the super admin role, no resource is required and so the resource dropdown is hidden via a new stimulus controller.This PR also modifies
UserInviteService
in order to fascilitate the above behavior. The service now permitsnil
as a resource when the sole role being added is super admin, and will automatically add the org user role if only the org admin role is specified.It is possible that some of this logic does not belong in the
UserInviteService
. Notably, theAddRoleService
already contains logic to automatically add the org user role when the org admin role is added. In theory, theUserInviteService
could call theAddRoleService
instead of directly callingadd_role
. However,AddRoleService
relies on being passed the id of the user to add roles to, and newly created users won't have an id until after the invitation. While it would be possible to refactorAddRoleService
, that seemed outside the scope of this PR and so the current solution was selected.Type of change
How Has This Been Tested?
This was manually tested to verify that the form worked as expected when creating all the different roles.
Tests were added to
spec/requests/admin/users_requests_spec.rb
to verify that post requests could create new users with all of the possible roles (org user, org admin, partner, super admin) and that the request would fail and report an error if a role wasn't specified, or a resource wasn't specified for a role which required one. Additionally, tests were modified and added to verify that the available roles were loaded for the new and create actions.Tests were added to
spec/services/user_invite_service_spec.rb
to verify that the service will accept a nil resource for the super admin role, raise an error for a nil resource for other roles, and that it will automatically add the org user role if only the org admin role is specified.Tests were added to
spec/system/admin/users_system_spec.rb
to verify the workflow of a super admin creating an org user and super admin user. Tests were also added to verify that the resource dropdown is hidden when the super admin role is selected, and a flash message is shown if the form is submitted without selecting a resource with a role that requires one.Screenshots
The new user form, showing the resource dropdown for an organization role
The new user form, hiding the resource dropdown for a the super admin role
The new user form, showing the organizations in the dropdown
The new user form, showing the partners in the dropdown