Class: DraftNote
Constant Summary
collapse
- PUBLISH_ATTRS =
%i[noteable_id noteable_type type note].freeze
- DIFF_ATTRS =
%i[position original_position change_position commit_id].freeze
ApplicationRecord::MAX_PLUCK
ResetOnUnionError::MAX_RESET_PERIOD
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#active?, #diff_refs_match_commit, #on_file?, #on_image?, #on_text?, #set_original_position, #should_update_position?, #supported?, #update_position
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, 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
#serializable_hash
Instance Attribute Details
#commands_changes ⇒ Object
Attribute used to store quick actions changes and users referenced.
14
15
16
|
# File 'app/models/draft_note.rb', line 14
def commands_changes
@commands_changes
end
|
#rendered_note ⇒ Object
Text with quick actions filtered out
18
19
20
|
# File 'app/models/draft_note.rb', line 18
def rendered_note
@rendered_note
end
|
#review ⇒ Object
Returns the value of attribute review.
20
21
22
|
# File 'app/models/draft_note.rb', line 20
def review
@review
end
|
#users_referenced ⇒ Object
Returns the value of attribute users_referenced.
15
16
17
|
# File 'app/models/draft_note.rb', line 15
def users_referenced
@users_referenced
end
|
Class Method Details
.positions ⇒ Object
34
35
36
37
38
|
# File 'app/models/draft_note.rb', line 34
def self.positions
where.not(position: nil)
.select(:position)
.map(&:position)
end
|
.preload_author(draft_notes) ⇒ Object
110
111
112
|
# File 'app/models/draft_note.rb', line 110
def self.preload_author(draft_notes)
ActiveRecord::Associations::Preloader.new(records: draft_notes, associations: { author: :status }).call
end
|
Instance Method Details
#commit ⇒ Object
124
125
126
|
# File 'app/models/draft_note.rb', line 124
def commit
@commit ||= project.commit(commit_id) if commit_id.present?
end
|
#diff_file ⇒ Object
114
115
116
117
118
119
120
121
122
|
# File 'app/models/draft_note.rb', line 114
def diff_file
strong_memoize(:diff_file) do
file = original_position&.diff_file(project.repository)
file&.unfold_diff_lines(original_position)
file
end
end
|
#emoji_awardable? ⇒ Boolean
70
71
72
|
# File 'app/models/draft_note.rb', line 70
def emoji_awardable?
false
end
|
#find_line_code ⇒ Object
96
97
98
|
# File 'app/models/draft_note.rb', line 96
def find_line_code
write_attribute(:line_code, diff_file&.line_code_for_position(original_position))
end
|
#for_commit? ⇒ Boolean
58
59
60
|
# File 'app/models/draft_note.rb', line 58
def for_commit?
commit_id.present?
end
|
#importing? ⇒ Boolean
62
63
64
|
# File 'app/models/draft_note.rb', line 62
def importing?
false
end
|
#line_code ⇒ Object
92
93
94
|
# File 'app/models/draft_note.rb', line 92
def line_code
super.presence || find_line_code
end
|
#noteable ⇒ Object
50
51
52
|
# File 'app/models/draft_note.rb', line 50
def noteable
merge_request
end
|
#noteable_id ⇒ Object
noteable_id and noteable_type methods are used to generate discussion_id on Discussion.discussion_id
46
47
48
|
# File 'app/models/draft_note.rb', line 46
def noteable_id
merge_request_id
end
|
#noteable_type ⇒ Object
54
55
56
|
# File 'app/models/draft_note.rb', line 54
def noteable_type
"MergeRequest"
end
|
#on_diff? ⇒ Boolean
74
75
76
|
# File 'app/models/draft_note.rb', line 74
def on_diff?
position&.complete?
end
|
#project ⇒ Object
40
41
42
|
# File 'app/models/draft_note.rb', line 40
def project
merge_request.target_project
end
|
#publish_params ⇒ Object
100
101
102
103
104
105
106
107
108
|
# File 'app/models/draft_note.rb', line 100
def publish_params
attrs = PUBLISH_ATTRS.dup
attrs.concat(DIFF_ATTRS) if on_diff?
params = slice(*attrs)
params[:in_reply_to_discussion_id] = discussion_id if discussion_id.present?
params[:review_id] = review.id if review.present?
params
end
|
#references ⇒ Object
85
86
87
88
89
90
|
# File 'app/models/draft_note.rb', line 85
def references
{
users: users_referenced,
commands: commands_changes
}
end
|
#resolvable? ⇒ Boolean
66
67
68
|
# File 'app/models/draft_note.rb', line 66
def resolvable?
false
end
|
#type ⇒ Object
78
79
80
81
82
83
|
# File 'app/models/draft_note.rb', line 78
def type
return 'DiffNote' if on_diff?
return 'DiscussionNote' if discussion_id.present?
'Note'
end
|