mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-09 21:36:44 +08:00
Merge pull request #5023 from aignatov-bio/ai-sci-8003-update-protocol-name-validation
Fix protocol name validation [SCI-8003]
This commit is contained in:
commit
aa6e9bf1bf
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? }
|
validates :parent_id, uniqueness: { scope: :protocol_type }, if: -> { parent_id.present? }
|
||||||
validate :versions_same_name_constrain
|
validate :versions_same_name_constrain
|
||||||
end
|
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
|
# Active protocol must have unique name inside its team
|
||||||
protocol
|
protocol
|
||||||
.validates_uniqueness_of :name, case_sensitive: false,
|
.validates_uniqueness_of :name, case_sensitive: false,
|
||||||
scope: :team,
|
scope: :team,
|
||||||
conditions: lambda {
|
conditions: lambda {
|
||||||
active.where(
|
where(
|
||||||
protocol_type: [
|
protocol_type: [
|
||||||
Protocol.protocol_types[:in_repository_published_original],
|
Protocol.protocol_types[:in_repository_published_original],
|
||||||
Protocol.protocol_types[:in_repository_draft]
|
Protocol.protocol_types[:in_repository_draft]
|
||||||
]
|
],
|
||||||
|
parent_id: nil
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
with_options if: -> { in_repository? && archived? && !previous_version } do |protocol|
|
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_by, presence: true
|
||||||
protocol.validates :archived_on, presence: true
|
protocol.validates :archived_on, presence: true
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue