Skip to content

Commit

Permalink
Move support users to using the multi-org views
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie committed Oct 7, 2024
1 parent 32a313d commit 44656f0
Show file tree
Hide file tree
Showing 23 changed files with 49 additions and 204 deletions.
19 changes: 17 additions & 2 deletions app/controllers/placements/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,24 @@ class Placements::ApplicationController < ApplicationController

private

def set_school
@school = if current_user.support_user?
Placements::School.find(params.require(:school_id))
else
current_user.schools.find(params.require(:school_id))
end
end

def set_provider
@provider = if current_user.support_user?
Placements::Provider.find(params.require(:provider_id))
else
current_user.providers.find(params.require(:provider_id))
end
end

def authorize_support_user!
user_not_authorized if (support_controller? && !current_user.support_user?) ||
(!support_controller? && restricted_placements_controller? && current_user.support_user?)
user_not_authorized if support_controller? && !current_user.support_user?
end

def support_controller?
Expand Down
17 changes: 10 additions & 7 deletions app/controllers/placements/organisations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@ def index
end

def show
membership = memberships.find(params[:id])
load_organisation(membership)
redirect_to landing_page_path(organisation)
end

private

def auto_redirect_if_only_one
load_organisation(memberships.first) if memberships.one?
redirect_to landing_page_path(memberships.first.organisation) if memberships.one?
end

def memberships
current_user.user_memberships.includes(:organisation)
end

def load_organisation(membership)
organisation = membership.organisation

redirect_to landing_page_path(organisation)
def organisation
@organisation ||= if !current_user.support_user?
memberships.find(params.require(:id)).organisation
elsif params.fetch(:type) == "School"
School.find(params.require(:id))
else
Provider.find(params.require(:id))
end
end

def landing_page_path(organisation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ class Placements::Providers::PartnerSchools::AddPartnerSchoolController < Placem
private

def set_organisation
provider_id = params.fetch(:provider_id)
@organisation = current_user.providers.find(provider_id)
@organisation = set_provider
end

def step_path(step)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ def set_partner_school
@partner_school = @provider.partner_schools.find(params.require(:partner_school_id)).becomes(Placements::School)
end

def set_provider
provider_id = params.fetch(:provider_id)
@provider = current_user.providers.find(provider_id)
end

def placements_scope
@partner_school.placements
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def destroy
private

def set_organisation
@provider = current_user.providers.find(params.fetch(:provider_id))
@provider = set_provider
end

def source_organisation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Placements::Providers::PlacementsController < Placements::ApplicationController
before_action :set_current_provider
before_action :set_provider
helper_method :filter_form, :location_coordinates

def index
Expand Down Expand Up @@ -33,10 +33,6 @@ def schools_scope
end
end

def set_current_provider
@provider = current_user.providers.find(params[:provider_id])
end

def filter_form
@filter_form ||= Placements::Placements::FilterForm.new(@provider, filter_params)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ class Placements::Providers::Users::AddUserController < Placements::Organisation
private

def set_organisation
provider_id = params.require(:provider_id)
@organisation = current_user.providers.find(provider_id)
@organisation = set_provider
end

def step_path(step)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/placements/providers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Placements::Providers::UsersController < Placements::Organisations::UsersC
private

def set_organisation
@organisation = current_user.providers.find(params.fetch(:provider_id))
@organisation = set_provider
end

def redirect_to_index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ def update

private

def set_school
@school = current_user.schools.find(params.require(:school_id))
end

def set_wizard
current_step = params[:step]&.to_sym
@wizard = Placements::AddMentorWizard.new(school: @school, params:, session:, current_step:)
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/placements/schools/mentors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ def destroy

private

def set_school
@school = current_user.schools.find(params.require(:school_id))
end

def set_mentor
@mentor = @school.mentors.find(params.require(:id))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ class Placements::Schools::PartnerProviders::AddPartnerProviderController < Plac
private

def set_organisation
school_id = params.require(:school_id)
@organisation = current_user.schools.find(school_id)
@organisation = set_school
end

def step_path(step)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def destroy
private

def set_organisation
@school = current_user.schools.find(params.fetch(:school_id))
@school = set_school
end

def source_organisation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ def after_create_placement_path(school)
placements_school_placements_path(school)
end

def set_school
school_id = params.require(:school_id)
@school = current_user.schools.find(school_id)
end

def set_wizard
current_step = params[:step]&.to_sym
@wizard = Placements::AddPlacementWizard.new(school:, params:, session:, current_step:)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ def update

private

def set_school
school_id = params.require(:school_id)
@school = current_user.schools.find(school_id)
end

def set_wizard
current_step = params.fetch(:step).to_sym
@wizard = Placements::EditPlacementWizard.new(school:, placement: @placement, session:, params:, current_step:)
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/placements/schools/placements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ def set_placement
@placement = @school.placements.find(params.require(:id))
end

def set_school
@school = current_user.schools.find(params.require(:school_id))
end

def set_decorated_placement
@placement = @placement.decorate
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ def update

private

def set_school
school_id = params.require(:school_id)
@school = current_user.schools.find(school_id)
end

def set_wizard
current_step = params[:step]&.to_sym
@wizard = Placements::AddSchoolContactWizard.new(school: @school, params:, session:, current_step:)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ def update

private

def set_school
school_id = params.require(:school_id)
@school = current_user.schools.find(school_id)
end

def set_school_contact
school_contact_id = params.require(:id)
@school_contact = Placements::SchoolContact.find_by!(id: school_contact_id, school: @school)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ class Placements::Schools::Users::AddUserController < Placements::Organisations:
private

def set_organisation
school_id = params.require(:school_id)
@organisation = current_user.schools.find(school_id)
@organisation = set_school
end

def step_path(step)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/placements/schools/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Placements::Schools::UsersController < Placements::Organisations::UsersCon
private

def set_organisation
@organisation = current_user.schools.find(params.fetch(:school_id))
@organisation = set_school
end

def redirect_to_index
Expand Down
8 changes: 6 additions & 2 deletions app/views/placements/providers/_primary_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<%# locals: (current_navigation: nil, provider:) -%>
<% if current_user.organisation_count > 1 %>
<% if current_user.support_user? || current_user.organisation_count > 1 %>
<%= content_for(:header_content) do %>
<%= render(ContentHeaderComponent.new(
title: provider.name,
actions: [govuk_link_to(t(".change_organisation"), placements_organisations_path, no_visited_state: true)],
actions: [govuk_link_to(
t(".change_organisation"),
current_user.support_user? ? placements_support_organisations_path : placements_organisations_path,
no_visited_state: true,
)],
)) %>
<% end %>
<% end %>
Expand Down
8 changes: 6 additions & 2 deletions app/views/placements/schools/_primary_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<%# locals: (current_navigation: nil, school:) -%>
<% if current_user.organisation_count > 1 %>
<% if current_user.support_user? || current_user.organisation_count > 1 %>
<%= content_for(:header_content) do %>
<%= render(ContentHeaderComponent.new(
title: school.name,
actions: [govuk_link_to(t(".change_organisation"), placements_organisations_path, no_visited_state: true)],
actions: [govuk_link_to(
t(".change_organisation"),
current_user.support_user? ? placements_support_organisations_path : placements_organisations_path,
no_visited_state: true,
)],
)) %>
<% end %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/placements/support/organisations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<% @organisations.each do |org| %>
<%= render OrganisationListItem.new(
organisation: org.searchable,
organisation_url: placements_support_organisation_path(org.searchable),
organisation_url: placements_organisation_path(id: org.searchable_id, type: org.searchable_type),
show_details: true,
) %>
<% end %>
Expand Down
Loading

0 comments on commit 44656f0

Please sign in to comment.