Module: Noteable

Extended by:
ActiveSupport::Concern
Included in:
AlertManagement::Alert, Commit, DesignManagement::Design, Issue, MergeRequest, Snippet
Defined in:
app/models/concerns/noteable.rb

Defined Under Namespace

Classes: NoteableMeta

Constant Summary collapse

MAX_NOTES_LIMIT =
5_000

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#system_note_timestampObject

The timestamp of the note (e.g. the :created_at or :updated_at attribute if provided via API call)


26
27
28
# File 'app/models/concerns/noteable.rb', line 26

def system_note_timestamp
  @system_note_timestamp || Time.current # rubocop:disable Gitlab/ModuleWithInstanceVariables
end

Instance Method Details

#after_note_created(_note) ⇒ Object


154
155
156
# File 'app/models/concerns/noteable.rb', line 154

def after_note_created(_note)
  # no-op
end

#after_note_destroyed(_note) ⇒ Object


158
159
160
# File 'app/models/concerns/noteable.rb', line 158

def after_note_destroyed(_note)
  # no-op
end

#base_class_nameObject


32
33
34
# File 'app/models/concerns/noteable.rb', line 32

def base_class_name
  self.class.base_class.name
end

#capped_notes_count(max) ⇒ Object


92
93
94
# File 'app/models/concerns/noteable.rb', line 92

def capped_notes_count(max)
  notes.limit(max).count
end

#discussion_ids_relationObject


86
87
88
89
90
# File 'app/models/concerns/noteable.rb', line 86

def discussion_ids_relation
  notes.select(:discussion_id)
    .group(:discussion_id)
    .order('MIN(created_at), MIN(id)')
end

#discussion_notesObject


74
75
76
# File 'app/models/concerns/noteable.rb', line 74

def discussion_notes
  notes
end

#discussionsObject


80
81
82
83
84
# File 'app/models/concerns/noteable.rb', line 80

def discussions
  @discussions ||= discussion_notes
    .inc_relations_for_view
    .discussions(self)
end

#discussions_can_be_resolved_by?(user) ⇒ Boolean

Returns:

  • (Boolean)

125
126
127
# File 'app/models/concerns/noteable.rb', line 125

def discussions_can_be_resolved_by?(user)
  discussions_to_be_resolved.all? { |discussion| discussion.can_resolve?(user) }
end

#discussions_rendered_on_frontend?Boolean

Returns:

  • (Boolean)

62
63
64
# File 'app/models/concerns/noteable.rb', line 62

def discussions_rendered_on_frontend?
  false
end

#discussions_resolvable?Boolean

rubocop:enable Gitlab/ModuleWithInstanceVariables

Returns:

  • (Boolean)

113
114
115
# File 'app/models/concerns/noteable.rb', line 113

def discussions_resolvable?
  resolvable_discussions.any?(&:resolvable?)
end

#discussions_resolved?Boolean

Returns:

  • (Boolean)

117
118
119
# File 'app/models/concerns/noteable.rb', line 117

def discussions_resolved?
  discussions_resolvable? && resolvable_discussions.none?(&:to_be_resolved?)
end

#discussions_to_be_resolvedObject


121
122
123
# File 'app/models/concerns/noteable.rb', line 121

def discussions_to_be_resolved
  @discussions_to_be_resolved ||= resolvable_discussions.select(&:to_be_resolved?)
end

#etag_caching_enabled?Boolean

Returns:

  • (Boolean)

133
134
135
# File 'app/models/concerns/noteable.rb', line 133

def etag_caching_enabled?
  false
end

#expire_note_etag_cacheObject


137
138
139
140
141
142
# File 'app/models/concerns/noteable.rb', line 137

def expire_note_etag_cache
  return unless discussions_rendered_on_frontend?
  return unless etag_caching_enabled?

  Gitlab::EtagCaching::Store.new.touch(note_etag_key)
end

#grouped_diff_discussions(*args) ⇒ Object


96
97
98
99
100
# File 'app/models/concerns/noteable.rb', line 96

def grouped_diff_discussions(*args)
  # Doesn't use `discussion_notes`, because this may include commit diff notes
  # besides MR diff notes, that we do not want to display on the MR Changes tab.
  notes.inc_relations_for_view.grouped_diff_discussions(*args)
end

#has_any_diff_note_positions?Boolean

Returns:

  • (Boolean)

70
71
72
# File 'app/models/concerns/noteable.rb', line 70

def has_any_diff_note_positions?
  notes.any? && DiffNotePosition.where(note: notes).exists?
end

#human_class_nameObject

Convert this Noteable class name to a format usable by notifications.

Examples:

noteable.class           # => MergeRequest
noteable.human_class_name # => "merge request"

42
43
44
# File 'app/models/concerns/noteable.rb', line 42

def human_class_name
  @human_class_name ||= base_class_name.titleize.downcase
end

#lockable?Boolean

Returns:

  • (Boolean)

129
130
131
# File 'app/models/concerns/noteable.rb', line 129

def lockable?
  [MergeRequest, Issue].include?(self.class)
end

#note_etag_keyObject


144
145
146
147
148
149
150
151
152
# File 'app/models/concerns/noteable.rb', line 144

def note_etag_key
  return Gitlab::Routing.url_helpers.designs_project_issue_path(project, issue, { vueroute: filename }) if self.is_a?(DesignManagement::Design)

  Gitlab::Routing.url_helpers.project_noteable_notes_path(
    project,
    target_type: self.class.name.underscore,
    target_id: id
  )
end

#preloads_discussion_diff_highlighting?Boolean

Returns:

  • (Boolean)

66
67
68
# File 'app/models/concerns/noteable.rb', line 66

def preloads_discussion_diff_highlighting?
  false
end

#resolvable_discussionsObject

rubocop:disable Gitlab/ModuleWithInstanceVariables


103
104
105
106
107
108
109
110
# File 'app/models/concerns/noteable.rb', line 103

def resolvable_discussions
  @resolvable_discussions ||=
    if defined?(@discussions)
      @discussions.select(&:resolvable?)
    else
      discussion_notes.resolvable.discussions(self)
    end
end

#supports_discussions?Boolean

Returns:

  • (Boolean)

50
51
52
# File 'app/models/concerns/noteable.rb', line 50

def supports_discussions?
  DiscussionNote.noteable_types.include?(base_class_name)
end

#supports_replying_to_individual_notes?Boolean

Returns:

  • (Boolean)

54
55
56
# File 'app/models/concerns/noteable.rb', line 54

def supports_replying_to_individual_notes?
  supports_discussions? && self.class.replyable_types.include?(base_class_name)
end

#supports_resolvable_notes?Boolean

Returns:

  • (Boolean)

46
47
48
# File 'app/models/concerns/noteable.rb', line 46

def supports_resolvable_notes?
  self.class.resolvable_types.include?(base_class_name)
end

#supports_suggestion?Boolean

Returns:

  • (Boolean)

58
59
60
# File 'app/models/concerns/noteable.rb', line 58

def supports_suggestion?
  false
end