Protocol validation fix [SCI-7978]

This commit is contained in:
Martin Artnik 2023-02-24 17:28:36 +01:00
parent 89459ae21a
commit 7357782144

View file

@ -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?
}