summaryrefslogtreecommitdiff
path: root/lib/gitlab/background_migration/user_mentions/models/note.rb
blob: 7da933c7b116dd2cae7ca5d689fd800877e874dc (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
60
61
62
63
64
65
66
67
68
69
70
71
72
# frozen_string_literal: true
# rubocop:disable Style/Documentation

module Gitlab
  module BackgroundMigration
    module UserMentions
      module Models
        class Note < ActiveRecord::Base
          include EachBatch
          include Concerns::IsolatedMentionable
          include CacheMarkdownField

          self.table_name = 'notes'
          self.inheritance_column = :_type_disabled

          attr_mentionable :note, pipeline: :note
          cache_markdown_field :note, pipeline: :note, issuable_state_filter_enabled: true

          belongs_to :author, class_name: "::Gitlab::BackgroundMigration::UserMentions::Models::User"
          belongs_to :noteable, polymorphic: true
          belongs_to :project, class_name: "::Gitlab::BackgroundMigration::UserMentions::Models::Project"

          def for_personal_snippet?
            noteable && noteable.class.name == 'PersonalSnippet'
          end

          def for_project_noteable?
            !for_personal_snippet? && !for_epic?
          end

          def skip_project_check?
            !for_project_noteable?
          end

          def for_epic?
            noteable && noteable_type == 'Epic'
          end

          def user_mention_resource_id
            noteable_id || commit_id
          end

          def user_mention_note_id
            id
          end

          def noteable
            super unless for_commit?
          end

          def for_commit?
            noteable_type == "Commit"
          end

          private

          def mentionable_params
            return super unless for_epic?

            super.merge(banzai_context_params)
          end

          def banzai_context_params
            return {} unless noteable

            { group: noteable.group, label_url_method: :group_epics_url }
          end
        end
      end
    end
  end
end