Browse Source

Refactor org edit permissions to helper

pull/484/head
baarkerlounger 3 years ago
parent
commit
81d14d426b
  1. 4
      app/helpers/user_helper.rb
  2. 2
      app/views/organisations/show.html.erb
  3. 24
      spec/helpers/user_helper_spec.rb

4
app/helpers/user_helper.rb

@ -30,4 +30,8 @@ module UserHelper
def can_edit_key_contact?(_user, current_user)
current_user.data_coordinator? || current_user.support?
end
def can_edit_org?(current_user)
current_user.data_coordinator? || current_user.support?
end
end

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

@ -9,7 +9,7 @@
<%= govuk_summary_list do |summary_list| %>
<% @organisation.display_attributes.each do |attr| %>
<% if current_user.data_coordinator? && attr[:editable] %>
<% if can_edit_org?(current_user) && attr[:editable] %>
<%= summary_list.row do |row| %>
<% row.key { attr[:name].to_s.humanize } %>
<% row.value { simple_format(attr[:value].to_s, {}, wrapper_tag: "div") } %>

24
spec/helpers/user_helper_spec.rb

@ -135,5 +135,29 @@ RSpec.describe UserHelper do
end
end
end
context "when the user is a data provider viewing organisation details" do
let(:current_user) { FactoryBot.create(:user, :data_provider) }
it "does not allow changing details" do
expect(can_edit_org?(current_user)).to be false
end
end
context "when the user is a data coordinator viewing organisation details" do
let(:current_user) { FactoryBot.create(:user, :data_coordinator) }
it "does not allow changing details" do
expect(can_edit_org?(current_user)).to be true
end
end
context "when the user is a support user viewing organisation details" do
let(:current_user) { FactoryBot.create(:user, :support) }
it "does not allow changing details" do
expect(can_edit_org?(current_user)).to be true
end
end
end
end

Loading…
Cancel
Save