From 5ae227870b319dbd3be973b26a61c280b99dc415 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Wed, 5 Apr 2023 11:06:36 +0100 Subject: [PATCH] only show visible sales logs --- app/controllers/sales_logs_controller.rb | 4 ++-- app/models/lettings_log.rb | 2 -- app/models/log.rb | 2 ++ spec/requests/sales_logs_controller_spec.rb | 16 ++++++++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/controllers/sales_logs_controller.rb b/app/controllers/sales_logs_controller.rb index ecfeabcad..155f606ab 100644 --- a/app/controllers/sales_logs_controller.rb +++ b/app/controllers/sales_logs_controller.rb @@ -9,7 +9,7 @@ class SalesLogsController < LogsController def index respond_to do |format| format.html do - all_logs = current_user.sales_logs + all_logs = current_user.sales_logs.visible unpaginated_filtered_logs = filtered_logs(all_logs, search_term, @session_filters) @search_term = search_term @@ -28,7 +28,7 @@ class SalesLogsController < LogsController end def edit - @log = current_user.sales_logs.find_by(id: params[:id]) + @log = current_user.sales_logs.visible.find_by(id: params[:id]) if @log render "logs/edit", locals: { current_user: } else diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 9e55bd0e5..4a0651a29 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -53,8 +53,6 @@ class LettingsLog < Log scope :unresolved, -> { where(unresolved: true) } scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } - scope :visible, -> { where(status: %w[not_started in_progress completed]) } - AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenancycode propcode chcharge].freeze RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze diff --git a/app/models/log.rb b/app/models/log.rb index 30293548a..bc036d356 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -17,6 +17,8 @@ class Log < ApplicationRecord enum status: STATUS enum status_cache: STATUS, _prefix: true + scope :visible, -> { where(status: %w[not_started in_progress completed]) } + scope :filter_by_status, ->(status, _user = nil) { where status: } scope :filter_by_years, lambda { |years, _user = nil| first_year = years.shift diff --git a/spec/requests/sales_logs_controller_spec.rb b/spec/requests/sales_logs_controller_spec.rb index 14341cd33..e400366df 100644 --- a/spec/requests/sales_logs_controller_spec.rb +++ b/spec/requests/sales_logs_controller_spec.rb @@ -159,6 +159,22 @@ RSpec.describe SalesLogsController, type: :request do end end + context "when there is a pending log" do + let!(:invisible_log) do + FactoryBot.create( + :sales_log, + owning_organisation: organisation, + status: "pending", + skip_update_status: true, + ) + end + + it "does not render pending logs" do + get "/sales-logs", headers: headers, params: {} + expect(page).not_to have_content(invisible_log.id) + end + end + context "when filtering" do context "with status filter" do let(:organisation_2) { FactoryBot.create(:organisation) }