75 changed files with 9864 additions and 180 deletions
@ -0,0 +1,142 @@ |
|||||||
|
class OrganisationRelationshipsController < ApplicationController |
||||||
|
include Pagy::Backend |
||||||
|
include Modules::SearchFilter |
||||||
|
|
||||||
|
before_action :authenticate_user! |
||||||
|
before_action :authenticate_scope! |
||||||
|
|
||||||
|
def housing_providers |
||||||
|
housing_providers = organisation.housing_providers |
||||||
|
unpaginated_filtered_housing_providers = filtered_collection(housing_providers, search_term) |
||||||
|
organisations = Organisation.where.not(id: @organisation.id).pluck(:id, :name) |
||||||
|
respond_to :html |
||||||
|
@pagy, @housing_providers = pagy(unpaginated_filtered_housing_providers) |
||||||
|
@organisations = organisations |
||||||
|
@searched = search_term.presence |
||||||
|
@total_count = housing_providers.size |
||||||
|
end |
||||||
|
|
||||||
|
def managing_agents |
||||||
|
managing_agents = organisation.managing_agents |
||||||
|
unpaginated_filtered_managing_agents = filtered_collection(managing_agents, search_term) |
||||||
|
organisations = Organisation.where.not(id: @organisation.id).pluck(:id, :name) |
||||||
|
respond_to :html |
||||||
|
@pagy, @managing_agents = pagy(unpaginated_filtered_managing_agents) |
||||||
|
@organisations = organisations |
||||||
|
@searched = search_term.presence |
||||||
|
@total_count = managing_agents.size |
||||||
|
end |
||||||
|
|
||||||
|
def add_housing_provider |
||||||
|
@organisations = Organisation.where.not(id: @organisation.id).pluck(:id, :name) |
||||||
|
respond_to :html |
||||||
|
end |
||||||
|
|
||||||
|
def add_managing_agent |
||||||
|
@organisations = Organisation.where.not(id: @organisation.id).pluck(:id, :name) |
||||||
|
respond_to :html |
||||||
|
end |
||||||
|
|
||||||
|
def create_housing_provider |
||||||
|
child_organisation = @organisation |
||||||
|
relationship_type = OrganisationRelationship::OWNING |
||||||
|
if params[:organisation][:related_organisation_id].empty? |
||||||
|
@organisation.errors.add :related_organisation_id, "You must choose a housing provider" |
||||||
|
@organisations = Organisation.where.not(id: child_organisation.id).pluck(:id, :name) |
||||||
|
render "organisation_relationships/add_housing_provider" |
||||||
|
return |
||||||
|
else |
||||||
|
parent_organisation = related_organisation |
||||||
|
if OrganisationRelationship.exists?(child_organisation:, parent_organisation:, relationship_type:) |
||||||
|
@organisation.errors.add :related_organisation_id, "You have already added this housing provider" |
||||||
|
@organisations = Organisation.where.not(id: child_organisation.id).pluck(:id, :name) |
||||||
|
render "organisation_relationships/add_housing_provider" |
||||||
|
return |
||||||
|
end |
||||||
|
end |
||||||
|
create!(child_organisation:, parent_organisation:, relationship_type:) |
||||||
|
flash[:notice] = "#{related_organisation.name} is now one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} housing providers" |
||||||
|
redirect_to housing_providers_organisation_path |
||||||
|
end |
||||||
|
|
||||||
|
def create_managing_agent |
||||||
|
parent_organisation = @organisation |
||||||
|
relationship_type = OrganisationRelationship::MANAGING |
||||||
|
if params[:organisation][:related_organisation_id].empty? |
||||||
|
@organisation.errors.add :related_organisation_id, "You must choose a managing agent" |
||||||
|
@organisations = Organisation.where.not(id: parent_organisation.id).pluck(:id, :name) |
||||||
|
render "organisation_relationships/add_managing_agent" |
||||||
|
return |
||||||
|
else |
||||||
|
child_organisation = related_organisation |
||||||
|
if OrganisationRelationship.exists?(child_organisation:, parent_organisation:, relationship_type:) |
||||||
|
@organisation.errors.add :related_organisation_id, "You have already added this managing agent" |
||||||
|
@organisations = Organisation.where.not(id: parent_organisation.id).pluck(:id, :name) |
||||||
|
render "organisation_relationships/add_managing_agent" |
||||||
|
return |
||||||
|
end |
||||||
|
end |
||||||
|
create!(child_organisation:, parent_organisation:, relationship_type:) |
||||||
|
flash[:notice] = "#{related_organisation.name} is now one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} managing agents" |
||||||
|
redirect_to managing_agents_organisation_path |
||||||
|
end |
||||||
|
|
||||||
|
def remove_housing_provider |
||||||
|
@target_organisation_id = target_organisation.id |
||||||
|
end |
||||||
|
|
||||||
|
def delete_housing_provider |
||||||
|
relationship = OrganisationRelationship.find_by!( |
||||||
|
child_organisation: @organisation, |
||||||
|
parent_organisation: target_organisation, |
||||||
|
relationship_type: OrganisationRelationship::OWNING, |
||||||
|
) |
||||||
|
relationship.destroy! |
||||||
|
flash[:notice] = "#{target_organisation.name} is no longer one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} housing providers" |
||||||
|
redirect_to housing_providers_organisation_path |
||||||
|
end |
||||||
|
|
||||||
|
def remove_managing_agent |
||||||
|
@target_organisation_id = target_organisation.id |
||||||
|
end |
||||||
|
|
||||||
|
def delete_managing_agent |
||||||
|
relationship = OrganisationRelationship.find_by!( |
||||||
|
parent_organisation: @organisation, |
||||||
|
child_organisation: target_organisation, |
||||||
|
relationship_type: OrganisationRelationship::MANAGING, |
||||||
|
) |
||||||
|
relationship.destroy! |
||||||
|
flash[:notice] = "#{target_organisation.name} is no longer one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} managing agents" |
||||||
|
redirect_to managing_agents_organisation_path |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def create!(child_organisation:, parent_organisation:, relationship_type:) |
||||||
|
@resource = OrganisationRelationship.new(child_organisation:, parent_organisation:, relationship_type:) |
||||||
|
@resource.save! |
||||||
|
end |
||||||
|
|
||||||
|
def organisation |
||||||
|
@organisation ||= Organisation.find(params[:id]) |
||||||
|
end |
||||||
|
|
||||||
|
def related_organisation |
||||||
|
@related_organisation ||= Organisation.find(params[:organisation][:related_organisation_id]) |
||||||
|
end |
||||||
|
|
||||||
|
def target_organisation |
||||||
|
@target_organisation ||= Organisation.find(params[:target_organisation_id]) |
||||||
|
end |
||||||
|
|
||||||
|
def search_term |
||||||
|
params["search"] |
||||||
|
end |
||||||
|
|
||||||
|
def authenticate_scope! |
||||||
|
if current_user.organisation != organisation && !current_user.support? |
||||||
|
render_not_found |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,16 @@ |
|||||||
|
class Form::Sales::Pages::PropertyLocalAuthority < ::Form::Page |
||||||
|
def initialize(id, hsh, subsection) |
||||||
|
super |
||||||
|
@id = "property_local_authority" |
||||||
|
@header = "" |
||||||
|
@description = "" |
||||||
|
@subsection = subsection |
||||||
|
end |
||||||
|
|
||||||
|
def questions |
||||||
|
@questions ||= [ |
||||||
|
Form::Sales::Questions::PropertyLocalAuthorityKnown.new(nil, nil, self), |
||||||
|
Form::Sales::Questions::PropertyLocalAuthority.new(nil, nil, self), |
||||||
|
] |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,331 @@ |
|||||||
|
class Form::Sales::Questions::PropertyLocalAuthority < ::Form::Question |
||||||
|
def initialize(id, hsh, page) |
||||||
|
super |
||||||
|
@id = "la" |
||||||
|
@check_answer_label = "Local authority" |
||||||
|
@header = "What is the local authority of the property?" |
||||||
|
@type = "select" |
||||||
|
@answer_options = ANSWER_OPTIONS |
||||||
|
@page = page |
||||||
|
end |
||||||
|
|
||||||
|
ANSWER_OPTIONS = { |
||||||
|
"" => "Select an option", |
||||||
|
"E07000223" => "Adur", |
||||||
|
"E07000026" => "Allerdale", |
||||||
|
"E07000032" => "Amber Valley", |
||||||
|
"E07000224" => "Arun", |
||||||
|
"E07000170" => "Ashfield", |
||||||
|
"E07000105" => "Ashford", |
||||||
|
"E07000200" => "Babergh", |
||||||
|
"E09000002" => "Barking and Dagenham", |
||||||
|
"E09000003" => "Barnet", |
||||||
|
"E08000016" => "Barnsley", |
||||||
|
"E07000027" => "Barrow-in-Furness", |
||||||
|
"E07000066" => "Basildon", |
||||||
|
"E07000084" => "Basingstoke and Deane", |
||||||
|
"E07000171" => "Bassetlaw", |
||||||
|
"E06000022" => "Bath and North East Somerset", |
||||||
|
"E06000055" => "Bedford", |
||||||
|
"E09000004" => "Bexley", |
||||||
|
"E08000025" => "Birmingham", |
||||||
|
"E07000129" => "Blaby", |
||||||
|
"E06000008" => "Blackburn with Darwen", |
||||||
|
"E06000009" => "Blackpool", |
||||||
|
"E07000033" => "Bolsover", |
||||||
|
"E08000001" => "Bolton", |
||||||
|
"E07000136" => "Boston", |
||||||
|
"E06000058" => "Bournemouth, Christchurch and Poole", |
||||||
|
"E06000036" => "Bracknell Forest", |
||||||
|
"E08000032" => "Bradford", |
||||||
|
"E07000067" => "Braintree", |
||||||
|
"E07000143" => "Breckland", |
||||||
|
"E09000005" => "Brent", |
||||||
|
"E07000068" => "Brentwood", |
||||||
|
"E06000043" => "Brighton and Hove", |
||||||
|
"E06000023" => "Bristol, City of", |
||||||
|
"E07000144" => "Broadland", |
||||||
|
"E09000006" => "Bromley", |
||||||
|
"E07000234" => "Bromsgrove", |
||||||
|
"E07000095" => "Broxbourne", |
||||||
|
"E07000172" => "Broxtowe", |
||||||
|
"E06000060" => "Buckinghamshire", |
||||||
|
"E07000117" => "Burnley", |
||||||
|
"E08000002" => "Bury", |
||||||
|
"E08000033" => "Calderdale", |
||||||
|
"E07000008" => "Cambridge", |
||||||
|
"E09000007" => "Camden", |
||||||
|
"E07000192" => "Cannock Chase", |
||||||
|
"E07000106" => "Canterbury", |
||||||
|
"E07000028" => "Carlisle", |
||||||
|
"E07000069" => "Castle Point", |
||||||
|
"E06000056" => "Central Bedfordshire", |
||||||
|
"E07000130" => "Charnwood", |
||||||
|
"E07000070" => "Chelmsford", |
||||||
|
"E07000078" => "Cheltenham", |
||||||
|
"E07000177" => "Cherwell", |
||||||
|
"E06000049" => "Cheshire East", |
||||||
|
"E06000050" => "Cheshire West and Chester", |
||||||
|
"E07000034" => "Chesterfield", |
||||||
|
"E07000225" => "Chichester", |
||||||
|
"E07000118" => "Chorley", |
||||||
|
"E09000001" => "City of London", |
||||||
|
"E07000071" => "Colchester", |
||||||
|
"E07000029" => "Copeland", |
||||||
|
"E07000150" => "Corby", |
||||||
|
"E06000052" => "Cornwall", |
||||||
|
"E07000079" => "Cotswold", |
||||||
|
"E06000047" => "County Durham", |
||||||
|
"E08000026" => "Coventry", |
||||||
|
"E07000163" => "Craven", |
||||||
|
"E07000226" => "Crawley", |
||||||
|
"E09000008" => "Croydon", |
||||||
|
"E07000096" => "Dacorum", |
||||||
|
"E06000005" => "Darlington", |
||||||
|
"E07000107" => "Dartford", |
||||||
|
"E07000151" => "Daventry", |
||||||
|
"E06000015" => "Derby", |
||||||
|
"E07000035" => "Derbyshire Dales", |
||||||
|
"E08000017" => "Doncaster", |
||||||
|
"E06000059" => "Dorset", |
||||||
|
"E07000108" => "Dover", |
||||||
|
"E08000027" => "Dudley", |
||||||
|
"E09000009" => "Ealing", |
||||||
|
"E07000009" => "East Cambridgeshire", |
||||||
|
"E07000040" => "East Devon", |
||||||
|
"E07000085" => "East Hampshire", |
||||||
|
"E07000242" => "East Hertfordshire", |
||||||
|
"E07000137" => "East Lindsey", |
||||||
|
"E07000152" => "East Northamptonshire", |
||||||
|
"E06000011" => "East Riding of Yorkshire", |
||||||
|
"E07000193" => "East Staffordshire", |
||||||
|
"E07000244" => "East Suffolk", |
||||||
|
"E07000061" => "Eastbourne", |
||||||
|
"E07000086" => "Eastleigh", |
||||||
|
"E07000030" => "Eden", |
||||||
|
"E07000207" => "Elmbridge", |
||||||
|
"E09000010" => "Enfield", |
||||||
|
"E07000072" => "Epping Forest", |
||||||
|
"E07000208" => "Epsom and Ewell", |
||||||
|
"E07000036" => "Erewash", |
||||||
|
"E07000041" => "Exeter", |
||||||
|
"E07000087" => "Fareham", |
||||||
|
"E07000010" => "Fenland", |
||||||
|
"E07000112" => "Folkestone and Hythe", |
||||||
|
"E07000080" => "Forest of Dean", |
||||||
|
"E07000119" => "Fylde", |
||||||
|
"E08000037" => "Gateshead", |
||||||
|
"E07000173" => "Gedling", |
||||||
|
"E07000081" => "Gloucester", |
||||||
|
"E07000088" => "Gosport", |
||||||
|
"E07000109" => "Gravesham", |
||||||
|
"E07000145" => "Great Yarmouth", |
||||||
|
"E09000011" => "Greenwich", |
||||||
|
"E07000209" => "Guildford", |
||||||
|
"W06000002" => "Gwynedd", |
||||||
|
"E09000012" => "Hackney", |
||||||
|
"E06000006" => "Halton", |
||||||
|
"E07000164" => "Hambleton", |
||||||
|
"E09000013" => "Hammersmith and Fulham", |
||||||
|
"E07000131" => "Harborough", |
||||||
|
"E09000014" => "Haringey", |
||||||
|
"E07000073" => "Harlow", |
||||||
|
"E07000165" => "Harrogate", |
||||||
|
"E09000015" => "Harrow", |
||||||
|
"E07000089" => "Hart", |
||||||
|
"E06000001" => "Hartlepool", |
||||||
|
"E07000062" => "Hastings", |
||||||
|
"E07000090" => "Havant", |
||||||
|
"E09000016" => "Havering", |
||||||
|
"E06000019" => "Herefordshire, County of", |
||||||
|
"E07000098" => "Hertsmere", |
||||||
|
"E07000037" => "High Peak", |
||||||
|
"S12000017" => "Highland", |
||||||
|
"E09000017" => "Hillingdon", |
||||||
|
"E07000132" => "Hinckley and Bosworth", |
||||||
|
"E07000227" => "Horsham", |
||||||
|
"E09000018" => "Hounslow", |
||||||
|
"E07000011" => "Huntingdonshire", |
||||||
|
"E07000120" => "Hyndburn", |
||||||
|
"E07000202" => "Ipswich", |
||||||
|
"E06000046" => "Isle of Wight", |
||||||
|
"E06000053" => "Isles of Scilly", |
||||||
|
"E09000019" => "Islington", |
||||||
|
"E09000020" => "Kensington and Chelsea", |
||||||
|
"E07000153" => "Kettering", |
||||||
|
"E07000146" => "King’s Lynn and West Norfolk", |
||||||
|
"E06000010" => "Kingston upon Hull, City of", |
||||||
|
"E09000021" => "Kingston upon Thames", |
||||||
|
"E08000034" => "Kirklees", |
||||||
|
"E08000011" => "Knowsley", |
||||||
|
"E09000022" => "Lambeth", |
||||||
|
"E07000121" => "Lancaster", |
||||||
|
"E08000035" => "Leeds", |
||||||
|
"E06000016" => "Leicester", |
||||||
|
"E07000063" => "Lewes", |
||||||
|
"E09000023" => "Lewisham", |
||||||
|
"E07000194" => "Lichfield", |
||||||
|
"E07000138" => "Lincoln", |
||||||
|
"E08000012" => "Liverpool", |
||||||
|
"E06000032" => "Luton", |
||||||
|
"E07000110" => "Maidstone", |
||||||
|
"E07000074" => "Maldon", |
||||||
|
"E07000235" => "Malvern Hills", |
||||||
|
"E08000003" => "Manchester", |
||||||
|
"E07000174" => "Mansfield", |
||||||
|
"E06000035" => "Medway", |
||||||
|
"E07000133" => "Melton", |
||||||
|
"E07000187" => "Mendip", |
||||||
|
"E09000024" => "Merton", |
||||||
|
"E07000042" => "Mid Devon", |
||||||
|
"E07000203" => "Mid Suffolk", |
||||||
|
"E07000228" => "Mid Sussex", |
||||||
|
"E06000002" => "Middlesbrough", |
||||||
|
"E06000042" => "Milton Keynes", |
||||||
|
"E07000210" => "Mole Valley", |
||||||
|
"E07000091" => "New Forest", |
||||||
|
"E07000175" => "Newark and Sherwood", |
||||||
|
"E08000021" => "Newcastle upon Tyne", |
||||||
|
"E07000195" => "Newcastle-under-Lyme", |
||||||
|
"E09000025" => "Newham", |
||||||
|
"E07000043" => "North Devon", |
||||||
|
"E07000038" => "North East Derbyshire", |
||||||
|
"E06000012" => "North East Lincolnshire", |
||||||
|
"E07000099" => "North Hertfordshire", |
||||||
|
"E07000139" => "North Kesteven", |
||||||
|
"E06000013" => "North Lincolnshire", |
||||||
|
"E07000147" => "North Norfolk", |
||||||
|
"E06000024" => "North Somerset", |
||||||
|
"E08000022" => "North Tyneside", |
||||||
|
"E07000218" => "North Warwickshire", |
||||||
|
"E07000134" => "North West Leicestershire", |
||||||
|
"E07000154" => "Northampton", |
||||||
|
"E06000057" => "Northumberland", |
||||||
|
"E07000148" => "Norwich", |
||||||
|
"E06000018" => "Nottingham", |
||||||
|
"E07000219" => "Nuneaton and Bedworth", |
||||||
|
"E07000135" => "Oadby and Wigston", |
||||||
|
"E08000004" => "Oldham", |
||||||
|
"E07000178" => "Oxford", |
||||||
|
"E07000122" => "Pendle", |
||||||
|
"E06000031" => "Peterborough", |
||||||
|
"E06000026" => "Plymouth", |
||||||
|
"E06000044" => "Portsmouth", |
||||||
|
"E07000123" => "Preston", |
||||||
|
"E06000038" => "Reading", |
||||||
|
"E09000026" => "Redbridge", |
||||||
|
"E06000003" => "Redcar and Cleveland", |
||||||
|
"E07000236" => "Redditch", |
||||||
|
"E07000211" => "Reigate and Banstead", |
||||||
|
"E07000124" => "Ribble Valley", |
||||||
|
"E09000027" => "Richmond upon Thames", |
||||||
|
"E07000166" => "Richmondshire", |
||||||
|
"E08000005" => "Rochdale", |
||||||
|
"E07000075" => "Rochford", |
||||||
|
"E07000125" => "Rossendale", |
||||||
|
"E07000064" => "Rother", |
||||||
|
"E08000018" => "Rotherham", |
||||||
|
"E07000220" => "Rugby", |
||||||
|
"E07000212" => "Runnymede", |
||||||
|
"E07000176" => "Rushcliffe", |
||||||
|
"E07000092" => "Rushmoor", |
||||||
|
"E06000017" => "Rutland", |
||||||
|
"E07000167" => "Ryedale", |
||||||
|
"E08000006" => "Salford", |
||||||
|
"E08000028" => "Sandwell", |
||||||
|
"E07000168" => "Scarborough", |
||||||
|
"E07000188" => "Sedgemoor", |
||||||
|
"E08000014" => "Sefton", |
||||||
|
"E07000169" => "Selby", |
||||||
|
"E07000111" => "Sevenoaks", |
||||||
|
"E08000019" => "Sheffield", |
||||||
|
"E06000051" => "Shropshire", |
||||||
|
"E06000039" => "Slough", |
||||||
|
"E08000029" => "Solihull", |
||||||
|
"E07000246" => "Somerset West and Taunton", |
||||||
|
"E07000012" => "South Cambridgeshire", |
||||||
|
"E07000039" => "South Derbyshire", |
||||||
|
"E06000025" => "South Gloucestershire", |
||||||
|
"E07000044" => "South Hams", |
||||||
|
"E07000140" => "South Holland", |
||||||
|
"E07000141" => "South Kesteven", |
||||||
|
"E07000031" => "South Lakeland", |
||||||
|
"E07000149" => "South Norfolk", |
||||||
|
"E07000155" => "South Northamptonshire", |
||||||
|
"E07000179" => "South Oxfordshire", |
||||||
|
"E07000126" => "South Ribble", |
||||||
|
"E07000189" => "South Somerset", |
||||||
|
"E07000196" => "South Staffordshire", |
||||||
|
"E08000023" => "South Tyneside", |
||||||
|
"E06000045" => "Southampton", |
||||||
|
"E06000033" => "Southend-on-Sea", |
||||||
|
"E09000028" => "Southwark", |
||||||
|
"E07000213" => "Spelthorne", |
||||||
|
"E07000240" => "St Albans", |
||||||
|
"E08000013" => "St. Helens", |
||||||
|
"E07000197" => "Stafford", |
||||||
|
"E07000198" => "Staffordshire Moorlands", |
||||||
|
"E07000243" => "Stevenage", |
||||||
|
"E08000007" => "Stockport", |
||||||
|
"E06000004" => "Stockton-on-Tees", |
||||||
|
"E06000021" => "Stoke-on-Trent", |
||||||
|
"E07000221" => "Stratford-on-Avon", |
||||||
|
"E07000082" => "Stroud", |
||||||
|
"E08000024" => "Sunderland", |
||||||
|
"E07000214" => "Surrey Heath", |
||||||
|
"E09000029" => "Sutton", |
||||||
|
"E07000113" => "Swale", |
||||||
|
"E06000030" => "Swindon", |
||||||
|
"E08000008" => "Tameside", |
||||||
|
"E07000199" => "Tamworth", |
||||||
|
"E07000215" => "Tandridge", |
||||||
|
"E07000045" => "Teignbridge", |
||||||
|
"E06000020" => "Telford and Wrekin", |
||||||
|
"E07000076" => "Tendring", |
||||||
|
"E07000093" => "Test Valley", |
||||||
|
"E07000083" => "Tewkesbury", |
||||||
|
"E07000114" => "Thanet", |
||||||
|
"E07000102" => "Three Rivers", |
||||||
|
"E06000034" => "Thurrock", |
||||||
|
"E07000115" => "Tonbridge and Malling", |
||||||
|
"E06000027" => "Torbay", |
||||||
|
"E07000046" => "Torridge", |
||||||
|
"E09000030" => "Tower Hamlets", |
||||||
|
"E08000009" => "Trafford", |
||||||
|
"E07000116" => "Tunbridge Wells", |
||||||
|
"E07000077" => "Uttlesford", |
||||||
|
"E07000180" => "Vale of White Horse", |
||||||
|
"E08000036" => "Wakefield", |
||||||
|
"E08000030" => "Walsall", |
||||||
|
"E09000031" => "Waltham Forest", |
||||||
|
"E09000032" => "Wandsworth", |
||||||
|
"E06000007" => "Warrington", |
||||||
|
"E07000222" => "Warwick", |
||||||
|
"E07000103" => "Watford", |
||||||
|
"E07000216" => "Waverley", |
||||||
|
"E07000065" => "Wealden", |
||||||
|
"E07000156" => "Wellingborough", |
||||||
|
"E07000241" => "Welwyn Hatfield", |
||||||
|
"E06000037" => "West Berkshire", |
||||||
|
"E07000047" => "West Devon", |
||||||
|
"E07000127" => "West Lancashire", |
||||||
|
"E07000142" => "West Lindsey", |
||||||
|
"E07000181" => "West Oxfordshire", |
||||||
|
"E07000245" => "West Suffolk", |
||||||
|
"E09000033" => "Westminster", |
||||||
|
"E08000010" => "Wigan", |
||||||
|
"E06000054" => "Wiltshire", |
||||||
|
"E07000094" => "Winchester", |
||||||
|
"E06000040" => "Windsor and Maidenhead", |
||||||
|
"E08000015" => "Wirral", |
||||||
|
"E07000217" => "Woking", |
||||||
|
"E06000041" => "Wokingham", |
||||||
|
"E08000031" => "Wolverhampton", |
||||||
|
"E07000237" => "Worcester", |
||||||
|
"E07000229" => "Worthing", |
||||||
|
"E07000238" => "Wychavon", |
||||||
|
"E07000128" => "Wyre", |
||||||
|
"E07000239" => "Wyre Forest", |
||||||
|
"E06000014" => "York", |
||||||
|
}.freeze |
||||||
|
end |
@ -0,0 +1,24 @@ |
|||||||
|
class Form::Sales::Questions::PropertyLocalAuthorityKnown < ::Form::Question |
||||||
|
def initialize(id, hsh, page) |
||||||
|
super |
||||||
|
@id = "la_known" |
||||||
|
@check_answer_label = "Local authority known" |
||||||
|
@header = "Do you know the local authority of the property?" |
||||||
|
@type = "radio" |
||||||
|
@answer_options = ANSWER_OPTIONS |
||||||
|
@conditional_for = { "la" => [1] } |
||||||
|
@hidden_in_check_answers = { |
||||||
|
"depends_on" => [ |
||||||
|
{ |
||||||
|
"la_known" => 1, |
||||||
|
}, |
||||||
|
], |
||||||
|
} |
||||||
|
@page = page |
||||||
|
end |
||||||
|
|
||||||
|
ANSWER_OPTIONS = { |
||||||
|
"1" => { "value" => "Yes" }, |
||||||
|
"0" => { "value" => "No" }, |
||||||
|
}.freeze |
||||||
|
end |
@ -1,2 +1,3 @@ |
|||||||
class LaRentRange < ApplicationRecord |
class LaRentRange < ApplicationRecord |
||||||
|
MAX_BEDS = 4 |
||||||
end |
end |
||||||
|
@ -1,4 +1,13 @@ |
|||||||
class OrganisationRelationship < ApplicationRecord |
class OrganisationRelationship < ApplicationRecord |
||||||
belongs_to :child_organisation, class_name: "Organisation" |
belongs_to :child_organisation, class_name: "Organisation" |
||||||
belongs_to :parent_organisation, class_name: "Organisation" |
belongs_to :parent_organisation, class_name: "Organisation" |
||||||
|
|
||||||
|
OWNING = "owning".freeze |
||||||
|
MANAGING = "managing".freeze |
||||||
|
RELATIONSHIP_TYPE = { |
||||||
|
OWNING => 0, |
||||||
|
MANAGING => 1, |
||||||
|
}.freeze |
||||||
|
|
||||||
|
enum relationship_type: RELATIONSHIP_TYPE |
||||||
end |
end |
||||||
|
@ -0,0 +1,22 @@ |
|||||||
|
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>"> |
||||||
|
<%= govuk_table do |table| %> |
||||||
|
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> |
||||||
|
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "housing providers", path: request.path)) %> |
||||||
|
<% end %> |
||||||
|
<% @housing_providers.each do |housing_provider| %> |
||||||
|
<%= table.body do |body| %> |
||||||
|
<%= body.row do |row| %> |
||||||
|
<% row.cell(text: housing_provider.name) %> |
||||||
|
<% if current_user.data_coordinator? || current_user.support? %> |
||||||
|
<% row.cell(html_attributes: { |
||||||
|
scope: "row", |
||||||
|
class: "govuk-!-text-align-right", |
||||||
|
}) do %> |
||||||
|
<%= govuk_link_to("Remove", housing_providers_remove_organisation_path(target_organisation_id: housing_provider.id)) %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
</section> |
@ -0,0 +1,22 @@ |
|||||||
|
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>"> |
||||||
|
<%= govuk_table do |table| %> |
||||||
|
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %> |
||||||
|
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "agents", path: request.path)) %> |
||||||
|
<% end %> |
||||||
|
<% @managing_agents.each do |managing_agent| %> |
||||||
|
<%= table.body do |body| %> |
||||||
|
<%= body.row do |row| %> |
||||||
|
<% row.cell(text: managing_agent.name) %> |
||||||
|
<% if current_user.data_coordinator? || current_user.support? %> |
||||||
|
<% row.cell(html_attributes: { |
||||||
|
scope: "row", |
||||||
|
class: "govuk-!-text-align-right", |
||||||
|
}) do %> |
||||||
|
<%= govuk_link_to("Remove", managing_agents_remove_organisation_path(target_organisation_id: managing_agent.id)) %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
</section> |
@ -0,0 +1,3 @@ |
|||||||
|
<% answers = question.answer_options.map { |key, value| OpenStruct.new(id: key, name: value) } %> |
||||||
|
<%= f.govuk_collection_select :related_organisation_id, answers, :id, :name, label: { hidden: true }, "data-controller": "accessible-autocomplete" do %> |
||||||
|
<% end %> |
@ -0,0 +1,34 @@ |
|||||||
|
<%= form_with model: @organisation, url: housing_providers_organisation_path, method: "post", local: true do |f| %> |
||||||
|
<% if current_user.support? %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> |
||||||
|
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %> |
||||||
|
<h2 class="govuk-visually-hidden">Add Housing Provider</h2> |
||||||
|
<%= govuk_back_link(href: :back) %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: "What is the name of this organisation's housing provider?", sub: nil } %> |
||||||
|
<p class="govuk-body">Start typing to search for a housing provider</p> |
||||||
|
<% else %> |
||||||
|
<% content_for :before_content do %> |
||||||
|
<%= govuk_back_link(href: :back) %> |
||||||
|
<% end %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: "What is the name of your housing provider?", sub: nil } %> |
||||||
|
<p class="govuk-body">Start typing to search for your housing provider</p> |
||||||
|
<% end %> |
||||||
|
<% answer_options = { "" => "Select an option" } %> |
||||||
|
<% @organisations.each do |organisation| %> |
||||||
|
<% answer_options[organisation[0]] = organisation[1] %> |
||||||
|
<% end %> |
||||||
|
<%= render partial: "organisation_relationships/related_organisation_select_question", locals: { |
||||||
|
question: Form::Question.new("", { "answer_options" => answer_options }, nil), |
||||||
|
f:, |
||||||
|
} %> |
||||||
|
<%= f.govuk_submit "Add" %> |
||||||
|
<%= govuk_details(summary_text: "Can't find the housing provider you're looking for?") do %> |
||||||
|
<ul class="govuk-list govuk-list--bullet"> |
||||||
|
<li>Double check the spelling and try again</li> |
||||||
|
<li>Type the first few letters to see the suggestions</li> |
||||||
|
<li>If you still can't find it, |
||||||
|
<%= govuk_link_to("contact the DLUHC service desk", "https://digital.dclg.gov.uk/jira/servicedesk/customer/portal/4/group/21", rel: "noreferrer noopener", target: "_blank") %> |
||||||
|
</li> |
||||||
|
</ul> |
||||||
|
<% end %> |
||||||
|
<% end %> |
@ -0,0 +1,34 @@ |
|||||||
|
<%= form_with model: @organisation, url: managing_agents_organisation_path, method: "post", local: true do |f| %> |
||||||
|
<% if current_user.support? %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> |
||||||
|
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %> |
||||||
|
<h2 class="govuk-visually-hidden">Add Managing Agent</h2> |
||||||
|
<%= govuk_back_link(href: :back) %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: "What is the name of this organisation's managing agent?", sub: nil } %> |
||||||
|
<p class="govuk-body">Start typing to search for a managing agent</p> |
||||||
|
<% else %> |
||||||
|
<% content_for :before_content do %> |
||||||
|
<%= govuk_back_link(href: :back) %> |
||||||
|
<% end %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: "What is the name of your managing agent?", sub: nil } %> |
||||||
|
<p class="govuk-body">Start typing to search for your managing agent</p> |
||||||
|
<% end %> |
||||||
|
<% answer_options = { "" => "Select an option" } %> |
||||||
|
<% @organisations.each do |organisation| %> |
||||||
|
<% answer_options[organisation[0]] = organisation[1] %> |
||||||
|
<% end %> |
||||||
|
<%= render partial: "organisation_relationships/related_organisation_select_question", locals: { |
||||||
|
question: Form::Question.new("", { "answer_options" => answer_options }, nil), |
||||||
|
f:, |
||||||
|
} %> |
||||||
|
<%= f.govuk_submit "Add" %> |
||||||
|
<%= govuk_details(summary_text: "Can't find the managing agent you're looking for?") do %> |
||||||
|
<ul class="govuk-list govuk-list--bullet"> |
||||||
|
<li>Double check the spelling and try again</li> |
||||||
|
<li>Type the first few letters to see the suggestions</li> |
||||||
|
<li>If you still can't find it, |
||||||
|
<%= govuk_link_to("contact the DLUHC service desk", "https://digital.dclg.gov.uk/jira/servicedesk/customer/portal/4/group/21", rel: "noreferrer noopener", target: "_blank") %> |
||||||
|
</li> |
||||||
|
</ul> |
||||||
|
<% end %> |
||||||
|
<% end %> |
@ -0,0 +1,24 @@ |
|||||||
|
<% item_label = format_label(@pagy.count, "housing providers") %> |
||||||
|
<% if current_user.support? %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> |
||||||
|
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %> |
||||||
|
<h2 class="govuk-visually-hidden">Housing Providers</h2> |
||||||
|
<p class="govuk-body">This organisation can submit logs for its housing providers.</p> |
||||||
|
<% if @total_count == 0 %> |
||||||
|
<p class="govuk-body">This organisation does not currently have any housing providers.</p> |
||||||
|
<% end %> |
||||||
|
<% else %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: "Your housing providers", sub: current_user.organisation.name } %> |
||||||
|
<p class="govuk-body">Your organisation can submit logs for its housing providers.</p> |
||||||
|
<% if @total_count == 0 %> |
||||||
|
<p class="govuk-body">You do not currently have any housing providers.</p> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% if current_user.support? || current_user.data_coordinator? %> |
||||||
|
<%= govuk_button_link_to "Add a housing provider", housing_providers_add_organisation_path, html: { method: :get } %> |
||||||
|
<% end %> |
||||||
|
<% if @total_count != 0 %> |
||||||
|
<%= render SearchComponent.new(current_user:, search_label: "Search for a housing provider", value: @searched) %> |
||||||
|
<%= render partial: "organisation_relationships/housing_provider_list", locals: { index: @housing_providers, title: "Housing providers", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> |
||||||
|
<%= render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "housing providers" } %> |
||||||
|
<% end %> |
@ -0,0 +1,27 @@ |
|||||||
|
<% item_label = format_label(@pagy.count, "managing agents") %> |
||||||
|
|
||||||
|
<% if current_user.support? %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> |
||||||
|
<%= render SubNavigationComponent.new( |
||||||
|
items: secondary_items(request.path, @organisation.id), |
||||||
|
) %> |
||||||
|
<h2 class="govuk-visually-hidden">Managing Agents</h2> |
||||||
|
<p class="govuk-body">A managing agent can submit logs for this organisation.</p> |
||||||
|
<% if @total_count == 0 %> |
||||||
|
<p class="govuk-body">This organisation does not currently have any managing agents.</p> |
||||||
|
<% end %> |
||||||
|
<% else %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: "This organisation managing agents", sub: current_user.organisation.name } %> |
||||||
|
<p class="govuk-body">A managing agent can submit logs for this organisation.</p> |
||||||
|
<% if @total_count == 0 %> |
||||||
|
<p class="govuk-body">This organisation does not currently have any managing agents.</p> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
<% if current_user.support? || current_user.data_coordinator? %> |
||||||
|
<%= govuk_button_link_to "Add a managing agent", managing_agents_add_organisation_path, html: { method: :get } %> |
||||||
|
<% end %> |
||||||
|
<% if @total_count != 0 %> |
||||||
|
<%= render SearchComponent.new(current_user:, search_label: "Search for a managing agent", value: @searched) %> |
||||||
|
<%= render partial: "organisation_relationships/managing_agent_list", locals: { index: @managing_agents, title: "Managing agents", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %> |
||||||
|
<%= render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "Managing agents" } %> |
||||||
|
<% end %> |
@ -0,0 +1,21 @@ |
|||||||
|
<%= form_with url: housing_providers_organisation_path(target_organisation_id: @target_organisation.id), method: "delete", local: true do |f| %> |
||||||
|
<% if current_user.support? %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> |
||||||
|
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %> |
||||||
|
<h2 class="govuk-visually-hidden">Remove Housing Provider</h2> |
||||||
|
<% end %> |
||||||
|
<% if current_user.support? %> |
||||||
|
<%= govuk_back_link(href: :back) %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: "You are removing ‘#{@target_organisation.name}’ from this organisation's housing providers", sub: nil } %> |
||||||
|
<% else %> |
||||||
|
<% content_for :before_content do %> |
||||||
|
<%= govuk_back_link(href: :back) %> |
||||||
|
<% end %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: "You are removing ‘#{@target_organisation.name}’ from your organisation's housing providers", sub: nil } %> |
||||||
|
<% end %> |
||||||
|
<%= govuk_warning_text text: "You will no longer be able to submit logs for #{@target_organisation.name}" %> |
||||||
|
<div class="govuk-button-group"> |
||||||
|
<%= f.govuk_submit "Confirm" %> |
||||||
|
<%= govuk_button_link_to "Cancel", housing_providers_organisation_path(current_user.organisation), html: { method: :get }, secondary: true %> |
||||||
|
</div> |
||||||
|
<% end %> |
@ -0,0 +1,21 @@ |
|||||||
|
<%= form_with url: managing_agents_organisation_path(target_organisation_id: @target_organisation.id), method: "delete", local: true do |f| %> |
||||||
|
<% if current_user.support? %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: @organisation.name, sub: nil } %> |
||||||
|
<%= render SubNavigationComponent.new(items: secondary_items(request.path, @organisation.id)) %> |
||||||
|
<h2 class="govuk-visually-hidden">Remove Managing Agent</h2> |
||||||
|
<% end %> |
||||||
|
<% if current_user.support? %> |
||||||
|
<%= govuk_back_link(href: :back) %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: "You are removing ‘#{@target_organisation.name}’ from this organisation's managing agents", sub: nil } %> |
||||||
|
<% else %> |
||||||
|
<% content_for :before_content do %> |
||||||
|
<%= govuk_back_link(href: :back) %> |
||||||
|
<% end %> |
||||||
|
<%= render partial: "organisations/headings", locals: { main: "You are removing ‘#{@target_organisation.name}’ from your organisation's managing agents", sub: nil } %> |
||||||
|
<% end %> |
||||||
|
<%= govuk_warning_text text: "#{@target_organisation.name} will no longer be able to submit logs for you" %> |
||||||
|
<div class="govuk-button-group"> |
||||||
|
<%= f.govuk_submit "Confirm" %> |
||||||
|
<%= govuk_button_link_to "Cancel", managing_agents_organisation_path(current_user.organisation), html: { method: :get }, secondary: true %> |
||||||
|
</div> |
||||||
|
<% end %> |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@ |
|||||||
|
class AddLaToSalesLog < ActiveRecord::Migration[7.0] |
||||||
|
def change |
||||||
|
change_table :sales_logs, bulk: true do |t| |
||||||
|
t.column :la, :string |
||||||
|
t.column :la_known, :integer |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,10 @@ |
|||||||
|
class AddRelationshipTypeToOrgRelationships < ActiveRecord::Migration[7.0] |
||||||
|
def change |
||||||
|
add_column( |
||||||
|
:organisation_relationships, |
||||||
|
:relationship_type, |
||||||
|
:integer, |
||||||
|
null: false, # rubocop:disable Rails/NotNullColumn |
||||||
|
) |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,5 @@ |
|||||||
|
class RenameManagingAgentsColumn < ActiveRecord::Migration[7.0] |
||||||
|
def change |
||||||
|
rename_column :organisations, :managing_agents, :managing_agents_label |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,14 @@ |
|||||||
|
FactoryBot.define do |
||||||
|
factory :organisation_relationship do |
||||||
|
child_organisation { FactoryBot.create(:organisation) } |
||||||
|
parent_organisation { FactoryBot.create(:organisation) } |
||||||
|
|
||||||
|
trait :owning do |
||||||
|
relationship_type { OrganisationRelationship::OWNING } |
||||||
|
end |
||||||
|
|
||||||
|
trait :managing do |
||||||
|
relationship_type { OrganisationRelationship::MANAGING } |
||||||
|
end |
||||||
|
end |
||||||
|
end |
|
@ -0,0 +1,583 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe OrganisationRelationshipsController, type: :request do |
||||||
|
let(:organisation) { user.organisation } |
||||||
|
let!(:unauthorised_organisation) { FactoryBot.create(:organisation) } |
||||||
|
let(:headers) { { "Accept" => "text/html" } } |
||||||
|
let(:page) { Capybara::Node::Simple.new(response.body) } |
||||||
|
|
||||||
|
context "when user is signed in" do |
||||||
|
let(:user) { FactoryBot.create(:user, :data_coordinator) } |
||||||
|
|
||||||
|
context "with a data coordinator user" do |
||||||
|
before do |
||||||
|
sign_in user |
||||||
|
end |
||||||
|
|
||||||
|
context "when accessing the housing providers tab" do |
||||||
|
context "with an organisation that the user belongs to" do |
||||||
|
let!(:housing_provider) { FactoryBot.create(:organisation) } |
||||||
|
let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") } |
||||||
|
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") } |
||||||
|
|
||||||
|
before do |
||||||
|
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) |
||||||
|
FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) |
||||||
|
get "/organisations/#{organisation.id}/housing-providers", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "shows the tab navigation" do |
||||||
|
expected_html = "<nav class=\"app-primary-navigation\"" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows an add housing provider button" do |
||||||
|
expect(page).to have_link("Add a housing provider") |
||||||
|
end |
||||||
|
|
||||||
|
it "shows a table of housing providers" do |
||||||
|
expected_html = "<table class=\"govuk-table\"" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
expect(response.body).to include(housing_provider.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows only housing providers for the current user's organisation" do |
||||||
|
expect(page).to have_content(housing_provider.name) |
||||||
|
expect(page).not_to have_content(other_org_housing_provider.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows the pagination count" do |
||||||
|
expect(page).to have_content("1 total housing providers") |
||||||
|
end |
||||||
|
|
||||||
|
context "when adding a housing provider" do |
||||||
|
before do |
||||||
|
get "/organisations/#{organisation.id}/housing-providers/add", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct header" do |
||||||
|
expect(response.body).to include("What is the name of your housing provider?") |
||||||
|
end |
||||||
|
|
||||||
|
it "shows an add button" do |
||||||
|
expect(page).to have_button("Add") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do |
||||||
|
before do |
||||||
|
get "/organisations/#{unauthorised_organisation.id}/housing-providers", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "returns not found 404 from users page" do |
||||||
|
expect(response).to have_http_status(:not_found) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when accessing the managing agents tab" do |
||||||
|
context "with an organisation that the user belongs to" do |
||||||
|
let!(:managing_agent) { FactoryBot.create(:organisation) } |
||||||
|
let!(:other_org_managing_agent) { FactoryBot.create(:organisation, name: "Foobar LTD") } |
||||||
|
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") } |
||||||
|
|
||||||
|
before do |
||||||
|
FactoryBot.create(:organisation_relationship, parent_organisation: organisation, child_organisation: managing_agent, relationship_type: OrganisationRelationship.relationship_types[:managing]) |
||||||
|
FactoryBot.create(:organisation_relationship, parent_organisation: other_organisation, child_organisation: other_org_managing_agent, relationship_type: OrganisationRelationship.relationship_types[:managing]) |
||||||
|
get "/organisations/#{organisation.id}/managing-agents", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "shows the tab navigation" do |
||||||
|
expected_html = "<nav class=\"app-primary-navigation\"" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows an add managing-agent button" do |
||||||
|
expect(page).to have_link("Add a managing agent") |
||||||
|
end |
||||||
|
|
||||||
|
it "shows a table of managing-agents" do |
||||||
|
expected_html = "<table class=\"govuk-table\"" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
expect(response.body).to include(managing_agent.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows only managing-agents for the current user's organisation" do |
||||||
|
expect(page).to have_content(managing_agent.name) |
||||||
|
expect(page).not_to have_content(other_org_managing_agent.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows the pagination count" do |
||||||
|
expect(page).to have_content("1 total agents") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when adding a managing agent" do |
||||||
|
before do |
||||||
|
get "/organisations/#{organisation.id}/managing-agents/add", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct header" do |
||||||
|
expect(response.body).to include("What is the name of your managing agent?") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do |
||||||
|
before do |
||||||
|
get "/organisations/#{unauthorised_organisation.id}/managing-agents", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "returns not found 404 from users page" do |
||||||
|
expect(response).to have_http_status(:not_found) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "organisation_relationships#create_housing_provider" do |
||||||
|
let!(:housing_provider) { FactoryBot.create(:organisation) } |
||||||
|
|
||||||
|
let(:params) do |
||||||
|
{ |
||||||
|
"organisation": { |
||||||
|
"related_organisation_id": housing_provider.id, |
||||||
|
}, |
||||||
|
} |
||||||
|
end |
||||||
|
|
||||||
|
let(:request) { post "/organisations/#{organisation.id}/housing-providers", headers:, params: } |
||||||
|
|
||||||
|
it "creates a new organisation relationship" do |
||||||
|
expect { request }.to change(OrganisationRelationship, :count).by(1) |
||||||
|
end |
||||||
|
|
||||||
|
it "sets the organisation relationship attributes correctly" do |
||||||
|
request |
||||||
|
expect(OrganisationRelationship).to exist(child_organisation_id: organisation.id, parent_organisation_id: housing_provider.id, relationship_type: OrganisationRelationship::OWNING) |
||||||
|
end |
||||||
|
|
||||||
|
it "redirects to the organisation list" do |
||||||
|
request |
||||||
|
expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "organisation_relationships#create_managing_agent" do |
||||||
|
let!(:managing_agent) { FactoryBot.create(:organisation) } |
||||||
|
|
||||||
|
let(:params) do |
||||||
|
{ |
||||||
|
"organisation": { |
||||||
|
"related_organisation_id": managing_agent.id, |
||||||
|
}, |
||||||
|
} |
||||||
|
end |
||||||
|
|
||||||
|
let(:request) { post "/organisations/#{organisation.id}/managing-agents", headers:, params: } |
||||||
|
|
||||||
|
it "creates a new organisation relationship" do |
||||||
|
expect { request }.to change(OrganisationRelationship, :count).by(1) |
||||||
|
end |
||||||
|
|
||||||
|
it "sets the organisation relationship attributes correctly" do |
||||||
|
request |
||||||
|
expect(OrganisationRelationship).to exist(parent_organisation_id: organisation.id, child_organisation_id: managing_agent.id, relationship_type: OrganisationRelationship::MANAGING) |
||||||
|
end |
||||||
|
|
||||||
|
it "redirects to the organisation list" do |
||||||
|
request |
||||||
|
expect(response).to redirect_to("/organisations/#{organisation.id}/managing-agents") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "organisation_relationships#delete_housing_provider" do |
||||||
|
let!(:housing_provider) { FactoryBot.create(:organisation) } |
||||||
|
let(:params) do |
||||||
|
{ |
||||||
|
"target_organisation_id": housing_provider.id, |
||||||
|
} |
||||||
|
end |
||||||
|
let(:request) { delete "/organisations/#{organisation.id}/housing-providers", headers:, params: } |
||||||
|
|
||||||
|
before do |
||||||
|
FactoryBot.create(:organisation_relationship, :owning, child_organisation: organisation, parent_organisation: housing_provider) |
||||||
|
end |
||||||
|
|
||||||
|
it "deletes the new organisation relationship" do |
||||||
|
expect { request }.to change(OrganisationRelationship, :count).by(-1) |
||||||
|
end |
||||||
|
|
||||||
|
it "redirects to the organisation list" do |
||||||
|
request |
||||||
|
expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "organisation_relationships#delete_managing_agent" do |
||||||
|
let!(:managing_agent) { FactoryBot.create(:organisation) } |
||||||
|
let(:params) do |
||||||
|
{ |
||||||
|
"target_organisation_id": managing_agent.id, |
||||||
|
} |
||||||
|
end |
||||||
|
let(:request) { delete "/organisations/#{organisation.id}/managing-agents", headers:, params: } |
||||||
|
|
||||||
|
before do |
||||||
|
FactoryBot.create( |
||||||
|
:organisation_relationship, |
||||||
|
:managing, |
||||||
|
parent_organisation: organisation, |
||||||
|
child_organisation: managing_agent, |
||||||
|
) |
||||||
|
end |
||||||
|
|
||||||
|
it "deletes the new organisation relationship" do |
||||||
|
expect { request }.to change(OrganisationRelationship, :count).by(-1) |
||||||
|
end |
||||||
|
|
||||||
|
it "redirects to the organisation list" do |
||||||
|
request |
||||||
|
expect(response).to redirect_to("/organisations/#{organisation.id}/managing-agents") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with a data provider user" do |
||||||
|
let(:user) { FactoryBot.create(:user) } |
||||||
|
|
||||||
|
before do |
||||||
|
sign_in user |
||||||
|
end |
||||||
|
|
||||||
|
context "when accessing the housing providers tab" do |
||||||
|
context "with an organisation that the user belongs to" do |
||||||
|
let!(:housing_provider) { FactoryBot.create(:organisation) } |
||||||
|
let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") } |
||||||
|
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") } |
||||||
|
|
||||||
|
before do |
||||||
|
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) |
||||||
|
FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) |
||||||
|
get "/organisations/#{organisation.id}/housing-providers", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "shows the tab navigation" do |
||||||
|
expected_html = "<nav class=\"app-primary-navigation\"" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
end |
||||||
|
|
||||||
|
it "doesn't show an add housing provider button" do |
||||||
|
expect(page).not_to have_link("Add a housing provider") |
||||||
|
end |
||||||
|
|
||||||
|
it "shows a table of housing providers" do |
||||||
|
expected_html = "<table class=\"govuk-table\"" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
expect(response.body).to include(housing_provider.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows only housing providers for the current user's organisation" do |
||||||
|
expect(page).to have_content(housing_provider.name) |
||||||
|
expect(page).not_to have_content(other_org_housing_provider.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows the pagination count" do |
||||||
|
expect(page).to have_content("1 total housing providers") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do |
||||||
|
before do |
||||||
|
get "/organisations/#{unauthorised_organisation.id}/housing-providers", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "returns not found 404 from users page" do |
||||||
|
expect(response).to have_http_status(:not_found) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when accessing the managing agents tab" do |
||||||
|
context "with an organisation that the user belongs to" do |
||||||
|
let!(:managing_agent) { FactoryBot.create(:organisation) } |
||||||
|
let!(:other_org_managing_agent) { FactoryBot.create(:organisation, name: "Foobar LTD") } |
||||||
|
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD") } |
||||||
|
|
||||||
|
before do |
||||||
|
FactoryBot.create(:organisation_relationship, parent_organisation: organisation, child_organisation: managing_agent, relationship_type: OrganisationRelationship.relationship_types[:managing]) |
||||||
|
FactoryBot.create(:organisation_relationship, parent_organisation: other_organisation, child_organisation: other_org_managing_agent, relationship_type: OrganisationRelationship.relationship_types[:managing]) |
||||||
|
get "/organisations/#{organisation.id}/managing-agents", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "shows the tab navigation" do |
||||||
|
expected_html = "<nav class=\"app-primary-navigation\"" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
end |
||||||
|
|
||||||
|
it "doesn't show an add managing agent button" do |
||||||
|
expect(page).not_to have_link("Add a managing agent") |
||||||
|
end |
||||||
|
|
||||||
|
it "shows a table of managing agents" do |
||||||
|
expected_html = "<table class=\"govuk-table\"" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
expect(response.body).to include(managing_agent.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows only managing agents for the current user's organisation" do |
||||||
|
expect(page).to have_content(managing_agent.name) |
||||||
|
expect(page).not_to have_content(other_org_managing_agent.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows the pagination count" do |
||||||
|
expect(page).to have_content("1 total agents") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when adding a managing agent" do |
||||||
|
before do |
||||||
|
get "/organisations/#{organisation.id}/managing-agents/add", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct header" do |
||||||
|
expect(response.body).to include("What is the name of your managing agent?") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with an organisation that are not in scope for the user, i.e. that they do not belong to" do |
||||||
|
before do |
||||||
|
get "/organisations/#{unauthorised_organisation.id}/managing-agents", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "returns not found 404 from users page" do |
||||||
|
expect(response).to have_http_status(:not_found) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "with a support user" do |
||||||
|
let(:user) { FactoryBot.create(:user, :support) } |
||||||
|
|
||||||
|
before do |
||||||
|
allow(user).to receive(:need_two_factor_authentication?).and_return(false) |
||||||
|
sign_in user |
||||||
|
end |
||||||
|
|
||||||
|
describe "organisation_relationships#create_housing_provider" do |
||||||
|
let!(:housing_provider) { FactoryBot.create(:organisation) } |
||||||
|
|
||||||
|
let(:params) do |
||||||
|
{ |
||||||
|
"organisation": { |
||||||
|
"related_organisation_id": housing_provider.id, |
||||||
|
}, |
||||||
|
} |
||||||
|
end |
||||||
|
|
||||||
|
let(:request) { post "/organisations/#{organisation.id}/housing-providers", headers:, params: } |
||||||
|
|
||||||
|
it "creates a new organisation relationship" do |
||||||
|
expect { request }.to change(OrganisationRelationship, :count).by(1) |
||||||
|
end |
||||||
|
|
||||||
|
it "sets the organisation relationship attributes correctly" do |
||||||
|
request |
||||||
|
expect(OrganisationRelationship).to exist(child_organisation_id: organisation.id, parent_organisation_id: housing_provider.id, relationship_type: OrganisationRelationship::OWNING) |
||||||
|
end |
||||||
|
|
||||||
|
it "redirects to the organisation list" do |
||||||
|
request |
||||||
|
expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "organisation_relationships#create_managing_agent" do |
||||||
|
let!(:managing_agent) { FactoryBot.create(:organisation) } |
||||||
|
|
||||||
|
let(:params) do |
||||||
|
{ |
||||||
|
"organisation": { |
||||||
|
"related_organisation_id": managing_agent.id, |
||||||
|
}, |
||||||
|
} |
||||||
|
end |
||||||
|
|
||||||
|
let(:request) { post "/organisations/#{organisation.id}/managing-agents", headers:, params: } |
||||||
|
|
||||||
|
it "creates a new organisation relationship" do |
||||||
|
expect { request }.to change(OrganisationRelationship, :count).by(1) |
||||||
|
end |
||||||
|
|
||||||
|
it "sets the organisation relationship attributes correctly" do |
||||||
|
request |
||||||
|
expect(OrganisationRelationship).to exist(parent_organisation_id: organisation.id, child_organisation_id: managing_agent.id, relationship_type: OrganisationRelationship::MANAGING) |
||||||
|
end |
||||||
|
|
||||||
|
it "redirects to the organisation list" do |
||||||
|
request |
||||||
|
expect(response).to redirect_to("/organisations/#{organisation.id}/managing-agents") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "organisation_relationships#delete_housing_provider" do |
||||||
|
let!(:housing_provider) { FactoryBot.create(:organisation) } |
||||||
|
let(:params) do |
||||||
|
{ |
||||||
|
"target_organisation_id": housing_provider.id, |
||||||
|
} |
||||||
|
end |
||||||
|
let(:request) { delete "/organisations/#{organisation.id}/housing-providers", headers:, params: } |
||||||
|
|
||||||
|
before do |
||||||
|
FactoryBot.create(:organisation_relationship, :owning, child_organisation: organisation, parent_organisation: housing_provider) |
||||||
|
end |
||||||
|
|
||||||
|
it "deletes the new organisation relationship" do |
||||||
|
expect { request }.to change(OrganisationRelationship, :count).by(-1) |
||||||
|
end |
||||||
|
|
||||||
|
it "redirects to the organisation list" do |
||||||
|
request |
||||||
|
expect(response).to redirect_to("/organisations/#{organisation.id}/housing-providers") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "organisation_relationships#delete_managing_agent" do |
||||||
|
let!(:managing_agent) { FactoryBot.create(:organisation) } |
||||||
|
let(:params) do |
||||||
|
{ |
||||||
|
"target_organisation_id": managing_agent.id, |
||||||
|
} |
||||||
|
end |
||||||
|
let(:request) { delete "/organisations/#{organisation.id}/managing-agents", headers:, params: } |
||||||
|
|
||||||
|
before do |
||||||
|
FactoryBot.create( |
||||||
|
:organisation_relationship, |
||||||
|
:managing, |
||||||
|
parent_organisation: organisation, |
||||||
|
child_organisation: managing_agent, |
||||||
|
) |
||||||
|
end |
||||||
|
|
||||||
|
it "deletes the new organisation relationship" do |
||||||
|
expect { request }.to change(OrganisationRelationship, :count).by(-1) |
||||||
|
end |
||||||
|
|
||||||
|
it "redirects to the organisation list" do |
||||||
|
request |
||||||
|
expect(response).to redirect_to("/organisations/#{organisation.id}/managing-agents") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when viewing a specific organisation's housing providers" do |
||||||
|
let!(:housing_provider) { FactoryBot.create(:organisation) } |
||||||
|
let!(:other_org_housing_provider) { FactoryBot.create(:organisation, name: "Foobar LTD") } |
||||||
|
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") } |
||||||
|
|
||||||
|
before do |
||||||
|
FactoryBot.create(:organisation_relationship, child_organisation: organisation, parent_organisation: housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) |
||||||
|
FactoryBot.create(:organisation_relationship, child_organisation: other_organisation, parent_organisation: other_org_housing_provider, relationship_type: OrganisationRelationship.relationship_types[:owning]) |
||||||
|
get "/organisations/#{organisation.id}/housing-providers", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "displays the name of the organisation" do |
||||||
|
expect(page).to have_content(organisation.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "has a sub-navigation with correct tabs" do |
||||||
|
expect(page).to have_css(".app-sub-navigation") |
||||||
|
expect(page).to have_content("Users") |
||||||
|
end |
||||||
|
|
||||||
|
it "shows a table of housing providers" do |
||||||
|
expected_html = "<table class=\"govuk-table\"" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
expect(response.body).to include(housing_provider.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows only housing providers for this organisation" do |
||||||
|
expect(page).to have_content(housing_provider.name) |
||||||
|
expect(page).not_to have_content(other_org_housing_provider.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows remove link(s)" do |
||||||
|
expect(response.body).to include("Remove") |
||||||
|
end |
||||||
|
|
||||||
|
it "shows the pagination count" do |
||||||
|
expect(page).to have_content("1 total housing providers") |
||||||
|
end |
||||||
|
|
||||||
|
context "when adding a housing provider" do |
||||||
|
before do |
||||||
|
get "/organisations/#{organisation.id}/housing-providers/add", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct header" do |
||||||
|
expect(response.body).to include("What is the name of this organisation's housing provider?") |
||||||
|
end |
||||||
|
|
||||||
|
it "shows an add button" do |
||||||
|
expect(page).to have_button("Add") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "when viewing a specific organisation's managing agents" do |
||||||
|
let!(:managing_agent) { FactoryBot.create(:organisation) } |
||||||
|
let!(:other_org_managing_agent) { FactoryBot.create(:organisation, name: "Foobar LTD") } |
||||||
|
let!(:other_organisation) { FactoryBot.create(:organisation, name: "Foobar LTD 2") } |
||||||
|
|
||||||
|
before do |
||||||
|
FactoryBot.create(:organisation_relationship, parent_organisation: organisation, child_organisation: managing_agent, relationship_type: OrganisationRelationship.relationship_types[:managing]) |
||||||
|
FactoryBot.create(:organisation_relationship, parent_organisation: other_organisation, child_organisation: other_org_managing_agent, relationship_type: OrganisationRelationship.relationship_types[:managing]) |
||||||
|
get "/organisations/#{organisation.id}/managing-agents", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "displays the name of the organisation" do |
||||||
|
expect(page).to have_content(organisation.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "has a sub-navigation with correct tabs" do |
||||||
|
expect(page).to have_css(".app-sub-navigation") |
||||||
|
expect(page).to have_content("Users") |
||||||
|
end |
||||||
|
|
||||||
|
it "shows a table of managing agents" do |
||||||
|
expected_html = "<table class=\"govuk-table\"" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
expect(response.body).to include(managing_agent.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows only managing agents for this organisation" do |
||||||
|
expect(page).to have_content(managing_agent.name) |
||||||
|
expect(page).not_to have_content(other_org_managing_agent.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows the pagination count" do |
||||||
|
expect(page).to have_content("1 total agents") |
||||||
|
end |
||||||
|
|
||||||
|
it "shows remove link(s)" do |
||||||
|
expect(response.body).to include("Remove") |
||||||
|
end |
||||||
|
|
||||||
|
context "when adding a housing provider" do |
||||||
|
before do |
||||||
|
get "/organisations/#{organisation.id}/managing-agents/add", headers:, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "has the correct header" do |
||||||
|
expect(response.body).to include("What is the name of this organisation's managing agent?") |
||||||
|
end |
||||||
|
|
||||||
|
it "shows an add button" do |
||||||
|
expect(page).to have_button("Add") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue