Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/concerns/issuable_link.rb')
-rw-r--r--app/models/concerns/issuable_link.rb28
1 files changed, 25 insertions, 3 deletions
diff --git a/app/models/concerns/issuable_link.rb b/app/models/concerns/issuable_link.rb
index e884e5acecf..dcd2705185f 100644
--- a/app/models/concerns/issuable_link.rb
+++ b/app/models/concerns/issuable_link.rb
@@ -9,8 +9,8 @@
module IssuableLink
extend ActiveSupport::Concern
- TYPE_RELATES_TO = 'relates_to'
- TYPE_BLOCKS = 'blocks' ## EE-only. Kept here to be used on link_type enum.
+ MAX_LINKS_COUNT = 100
+ TYPE_RELATES_TO = Enums::IssuableLink::TYPE_RELATES_TO
class_methods do
def inverse_link_type(type)
@@ -38,10 +38,11 @@ module IssuableLink
validates :source, uniqueness: { scope: :target_id, message: 'is already related' }
validate :check_self_relation
validate :check_opposite_relation
+ validate :validate_max_number_of_links, on: :create
scope :for_source_or_target, ->(issuable) { where(source: issuable).or(where(target: issuable)) }
- enum link_type: { TYPE_RELATES_TO => 0, TYPE_BLOCKS => 1 }
+ enum link_type: Enums::IssuableLink.link_types
private
@@ -60,6 +61,27 @@ module IssuableLink
errors.add(:source, "is already related to this #{self.class.issuable_name}")
end
end
+
+ def validate_max_number_of_links
+ return unless source && target
+
+ validate_max_number_of_links_for(source, :source)
+ validate_max_number_of_links_for(target, :target)
+ end
+
+ def validate_max_number_of_links_for(item, attribute_name)
+ return unless item.linked_items_count >= MAX_LINKS_COUNT
+
+ errors.add(
+ attribute_name,
+ format(
+ s_('This %{issuable} would exceed the maximum number of linked %{issuables} (%{limit}).'),
+ issuable: self.class.issuable_name,
+ issuables: self.class.issuable_name.pluralize,
+ limit: MAX_LINKS_COUNT
+ )
+ )
+ end
end
end