From 452547564e0c610642ba8c37a691e7e8f4ef3490 Mon Sep 17 00:00:00 2001 From: Andrej Date: Tue, 30 Jul 2024 10:41:06 +0200 Subject: [PATCH 1/2] Enable protocol template renaming [SCI-10851] --- app/controllers/protocols_controller.rb | 1 - app/models/protocol.rb | 8 -------- config/locales/en.yml | 1 - 3 files changed, 10 deletions(-) diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index b0ade7fb4..63a782d59 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -909,7 +909,6 @@ class ProtocolsController < ApplicationController end def set_inline_name_editing - return unless @protocol.initial_draft? return unless can_manage_protocol_draft_in_repository?(@protocol) @inline_editable_title_config = { diff --git a/app/models/protocol.rb b/app/models/protocol.rb index a1a69b3d8..f26da6f07 100644 --- a/app/models/protocol.rb +++ b/app/models/protocol.rb @@ -70,12 +70,10 @@ class Protocol < ApplicationRecord with_options if: :in_repository_published_version? do validates :parent, presence: true validate :parent_type_constraint - validate :versions_same_name_constraint end with_options if: :in_repository_draft? do # Only one draft can exist for each protocol validate :ensure_single_draft - validate :versions_same_name_constraint end with_options if: -> { in_repository? && !parent && !archived_changed?(from: false) } do |protocol| # Active protocol must have unique name inside its team @@ -797,12 +795,6 @@ class Protocol < ApplicationRecord end end - def versions_same_name_constraint - if parent.present? && !parent.name.eql?(name) - errors.add(:base, I18n.t('activerecord.errors.models.protocol.wrong_version_name')) - end - end - def version_number_constraint if Protocol.where(protocol_type: Protocol::REPOSITORY_TYPES) .where.not(id: id) diff --git a/config/locales/en.yml b/config/locales/en.yml index a6e68a6b6..9eb819df6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -166,7 +166,6 @@ en: protocol: unchangable: "Published protocols can not be changed!" 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: From d707f9121c71a96bbd8853d719f473d14b913e64 Mon Sep 17 00:00:00 2001 From: Andrej Date: Tue, 29 Oct 2024 15:12:27 +0100 Subject: [PATCH 2/2] Remove constraint for the protocol template name [SCI-10851] --- app/models/protocol.rb | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/app/models/protocol.rb b/app/models/protocol.rb index 1c961de68..6a5a61e2a 100644 --- a/app/models/protocol.rb +++ b/app/models/protocol.rb @@ -75,21 +75,6 @@ class Protocol < ApplicationRecord # Only one draft can exist for each protocol validate :ensure_single_draft end - with_options if: -> { in_repository? && !parent && !archived_changed?(from: false) } do |protocol| - # Active protocol must have unique name inside its team - protocol - .validates_uniqueness_of :name, case_sensitive: false, - scope: :team, - conditions: lambda { - 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| protocol.validates :archived_by, presence: true protocol.validates :archived_on, presence: true