mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 23:16:15 +08:00
Fix validation for multiple parent protocols for drafts [SCI-7994] (#5020)
* Fix validation for multiple parent protocols for drafts [SCI-7994] * Fix validation for drafts [SCI-7994] * Fix validation for drafts [SCI-7994]
This commit is contained in:
parent
ced0da6dbc
commit
95d04d11d2
|
@ -66,7 +66,7 @@ class Protocol < ApplicationRecord
|
|||
end
|
||||
with_options if: :in_repository_draft? do
|
||||
# Only one draft can exist for each protocol
|
||||
validates :parent_id, uniqueness: { scope: :protocol_type }, if: -> { parent_id.present? }
|
||||
validate :ensure_single_draft
|
||||
validate :versions_same_name_constrain
|
||||
end
|
||||
with_options if: -> { in_repository? && !parent } do |protocol|
|
||||
|
@ -744,4 +744,10 @@ class Protocol < ApplicationRecord
|
|||
errors.add(:base, I18n.t('activerecord.errors.models.protocol.wrong_version_number'))
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_single_draft
|
||||
if parent&.draft && parent.draft.id != id
|
||||
errors.add(:base, I18n.t('activerecord.errors.models.protocol.wrong_parent_draft_number'))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -152,6 +152,7 @@ en:
|
|||
wrong_parent_type: "Protocol can only be linked to published protocol!"
|
||||
wrong_version_name: "Protocol versions should have same name!"
|
||||
wrong_version_number: "Protocol version number should be sequential!"
|
||||
wrong_parent_draft_number: "Procol can have only 1 draft"
|
||||
attributes:
|
||||
step_order:
|
||||
invalid: "Invalid step order."
|
||||
|
|
Loading…
Reference in a new issue