Module: Noteable
- Extended by:
- ActiveSupport::Concern, ClassMethods
- 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
-
#system_note_timestamp ⇒ Object
The timestamp of the note (e.g. the :created_at or :updated_at attribute if provided via API call).
Instance Method Summary collapse
- #after_note_created(_note) ⇒ Object
- #after_note_destroyed(_note) ⇒ Object
- #base_class_name ⇒ Object
- #capped_notes_count(max) ⇒ Object
-
#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.
- #discussion_ids_relation ⇒ Object
- #discussion_notes ⇒ Object
-
#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.
- #discussions ⇒ Object
- #discussions_can_be_resolved_by?(user) ⇒ Boolean
- #discussions_rendered_on_frontend? ⇒ Boolean
-
#discussions_resolvable? ⇒ Boolean
rubocop:enable Gitlab/ModuleWithInstanceVariables.
- #discussions_resolved? ⇒ Boolean
- #discussions_to_be_resolved ⇒ Object
- #etag_caching_enabled? ⇒ Boolean
- #expire_note_etag_cache ⇒ Object
- #grouped_diff_discussions(*args) ⇒ Object
- #has_any_diff_note_positions? ⇒ Boolean
-
#human_class_name ⇒ Object
Convert this Noteable class name to a format usable by notifications.
- #lockable? ⇒ Boolean
- #note_etag_key ⇒ Object
- #noteable_target_type_name ⇒ Object
- #preloads_discussion_diff_highlighting? ⇒ Boolean
-
#resolvable_discussions ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables.
- #supports_creating_notes_by_email? ⇒ Boolean
- #supports_discussions? ⇒ Boolean
- #supports_replying_to_individual_notes? ⇒ Boolean
- #supports_resolvable_notes? ⇒ Boolean
- #supports_suggestion? ⇒ Boolean
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 || Time.current # rubocop:disable Gitlab/ModuleWithInstanceVariables end |
Instance Method Details
#after_note_created(_note) ⇒ Object
184 185 186 |
# File 'app/models/concerns/noteable.rb', line 184 def after_note_created(_note) # no-op end |
#after_note_destroyed(_note) ⇒ Object
188 189 190 |
# File 'app/models/concerns/noteable.rb', line 188 def after_note_destroyed(_note) # no-op 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 |
#capped_notes_count(max) ⇒ Object
122 123 124 |
# File 'app/models/concerns/noteable.rb', line 122 def capped_notes_count(max) notes.limit(max).count 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: incom[email protected]localhost.com
195 196 197 198 199 200 201 202 |
# File 'app/models/concerns/noteable.rb', line 195 def creatable_note_email_address() return unless supports_creating_notes_by_email? project_email = project.new_issuable_address(, self.class.name.underscore) return unless project_email project_email.sub('@', "-#{iid}@") end |
#discussion_ids_relation ⇒ Object
95 96 97 98 99 |
# File 'app/models/concerns/noteable.rb', line 95 def discussion_ids_relation notes.select(:discussion_id) .group(:discussion_id) .order('MIN(created_at), MIN(id)') end |
#discussion_notes ⇒ Object
83 84 85 |
# File 'app/models/concerns/noteable.rb', line 83 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
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/models/concerns/noteable.rb', line 104 def discussion_root_note_ids(notes_filter:) relations = [] relations << discussion_notes.select( "'notes' AS table_name", 'discussion_id', 'MIN(id) AS id', 'MIN(created_at) AS created_at' ).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).fresh end |
#discussions ⇒ Object
89 90 91 92 93 |
# File 'app/models/concerns/noteable.rb', line 89 def discussions @discussions ||= discussion_notes .inc_relations_for_view .discussions(self) end |
#discussions_can_be_resolved_by?(user) ⇒ Boolean
155 156 157 |
# File 'app/models/concerns/noteable.rb', line 155 def discussions_can_be_resolved_by?(user) discussions_to_be_resolved.all? { |discussion| discussion.can_resolve?(user) } end |
#discussions_rendered_on_frontend? ⇒ Boolean
71 72 73 |
# File 'app/models/concerns/noteable.rb', line 71 def discussions_rendered_on_frontend? false end |
#discussions_resolvable? ⇒ Boolean
rubocop:enable Gitlab/ModuleWithInstanceVariables
143 144 145 |
# File 'app/models/concerns/noteable.rb', line 143 def discussions_resolvable? resolvable_discussions.any?(&:resolvable?) end |
#discussions_resolved? ⇒ Boolean
147 148 149 |
# File 'app/models/concerns/noteable.rb', line 147 def discussions_resolved? discussions_resolvable? && resolvable_discussions.none?(&:to_be_resolved?) end |
#discussions_to_be_resolved ⇒ Object
151 152 153 |
# File 'app/models/concerns/noteable.rb', line 151 def discussions_to_be_resolved @discussions_to_be_resolved ||= resolvable_discussions.select(&:to_be_resolved?) end |
#etag_caching_enabled? ⇒ Boolean
163 164 165 |
# File 'app/models/concerns/noteable.rb', line 163 def etag_caching_enabled? false end |
#expire_note_etag_cache ⇒ Object
167 168 169 170 171 172 |
# File 'app/models/concerns/noteable.rb', line 167 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
126 127 128 129 130 |
# File 'app/models/concerns/noteable.rb', line 126 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
79 80 81 |
# File 'app/models/concerns/noteable.rb', line 79 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 # => MergeRequest
noteable.human_class_name # => "merge request"
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
159 160 161 |
# File 'app/models/concerns/noteable.rb', line 159 def lockable? [MergeRequest, Issue].include?(self.class) end |
#note_etag_key ⇒ Object
174 175 176 177 178 179 180 181 182 |
# File 'app/models/concerns/noteable.rb', line 174 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: noteable_target_type_name, target_id: id ) end |
#noteable_target_type_name ⇒ Object
204 205 206 |
# File 'app/models/concerns/noteable.rb', line 204 def noteable_target_type_name model_name.singular end |
#preloads_discussion_diff_highlighting? ⇒ Boolean
75 76 77 |
# File 'app/models/concerns/noteable.rb', line 75 def preloads_discussion_diff_highlighting? false end |
#resolvable_discussions ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables
133 134 135 136 137 138 139 140 |
# File 'app/models/concerns/noteable.rb', line 133 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
63 64 65 |
# File 'app/models/concerns/noteable.rb', line 63 def supports_creating_notes_by_email? self.class.email_creatable_types.include?(base_class_name) end |
#supports_discussions? ⇒ Boolean
55 56 57 |
# File 'app/models/concerns/noteable.rb', line 55 def supports_discussions? DiscussionNote.noteable_types.include?(base_class_name) end |
#supports_replying_to_individual_notes? ⇒ Boolean
59 60 61 |
# File 'app/models/concerns/noteable.rb', line 59 def supports_discussions? && self.class.replyable_types.include?(base_class_name) end |
#supports_resolvable_notes? ⇒ Boolean
51 52 53 |
# File 'app/models/concerns/noteable.rb', line 51 def supports_resolvable_notes? self.class.resolvable_types.include?(base_class_name) end |
#supports_suggestion? ⇒ Boolean
67 68 69 |
# File 'app/models/concerns/noteable.rb', line 67 def supports_suggestion? false end |