-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- All users can see services, but only their own - GDS Editors can see all services, and update the organisation_slugs for a service using the new Update Owner form Co-authored-by: Ramya Vidapanakal <[email protected]>
- Loading branch information
1 parent
4105168
commit 2534848
Showing
9 changed files
with
276 additions
and
9 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
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 @@ | ||
<% content_for :page_title, "Update Owner" %> | ||
<%= render "govuk_publishing_components/components/heading", { | ||
text: "Update Owner", | ||
heading_level: 1, | ||
font_size: "l", | ||
margin_bottom: 5, | ||
} %> | ||
<%= form_for(@service, url: update_owner_service_path(@service)) do %> | ||
<%= render "govuk_publishing_components/components/input", { | ||
label: { text: "Organisation Slugs" }, | ||
hint: "For multiple owning organisations, list slugs separated by spaces", | ||
name: "service[organisation_slugs]", | ||
value: @service&.organisation_slugs, | ||
} %> | ||
<%= render "govuk_publishing_components/components/button", { text: "Submit" } %> | ||
<%= render "govuk_publishing_components/components/button", { | ||
text: "Cancel", | ||
secondary_quiet: true, | ||
href: service_path(@service, filter: "broken_links"), | ||
} %> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
RSpec.describe "Services page" do | ||
let(:owning_department) { "department-of-aardvarks" } | ||
let!(:service) { create(:service, label: "Aardvark Wardens", organisation_slugs: [owning_department]) } | ||
|
||
describe "GET /services/:service_slug" do | ||
it_behaves_like "it is forbidden to non-owners", "/services/aardvark-wardens", "department-of-aardvarks" | ||
end | ||
|
||
describe "GET /services/:service_slug/download_links_form" do | ||
it_behaves_like "it is forbidden to non-owners", "/services/aardvark-wardens/download_links_form", "department-of-aardvarks" | ||
end | ||
|
||
describe "GET /services/:service_slug/upload_links_form" do | ||
it_behaves_like "it is forbidden to non-owners", "/services/aardvark-wardens/upload_links_form", "department-of-aardvarks" | ||
end | ||
|
||
describe "GET /services/:service_slug/update-owner-form" do | ||
context "as a GDS Editor" do | ||
before { login_as_gds_editor } | ||
|
||
it "returns 200 OK" do | ||
get "/services/aardvark-wardens/update-owner-form" | ||
|
||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
|
||
context "as a department user (even) from the owning department" do | ||
before { login_as_department_user(organisation_slug: owning_department) } | ||
|
||
it "returns 403 Forbidden" do | ||
get "/services/aardvark-wardens/update-owner-form" | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
end | ||
|
||
describe "PATCH /services/:service_slug/update-owner" do | ||
context "as a GDS Editor" do | ||
before { login_as_gds_editor } | ||
|
||
it "returns 200 OK" do | ||
patch "/services/aardvark-wardens/update-owner", params: { service: { organisation_slugs: "new-owner" } } | ||
|
||
expect(response).to redirect_to("/services/aardvark-wardens?filter=broken_links") | ||
end | ||
|
||
it "updates the organisation slugs" do | ||
patch "/services/aardvark-wardens/update-owner", params: { service: { organisation_slugs: "new-owner" } } | ||
|
||
expect(service.reload.organisation_slugs).to eq(%w[new-owner]) | ||
end | ||
end | ||
|
||
context "as a department user (even) from the owning department" do | ||
before { login_as_department_user(organisation_slug: owning_department) } | ||
|
||
it "returns 403 Forbidden" do | ||
patch "/services/aardvark-wardens/update-owner", params: { service: { organisation_slugs: "new-owner" } } | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
|
||
it "does not update the organisation slugs" do | ||
patch "/services/aardvark-wardens/update-owner", params: { service: { organisation_slugs: "new-owner" } } | ||
|
||
expect(service.reload.organisation_slugs).to eq([owning_department]) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
RSpec.describe "Service page" do | ||
before do | ||
create(:service, label: "Aardvark Wardens", organisation_slugs: %w[department-of-aardvarks]) | ||
end | ||
|
||
describe "Visiting the page" do | ||
context "as an owning department user" do | ||
before { login_as_department_user(organisation_slug: "department-of-aardvarks") } | ||
|
||
it "does not show the Update Owner link" do | ||
visit "/services/aardvark-wardens" | ||
|
||
expect(page).not_to have_content("Update Owner") | ||
end | ||
end | ||
|
||
context "as a GDS Editor" do | ||
before { login_as_gds_editor } | ||
|
||
it "shows the Update Owner link" do | ||
visit "/services/aardvark-wardens" | ||
|
||
expect(page).to have_content("Update Owner") | ||
end | ||
end | ||
end | ||
|
||
describe "Updating the owner" do | ||
before { login_as_gds_editor } | ||
|
||
it "allows us to update the owner" do | ||
visit "/services/aardvark-wardens" | ||
|
||
expect(page).to have_content("department-of-aardvarks") | ||
expect(page).not_to have_content("government-digital-service") | ||
|
||
click_on "Update Owner" | ||
fill_in "Organisation Slug", with: "government-digital-service" | ||
click_on "Submit" | ||
|
||
expect(page).not_to have_content("department-of-aardvarks") | ||
expect(page).to have_content("government-digital-service") | ||
end | ||
|
||
it "allows us to cancel updating the owner" do | ||
visit "/services/aardvark-wardens" | ||
|
||
expect(page).to have_content("department-of-aardvarks") | ||
expect(page).not_to have_content("government-digital-service") | ||
|
||
click_on "Update Owner" | ||
fill_in "Organisation Slug", with: "government-digital-service" | ||
click_on "Cancel" | ||
|
||
expect(page).to have_content("department-of-aardvarks") | ||
expect(page).not_to have_content("government-digital-service") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require "gds_api/test_helpers/organisations" | ||
|
||
RSpec.describe "Services page" do | ||
include GdsApi::TestHelpers::Organisations | ||
|
||
before do | ||
create(:service, label: "Aardvark Wardens", organisation_slugs: %w[department-of-aardvarks]) | ||
end | ||
|
||
context "as a gds editor" do | ||
before { login_as_gds_editor } | ||
|
||
it "shows all the services" do | ||
visit "/services" | ||
|
||
expect(page).to have_content("Aardvark Wardens") | ||
end | ||
|
||
it "shows a generic title" do | ||
visit "/services" | ||
|
||
expect(page).to have_content("Services (1)") | ||
end | ||
end | ||
|
||
context "as a department user" do | ||
before do | ||
stub_organisations_api_has_organisations_with_bodies([{ "title" => "Department of Randomness", "details" => { "slug" => "random-department" } }]) | ||
login_as_department_user | ||
end | ||
|
||
it "does not show Aardvark Wardens service" do | ||
visit "/services" | ||
|
||
expect(page).not_to have_content("Aardvark Wardens") | ||
end | ||
|
||
it "shows a department title" do | ||
visit "/services" | ||
|
||
expect(page).to have_content("Services for Department of Randomness (0)") | ||
end | ||
|
||
context "if the Organisations API fails" do | ||
before do | ||
stub_request(:get, "#{Plek.new.website_root}/api/organisations/random-department").to_raise(GdsApi::HTTPUnavailable) | ||
end | ||
|
||
it "shows a generic title" do | ||
visit "/services" | ||
|
||
expect(page).to have_content("Services for random-department (0)") | ||
end | ||
end | ||
end | ||
|
||
context "as a user from an owning department" do | ||
before do | ||
stub_organisations_api_has_organisations_with_bodies([{ "title" => "Department of Aardvarks", "details" => { "slug" => "department-of-aardvarks" } }]) | ||
login_as_department_user(organisation_slug: "department-of-aardvarks") | ||
end | ||
|
||
before { login_as_department_user(organisation_slug: "department-of-aardvarks") } | ||
|
||
it "shows the related services only" do | ||
visit "/services" | ||
|
||
expect(page).to have_content("Aardvark Wardens") | ||
end | ||
|
||
it "shows a department title" do | ||
visit "/services" | ||
|
||
expect(page).to have_content("Services for Department of Aardvarks (1)") | ||
end | ||
end | ||
end |