summaryrefslogtreecommitdiff
path: root/app/services/notes/create_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/notes/create_service.rb')
-rw-r--r--app/services/notes/create_service.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb
index 482c0444049..de5c5504d03 100644
--- a/app/services/notes/create_service.rb
+++ b/app/services/notes/create_service.rb
@@ -7,6 +7,7 @@ module Notes
if note.save
notification_service.new_note(note)
+ update_participants(note)
# Skip system notes, like status changes and cross-references.
unless note.system
@@ -34,5 +35,25 @@ module Notes
note.project.execute_hooks(note_data, :note_hooks)
note.project.execute_services(note_data, :note_hooks)
end
+
+ def update_participants(note)
+ users = [note.author, note.mentioned_users].flatten
+ noteable = note.noteable
+
+ # Add users as participants only if they have access to project
+ users.select! do |user|
+ user.can?(:read_project, note.project)
+ end
+
+ users.each do |user|
+ if Participant.where(user_id: user, target_id: noteable.id.to_s, target_type: noteable.class.name).blank?
+ participant = Participant.new
+ participant.target_id = noteable.id
+ participant.target_type = noteable.class.name
+ participant.user = user
+ participant.save
+ end
+ end
+ end
end
end