Merge pull request #7516 from aignatov-bio/ai-sci-10432-fix-activties-for-deleted-results

Fix activties for deleted results [SCI-10432]
This commit is contained in:
Martin Artnik 2024-05-24 10:36:54 +02:00 committed by GitHub
commit 2b610f0b04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 28 additions and 5 deletions

View file

@ -121,7 +121,7 @@ class ResultsController < ApplicationController
def destroy
name = @result.name
if @result.destroy
if @result.discard
log_activity(:destroy_result, { destroyed_result: name })
render json: {}, status: :ok
else

View file

@ -56,6 +56,7 @@ class MyModule < ApplicationRecord
belongs_to :changing_from_my_module_status, optional: true, class_name: 'MyModuleStatus'
delegate :my_module_status_flow, to: :my_module_status, allow_nil: true
has_many :results, inverse_of: :my_module, dependent: :destroy
has_many :results_include_discarded, -> { with_discarded }, class_name: 'Result', inverse_of: :my_module
has_many :my_module_tags, inverse_of: :my_module, dependent: :destroy
has_many :tags, through: :my_module_tags, dependent: :destroy
has_many :task_comments, foreign_key: :associated_id, dependent: :destroy

View file

@ -5,6 +5,9 @@ class Result < ApplicationRecord
include SearchableModel
include SearchableByNameModel
include ViewableModel
include Discard::Model
default_scope -> { kept }
auto_strip_attributes :name, nullify: false
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }

View file

@ -55,9 +55,20 @@ class ActivitiesService
child_model = parent_model.reflect_on_association(child).class_name.to_sym
next if subjects[child_model]
subjects[child_model] = parent_model.where(id: subjects[subject_name])
.joins(child)
.pluck("#{child.to_s.pluralize}.id")
if subject_name == 'Result'
parent_model = parent_model.with_discarded
end
if child == :results
subjects[child_model] = parent_model.where(id: subjects[subject_name])
.joins(:results_include_discarded)
.pluck('results.id')
else
subjects[child_model] = parent_model.where(id: subjects[subject_name])
.joins(child)
.pluck("#{child.to_s.pluralize}.id")
end
end
end

View file

@ -0,0 +1,6 @@
class AddDiscardedAtToResults < ActiveRecord::Migration[7.0]
def change
add_column :results, :discarded_at, :datetime
add_index :results, :discarded_at
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2024_01_18_094253) do
ActiveRecord::Schema[7.0].define(version: 2024_04_29_070135) do
# These are extensions that must be enabled in order to support this database
enable_extension "btree_gist"
enable_extension "pg_trgm"
@ -984,10 +984,12 @@ ActiveRecord::Schema[7.0].define(version: 2024_01_18_094253) do
t.bigint "restored_by_id"
t.datetime "restored_on", precision: nil
t.integer "assets_view_mode", default: 0
t.datetime "discarded_at"
t.index "trim_html_tags((name)::text) gin_trgm_ops", name: "index_results_on_name", using: :gin
t.index ["archived"], name: "index_results_on_archived"
t.index ["archived_by_id"], name: "index_results_on_archived_by_id"
t.index ["created_at"], name: "index_results_on_created_at"
t.index ["discarded_at"], name: "index_results_on_discarded_at"
t.index ["last_modified_by_id"], name: "index_results_on_last_modified_by_id"
t.index ["my_module_id"], name: "index_results_on_my_module_id"
t.index ["restored_by_id"], name: "index_results_on_restored_by_id"