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

forbid_issue_type_column_usage.rb « issues « concerns « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 46a8a0278d94112878d2008cb5292e3de801bf5f (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true

# TODO: Remove with https://gitlab.com/gitlab-org/gitlab/-/issues/402699
module Issues
  module ForbidIssueTypeColumnUsage
    extend ActiveSupport::Concern

    ForbiddenColumnUsed = Class.new(StandardError)

    included do
      WorkItems::Type.base_types.each do |base_type, _value|
        define_method "#{base_type}?".to_sym do
          error_message = <<~ERROR
            `#{model_name.element}.#{base_type}?` uses the `issue_type` column underneath. As we want to remove the column,
            its usage is forbidden. You should use the `work_item_types` table instead.

            # Before

            #{model_name.element}.#{base_type}? => true

            # After

            #{model_name.element}.work_item_type.#{base_type}? => true

            More details in https://gitlab.com/groups/gitlab-org/-/epics/10529
          ERROR

          raise ForbiddenColumnUsed, error_message
        end

        define_singleton_method base_type.to_sym do
          error = ForbiddenColumnUsed.new(
            <<~ERROR
              `#{name}.#{base_type}` uses the `issue_type` column underneath. As we want to remove the column,
              its usage is forbidden. You should use the `work_item_types` table instead.

              # Before

              #{name}.#{base_type}

              # After

              #{name}.with_issue_type(:#{base_type})

              More details in https://gitlab.com/groups/gitlab-org/-/epics/10529
            ERROR
          )

          Gitlab::ErrorTracking.track_and_raise_for_dev_exception(
            error,
            method_name: "#{name}.#{base_type}"
          )

          with_issue_type(base_type.to_sym)
        end
      end
    end
  end
end