From 5e932d998543bde8f2d5c7525d8e193e8bc282ad Mon Sep 17 00:00:00 2001 From: Sawy Date: Tue, 13 Aug 2024 15:00:48 +0300 Subject: [PATCH] CV2-5051: log FactCheck update and add meta for ClaimDescription logs --- app/models/claim_description.rb | 4 ++++ app/models/explainer_item.rb | 11 ++++------- app/models/version.rb | 9 +++++++-- .../20240812063317_add_user_to_explainer_item.rb | 5 ----- db/schema.rb | 5 +---- 5 files changed, 16 insertions(+), 18 deletions(-) delete mode 100644 db/migrate/20240812063317_add_user_to_explainer_item.rb diff --git a/app/models/claim_description.rb b/app/models/claim_description.rb index 048f72a4d5..a0a212adee 100644 --- a/app/models/claim_description.rb +++ b/app/models/claim_description.rb @@ -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 diff --git a/app/models/explainer_item.rb b/app/models/explainer_item.rb index b08b95c54d..7fc5be1f49 100644 --- a/app/models/explainer_item.rb +++ b/app/models/explainer_item.rb @@ -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 diff --git a/app/models/version.rb b/app/models/version.rb index 7f431f40fd..7c13f00601 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -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] diff --git a/db/migrate/20240812063317_add_user_to_explainer_item.rb b/db/migrate/20240812063317_add_user_to_explainer_item.rb deleted file mode 100644 index f5672be744..0000000000 --- a/db/migrate/20240812063317_add_user_to_explainer_item.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddUserToExplainerItem < ActiveRecord::Migration[6.1] - def change - add_reference(:explainer_items, :user, foreign_key: true, null: true) - end -end diff --git a/db/schema.rb b/db/schema.rb index 160391520e..2ba6278e80 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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| @@ -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"