mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-25 00:03:27 +08:00
Fix protocol name validation [SCI-8003]
This commit is contained in:
parent
8906bc25e7
commit
dd27b13537
1 changed files with 4 additions and 15 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue