Browse Source

Update current user logic

CLDC-3857-Add-new-questions-to-organisation-setup
Manny Dinssa 1 month ago
parent
commit
fa84e1336a
  1. 8
      app/helpers/organisations_helper.rb
  2. 2
      app/views/organisations/show.html.erb
  3. 30
      spec/helpers/organisations_helper_spec.rb

8
app/helpers/organisations_helper.rb

@ -9,7 +9,7 @@ module OrganisationsHelper
end end
end end
def display_organisation_attributes(organisation) def display_organisation_attributes(user, organisation)
attributes = [ attributes = [
{ name: "Organisation ID", value: "ORG#{organisation.id}", editable: false }, { name: "Organisation ID", value: "ORG#{organisation.id}", editable: false },
{ name: "Address", value: organisation.address_string, editable: true }, { name: "Address", value: organisation.address_string, editable: true },
@ -17,14 +17,14 @@ module OrganisationsHelper
{ name: "Registration number", value: organisation.housing_registration_no || "", editable: false }, { name: "Registration number", value: organisation.housing_registration_no || "", editable: false },
{ name: "Type of provider", value: organisation.display_provider_type, editable: false }, { name: "Type of provider", value: organisation.display_provider_type, editable: false },
{ name: "Owns housing stock", value: organisation.holds_own_stock ? "Yes" : "No", editable: false }, { name: "Owns housing stock", value: organisation.holds_own_stock ? "Yes" : "No", editable: false },
{ name: "Part of group", value: organisation.group_member ? "Yes" : "No", editable: current_user.support? }, { name: "Part of group", value: organisation.group_member ? "Yes" : "No", editable: user.support? },
] ]
if organisation.group_member if organisation.group_member
attributes << { name: "Group number", value: "GROUP#{organisation.group}", editable: current_user.support? } attributes << { name: "Group number", value: "GROUP#{organisation.group}", editable: user.support? }
end end
attributes << { name: "For profit", value: organisation.display_profit_status, editable: current_user.support? } attributes << { name: "For profit", value: organisation.display_profit_status, editable: user.support? }
attributes << { name: "Rent periods", value: organisation.rent_period_labels, editable: true, format: :bullet } attributes << { name: "Rent periods", value: organisation.rent_period_labels, editable: true, format: :bullet }
attributes << { name: "Data Sharing Agreement" } attributes << { name: "Data Sharing Agreement" }
attributes << { name: "Status", value: status_tag(organisation.status) + delete_organisation_text(organisation), editable: false } attributes << { name: "Status", value: status_tag(organisation.status) + delete_organisation_text(organisation), editable: false }

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

@ -15,7 +15,7 @@
<div class="govuk-grid-column-two-thirds-from-desktop"> <div class="govuk-grid-column-two-thirds-from-desktop">
<%= govuk_summary_list do |summary_list| %> <%= govuk_summary_list do |summary_list| %>
<%= organisation_name_row(user: current_user, organisation: @organisation, summary_list:) %> <%= organisation_name_row(user: current_user, organisation: @organisation, summary_list:) %>
<% display_organisation_attributes(@organisation).each do |attr| %> <% display_organisation_attributes(current_user, @organisation).each do |attr| %>
<% if attr[:name] == "Data Sharing Agreement" %> <% if attr[:name] == "Data Sharing Agreement" %>
<%= data_sharing_agreement_row(organisation: @organisation, user: current_user, summary_list:) %> <%= data_sharing_agreement_row(organisation: @organisation, user: current_user, summary_list:) %>
<% else %> <% else %>

30
spec/helpers/organisations_helper_spec.rb

@ -3,10 +3,12 @@ require "rails_helper"
RSpec.describe OrganisationsHelper do RSpec.describe OrganisationsHelper do
include TagHelper include TagHelper
describe "display_organisation_attributes" do describe "display_organisation_attributes" do
let(:organisation) { create(:organisation, :la, :holds_own_stock, address_line1: "2 Marsham Street", address_line2: "London", postcode: "SW1P 4DF", housing_registration_no: 1234, organisation_rent_periods: []) } let(:support_user) { create(:user, :support) }
let(:coordinator_user) { create(:user, :data_coordinator) }
let(:organisation) { create(:organisation, :la, :holds_own_stock, address_line1: "2 Marsham Street", address_line2: "London", postcode: "SW1P 4DF", housing_registration_no: 1234, organisation_rent_periods: [], group_member: true, group_member_id: 99, group: 1) }
it "has the correct values" do it "has the correct values and editable status for support users" do
expect(display_organisation_attributes(organisation)).to eq( expect(display_organisation_attributes(support_user, organisation)).to eq(
[{ editable: false, name: "Organisation ID", value: "ORG#{organisation.id}" }, [{ editable: false, name: "Organisation ID", value: "ORG#{organisation.id}" },
{ editable: true, { editable: true,
name: "Address", name: "Address",
@ -15,11 +17,33 @@ RSpec.describe OrganisationsHelper do
{ editable: false, name: "Registration number", value: "1234" }, { editable: false, name: "Registration number", value: "1234" },
{ editable: false, name: "Type of provider", value: "Local authority" }, { editable: false, name: "Type of provider", value: "Local authority" },
{ editable: false, name: "Owns housing stock", value: "Yes" }, { editable: false, name: "Owns housing stock", value: "Yes" },
{ editable: true, name: "Part of group", value: "Yes"},
{ editable: true, name: "Group number", value: "GROUP1"},
{ editable: true, name: "For profit", value: ""},
{ editable: true, format: :bullet, name: "Rent periods", value: [] }, { editable: true, format: :bullet, name: "Rent periods", value: [] },
{ name: "Data Sharing Agreement" }, { name: "Data Sharing Agreement" },
{ editable: false, name: "Status", value: status_tag(organisation.status) }], { editable: false, name: "Status", value: status_tag(organisation.status) }],
) )
end end
it "has the correct values and editable status for non-support users" do
expect(display_organisation_attributes(coordinator_user, organisation)).to eq(
[{ editable: false, name: "Organisation ID", value: "ORG#{organisation.id}" },
{ editable: true,
name: "Address",
value: "2 Marsham Street\nLondon\nSW1P 4DF" },
{ editable: true, name: "Telephone number", value: nil },
{ editable: false, name: "Registration number", value: "1234" },
{ editable: false, name: "Type of provider", value: "Local authority" },
{ editable: false, name: "Owns housing stock", value: "Yes" },
{ editable: false, name: "Part of group", value: "Yes"},
{ editable: false, name: "Group number", value: "GROUP1"},
{ editable: false, name: "For profit", value: ""},
{ editable: true, format: :bullet, name: "Rent periods", value: [] },
{ name: "Data Sharing Agreement" },
{ editable: false, name: "Status", value: status_tag(organisation.status) }],
)
end
end end
describe "rent_periods_with_checked_attr" do describe "rent_periods_with_checked_attr" do

Loading…
Cancel
Save