From cf0799462ae1252324d2b641a54bf3ae1bcacd6a Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Tue, 9 Apr 2024 09:16:33 +0200 Subject: [PATCH] Add previewable update_data! to repository checklist value [SCI-10582] --- app/models/repository_checklist_value.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/models/repository_checklist_value.rb b/app/models/repository_checklist_value.rb index d9a37dfc5..a79f62b4b 100644 --- a/app/models/repository_checklist_value.rb +++ b/app/models/repository_checklist_value.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class RepositoryChecklistValue < ApplicationRecord + attribute :current_repository_checklist_items + belongs_to :created_by, foreign_key: 'created_by_id', class_name: 'User', inverse_of: :created_repository_checklist_values belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User', @@ -78,11 +80,18 @@ class RepositoryChecklistValue < ApplicationRecord self.last_modified_by = user - self.repository_checklist_items = repository_cell.repository_column - .repository_checklist_items - .where(id: item_ids) - - preview ? validate : save! + if preview + self.current_repository_checklist_items = repository_checklist_items + clear_current_repository_checklist_items_change + self.current_repository_checklist_items = + repository_cell.repository_column.repository_checklist_items.where(id: item_ids) + validate + else + self.repository_checklist_items = repository_cell.repository_column + .repository_checklist_items + .where(id: item_ids) + save! + end end def snapshot!(cell_snapshot)