Browse Source

only show visible sales logs

pull/1503/head
Phil Lee 3 years ago
parent
commit
5ae227870b
  1. 4
      app/controllers/sales_logs_controller.rb
  2. 2
      app/models/lettings_log.rb
  3. 2
      app/models/log.rb
  4. 16
      spec/requests/sales_logs_controller_spec.rb

4
app/controllers/sales_logs_controller.rb

@ -9,7 +9,7 @@ class SalesLogsController < LogsController
def index def index
respond_to do |format| respond_to do |format|
format.html do 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) unpaginated_filtered_logs = filtered_logs(all_logs, search_term, @session_filters)
@search_term = search_term @search_term = search_term
@ -28,7 +28,7 @@ class SalesLogsController < LogsController
end end
def edit 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 if @log
render "logs/edit", locals: { current_user: } render "logs/edit", locals: { current_user: }
else else

2
app/models/lettings_log.rb

@ -53,8 +53,6 @@ class LettingsLog < Log
scope :unresolved, -> { where(unresolved: true) } scope :unresolved, -> { where(unresolved: true) }
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } 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 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 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 RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze

2
app/models/log.rb

@ -17,6 +17,8 @@ class Log < ApplicationRecord
enum status: STATUS enum status: STATUS
enum status_cache: STATUS, _prefix: true 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_status, ->(status, _user = nil) { where status: }
scope :filter_by_years, lambda { |years, _user = nil| scope :filter_by_years, lambda { |years, _user = nil|
first_year = years.shift first_year = years.shift

16
spec/requests/sales_logs_controller_spec.rb

@ -159,6 +159,22 @@ RSpec.describe SalesLogsController, type: :request do
end end
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 "when filtering" do
context "with status filter" do context "with status filter" do
let(:organisation_2) { FactoryBot.create(:organisation) } let(:organisation_2) { FactoryBot.create(:organisation) }

Loading…
Cancel
Save