Skip to content

Commit

Permalink
Sync'ing report status between item and fact-check
Browse files Browse the repository at this point in the history
  • Loading branch information
caiosba committed Jul 23, 2024
1 parent b3a8c11 commit 31fa8c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/models/claim_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def update_fact_check
if fact_check && self.project_media_id
fact_check.updated_at = Time.now
fact_check.save!
fact_check.update_item_status
end
end
end
26 changes: 16 additions & 10 deletions app/models/fact_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class FactCheck < ApplicationRecord
validates_format_of :url, with: URI.regexp, allow_blank: true, allow_nil: true
validate :language_in_allowed_values, :title_or_summary_exists, :rating_in_allowed_values

before_save :set_report_status
after_save :update_report, unless: proc { |fc| fc.skip_report_update || !DynamicAnnotation::AnnotationType.where(annotation_type: 'report_design').exists? || fc.project_media.blank? }
after_save :update_item_status, if: proc { |fc| fc.saved_change_to_rating? }

Expand All @@ -35,6 +36,16 @@ def team
self.claim_description&.team
end

def update_item_status
pm = self.project_media
s = pm&.last_status_obj
if !s.nil? && s.status != self.rating
s.skip_check_ability = true
s.status = self.rating
s.save!
end
end

private

def set_language
Expand Down Expand Up @@ -102,16 +113,6 @@ def update_report
reports.save!
end

def update_item_status
pm = self.project_media
s = pm&.last_status_obj
if !s.nil? && s.status != self.rating
s.skip_check_ability = true
s.status = self.rating
s.save!
end
end

def article_elasticsearch_data(action = 'create_or_update')
return if self.disable_es_callbacks || RequestStore.store[:disable_es_callbacks]
data = action == 'destroy' ? {
Expand All @@ -133,4 +134,9 @@ def set_initial_rating
default_rating = self.claim_description.team.verification_statuses('media', nil)['default']
self.rating = pm_rating || default_rating
end

def set_report_status
pm_report_status = self.project_media&.report_status
self.report_status = pm_report_status if pm_report_status && pm_report_status != self.report_status
end
end

0 comments on commit 31fa8c5

Please sign in to comment.