diff options
author | Jarka Kadlecova <jarka@gitlab.com> | 2017-01-05 14:36:06 +0100 |
---|---|---|
committer | Jarka Kadlecova <jarka@gitlab.com> | 2017-01-18 18:38:17 -0500 |
commit | d6b11dafd37e78c12c982c42f274928293cdfa53 (patch) | |
tree | e20c62bc3b11b77e366bce2251146d5f5ec86e0c /app/services | |
parent | 270dc22658424ee7f279db99e56c6fc69acd3eb7 (diff) | |
download | gitlab-ce-d6b11dafd37e78c12c982c42f274928293cdfa53.tar.gz |
Support notes without project
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/notes/create_service.rb | 7 | ||||
-rw-r--r-- | app/services/notes/post_process_service.rb | 6 | ||||
-rw-r--r-- | app/services/notification_service.rb | 27 |
3 files changed, 28 insertions, 12 deletions
diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb index cdd765c85eb..b4f8b33d564 100644 --- a/app/services/notes/create_service.rb +++ b/app/services/notes/create_service.rb @@ -3,9 +3,10 @@ module Notes def execute merge_request_diff_head_sha = params.delete(:merge_request_diff_head_sha) - note = project.notes.new(params) - note.author = current_user - note.system = false + note = Note.new(params) + note.project = project + note.author = current_user + note.system = false if note.award_emoji? noteable = note.noteable diff --git a/app/services/notes/post_process_service.rb b/app/services/notes/post_process_service.rb index e4cd3fc7833..45d916800f6 100644 --- a/app/services/notes/post_process_service.rb +++ b/app/services/notes/post_process_service.rb @@ -10,8 +10,10 @@ module Notes # Skip system notes, like status changes and cross-references and awards unless @note.system? EventCreateService.new.leave_note(@note, @note.author) - @note.create_cross_references! - execute_note_hooks + unless @note.for_personal_snippet? + @note.create_cross_references! + execute_note_hooks + end end end diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index c3b61e68eab..2a467ade542 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -178,8 +178,15 @@ class NotificationService recipients = [] mentioned_users = note.mentioned_users - mentioned_users.select! do |user| - user.can?(:read_project, note.project) + + if note.for_personal_snippet? + mentioned_users.select! do |user| + user.can?(:read_personal_snippet, note.noteable) + end + else + mentioned_users.select! do |user| + user.can?(:read_project, note.project) + end end # Add all users participating in the thread (author, assignee, comment authors) @@ -192,11 +199,13 @@ class NotificationService recipients = recipients.concat(participants) - # Merge project watchers - recipients = add_project_watchers(recipients, note.project) + unless note.for_personal_snippet? + # Merge project watchers + recipients = add_project_watchers(recipients, note.project) - # Merge project with custom notification - recipients = add_custom_notifications(recipients, note.project, :new_note) + # Merge project with custom notification + recipients = add_custom_notifications(recipients, note.project, :new_note) + end # Reject users with Mention notification level, except those mentioned in _this_ note. recipients = reject_mention_users(recipients - mentioned_users, note.project) @@ -212,7 +221,11 @@ class NotificationService recipients = recipients.uniq # build notify method like 'note_commit_email' - notify_method = "note_#{note.noteable_type.underscore}_email".to_sym + if note.for_personal_snippet? + notify_method = "note_personal_snippet_email".to_sym + else + notify_method = "note_#{note.noteable_type.underscore}_email".to_sym + end recipients.each do |recipient| mailer.send(notify_method, recipient.id, note.id).deliver_later |