Browse Source

CLDC-2626 Communicate permissions around editing schemes (#1970)

* Communicate permissions around editing schemes

* lint

* Move location text
pull/1984/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
68eb307d51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/helpers/locations_helper.rb
  2. 8
      app/helpers/schemes_helper.rb
  3. 2
      app/views/locations/show.html.erb
  4. 1
      app/views/schemes/show.html.erb
  5. 35
      spec/helpers/locations_helper_spec.rb
  6. 35
      spec/helpers/schemes_helper_spec.rb

8
app/helpers/locations_helper.rb

@ -83,6 +83,14 @@ module LocationsHelper
user.support? || user.organisation == scheme.owning_organisation user.support? || user.organisation == scheme.owning_organisation
end end
def edit_location_text(scheme, user)
if user.data_provider?
"If you think this location should be updated, ask a data coordinator to make the changes. Find your data coordinators on the #{link_to('users page', users_path)}.".html_safe
elsif user.data_coordinator? && user.organisation.parent_organisations.include?(scheme.owning_organisation)
"This location belongs to your stock owner #{scheme.owning_organisation.name}."
end
end
private private
ActivePeriod = Struct.new(:from, :to) ActivePeriod = Struct.new(:from, :to)

8
app/helpers/schemes_helper.rb

@ -45,6 +45,14 @@ module SchemesHelper
[OpenStruct.new(id: "", name: "Select an option")] [OpenStruct.new(id: "", name: "Select an option")]
end end
def edit_scheme_text(scheme, user)
if user.data_provider?
"If you think this scheme should be updated, ask a data coordinator to make the changes. Find your data coordinators on the #{link_to('users page', users_path)}.".html_safe
elsif user.data_coordinator? && user.organisation.parent_organisations.include?(scheme.owning_organisation)
"This scheme belongs to your stock owner #{scheme.owning_organisation.name}."
end
end
private private
ActivePeriod = Struct.new(:from, :to) ActivePeriod = Struct.new(:from, :to)

2
app/views/locations/show.html.erb

@ -11,6 +11,8 @@
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop"> <div class="govuk-grid-column-two-thirds-from-desktop">
<%= govuk_inset_text(text: edit_location_text(@scheme, current_user)) %>
<%= govuk_summary_list do |summary_list| %> <%= govuk_summary_list do |summary_list| %>
<% display_location_attributes(@location).each do |attr| %> <% display_location_attributes(@location).each do |attr| %>
<%= summary_list.row do |row| %> <%= summary_list.row do |row| %>

1
app/views/schemes/show.html.erb

@ -14,6 +14,7 @@
<%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id, "Locations")) %> <%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id, "Locations")) %>
<h2 class="govuk-visually-hidden">Scheme</h2> <h2 class="govuk-visually-hidden">Scheme</h2>
<%= govuk_inset_text(text: edit_scheme_text(@scheme, current_user)) %>
<%= govuk_summary_list do |summary_list| %> <%= govuk_summary_list do |summary_list| %>
<% display_scheme_attributes(@scheme).each do |attr| %> <% display_scheme_attributes(@scheme).each do |attr| %>

35
spec/helpers/locations_helper_spec.rb

@ -308,4 +308,39 @@ RSpec.describe LocationsHelper do
end end
end end
end end
describe "edit_location_text" do
let(:parent_organisation) { FactoryBot.create(:organisation, name: "Parent") }
let(:child_organisation) { FactoryBot.create(:organisation, name: "Child") }
let(:scheme) { FactoryBot.create(:scheme, owning_organisation: parent_organisation) }
let(:data_coordinator) { FactoryBot.create(:user, :data_coordinator, organisation: child_organisation) }
let(:data_provider) { FactoryBot.create(:user, :data_provider, organisation: child_organisation) }
let(:location) { FactoryBot.build(:location, scheme:) }
before do
create(:organisation_relationship, child_organisation:, parent_organisation:)
end
context "with data coordinator user" do
it "returns correct edit location text for a parent organisation location" do
expect(edit_location_text(scheme, data_coordinator)).to include("This location belongs to your stock owner Parent.")
end
it "returns nil when viewing your organisation location" do
data_coordinator.update!(organisation: parent_organisation)
expect(edit_location_text(scheme, data_coordinator)).to be_nil
end
end
context "with data provider user" do
it "returns correct edit location text for a parent organisation location" do
expect(edit_location_text(scheme, data_provider)).to include("If you think this location should be updated, ask a data coordinator to make the changes. Find your data coordinators on the ")
end
it "returns correct edit location text for your organisation location" do
data_provider.update!(organisation: parent_organisation)
expect(edit_location_text(scheme, data_provider)).to include("If you think this location should be updated, ask a data coordinator to make the changes. Find your data coordinators on the ")
end
end
end
end end

35
spec/helpers/schemes_helper_spec.rb

@ -267,4 +267,39 @@ RSpec.describe SchemesHelper do
end end
end end
end end
describe "edit_scheme_text" do
let(:parent_organisation) { FactoryBot.create(:organisation, name: "Parent") }
let(:child_organisation) { FactoryBot.create(:organisation, name: "Child") }
let(:scheme) { FactoryBot.create(:scheme, owning_organisation: parent_organisation) }
let(:data_coordinator) { FactoryBot.create(:user, :data_coordinator, organisation: child_organisation) }
let(:data_provider) { FactoryBot.create(:user, :data_provider, organisation: child_organisation) }
before do
create(:organisation_relationship, child_organisation:, parent_organisation:)
end
context "with data coordinator user" do
it "returns correct edit scheme text for a parent organisation scheme" do
expect(edit_scheme_text(scheme, data_coordinator)).to include("This scheme belongs to your stock owner Parent.")
end
it "returns nil when viewing your organisation scheme" do
data_coordinator.update!(organisation: parent_organisation)
expect(edit_scheme_text(scheme, data_coordinator)).to be_nil
end
end
context "with data provider user" do
it "returns correct edit scheme text for a parent organisation scheme" do
expect(edit_scheme_text(scheme, data_provider)).to include("If you think this scheme should be updated, ask a data coordinator to make the changes. Find your data coordinators on the ")
end
it "returns correct edit scheme text for your organisation scheme" do
data_provider.update!(organisation: parent_organisation)
expect(edit_scheme_text(scheme, data_provider)).to include("If you think this scheme should be updated, ask a data coordinator to make the changes. Find your data coordinators on the ")
end
end
end
end end

Loading…
Cancel
Save