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

type.rb « work_item « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 16cb7a8be45045c1c8caa00676d2db788ff43a05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

# Note: initial thinking behind `icon_name` is for it to do triple duty:
# 1. one of our svg icon names, such as `external-link` or a new one `bug`
# 2. if it's an absolute url, then url to a user uploaded icon/image
# 3. an emoji, with the format of `:smile:`
class WorkItem::Type < ApplicationRecord
  self.table_name = 'work_item_types'

  include CacheMarkdownField

  cache_markdown_field :description, pipeline: :single_line

  enum base_type: {
    issue:       0,
    incident:    1,
    test_case:   2, ## EE-only
    requirement: 3 ## EE-only
  }

  belongs_to :namespace, optional: true
  has_many :work_items, class_name: 'Issue', foreign_key: :work_item_type_id, inverse_of: :work_item_type

  before_validation :strip_whitespace

  # TODO: review validation rules
  # https://gitlab.com/gitlab-org/gitlab/-/issues/336919
  validates :name, presence: true
  validates :name, uniqueness: { case_sensitive: false, scope: [:namespace_id] }
  validates :name, length: { maximum: 255 }
  validates :icon_name, length: { maximum: 255 }

  private

  def strip_whitespace
    name&.strip!
  end
end