2018-07-17 12:50:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-01-27 10:59:16 -05:00
|
|
|
module Notes
|
|
|
|
class PostProcessService
|
|
|
|
attr_accessor :note
|
|
|
|
|
|
|
|
def initialize(note)
|
|
|
|
@note = note
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
# Skip system notes, like status changes and cross-references and awards
|
2020-07-10 17:09:29 -04:00
|
|
|
unless note.system?
|
|
|
|
EventCreateService.new.leave_note(note, note.author)
|
2017-01-20 05:28:40 -05:00
|
|
|
|
2020-07-10 17:09:29 -04:00
|
|
|
return if note.for_personal_snippet?
|
2017-01-20 05:28:40 -05:00
|
|
|
|
2020-07-10 17:09:29 -04:00
|
|
|
note.create_cross_references!
|
|
|
|
::SystemNoteService.design_discussion_added(note) if create_design_discussion_system_note?
|
2020-05-13 14:08:47 -04:00
|
|
|
|
2017-01-20 05:28:40 -05:00
|
|
|
execute_note_hooks
|
2016-01-27 10:59:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-13 14:08:47 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def create_design_discussion_system_note?
|
2020-07-10 17:09:29 -04:00
|
|
|
note && note.for_design? && note.start_of_discussion?
|
2020-05-13 14:08:47 -04:00
|
|
|
end
|
|
|
|
|
2016-01-27 10:59:16 -05:00
|
|
|
def hook_data
|
2020-07-10 17:09:29 -04:00
|
|
|
Gitlab::DataBuilder::Note.build(note, note.author)
|
2016-01-27 10:59:16 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute_note_hooks
|
2020-07-10 17:09:29 -04:00
|
|
|
return unless note.project
|
2018-03-30 13:27:03 -04:00
|
|
|
|
2016-01-27 10:59:16 -05:00
|
|
|
note_data = hook_data
|
2020-07-10 17:09:29 -04:00
|
|
|
hooks_scope = note.confidential?(include_noteable: true) ? :confidential_note_hooks : :note_hooks
|
2018-04-03 07:00:33 -04:00
|
|
|
|
2020-07-10 17:09:29 -04:00
|
|
|
note.project.execute_hooks(note_data, hooks_scope)
|
|
|
|
note.project.execute_services(note_data, hooks_scope)
|
2016-01-27 10:59:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-11-14 01:06:26 -05:00
|
|
|
|
|
|
|
Notes::PostProcessService.prepend_if_ee('EE::Notes::PostProcessService')
|