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.
- Loading branch information
Showing
18 changed files
with
304 additions
and
20 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
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,14 @@ | ||
class Users::OrganisationSessionController < ApplicationController | ||
include Secured | ||
|
||
def update | ||
desired_organisation_id = params[:current_user_organisation] | ||
|
||
if desired_organisation_id | ||
if current_user.all_organisations.pluck(:id).include?(desired_organisation_id) | ||
session[:current_user_organisation] = desired_organisation_id | ||
end | ||
end | ||
redirect_to current_user.service_owner? ? request.referer : root_path | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
- if authenticated? && current_user.additional_organisations? | ||
.govuk-grid-row | ||
.govuk-grid-column-full{:class => "govuk-!-padding-top-4"} | ||
=form_with url: users_session_organisation_path, method: :patch do |form| | ||
=form.label t("organisation_switcher.label"), class: "govuk-label", for: "current_user_organisation" | ||
=form.select :current_user_organisation, options_for_select(@organisation_list.pluck(:name, :id), current_user.current_organisation_id), {}, class: "govuk-select" | ||
=form.submit t("organisation_switcher.submit"), class: "govuk-button govuk-!-margin-bottom-1", "data-module": "govuk-button" |
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,5 @@ | ||
--- | ||
en: | ||
organisation_switcher: | ||
label: "Available organisations" | ||
submit: "Set organisation" |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe OrganisationSessionController do | ||
let(:user) { create(:partner_organisation_user, organisation: organisation) } | ||
let(:organisation) { create(:partner_organisation) } | ||
let(:other_organisation) { create(:partner_organisation) } | ||
|
||
before do | ||
allow(controller).to receive(:current_user).and_return(user) | ||
|
||
user.additional_organisations << [create(:partner_organisation), create(:partner_organisation)] | ||
end | ||
|
||
describe "#update" do | ||
it "sets the session `current_user_organisation` to the user's primary organisation's ID" do | ||
put :update, params: build_params(user.primary_organisation.id) | ||
|
||
expect(session[:current_user_organisation]).to eq(user.primary_organisation.id) | ||
end | ||
|
||
it "sets the session `current_user_organisation` to an ID from the user's additional organisations" do | ||
id = user.additional_organisations.pluck(:id).sample | ||
|
||
put :update, params: build_params(id) | ||
|
||
expect(session[:current_user_organisation]).to eq(id) | ||
end | ||
|
||
it "does not set the session `current_user_organisation` to a random ID" do | ||
random_id = SecureRandom.uuid | ||
|
||
put :update, params: build_params(random_id) | ||
|
||
expect(session[:current_user_organisation]).not_to eq(random_id) | ||
end | ||
|
||
it "does not set the session `current_user_organisation` to an organisation ID not in the user's additional organisations" do | ||
put :update, params: build_params(other_organisation.id) | ||
|
||
expect(session[:current_user_organisation]).not_to eq(other_organisation.id) | ||
end | ||
|
||
def build_params(id) | ||
{current_user_organisation: id} | ||
end | ||
end | ||
end |
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
Oops, something went wrong.