Skip to content

Commit

Permalink
Exclude closed organisations from the organisation select
Browse files Browse the repository at this point in the history
We don't want to assign users to closed organisations so it doesn't
make sense to include them in the select list.
  • Loading branch information
chrislo committed Oct 10, 2023
1 parent fb252b1 commit 3ef31be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/role_organisations_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module RoleOrganisationsHelper
def options_for_organisation_select(current_user)
organisations = Pundit.policy_scope(current_user, Organisation).order(:name)
organisations = Pundit.policy_scope(current_user, Organisation).order(:name).where(closed: false)

organisations.map do |organisation|
{ text: organisation.name_with_abbreviation,
Expand Down
7 changes: 7 additions & 0 deletions test/helpers/role_organisations_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class RoleOrganisationsHelperTest < ActionView::TestCase
setup do
@user_organisation = create(:organisation, name: "User Organisation", abbreviation: "UO")
@other_organisation = create(:organisation, name: "Other Organisation")
@closed_organisation = create(:organisation, name: "Closed Organisation", closed: true)
@user = create(:admin_user, organisation: @user_organisation)
end

Expand Down Expand Up @@ -34,5 +35,11 @@ class RoleOrganisationsHelperTest < ActionView::TestCase
options.map { |o| o[:text] },
)
end

should "not include closed organisations" do
closed_organisation_option = options_for_organisation_select(@user).detect { |o| o[:value] == @closed_organisation.id }

assert_not closed_organisation_option
end
end
end

0 comments on commit 3ef31be

Please sign in to comment.