|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 | 3 | class Label < ApplicationRecord
|
4 |
| - include CacheMarkdownField |
| 4 | + include BaseLabel |
5 | 5 | include Referable
|
6 | 6 | include Subscribable
|
7 |
| - include Gitlab::SQL::Pattern |
8 | 7 | include OptionallySearch
|
9 | 8 | include Sortable
|
10 | 9 | include FromUnion
|
11 | 10 | include Presentable
|
12 | 11 | include EachBatch
|
13 | 12 |
|
14 |
| - cache_markdown_field :description, pipeline: :single_line |
15 |
| - |
16 |
| - DEFAULT_COLOR = ::Gitlab::Color.of('#6699cc') |
17 | 13 | DESCRIPTION_LENGTH_MAX = 512.kilobytes
|
18 | 14 |
|
19 |
| - attribute :color, ::Gitlab::Database::Type::Color.new, default: DEFAULT_COLOR |
20 |
| - |
21 | 15 | has_many :lists, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
22 | 16 | has_many :priorities, class_name: 'LabelPriority'
|
23 | 17 | has_many :label_links, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
24 | 18 | has_many :issues, through: :label_links, source: :target, source_type: 'Issue'
|
25 | 19 | has_many :merge_requests, through: :label_links, source: :target, source_type: 'MergeRequest'
|
26 | 20 |
|
27 |
| - before_validation :strip_whitespace_from_title |
28 | 21 | before_destroy :prevent_locked_label_destroy, prepend: true
|
29 | 22 |
|
30 |
| - validates :color, color: true, presence: true |
31 | 23 | validate :ensure_lock_on_merge_allowed
|
32 |
| - |
33 |
| - # Don't allow ',' for label titles |
34 |
| - validates :title, presence: true, format: { with: /\A[^,]+\z/ } |
35 | 24 | validates :title, uniqueness: { scope: [:group_id, :project_id] }
|
36 |
| - validates :title, length: { maximum: 255 } |
37 | 25 |
|
38 | 26 | # we validate the description against DESCRIPTION_LENGTH_MAX only for labels being created and on updates if
|
39 | 27 | # the description changes to avoid breaking the existing labels which may have their descriptions longer
|
@@ -182,34 +170,6 @@ def self.ids_on_board(board_id)
|
182 | 170 | on_board(board_id).pluck(:label_id)
|
183 | 171 | end
|
184 | 172 |
|
185 |
| - # Searches for labels with a matching title or description. |
186 |
| - # |
187 |
| - # This method uses ILIKE on PostgreSQL. |
188 |
| - # |
189 |
| - # query - The search query as a String. |
190 |
| - # |
191 |
| - # Returns an ActiveRecord::Relation. |
192 |
| - def self.search(query, **options) |
193 |
| - # make sure we prevent passing in disallowed columns |
194 |
| - search_in = case options[:search_in] |
195 |
| - when [:title] |
196 |
| - [:title] |
197 |
| - when [:description] |
198 |
| - [:description] |
199 |
| - else |
200 |
| - [:title, :description] |
201 |
| - end |
202 |
| - |
203 |
| - fuzzy_search(query, search_in) |
204 |
| - end |
205 |
| - |
206 |
| - # Override Gitlab::SQL::Pattern.min_chars_for_partial_matching as |
207 |
| - # label queries are never global, and so will not use a trigram |
208 |
| - # index. That means we can have just one character in the LIKE. |
209 |
| - def self.min_chars_for_partial_matching |
210 |
| - 1 |
211 |
| - end |
212 |
| - |
213 | 173 | def self.on_project_board?(project_id, label_id)
|
214 | 174 | return false if label_id.blank?
|
215 | 175 |
|
@@ -259,30 +219,6 @@ def priority?
|
259 | 219 | priorities.present?
|
260 | 220 | end
|
261 | 221 |
|
262 |
| - def color |
263 |
| - super || DEFAULT_COLOR |
264 |
| - end |
265 |
| - |
266 |
| - def text_color |
267 |
| - color.contrast |
268 |
| - end |
269 |
| - |
270 |
| - def title=(value) |
271 |
| - if value.blank? |
272 |
| - super |
273 |
| - else |
274 |
| - write_attribute(:title, sanitize_value(value)) |
275 |
| - end |
276 |
| - end |
277 |
| - |
278 |
| - def description=(value) |
279 |
| - if value.blank? |
280 |
| - super |
281 |
| - else |
282 |
| - write_attribute(:description, sanitize_value(value)) |
283 |
| - end |
284 |
| - end |
285 |
| - |
286 | 222 | ##
|
287 | 223 | # Returns the String necessary to reference this Label in Markdown
|
288 | 224 | #
|
@@ -362,14 +298,6 @@ def label_format_reference(format = :id)
|
362 | 298 | end
|
363 | 299 | end
|
364 | 300 |
|
365 |
| - def sanitize_value(value) |
366 |
| - CGI.unescapeHTML(Sanitize.clean(value.to_s)) |
367 |
| - end |
368 |
| - |
369 |
| - def strip_whitespace_from_title |
370 |
| - self[:title] = title&.strip |
371 |
| - end |
372 |
| - |
373 | 301 | def prevent_locked_label_destroy
|
374 | 302 | return unless lock_on_merge
|
375 | 303 |
|
|
0 commit comments