Module: Noteable
Defined Under Namespace
Classes: NoteableMeta, NotesChannel
Constant Summary
collapse
- MAX_NOTES_LIMIT =
5_000
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#system_note_timestamp ⇒ Object
The timestamp of the note (e.g. the :created_at or :updated_at attribute if provided via API call)
31
32
33
|
# File 'app/models/concerns/noteable.rb', line 31
def system_note_timestamp
@system_note_timestamp || Time.current end
|
Instance Method Details
#after_note_created(_note) ⇒ Object
178
179
180
|
# File 'app/models/concerns/noteable.rb', line 178
def after_note_created(_note)
end
|
#after_note_destroyed(_note) ⇒ Object
182
183
184
|
# File 'app/models/concerns/noteable.rb', line 182
def after_note_destroyed(_note)
end
|
#base_class_name ⇒ Object
37
38
39
|
# File 'app/models/concerns/noteable.rb', line 37
def base_class_name
self.class.base_class.name
end
|
#broadcast_notes_changed ⇒ Object
171
172
173
174
175
176
|
# File 'app/models/concerns/noteable.rb', line 171
def broadcast_notes_changed
return unless discussions_rendered_on_frontend?
return unless real_time_notes_enabled?
Noteable::NotesChannel.broadcast_to(self, event: 'updated')
end
|
#capped_notes_count(max) ⇒ Object
126
127
128
|
# File 'app/models/concerns/noteable.rb', line 126
def capped_notes_count(max)
notes.limit(max).count
end
|
202
203
204
205
206
207
208
|
# File 'app/models/concerns/noteable.rb', line 202
def (user: nil)
eligable_notes = notes.user
eligable_notes = eligable_notes.not_internal unless user&.can?(:read_internal_note, self)
User.where(id: eligable_notes.select(:author_id).distinct)
end
|
#creatable_note_email_address(author) ⇒ Object
Email address that an authorized user can send/forward an email to be added directly to an issue or merge request. example: incoming+h5bp-html5-boilerplate-8-1234567890abcdef123456789-issue-34@localhost.com
189
190
191
192
193
194
195
196
|
# File 'app/models/concerns/noteable.rb', line 189
def creatable_note_email_address(author)
return unless supports_creating_notes_by_email?
project_email = project&.new_issuable_address(author, base_class_name.underscore)
return unless project_email
project_email.sub('@', "-#{iid}@")
end
|
#discussion_ids_relation ⇒ Object
97
98
99
100
101
|
# File 'app/models/concerns/noteable.rb', line 97
def discussion_ids_relation
notes.select(:discussion_id)
.group(:discussion_id)
.order('MIN(created_at), MIN(id)')
end
|
#discussion_notes ⇒ Object
85
86
87
|
# File 'app/models/concerns/noteable.rb', line 85
def discussion_notes
notes
end
|
#discussion_root_note_ids(notes_filter:) ⇒ Object
This does not consider OutOfContextDiscussions in MRs where notes from commits are overriden so that they have the same discussion_id
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'app/models/concerns/noteable.rb', line 106
def discussion_root_note_ids(notes_filter:)
relations = []
relations << discussion_notes.select(
"'notes' AS table_name",
'MIN(id) AS id',
'MIN(created_at) AS created_at',
'ARRAY_AGG(id) AS ids'
).with_notes_filter(notes_filter)
.group(:discussion_id)
if notes_filter != UserPreference::NOTES_FILTERS[:only_comments]
relations += synthetic_note_ids_relations
end
Note.from_union(relations, remove_duplicates: false)
.select(:table_name, :id, :created_at, :ids)
.fresh
end
|
#discussions ⇒ Object
91
92
93
94
95
|
# File 'app/models/concerns/noteable.rb', line 91
def discussions
@discussions ||= discussion_notes
.inc_relations_for_view(self)
.discussions(self)
end
|
#discussions_can_be_resolved_by?(user) ⇒ Boolean
159
160
161
|
# File 'app/models/concerns/noteable.rb', line 159
def discussions_can_be_resolved_by?(user)
discussions_to_be_resolved.all? { |discussion| discussion.can_resolve?(user) }
end
|
#discussions_rendered_on_frontend? ⇒ Boolean
73
74
75
|
# File 'app/models/concerns/noteable.rb', line 73
def discussions_rendered_on_frontend?
false
end
|
#discussions_resolvable? ⇒ Boolean
rubocop:enable Gitlab/ModuleWithInstanceVariables
147
148
149
|
# File 'app/models/concerns/noteable.rb', line 147
def discussions_resolvable?
resolvable_discussions.any?(&:resolvable?)
end
|
#discussions_resolved? ⇒ Boolean
151
152
153
|
# File 'app/models/concerns/noteable.rb', line 151
def discussions_resolved?
discussions_resolvable? && resolvable_discussions.none?(&:to_be_resolved?)
end
|
#discussions_to_be_resolved ⇒ Object
155
156
157
|
# File 'app/models/concerns/noteable.rb', line 155
def discussions_to_be_resolved
@discussions_to_be_resolved ||= resolvable_discussions.select(&:to_be_resolved?)
end
|
#grouped_diff_discussions ⇒ Object
130
131
132
133
134
|
# File 'app/models/concerns/noteable.rb', line 130
def grouped_diff_discussions(...)
notes.inc_relations_for_view(self).grouped_diff_discussions(...)
end
|
#has_any_diff_note_positions? ⇒ Boolean
81
82
83
|
# File 'app/models/concerns/noteable.rb', line 81
def has_any_diff_note_positions?
notes.any? && DiffNotePosition.where(note: notes).exists?
end
|
#human_class_name ⇒ Object
Convert this Noteable class name to a format usable by notifications.
Examples:
noteable.class noteable.human_class_name
47
48
49
|
# File 'app/models/concerns/noteable.rb', line 47
def human_class_name
@human_class_name ||= base_class_name.titleize.downcase
end
|
#lockable? ⇒ Boolean
163
164
165
|
# File 'app/models/concerns/noteable.rb', line 163
def lockable?
[MergeRequest, Issue].include?(self.class)
end
|
#noteable_target_type_name ⇒ Object
198
199
200
|
# File 'app/models/concerns/noteable.rb', line 198
def noteable_target_type_name
model_name.singular
end
|
#preloads_discussion_diff_highlighting? ⇒ Boolean
77
78
79
|
# File 'app/models/concerns/noteable.rb', line 77
def preloads_discussion_diff_highlighting?
false
end
|
#real_time_notes_enabled? ⇒ Boolean
167
168
169
|
# File 'app/models/concerns/noteable.rb', line 167
def real_time_notes_enabled?
false
end
|
#resolvable_discussions ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables
137
138
139
140
141
142
143
144
|
# File 'app/models/concerns/noteable.rb', line 137
def resolvable_discussions
@resolvable_discussions ||=
if defined?(@discussions)
@discussions.select(&:resolvable?)
else
discussion_notes.resolvable.discussions(self)
end
end
|
#supports_creating_notes_by_email? ⇒ Boolean
65
66
67
|
# File 'app/models/concerns/noteable.rb', line 65
def supports_creating_notes_by_email?
self.class.email_creatable_types.include?(base_class_name)
end
|
#supports_discussions? ⇒ Boolean
57
58
59
|
# File 'app/models/concerns/noteable.rb', line 57
def supports_discussions?
DiscussionNote.noteable_types.include?(base_class_name)
end
|
#supports_replying_to_individual_notes? ⇒ Boolean
61
62
63
|
# File 'app/models/concerns/noteable.rb', line 61
def supports_replying_to_individual_notes?
supports_discussions? && self.class.replyable_types.include?(base_class_name)
end
|
#supports_resolvable_notes? ⇒ Boolean
51
52
53
54
55
|
# File 'app/models/concerns/noteable.rb', line 51
def supports_resolvable_notes?
return false if is_a?(Issue) && Feature.disabled?(:resolvable_issue_threads, project)
self.class.resolvable_types.include?(base_class_name)
end
|
#supports_suggestion? ⇒ Boolean
69
70
71
|
# File 'app/models/concerns/noteable.rb', line 69
def supports_suggestion?
false
end
|