Skip to content

Commit

Permalink
Refactor CaseContact form controller:
Browse files Browse the repository at this point in the history
- Introduced `set_case_contact` filter for DRYness.
- Applied `set_case_contact` filter before `show` and `update` actions.
- Removed duplicate fetching of `@case_contact` in those actions.
  • Loading branch information
yosefbennywidyo committed May 11, 2024
1 parent f5d5348 commit ca31f6a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/controllers/case_contacts/form_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ class CaseContacts::FormController < ApplicationController

before_action :set_progress
before_action :require_organization!
before_action :set_case_contact, only: [:show, :update]
after_action :verify_authorized

steps(*CaseContact::FORM_STEPS)

# wizard_path
def show
@case_contact = CaseContact.find(params[:case_contact_id])
authorize @case_contact
get_cases_and_contact_types
@page = wizard_steps.index(step) + 1
Expand All @@ -20,7 +20,6 @@ def show
end

def update
@case_contact = CaseContact.find(params[:case_contact_id])
authorize @case_contact
params[:case_contact][:status] = step.to_s if !@case_contact.active? && params.key?(:case_contact)
remove_unwanted_contact_types
Expand Down Expand Up @@ -49,6 +48,10 @@ def update

private

def set_case_contact
@case_contact = CaseContact.find(params[:case_contact_id])
end

def get_cases_and_contact_types
@casa_cases = policy_scope(current_organization.casa_cases)
@casa_cases = @casa_cases.where(id: @case_contact.casa_case_id) if @case_contact.active?
Expand Down

0 comments on commit ca31f6a

Please sign in to comment.