Class: DraftNotes::CreateService
- Inherits:
-
BaseService
- Object
- BaseService
- BaseService
- DraftNotes::CreateService
- Defined in:
- app/services/draft_notes/create_service.rb
Instance Attribute Summary collapse
-
#in_draft_mode ⇒ Object
Returns the value of attribute in_draft_mode.
-
#in_reply_to_discussion_id ⇒ Object
Returns the value of attribute in_reply_to_discussion_id.
Attributes inherited from BaseService
#current_user, #merge_request, #params
Attributes inherited from BaseService
#current_user, #params, #project
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(merge_request, current_user, params = nil) ⇒ CreateService
constructor
A new instance of CreateService.
Methods inherited from BaseService
#merge_request_activity_counter
Methods included from BaseServiceUtility
#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level
Methods included from Gitlab::Allowable
Constructor Details
#initialize(merge_request, current_user, params = nil) ⇒ CreateService
Returns a new instance of CreateService.
7 8 9 10 |
# File 'app/services/draft_notes/create_service.rb', line 7 def initialize(merge_request, current_user, params = nil) @in_reply_to_discussion_id = params.delete(:in_reply_to_discussion_id) super end |
Instance Attribute Details
#in_draft_mode ⇒ Object
Returns the value of attribute in_draft_mode.
5 6 7 |
# File 'app/services/draft_notes/create_service.rb', line 5 def in_draft_mode @in_draft_mode end |
#in_reply_to_discussion_id ⇒ Object
Returns the value of attribute in_reply_to_discussion_id.
5 6 7 |
# File 'app/services/draft_notes/create_service.rb', line 5 def in_reply_to_discussion_id @in_reply_to_discussion_id end |
Instance Method Details
#execute ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/services/draft_notes/create_service.rb', line 12 def execute if in_reply_to_discussion_id.present? unless discussion return base_error(_('Thread to reply to cannot be found')) end params[:discussion_id] = discussion.reply_id end if params[:resolve_discussion] && !can_resolve_discussion? return base_error(_('User is not allowed to resolve thread')) end draft_note = DraftNote.new(params) draft_note.merge_request = merge_request draft_note. = current_user return draft_note unless draft_note.save if in_reply_to_discussion_id.blank? && draft_note.diff_file&.unfolded? merge_request.diffs.clear_cache end if draft_note.persisted? merge_request_activity_counter.track_create_review_note_action(user: current_user) end after_execute draft_note end |