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

Simplify organisation selection #3178

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/organisations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class OrganisationsController < ApplicationController

def index
authorize Organisation
@organisations = policy_scope(Organisation)
@organisations = Organisation.all
end

def update
Expand Down
9 changes: 9 additions & 0 deletions app/helpers/organisation_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module OrganisationHelper
def options_for_organisation_select(selected: nil)
[{ text: "None", value: nil }] + Organisation.not_closed.map do |organisation|
{ text: organisation.name_with_abbreviation, value: organisation.id }.tap do |option|
option[:selected] = true if option[:value] == selected
end
end
end
end
11 changes: 0 additions & 11 deletions app/helpers/role_organisations_helper.rb

This file was deleted.

22 changes: 0 additions & 22 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ def two_step_status_with_requirement(user)
end
end

def organisation_options(form_builder)
accessible_organisations = policy_scope(Organisation)
options_from_collection_for_select(
accessible_organisations,
:id,
:name_with_abbreviation,
selected: form_builder.object.organisation_id,
)
end

def organisation_select_options
{ include_blank: current_user.publishing_manager? ? false : Organisation::NONE }
end

def user_email_tokens(user = current_user)
[user.email] + DeviseZxcvbn::EmailTokeniser.split(user.email)
end
Expand Down Expand Up @@ -84,14 +70,6 @@ def options_for_role_select(selected: nil)
end
end

def options_for_organisation_select(selected: nil)
[{ text: "None", value: nil }] + policy_scope(Organisation).not_closed.order(:name).map do |organisation|
{ text: organisation.name_with_abbreviation, value: organisation.id }.tap do |option|
option[:selected] = true if option[:value] == selected
end
end
end

def options_for_permission_option_select(application:, user: nil)
application.sorted_supported_permissions_grantable_from_ui.map do |permission|
{
Expand Down
4 changes: 3 additions & 1 deletion app/models/organisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ class Organisation < ApplicationRecord

scope :not_closed, -> { where(closed: false) }

default_scope { order(:name) }

def name_with_abbreviation
return_value = if abbreviation.present? && abbreviation != name
"#{name} #{abbreviation}"
"#{name} - #{abbreviation}"
else
name
end
Expand Down
10 changes: 0 additions & 10 deletions app/policies/organisation_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,4 @@ def can_assign?
def edit?
current_user.superadmin?
end

class Scope < ::BasePolicy::Scope
def resolve
if current_user.govuk_admin?
scope.all
else
scope.none
end
end
end
end
2 changes: 1 addition & 1 deletion app/views/account/organisations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
id: "user_organisation_id",
name: "user[organisation_id]",
label: "Organisation",
options: options_for_your_organisation_select(current_user)
options: options_for_organisation_select(selected: current_user.organisation_id)
} %>
<%= render "govuk_publishing_components/components/button", {
text: "Change organisation"
Expand Down
4 changes: 2 additions & 2 deletions app/views/batch_invitations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
id: "batch_invitation_organisation_id",
name: "batch_invitation[organisation_id]",
label: "Organisation",
options: policy_scope(Organisation).not_closed.order(:name).map { |organisation| { text: organisation.name_with_abbreviation, value: organisation.id } }
} %>
options: options_for_organisation_select
} %>

<% end %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/organisations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<%= t.body do %>
<% @organisations.each do |organisation| %>
<%= t.row do %>
<%= t.cell "#{organisation.name} (#{organisation.abbreviation})" %>
<%= t.cell "#{organisation.name_with_abbreviation}" %>
<%= t.cell organisation.organisation_type %>
<%= t.cell organisation.slug %>
<td class="govuk-table__cell">
Expand Down
54 changes: 0 additions & 54 deletions test/policies/organisation_policy_scope_test.rb

This file was deleted.

Loading