Class: LegacyDiffNote
- Inherits:
-
Note
- Object
- ActiveRecord::Base
- ApplicationRecord
- Note
- LegacyDiffNote
- Includes:
- NoteOnDiff
- Defined in:
- app/models/legacy_diff_note.rb
Overview
A note on merge request or commit diffs, using the legacy implementation.
All new diff notes are of the type DiffNote, but any diff notes created before the introduction of the new implementation still use LegacyDiffNote.
A note of this type is never resolvable.
Constant Summary
Constants inherited from Note
Note::NON_DIFF_NOTE_TYPES, Note::TYPES_RESTRICTED_BY_GROUP_ABILITY, Note::TYPES_RESTRICTED_BY_PROJECT_ABILITY
Constants included from ThrottledTouch
ThrottledTouch::TOUCH_INTERVAL
Constants included from Gitlab::SQL::Pattern
Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_TERM
Constants included from ResolvableNote
ResolvableNote::RESOLVABLE_TYPES
Constants included from CacheMarkdownField
CacheMarkdownField::INVALIDATED_BY
Constants included from Redactable
Redactable::UNSUBSCRIBE_PATTERN
Constants included from Import::HasImportSource
Import::HasImportSource::IMPORT_SOURCES
Constants inherited from ApplicationRecord
Constants included from HasCheckConstraints
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
Constants included from ResetOnColumnErrors
ResetOnColumnErrors::MAX_RESET_PERIOD
Instance Attribute Summary
Attributes inherited from Note
#commands_changes, #quick_actions_status, #redacted_note_html, #skip_keep_around_commits, #skip_touch_noteable, #total_reference_count, #user_visible_reference_count
Attributes included from CacheMarkdownField
#skip_markdown_cache_validation
Attributes included from Importable
#importing, #user_contributions
Instance Method Summary collapse
-
#active?(diff_refs = nil) ⇒ Boolean
Check if this note is part of an “active” discussion.
- #diff ⇒ Object
- #diff_file ⇒ Object
- #diff_file_hash ⇒ Object
- #diff_line ⇒ Object
- #discussion_class ⇒ Object
- #original_line_code ⇒ Object
- #project_repository ⇒ Object
Methods included from NoteOnDiff
#created_at_diff?, #diff_attributes, #diff_note?
Methods inherited from Note
#award_emoji?, #banzai_render_context, #broadcast_noteable_notes_changed, #bump_updated_at, #can_be_award_emoji?, #can_be_discussion_note?, #can_create_todo?, #check_for_spam?, cherry_picked_merge_requests, #commit, #confidential?, #contains_emoji_only?, #contributor?, count_for_collection, #diff_note?, #editable?, #edited?, #emoji_awardable?, #exportable_record?, #for_abuse_report?, #for_alert_mangement_alert?, #for_commit?, #for_compliance_violation?, #for_design?, #for_issuable?, #for_issue?, #for_merge_request?, #for_personal_snippet?, #for_project_noteable?, #for_project_snippet?, #for_snippet?, #for_vulnerability?, #for_wiki_page?, #for_work_item?, #group_level_issue?, grouped_diff_discussions, #hook_attrs, #human_max_access, #issuable_ability_name, #last_edited_at, #mentioned_filtered_user_ids_for, #mentioned_users, #merge_requests, model_name, #noteable, #noteable_ability_name, #noteable_author?, #noteable_type=, #notify_after_create, #notify_after_destroy, parent_object_field, #parent_user, positions, #post_processed_cache_key, #project_name, #references, #resource_parent, #retrieve_upload, search, #show_outdated_changes?, simple_sorts, #skip_notification?, #skip_project_check?, #supports_suggestion?, #system_note_visible_for?, #system_note_with_references?, #touch, #touch_noteable, #trigger_note_subscription_create, #trigger_note_subscription_destroy, #trigger_note_subscription_update, #trigger_work_item_updated_subscription, #user_mention_class, #user_mention_identifier, #user_mentions, with_web_entity_associations
Methods included from Gitlab::Utils::Override
#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!
Methods included from Spammable
#allow_possible_spam?, #check_for_spam, #check_for_spam?, #clear_spam_flags!, #invalidate_if_spam, #needs_recaptcha!, #recaptcha_error!, #render_recaptcha?, #spam, #spam!, #spam_description, #spam_title, #spammable_attribute_changed?, #spammable_entity_type, #spammable_text, #submittable_as_spam?, #submittable_as_spam_by?, #supports_recaptcha?, #unrecoverable_spam_error!
Methods included from ThrottledTouch
Methods included from Gitlab::SQL::Pattern
Methods included from Editable
Methods included from ResolvableNote
#potentially_resolvable?, #resolvable?, #resolve!, #resolve_without_save, #resolved?, #to_be_resolved?, #unresolve!, #unresolve_without_save
Methods included from AfterCommitQueue
#run_after_commit, #run_after_commit_or_now
Methods included from CacheMarkdownField
#attribute_invalidated?, #banzai_render_context, #cached_html_for, #cached_html_up_to_date?, #can_cache_field?, #invalidated_markdown_cache?, #latest_cached_markdown_version, #mentionable_attributes_changed?, #mentioned_filtered_user_ids_for, #parent_user, #refresh_markdown_cache, #refresh_markdown_cache!, #rendered_field_content, #skip_project_check?, #store_mentions!, #store_mentions?, #store_mentions_after_commit?, #updated_cached_html_for
Methods included from FasterCacheKeys
Methods included from Import::HasImportSource
Methods included from Awardable
#awarded_emoji?, #downvotes, #emoji_awardable?, #grouped_awards, #upvotes, #user_authored?, #user_can_award?
Methods included from Mentionable
#all_references, #create_cross_references!, #create_new_cross_references!, #directly_addressed_users, #extractors, #gfm_reference, #local_reference, #matches_cross_reference_regex?, #mentioned_users, #referenced_group_users, #referenced_groups, #referenced_mentionables, #referenced_projects, #referenced_users, #user_mention_class, #user_mention_identifier
Methods included from Participable
#participant?, #participants, #visible_participants
Methods included from Notes::Discussion
#derive_discussion_id, #discussion, #discussion=, #discussion_id, #ensure_discussion_id, #in_reply_to?, #part_of_discussion?, #start_of_discussion?, #to_discussion
Methods included from Notes::ActiveRecord
Methods inherited from ApplicationRecord
===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Methods included from Organizations::Sharding
Methods included from ResetOnColumnErrors
#reset_on_union_error, #reset_on_unknown_attribute_error
Methods included from Gitlab::SensitiveSerializableHash
Instance Method Details
#active?(diff_refs = nil) ⇒ Boolean
Check if this note is part of an “active” discussion
This will always return true for anything except MergeRequest noteables, which have special logic.
If the note’s current diff cannot be matched in the MergeRequest’s current diff, it’s considered inactive.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/legacy_diff_note.rb', line 55 def active?(diff_refs = nil) return @active if defined?(@active) return true if for_commit? return true unless diff_line return false unless noteable return false if diff_refs && diff_refs != noteable.diff_refs noteable_diff = find_noteable_diff if noteable_diff parsed_lines = Gitlab::Diff::Parser.new.parse(noteable_diff.diff.each_line) @active = parsed_lines.any? { |line_obj| line_obj.text == diff_line.text } else @active = false end @active end |
#diff ⇒ Object
32 33 34 |
# File 'app/models/legacy_diff_note.rb', line 32 def diff @diff ||= Gitlab::Git::Diff.new(st_diff) if st_diff.respond_to?(:map) end |
#diff_file ⇒ Object
36 37 38 |
# File 'app/models/legacy_diff_note.rb', line 36 def diff_file @diff_file ||= Gitlab::Diff::File.new(diff, repository: project_repository) if diff end |
#diff_file_hash ⇒ Object
28 29 30 |
# File 'app/models/legacy_diff_note.rb', line 28 def diff_file_hash line_code.split('_')[0] if line_code end |
#diff_line ⇒ Object
40 41 42 |
# File 'app/models/legacy_diff_note.rb', line 40 def diff_line @diff_line ||= diff_file&.line_for_line_code(self.line_code) end |
#discussion_class ⇒ Object
20 21 22 |
# File 'app/models/legacy_diff_note.rb', line 20 def discussion_class(*) LegacyDiffDiscussion end |
#original_line_code ⇒ Object
44 45 46 |
# File 'app/models/legacy_diff_note.rb', line 44 def original_line_code self.line_code end |
#project_repository ⇒ Object
24 25 26 |
# File 'app/models/legacy_diff_note.rb', line 24 def project_repository Gitlab::SafeRequestStore.fetch("project:#{project_id}:repository") { self.project.repository } end |