Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
4.9 KiB

class OrganisationRelationshipsController < ApplicationController
include Pagy::Backend
include Modules::SearchFilter
before_action :authenticate_user!
before_action :authenticate_scope!
before_action :organisations
before_action :target_organisation, only: %i[
remove_stock_owner
remove_managing_agent
delete_stock_owner
delete_managing_agent
]
def stock_owners
stock_owners = organisation.stock_owners.filter_by_active
unpaginated_filtered_stock_owners = filtered_collection(stock_owners, search_term)
@pagy, @stock_owners = pagy(unpaginated_filtered_stock_owners)
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
@searched = search_term.presence
@total_count = stock_owners.size
end
def managing_agents
managing_agents = organisation.managing_agents.filter_by_active
unpaginated_filtered_managing_agents = filtered_collection(managing_agents, search_term)
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
@pagy, @managing_agents = pagy(unpaginated_filtered_managing_agents)
@searched = search_term.presence
@total_count = managing_agents.size
end
def add_stock_owner
@organisation_relationship = organisation.parent_organisation_relationships.new
authorize @organisation_relationship
Cldc 1662 add housing provider (#954) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: remove create_managing_agent * test: add support user tests * test: add create_housing_provider tests * refactor: rubocop autocorrect * refactor: erblinting * test: fix tests * refactor: erblinting * feat: don't use !important tag Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
end
def add_managing_agent
@organisation_relationship = organisation.child_organisation_relationships.new
authorize @organisation_relationship
end
def create_stock_owner
@organisation_relationship = organisation.parent_organisation_relationships.new(organisation_relationship_params)
authorize @organisation_relationship
if @organisation_relationship.save(context: :stock_owner)
flash[:notice] = "#{@organisation_relationship.parent_organisation.name} is now one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} stock owners"
redirect_to stock_owners_organisation_path
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
else
@organisations = Organisation.filter_by_active.where.not(id: organisation.id).pluck(:id, :name)
render "organisation_relationships/add_stock_owner", status: :unprocessable_entity
Cldc 1662 add housing provider (#954) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: remove create_managing_agent * test: add support user tests * test: add create_housing_provider tests * refactor: rubocop autocorrect * refactor: erblinting * test: fix tests * refactor: erblinting * feat: don't use !important tag Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
end
end
def create_managing_agent
@organisation_relationship = organisation.child_organisation_relationships.new(organisation_relationship_params)
authorize @organisation_relationship
if @organisation_relationship.save
flash[:notice] = "#{@organisation_relationship.child_organisation.name} is now one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} managing agents"
redirect_to managing_agents_organisation_path
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
else
@organisations = Organisation.filter_by_active.where.not(id: organisation.id).pluck(:id, :name)
render "organisation_relationships/add_managing_agent", status: :unprocessable_entity
end
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
end
def remove_stock_owner
organisation_relationship = OrganisationRelationship.find_by!(
parent_organisation: @target_organisation,
child_organisation: organisation,
)
authorize organisation_relationship
end
def delete_stock_owner
OrganisationRelationship.find_by!(
child_organisation: organisation,
parent_organisation: target_organisation,
).destroy!
flash[:notice] = "#{target_organisation.name} is no longer one of #{current_user.data_coordinator? ? 'your' : "this organisation's"} stock owners"
redirect_to stock_owners_organisation_path
end
def remove_managing_agent
organisation_relationship = OrganisationRelationship.find_by!(
parent_organisation: organisation,
child_organisation: @target_organisation,
)
authorize organisation_relationship
end
def delete_managing_agent
OrganisationRelationship.find_by!(
parent_organisation: organisation,
child_organisation: target_organisation,
).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 organisation
@organisation ||= if current_user.support?
Organisation.find(params[:id])
else
current_user.organisation
end
Cldc 1662 add housing provider (#954) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: remove create_managing_agent * test: add support user tests * test: add create_housing_provider tests * refactor: rubocop autocorrect * refactor: erblinting * test: fix tests * refactor: erblinting * feat: don't use !important tag Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
end
def organisations
@organisations ||= Organisation.filter_by_active.where.not(id: organisation.id).pluck(:id, :name)
end
def parent_organisation
@parent_organisation ||= Organisation.find(params[:organisation_relationship][:parent_organisation_id])
end
def child_organisation
@child_organisation ||= Organisation.find(params[:organisation_relationship][:child_organisation_id])
Cldc 1662 add housing provider (#954) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: remove create_managing_agent * test: add support user tests * test: add create_housing_provider tests * refactor: rubocop autocorrect * refactor: erblinting * test: fix tests * refactor: erblinting * feat: don't use !important tag Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
end
Cldc 1663 remove housing provider (#957) * wip * Rename managing_agents column * add managing relationship * f * feat: add my features branched off managing agents branch * feat: update nav behaviour * feat: simplify housing_providers view * feat: fix pluralise to default to plural rather than singular * feat: remove managing agent related code so can be merged directly * tests: update tests and add new ones for housing_providers * refactor: rubocop conciliation * tests: fix failing navigation tests * tests: one more plural test * refactor: erb linting * refactor: erb linting * feat: right-align "Remove" text * feat: update nokogiri to pass bundler-audit * feat: grey out search button * feat: remove section-break * feat: add housing provider page with details and button * feat: tidy up routing * feat: add wip housing provider behaviour without functioning search * feat: wip add housing provider functionality hard coded to add FooBar LTD as provider to DLUHC * feat: remove redundant code * feat: add data passing behaviour without accessible autocomplete * feat: use accessible autocomplete (not working) * feat: use accessible autocomplete (now working) * feat: wip commit error messages * feat: add banner always * feat: add conditional banner behaviour, back link and update logs titles * feat: add search icon to accessible autocomplete, make hint text aligned correctly * feat: use pluck not all * tests: add initial test * feat: refactor create logic * feat: add sub org title * feat: add correct no housing providers text * feat: add correct no housing providers text * tests: add tests for add housing provider page * feat: remove unnecessary line from controller * fet: simplify controller args * fet: update schema * feat: update schema * feat: add core removal functionality * fix: make secondary navbar display selected org not user org for support users * refactor: tidy up code and add single quotes instead of apostrophes * refactor: remove unnecessary lines * test: add housing provider removal tests * feat: use path helpers and beng methods * refactor: linting * refactor: erblinting * refactor: renaming and tidying * refactor: simplify format response and paths and remove redundant rendering * feat: user flash notices instead of explicit notification banners * test: update tests with new urls * feat: add target org helper * feat: add target org helper fix * feat: add related org helper * test: update paths in tests Co-authored-by: Jack S <jacopo.scotti@softwire.com>
2 years ago
def target_organisation
@target_organisation ||= Organisation.find(params[:target_organisation_id])
end
def search_term
params["search"]
end
def organisation_relationship_params
params.require(:organisation_relationship).permit(:parent_organisation_id, :child_organisation_id)
end
def authenticate_scope!
if current_user.organisation != Organisation.find(params[:id]) && !current_user.support?
render_not_found
end
end
end