diff --git a/app/models/protocol.rb b/app/models/protocol.rb index 36068b95c..8ce4f25a2 100644 --- a/app/models/protocol.rb +++ b/app/models/protocol.rb @@ -69,33 +69,22 @@ class Protocol < ApplicationRecord validates :parent_id, uniqueness: { scope: :protocol_type }, if: -> { parent_id.present? } validate :versions_same_name_constrain end - with_options if: -> { in_repository? && active? && !parent } do |protocol| + with_options if: -> { in_repository? && !parent } do |protocol| # Active protocol must have unique name inside its team protocol .validates_uniqueness_of :name, case_sensitive: false, scope: :team, conditions: lambda { - active.where( + where( protocol_type: [ Protocol.protocol_types[:in_repository_published_original], Protocol.protocol_types[:in_repository_draft] - ] + ], + parent_id: nil ) } end with_options if: -> { in_repository? && archived? && !previous_version } do |protocol| - # Archived protocol must have unique name inside its team - protocol - .validates_uniqueness_of :name, case_sensitive: false, - scope: :team, - conditions: lambda { - archived.where( - protocol_type: [ - Protocol.protocol_types[:in_repository_published_original], - Protocol.protocol_types[:in_repository_draft] - ] - ) - } protocol.validates :archived_by, presence: true protocol.validates :archived_on, presence: true end