Browse Source

Address comments

pull/1620/head
Jack S 3 years ago
parent
commit
9c766025c4
  1. 26
      app/controllers/lettings_logs_controller.rb
  2. 20
      app/controllers/sales_logs_controller.rb
  3. 2
      app/policies/lettings_log_policy.rb
  4. 2
      app/policies/sales_log_policy.rb

26
app/controllers/lettings_logs_controller.rb

@ -1,5 +1,8 @@
class LettingsLogsController < LogsController
before_action :find_resource, except: %i[create index edit delete_confirmation]
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
before_action :find_resource, only: %i[update show]
before_action :session_filters, if: :current_user, only: %i[index email_csv download_csv]
before_action :set_session_filters, if: :current_user, only: %i[index email_csv download_csv]
before_action :authenticate_scope!, only: %i[download_csv email_csv]
@ -55,22 +58,19 @@ class LettingsLogsController < LogsController
end
def edit
@log = current_user.lettings_logs.find_by(id: params[:id])
if @log
@log = current_user.lettings_logs.find(params[:id])
if @log.unresolved
redirect_to(send(@log.form.unresolved_log_path, @log))
else
render("logs/edit", locals: { current_user: })
end
else
render_not_found
end
end
def destroy
render_not_found and return unless @log
@log = LettingsLog.visible.find(params[:id])
authorize @log, policy_class: LogPolicy
authorize @log
@log.discard!
@ -78,11 +78,9 @@ class LettingsLogsController < LogsController
end
def delete_confirmation
@log = LettingsLog.visible.find_by(id: params[:lettings_log_id])
@log = LettingsLog.visible.find(params[:lettings_log_id])
render_not_found and return unless @log
authorize @log, :destroy?, policy_class: LogPolicy
authorize @log, :destroy?
render "logs/delete_confirmation"
end
@ -113,14 +111,14 @@ class LettingsLogsController < LogsController
end
end
private
def org_params
super.merge(
{ "managing_organisation_id" => current_user.organisation.id },
)
end
private
def authenticate_scope!
head :unauthorized and return if codes_only_export? && !current_user.support?
end

20
app/controllers/sales_logs_controller.rb

@ -1,4 +1,6 @@
class SalesLogsController < LogsController
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
before_action :session_filters, if: :current_user, only: %i[index email_csv download_csv]
before_action :set_session_filters, if: :current_user, only: %i[index email_csv download_csv]
before_action :authenticate_scope!, only: %i[download_csv email_csv]
@ -32,20 +34,14 @@ class SalesLogsController < LogsController
end
def edit
@log = current_user.sales_logs.visible.find_by(id: params[:id])
if @log
@log = current_user.sales_logs.visible.find(params[:id])
render "logs/edit", locals: { current_user: }
else
render_not_found
end
end
def destroy
@log = SalesLog.visible.find_by(id: params[:id])
@log = SalesLog.visible.find(params[:id])
render_not_found and return unless @log
authorize @log, policy_class: LogPolicy
authorize @log
@log.discard!
@ -53,11 +49,9 @@ class SalesLogsController < LogsController
end
def delete_confirmation
@log = SalesLog.visible.find_by(id: params[:sales_log_id])
render_not_found and return unless @log
@log = SalesLog.visible.find(params[:sales_log_id])
authorize @log, :destroy?, policy_class: LogPolicy
authorize @log, :destroy?
render "logs/delete_confirmation"
end

2
app/policies/lettings_log_policy.rb

@ -0,0 +1,2 @@
class LettingsLogPolicy < LogPolicy
end

2
app/policies/sales_log_policy.rb

@ -0,0 +1,2 @@
class SalesLogPolicy < LogPolicy
end
Loading…
Cancel
Save