generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Administrative interface for user additional organisations
We now have the ability to add additional organisations from the app itself via the create/edit user forms. This replaces the radio list of BEIS + partner organisations with a dropdown, for the primary organisation, and also adds a checkbox list of partner organisations for the additional organisations. Appropriate explanatory hint text is also provided. We also have a sprinkling of JavaScript to enhance the form such that a user's additional organisation selections cannot include their primary organisation. As a safeguard for users who do not have JavaScript enabled, we have validation in the model for this too.
- Loading branch information
1 parent
a2def15
commit 5114d21
Showing
14 changed files
with
152 additions
and
22 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
This progressively enhances the "Create/Edit user" form such that a primary | ||
organisation will be hidden from the list of additional organisations (and | ||
also unchecked), because a user's primary organisation can never be a member | ||
of that user's additional organisations. | ||
*/ | ||
document.addEventListener("DOMContentLoaded", function() { | ||
const primaryOrgSelect = document.querySelector("#user_organisation_id"); | ||
|
||
if (!primaryOrgSelect) return; | ||
|
||
const handleCheckboxes = () => { | ||
const val = primaryOrgSelect.querySelector("option:checked").value; | ||
|
||
document.querySelectorAll(".additional-organisations .govuk-checkboxes__item").forEach((checkboxItem) => { | ||
const match = checkboxItem.querySelector(`input[value="${val}"`); | ||
checkboxItem.style.display = match ? (match.checked = false, "none") : "block"; | ||
}); | ||
} | ||
|
||
primaryOrgSelect.addEventListener("change", handleCheckboxes); | ||
handleCheckboxes(); | ||
}); |
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,15 +12,17 @@ | |
scenario "a new user can be created" do | ||
organisation = create(:partner_organisation) | ||
second_organisation = create(:partner_organisation) | ||
additional_organisation = create(:partner_organisation) | ||
new_user_name = "Foo Bar" | ||
new_user_email = "[email protected]" | ||
|
||
perform_enqueued_jobs do | ||
create_user(organisation, new_user_name, new_user_email) | ||
create_user(organisation, additional_organisation, new_user_name, new_user_email) | ||
end | ||
|
||
expect(page).to have_content(organisation.name) | ||
expect(page).not_to have_content(second_organisation.name) | ||
expect(page).to have_content(additional_organisation.name) | ||
|
||
new_user = User.where(email: new_user_email).first | ||
reset_password_link_regex = %r{http://test.local/users/password/edit\?reset_password_token=.*} | ||
|
@@ -56,7 +58,7 @@ | |
end | ||
end | ||
|
||
def create_user(organisation, new_user_name, new_user_email) | ||
def create_user(organisation, additional_organisation, new_user_name, new_user_email) | ||
# Navigate from the landing page | ||
visit organisation_path(organisation) | ||
click_on("Users") | ||
|
@@ -67,19 +69,24 @@ def create_user(organisation, new_user_name, new_user_email) | |
# Create a new user | ||
click_on("Add user") | ||
|
||
# We expect to see BEIS separately on this page | ||
# We expect to see BEIS on this page in the dropdown | ||
within(".user-organisations") do | ||
beis_identifier = Organisation.service_owner.id | ||
expect(page).to have_css("input[type='radio'][value='#{beis_identifier}']:first-child") | ||
expect(page).to have_css(".govuk-radios__divider:nth-child(2)") | ||
expect(page).to have_css("select option[value='#{beis_identifier}']") | ||
end | ||
|
||
# We expect to see the additional organisation too | ||
within(".additional-organisations") do | ||
expect(page).to have_css("input[value='#{additional_organisation.id}']") | ||
end | ||
|
||
# Fill out the form | ||
expect(page).not_to have_content("Reset the user's mobile number?") | ||
expect(page).to have_content("Create user") | ||
fill_in "user[name]", with: new_user_name | ||
fill_in "user[email]", with: new_user_email | ||
choose organisation.name | ||
select organisation.name | ||
check additional_organisation.name | ||
|
||
# Submit the form | ||
click_button "Submit" | ||
|
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
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
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