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.

207 lines
6.9 KiB

CLDC-2290 implement delete multiple logs story (#1657) * add a button to the logs list to delete multiple logs style and position of button helpers for displaying the button conditionally depending on user role and what filters and search are active * correct indentation from 4 spaces to 2 in view file * test appearance of delete logs button on index page for lettings logs * write a happy path feature test for the entire journey * create basic tests for the view component for listing logs to delete * create request tests for the GET delete-logs path * create request tests for the GET delete-logs-confirmation path * create request tests for the DELETE delete-logs path * comprehensive reworking after code review ensure that we are not passing lists of ids through params in the query string, risking overflowing the maximum URL length, adjust tests accordingly, do not attempt to reuse the same table for sales and lettings * alter config to allow creating controllers from the command line with associated spec files that matches how we test * extract controller methods and associated tests to do with the delete logs feature into their own controller, amend routes accordingly * implement same work for sales as for lettings * implement the story for lettings and sales logs under the organisation tab routing and controller methods testing for deleting sales logs, lettings or sales logs for an organisation move storage of relevant routes inside the form object as a comprehensive view model * merge the delete pages for lettings logs and sales logs, add to the tests for the lettings page to test sales specific content * minor refactor to delete logs controller: ensure session filters are only fetched from teh session when needed and extract discard logs method to private method * extract tables for lettings and sales to own partials * refactor delete logs controller after tech review improve the private method that builds the form object so that it has the flexibility to do so for all controller methods ensure that the search term is passed to the delete logs controller when navigating through the organisations tab ensure that noly logs for that organisation are displayed when navigating to delete logs through the organisations tab * remove unnecessary untested arguments * test new helper methods * implement dirty fiddle to get the checkboxes smaller and also not misaligned * ensure delete logs button is always visible on log lists when in the organisations tab * minor linting corrections * revert change, causing errors and outside the scope of this ticket * simplify tests for whether delete logs button appears on index page * replicate request specs from lettings for sales and organisations controllers * minor refactor of lettings log feature spec setup, replicate happy path for sales * minor refactors after rebasing onto Nat's work * temp * write tests for the delete logs form object * lint: add new line at end of file * respond to PO feedback the log id in the delte logs table should be a link to the log the delete logs button should be visible when the user is in a bulk upload journey updated associated tests
1 year ago
class DeleteLogsController < ApplicationController
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
before_action :session_filters, if: :current_user, except: %i[discard_lettings_logs discard_sales_logs discard_lettings_logs_for_organisation discard_sales_logs_for_organisation]
before_action :add_organisation_to_filters, only: %i[delete_lettings_logs_for_organisation delete_lettings_logs_for_organisation_with_selected_ids delete_lettings_logs_for_organisation_confirmation delete_sales_logs_for_organisation delete_sales_logs_for_organisation_with_selected_ids delete_sales_logs_for_organisation_confirmation]
def delete_lettings_logs
@delete_logs_form = delete_logs_form(log_type: :lettings)
render "logs/delete_logs"
end
def delete_lettings_logs_with_selected_ids
@delete_logs_form = delete_logs_form(log_type: :lettings, selected_ids:)
render "logs/delete_logs"
end
def delete_lettings_logs_confirmation
@delete_logs_form = delete_logs_form(log_type: :lettings, form_params:)
if @delete_logs_form.valid?
render "logs/delete_logs_confirmation"
else
render "logs/delete_logs"
end
end
def discard_lettings_logs
logs = LettingsLog.find(params.require(:ids))
discard logs
if request.referer&.include?("delete-duplicates")
redirect_to lettings_log_duplicate_logs_path(lettings_log_id: params["remaining_log_id"], original_log_id: params["original_log_id"]), notice: I18n.t("notification.duplicate_logs_deleted", count: logs.count, log_ids: duplicate_log_ids(logs))
else
redirect_to lettings_logs_path, notice: I18n.t("notification.logs_deleted", count: logs.count)
end
CLDC-2290 implement delete multiple logs story (#1657) * add a button to the logs list to delete multiple logs style and position of button helpers for displaying the button conditionally depending on user role and what filters and search are active * correct indentation from 4 spaces to 2 in view file * test appearance of delete logs button on index page for lettings logs * write a happy path feature test for the entire journey * create basic tests for the view component for listing logs to delete * create request tests for the GET delete-logs path * create request tests for the GET delete-logs-confirmation path * create request tests for the DELETE delete-logs path * comprehensive reworking after code review ensure that we are not passing lists of ids through params in the query string, risking overflowing the maximum URL length, adjust tests accordingly, do not attempt to reuse the same table for sales and lettings * alter config to allow creating controllers from the command line with associated spec files that matches how we test * extract controller methods and associated tests to do with the delete logs feature into their own controller, amend routes accordingly * implement same work for sales as for lettings * implement the story for lettings and sales logs under the organisation tab routing and controller methods testing for deleting sales logs, lettings or sales logs for an organisation move storage of relevant routes inside the form object as a comprehensive view model * merge the delete pages for lettings logs and sales logs, add to the tests for the lettings page to test sales specific content * minor refactor to delete logs controller: ensure session filters are only fetched from teh session when needed and extract discard logs method to private method * extract tables for lettings and sales to own partials * refactor delete logs controller after tech review improve the private method that builds the form object so that it has the flexibility to do so for all controller methods ensure that the search term is passed to the delete logs controller when navigating through the organisations tab ensure that noly logs for that organisation are displayed when navigating to delete logs through the organisations tab * remove unnecessary untested arguments * test new helper methods * implement dirty fiddle to get the checkboxes smaller and also not misaligned * ensure delete logs button is always visible on log lists when in the organisations tab * minor linting corrections * revert change, causing errors and outside the scope of this ticket * simplify tests for whether delete logs button appears on index page * replicate request specs from lettings for sales and organisations controllers * minor refactor of lettings log feature spec setup, replicate happy path for sales * minor refactors after rebasing onto Nat's work * temp * write tests for the delete logs form object * lint: add new line at end of file * respond to PO feedback the log id in the delte logs table should be a link to the log the delete logs button should be visible when the user is in a bulk upload journey updated associated tests
1 year ago
end
def delete_sales_logs
@delete_logs_form = delete_logs_form(log_type: :sales)
render "logs/delete_logs"
end
def delete_sales_logs_with_selected_ids
@delete_logs_form = delete_logs_form(log_type: :sales, selected_ids:)
render "logs/delete_logs"
end
def delete_sales_logs_confirmation
@delete_logs_form = delete_logs_form(log_type: :sales, form_params:)
if @delete_logs_form.valid?
render "logs/delete_logs_confirmation"
else
render "logs/delete_logs"
end
end
def discard_sales_logs
logs = SalesLog.find(params.require(:ids))
discard logs
if request.referer&.include?("delete-duplicates")
redirect_to sales_log_duplicate_logs_path(sales_log_id: params["remaining_log_id"], original_log_id: params["original_log_id"]), notice: I18n.t("notification.duplicate_logs_deleted", count: logs.count, log_ids: duplicate_log_ids(logs))
else
redirect_to sales_logs_path, notice: I18n.t("notification.logs_deleted", count: logs.count)
end
CLDC-2290 implement delete multiple logs story (#1657) * add a button to the logs list to delete multiple logs style and position of button helpers for displaying the button conditionally depending on user role and what filters and search are active * correct indentation from 4 spaces to 2 in view file * test appearance of delete logs button on index page for lettings logs * write a happy path feature test for the entire journey * create basic tests for the view component for listing logs to delete * create request tests for the GET delete-logs path * create request tests for the GET delete-logs-confirmation path * create request tests for the DELETE delete-logs path * comprehensive reworking after code review ensure that we are not passing lists of ids through params in the query string, risking overflowing the maximum URL length, adjust tests accordingly, do not attempt to reuse the same table for sales and lettings * alter config to allow creating controllers from the command line with associated spec files that matches how we test * extract controller methods and associated tests to do with the delete logs feature into their own controller, amend routes accordingly * implement same work for sales as for lettings * implement the story for lettings and sales logs under the organisation tab routing and controller methods testing for deleting sales logs, lettings or sales logs for an organisation move storage of relevant routes inside the form object as a comprehensive view model * merge the delete pages for lettings logs and sales logs, add to the tests for the lettings page to test sales specific content * minor refactor to delete logs controller: ensure session filters are only fetched from teh session when needed and extract discard logs method to private method * extract tables for lettings and sales to own partials * refactor delete logs controller after tech review improve the private method that builds the form object so that it has the flexibility to do so for all controller methods ensure that the search term is passed to the delete logs controller when navigating through the organisations tab ensure that noly logs for that organisation are displayed when navigating to delete logs through the organisations tab * remove unnecessary untested arguments * test new helper methods * implement dirty fiddle to get the checkboxes smaller and also not misaligned * ensure delete logs button is always visible on log lists when in the organisations tab * minor linting corrections * revert change, causing errors and outside the scope of this ticket * simplify tests for whether delete logs button appears on index page * replicate request specs from lettings for sales and organisations controllers * minor refactor of lettings log feature spec setup, replicate happy path for sales * minor refactors after rebasing onto Nat's work * temp * write tests for the delete logs form object * lint: add new line at end of file * respond to PO feedback the log id in the delte logs table should be a link to the log the delete logs button should be visible when the user is in a bulk upload journey updated associated tests
1 year ago
end
def delete_lettings_logs_for_organisation
@delete_logs_form = delete_logs_form(log_type: :lettings, organisation: true)
render "logs/delete_logs"
end
def delete_lettings_logs_for_organisation_with_selected_ids
@delete_logs_form = delete_logs_form(log_type: :lettings, organisation: true, selected_ids:)
render "logs/delete_logs"
end
def delete_lettings_logs_for_organisation_confirmation
@delete_logs_form = delete_logs_form(log_type: :lettings, organisation: true, form_params:)
if @delete_logs_form.valid?
render "logs/delete_logs_confirmation"
else
render "logs/delete_logs"
end
end
def discard_lettings_logs_for_organisation
logs = LettingsLog.where(owning_organisation: params[:id]).find(params.require(:ids))
discard logs
redirect_to lettings_logs_organisation_path, notice: I18n.t("notification.logs_deleted", count: logs.count)
end
def delete_sales_logs_for_organisation
@delete_logs_form = delete_logs_form(log_type: :sales, organisation: true)
render "logs/delete_logs"
end
def delete_sales_logs_for_organisation_with_selected_ids
@delete_logs_form = delete_logs_form(log_type: :sales, organisation: true, selected_ids:)
render "logs/delete_logs"
end
def delete_sales_logs_for_organisation_confirmation
@delete_logs_form = delete_logs_form(log_type: :sales, organisation: true, form_params:)
if @delete_logs_form.valid?
render "logs/delete_logs_confirmation"
else
render "logs/delete_logs"
end
end
def discard_sales_logs_for_organisation
logs = SalesLog.where(owning_organisation: params[:id]).find(params.require(:ids))
discard logs
redirect_to sales_logs_organisation_path, notice: I18n.t("notification.logs_deleted", count: logs.count)
end
private
def session_filters
@session_filters ||= filter_manager.session_filters
end
def filter_manager
log_type = action_name.include?("lettings") ? "lettings_logs" : "sales_logs"
FilterManager.new(current_user:, session:, params:, filter_type: log_type)
end
def delete_logs_form(log_type:, organisation: false, selected_ids: nil, form_params: {})
paths = case log_type
when :lettings
organisation ? lettings_logs_for_organisation_paths : lettings_logs_paths
when :sales
organisation ? sales_logs_for_organisation_paths : sales_logs_paths
end
attributes = {
log_type:,
current_user:,
log_filters: @session_filters,
search_term:,
selected_ids:,
**paths,
}.merge(form_params).transform_keys(&:to_sym)
Forms::DeleteLogsForm.new(attributes)
end
def form_params
form_attributes = params.require(:forms_delete_logs_form).permit(:search_term, selected_ids: [])
form_attributes[:selected_ids] = [] unless form_attributes.key? :selected_ids
form_attributes
end
def lettings_logs_paths
{
delete_confirmation_path: delete_logs_confirmation_lettings_logs_path,
back_to_logs_path: lettings_logs_path(search: search_term),
delete_path: delete_logs_lettings_logs_path,
}
end
def sales_logs_paths
{
delete_confirmation_path: delete_logs_confirmation_sales_logs_path,
back_to_logs_path: sales_logs_path(search: search_term),
delete_path: delete_logs_sales_logs_path,
}
end
def lettings_logs_for_organisation_paths
{
delete_confirmation_path: delete_lettings_logs_confirmation_organisation_path,
back_to_logs_path: lettings_logs_organisation_path(search: search_term),
delete_path: delete_lettings_logs_organisation_path,
}
end
def sales_logs_for_organisation_paths
{
delete_confirmation_path: delete_sales_logs_confirmation_organisation_path,
back_to_logs_path: sales_logs_organisation_path(search: search_term),
delete_path: delete_sales_logs_organisation_path,
}
end
def add_organisation_to_filters
@session_filters[:organisation] = params[:id]
end
def search_term
params["search"]
end
def selected_ids
params.require(:selected_ids).split.map(&:to_i)
end
def discard(logs)
logs.each do |log|
authorize log, :destroy?
log.discard!
end
end
def duplicate_log_ids(logs)
logs.map { |log| "Log #{log.id}" }.to_sentence(last_word_connector: " and ")
end
CLDC-2290 implement delete multiple logs story (#1657) * add a button to the logs list to delete multiple logs style and position of button helpers for displaying the button conditionally depending on user role and what filters and search are active * correct indentation from 4 spaces to 2 in view file * test appearance of delete logs button on index page for lettings logs * write a happy path feature test for the entire journey * create basic tests for the view component for listing logs to delete * create request tests for the GET delete-logs path * create request tests for the GET delete-logs-confirmation path * create request tests for the DELETE delete-logs path * comprehensive reworking after code review ensure that we are not passing lists of ids through params in the query string, risking overflowing the maximum URL length, adjust tests accordingly, do not attempt to reuse the same table for sales and lettings * alter config to allow creating controllers from the command line with associated spec files that matches how we test * extract controller methods and associated tests to do with the delete logs feature into their own controller, amend routes accordingly * implement same work for sales as for lettings * implement the story for lettings and sales logs under the organisation tab routing and controller methods testing for deleting sales logs, lettings or sales logs for an organisation move storage of relevant routes inside the form object as a comprehensive view model * merge the delete pages for lettings logs and sales logs, add to the tests for the lettings page to test sales specific content * minor refactor to delete logs controller: ensure session filters are only fetched from teh session when needed and extract discard logs method to private method * extract tables for lettings and sales to own partials * refactor delete logs controller after tech review improve the private method that builds the form object so that it has the flexibility to do so for all controller methods ensure that the search term is passed to the delete logs controller when navigating through the organisations tab ensure that noly logs for that organisation are displayed when navigating to delete logs through the organisations tab * remove unnecessary untested arguments * test new helper methods * implement dirty fiddle to get the checkboxes smaller and also not misaligned * ensure delete logs button is always visible on log lists when in the organisations tab * minor linting corrections * revert change, causing errors and outside the scope of this ticket * simplify tests for whether delete logs button appears on index page * replicate request specs from lettings for sales and organisations controllers * minor refactor of lettings log feature spec setup, replicate happy path for sales * minor refactors after rebasing onto Nat's work * temp * write tests for the delete logs form object * lint: add new line at end of file * respond to PO feedback the log id in the delte logs table should be a link to the log the delete logs button should be visible when the user is in a bulk upload journey updated associated tests
1 year ago
end