Skip to content

Commit

Permalink
Fallback to custom title with previous value if item title gets blank.
Browse files Browse the repository at this point in the history
If an item has the title field set to claim title or fact-check title and one of those are deleted, then in order to avoid that the title gets blank, the title field is set to "custom_title" and the value is the previous title value.

Reference: CV2-3986.
  • Loading branch information
caiosba committed Jan 5, 2024
1 parent eb0dc5b commit ab47a35
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/models/concerns/project_media_cached_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,10 @@ def recalculate_description
end

def recalculate_title
self.get_title
title = self.get_title
# Always save the title as a custom title so we can fallback to it in case the title gets blank (for example, title_field is claim title and claim is deleted)
title.blank? ? self.update_column(:title_field, 'custom_title') : self.update_column(:custom_title, title)
title.blank? ? self.custom_title&.to_s : title
end

def recalculate_status
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/project_media_getters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def get_title
custom_title: :custom_title,
pinned_media_id: :media_slug,
claim_title: :claim_description_content,
fact_check_title: :fact_check_title
fact_check_title: :recalculate_fact_check_title
}
title_field = self.title_field&.to_sym
if !title_field.blank? && title_mapping.keys.include?(title_field)
Expand Down

0 comments on commit ab47a35

Please sign in to comment.