From 7357782144a1b962f32ad868dc8005d6ed4f2d73 Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Fri, 24 Feb 2023 17:28:36 +0100 Subject: [PATCH] Protocol validation fix [SCI-7978] --- app/models/protocol.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/protocol.rb b/app/models/protocol.rb index 619643cad..1a7046187 100644 --- a/app/models/protocol.rb +++ b/app/models/protocol.rb @@ -16,10 +16,10 @@ class Protocol < ApplicationRecord include TinyMceImages before_validation :assign_version_number, on: :update, if: -> { protocol_type_changed? && in_repository_published? } - after_update :update_user_assignments, if: -> { saved_change_to_protocol_type? && in_repository? } - after_destroy :decrement_linked_children - after_save :update_linked_children after_create :auto_assign_protocol_members, if: :visible? + after_destroy :decrement_linked_children + after_save :update_user_assignments, if: -> { saved_change_to_visibility? && in_repository? } + after_save :update_linked_children skip_callback :create, :after, :create_users_assignments, if: -> { in_module? } enum visibility: { hidden: 0, visible: 1 } @@ -40,7 +40,8 @@ class Protocol < ApplicationRecord validate :prevent_update, on: :update, if: lambda { - changes.keys != %w(default_public_user_role_id) && # skip check if only public role changed + # skip check if only public role of visibility changed + (changes.keys | %w(default_public_user_role_id visibility)).length != 2 && in_repository_published? && !protocol_type_changed?(from: 'in_repository_draft') && !archived_changed? }