Skip to content

Commit

Permalink
Merge pull request #16024 from hellcp-work/refactor-decision-kind-3
Browse files Browse the repository at this point in the history
Get rid of kind from the decision model
  • Loading branch information
danidoni committed Apr 24, 2024
2 parents ebba548 + 4258759 commit b4c594f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
4 changes: 1 addition & 3 deletions src/api/app/controllers/webui/decisions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def create
private

def decision_params
# TODO: remove merge and replace decision_kind with decision_type
kind = params[:decision][:type] == 'DecisionFavored' ? 'favor' : 'cleared'
params.require(:decision).permit(:reason, :type, report_ids: []).merge(kind: kind)
params.require(:decision).permit(:reason, :type, report_ids: [])
end
end
18 changes: 2 additions & 16 deletions src/api/app/models/decision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ class Decision < ApplicationRecord

has_many :reports, dependent: :nullify

# TODO: Remove this after type is deployed
enum kind: {
cleared: 0,
favor: 1
}

after_create :create_event
after_create :track_decision

def description
Expand All @@ -41,23 +34,16 @@ def self.display_name

private

# TODO: Replace this with `AbstractMethodCalled` after type is deployed
def create_event
case kind
when 'cleared'
Event::ClearedDecision.create(event_parameters)
else
Event::FavoredDecision.create(event_parameters)
end
raise AbstractMethodCalled
end

def event_parameters
{ id: id, moderator_id: moderator.id, reason: reason, report_last_id: reports.last.id, reportable_type: reports.first.reportable.class.name }
end

# TODO: Remove kind after type is deployed
def track_decision
RabbitmqBus.send_to_bus('metrics', "decision,kind=#{kind},type=#{type} hours_before_decision=#{hours_before_decision},count=1")
RabbitmqBus.send_to_bus('metrics', "decision,type=#{type} hours_before_decision=#{hours_before_decision},count=1")
end

def hours_before_decision
Expand Down

0 comments on commit b4c594f

Please sign in to comment.