Skip to content

Commit

Permalink
Merge pull request #2177 from unboxed/organise-state-machine-methods
Browse files Browse the repository at this point in the history
Move application state methods into concern
  • Loading branch information
benjamineskola authored Feb 19, 2025
2 parents 4cf448d + b7af51a commit 21ebb45
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 60 deletions.
52 changes: 52 additions & 0 deletions app/models/concerns/planning_application_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,57 @@ module PlanningApplicationStatus

after_all_transitions :timestamp_status_change # FIXME: https://github.com/aasm/aasm#timestamps
end

def recommendable?
true unless closed_or_cancelled? || invalidated? || not_started?
end

def in_progress?
true unless closed_or_cancelled?
end

def validated?
true unless not_started? || invalidated?
end

def can_validate?
true unless awaiting_determination? || closed_or_cancelled?
end

def validation_complete?
!not_started?
end

def can_assess?
assessment_in_progress? || in_assessment? || to_be_reviewed?
end

def closed_or_cancelled?
determined? || returned? || withdrawn? || closed?
end

def can_submit_recommendation?
assessment_complete? && (in_assessment? || to_be_reviewed?)
end

def submit_recommendation_complete?
awaiting_determination? || determined?
end

def publish_complete?
determined?
end

def officer_can_draw_boundary?
not_started? || invalidated?
end

def can_edit_documents?
can_validate? || publish_complete?
end

def review_complete?
to_be_reviewed? || determined?
end
end
end
60 changes: 0 additions & 60 deletions app/models/planning_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,6 @@ def application_number
self[:application_number].to_s.rjust(5, "0")
end

def reviewer_disagrees_with_assessor?
to_be_reviewed?
end

def assessor_decision_updated?
awaiting_determination? && recommendations.count > 1
end
Expand All @@ -292,50 +288,10 @@ def applicant?
applicant_first_name? || applicant_last_name? || applicant_phone? || applicant_email?
end

def review_complete?
to_be_reviewed? || determined?
end

def recommendable?
true unless closed_or_cancelled? || invalidated? || not_started?
end

def in_progress?
true unless closed_or_cancelled?
end

def validated?
true unless not_started? || invalidated?
end

def can_validate?
true unless awaiting_determination? || closed_or_cancelled?
end

def validation_complete?
!not_started?
end

def can_assess?
assessment_in_progress? || in_assessment? || to_be_reviewed?
end

def closed_or_cancelled?
determined? || returned? || withdrawn? || closed?
end

def assessment_complete?
(validation_complete? && pending_review? && !assessment_in_progress?) || awaiting_determination? || determined?
end

def can_submit_recommendation?
assessment_complete? && (in_assessment? || to_be_reviewed?)
end

def submit_recommendation_complete?
awaiting_determination? || determined?
end

def can_review_assessment?
(awaiting_determination? || in_committee?) && Current.user.reviewer?
end
Expand All @@ -348,10 +304,6 @@ def can_publish?
awaiting_determination? && !pending_review?
end

def publish_complete?
determined?
end

def refused_with_public_comment?
refused? && public_comment.present?
end
Expand All @@ -360,14 +312,6 @@ def pending_review?
recommendations.pending_review.any?
end

def pending_recommendation?
may_assess? && !pending_review?
end

def officer_can_draw_boundary?
not_started? || invalidated?
end

def pending_or_new_recommendation
recommendations.pending_review.last || recommendations.build
end
Expand All @@ -380,10 +324,6 @@ def consultees_checked?
consultation&.consultees_checked?
end

def can_edit_documents?
can_validate? || publish_complete?
end

def proposal_details
Array(super).each_with_index.map do |hash, index|
ProposalDetail.new(hash, index)
Expand Down

0 comments on commit 21ebb45

Please sign in to comment.