Skip to content

Commit

Permalink
CV2-5051: log FactCheck update and add meta for ClaimDescription logs
Browse files Browse the repository at this point in the history
  • Loading branch information
melsawy committed Aug 13, 2024
1 parent 1dbf2ee commit 5e932d9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
4 changes: 4 additions & 0 deletions app/models/claim_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def project_media_was
ProjectMedia.find_by_id(self.project_media_id_before_last_save)
end

def version_metadata(_changes)
{ fact_check: self.fact_check&.title }.to_json
end

private

def set_team
Expand Down
11 changes: 4 additions & 7 deletions app/models/explainer_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ class ExplainerItem < ApplicationRecord

belongs_to :explainer
belongs_to :project_media
belongs_to :user

before_validation :set_user

validates_presence_of :explainer, :project_media
validate :same_team

def version_metadata(_changes)
{ explainer_title: self.explainer.title }.to_json
end

private

def same_team
errors.add(:base, I18n.t(:explainer_and_item_must_be_from_the_same_team)) unless self.explainer&.team_id == self.project_media&.team_id
end

def set_user
self.user = User.current unless User.current.nil?
end
end
9 changes: 7 additions & 2 deletions app/models/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ def get_associated
when 'create_assignment', 'destroy_assignment'
self.get_associated_from_assignment
when 'create_claimdescription', 'update_claimdescription'
['ProjectMedia', self.item.project_media_id]
when 'create_factcheck'
pm_id = self.item.project_media_id
if pm_id.nil?
changes = self.get_object_changes
pm_id = changes['project_media_id'][0] if changes.has_key?('project_media_id') && changes['project_media_id'][1].nil?
end
['ProjectMedia', pm_id]
when 'create_factcheck', 'update_factcheck'
['ProjectMedia', self.item.claim_description.project_media_id]
when 'create_explaineritem', 'destroy_explaineritem'
['ProjectMedia', self.item.project_media_id]
Expand Down
5 changes: 0 additions & 5 deletions db/migrate/20240812063317_add_user_to_explainer_item.rb

This file was deleted.

5 changes: 1 addition & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_08_12_063317) do
ActiveRecord::Schema.define(version: 2024_07_19_183518) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -309,11 +309,9 @@
t.bigint "project_media_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "user_id"
t.index ["explainer_id", "project_media_id"], name: "index_explainer_items_on_explainer_id_and_project_media_id", unique: true
t.index ["explainer_id"], name: "index_explainer_items_on_explainer_id"
t.index ["project_media_id"], name: "index_explainer_items_on_project_media_id"
t.index ["user_id"], name: "index_explainer_items_on_user_id"
end

create_table "explainers", force: :cascade do |t|
Expand Down Expand Up @@ -931,7 +929,6 @@
add_foreign_key "claim_descriptions", "users"
add_foreign_key "explainer_items", "explainers"
add_foreign_key "explainer_items", "project_medias"
add_foreign_key "explainer_items", "users"
add_foreign_key "explainers", "teams"
add_foreign_key "explainers", "users"
add_foreign_key "fact_checks", "claim_descriptions"
Expand Down

0 comments on commit 5e932d9

Please sign in to comment.