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

4503 super admin create users #5097

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

Benjamin-Couey
Copy link
Contributor

Resolves #4503

Description

This PR modifies app/controllers/admin/users_controller.rband app/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 permits nil 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, the AddRoleService already contains logic to automatically add the org user role when the org admin role is added. In theory, the UserInviteService could call the
AddRoleService instead of directly calling add_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 refactor AddRoleService, that seemed outside the scope of this PR and so the current solution was selected.

Type of change

  • New feature (non-breaking change which adds functionality)

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

NewUserFormOrgRole

The new user form, hiding the resource dropdown for a the super admin role

NewUserFormSuperAdminRole

The new user form, showing the organizations in the dropdown

NewUserFormOrgResourceDropdown

The new user form, showing the partners in the dropdown

NewUserFormPartnerResourceDropdown

Benjamin-Couey and others added 19 commits March 2, 2025 08:06
…esources should be available seems like it would come down to the user's permissions, which a controller should handle
…der of role-resource and double-select controller action doesn't impact behavior
…s super admin, added comments explaining constraints
…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
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.

Super admin should be able to add different kinds of users
1 participant