summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/projects/commit_controller.rb6
-rw-r--r--app/models/commit.rb19
-rw-r--r--app/models/concerns/issuable.rb8
-rw-r--r--app/models/concerns/mentionable.rb4
-rw-r--r--app/models/note.rb8
-rw-r--r--app/models/snippet.rb12
-rw-r--r--app/services/notification_service.rb13
-rw-r--r--app/services/projects/participants_service.rb28
-rw-r--r--app/views/projects/commits/_commit.html.haml2
-rw-r--r--spec/services/notification_service_spec.rb2
10 files changed, 61 insertions, 41 deletions
diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb
index 87e39f1363a..894cf93b9ae 100644
--- a/app/controllers/projects/commit_controller.rb
+++ b/app/controllers/projects/commit_controller.rb
@@ -10,11 +10,11 @@ class Projects::CommitController < Projects::ApplicationController
def show
return git_not_found! unless @commit
- @line_notes = @project.notes.for_commit_id(commit.id).inline
+ @line_notes = commit.notes(@project).inline
@diffs = @commit.diffs
@note = @project.build_commit_note(commit)
- @notes_count = @project.notes.for_commit_id(commit.id).count
- @notes = @project.notes.for_commit_id(@commit.id).not_inline.fresh
+ @notes_count = commit.notes(@project).count
+ @notes = commit.notes(@project).not_inline.fresh
@noteable = @commit
@comments_allowed = @reply_allowed = true
@comments_target = {
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 006fa62c8f9..1cabc060c2a 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -134,6 +134,25 @@ class Commit
User.find_for_commit(committer_email, committer_name)
end
+ def participants(project, current_user = nil)
+ users = []
+ users << author
+ users << committer
+
+ users.push *self.mentioned_users(current_user, project)
+
+ notes(project).each do |note|
+ users << note.author
+ users.push *note.mentioned_users(current_user, project)
+ end
+
+ users.uniq
+ end
+
+ def notes(project)
+ project.notes.for_commit_id(self.id)
+ end
+
def method_missing(m, *args, &block)
@raw.send(m, *args, &block)
end
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index 478134dff68..a21d9bdfe8a 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -122,15 +122,15 @@ module Issuable
users = []
users << author
users << assignee if is_assigned?
- mentions = []
- mentions << self.mentioned_users(current_user)
+
+ users.push *self.mentioned_users(current_user)
notes.each do |note|
users << note.author
- mentions << note.mentioned_users(current_user)
+ users.push *note.mentioned_users(current_user)
end
- users.concat(mentions.reduce([], :|)).uniq
+ users.uniq
end
def subscribed?(user)
diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb
index b7882a2bb16..acd9a1edc48 100644
--- a/app/models/concerns/mentionable.rb
+++ b/app/models/concerns/mentionable.rb
@@ -42,10 +42,10 @@ module Mentionable
Note.cross_reference_exists?(target, local_reference)
end
- def mentioned_users(current_user = nil)
+ def mentioned_users(current_user = nil, p = project)
return [] if mentionable_text.blank?
- ext = Gitlab::ReferenceExtractor.new(self.project, current_user)
+ ext = Gitlab::ReferenceExtractor.new(p, current_user)
ext.analyze(mentionable_text)
ext.users.uniq
end
diff --git a/app/models/note.rb b/app/models/note.rb
index 2cf3fac2def..4b5fa7a2ab5 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -327,14 +327,6 @@ class Note < ActiveRecord::Base
current_application_settings.max_attachment_size.megabytes.to_i
end
- def commit_author
- @commit_author ||=
- project.team.users.find_by(email: noteable.author_email) ||
- project.team.users.find_by(name: noteable.author_name)
- rescue
- nil
- end
-
def cross_reference?
note.start_with?(self.class.cross_reference_note_prefix)
end
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index b35e72c4bdb..c11c28805eb 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -87,6 +87,18 @@ class Snippet < ActiveRecord::Base
visibility_level
end
+ def participants(current_user = self.author)
+ users = []
+ users << author
+
+ notes.each do |note|
+ users << note.author
+ users.push *note.mentioned_users(current_user)
+ end
+
+ users.uniq
+ end
+
class << self
def search(query)
where('(title LIKE :query OR file_name LIKE :query)', query: "%#{query}%")
diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb
index cfed7964c37..c7e45a2c2c7 100644
--- a/app/services/notification_service.rb
+++ b/app/services/notification_service.rb
@@ -127,17 +127,12 @@ class NotificationService
recipients = []
- if note.commit_id.present?
- recipients << note.commit_author
- end
-
# Add all users participating in the thread (author, assignee, comment authors)
participants =
- if target.respond_to?(:participants)
- target.participants
- elsif target.is_a?(Commit)
- author_ids = Note.for_commit_id(target.id).pluck(:author_id).uniq
- User.where(id: author_ids)
+ if target.is_a?(Commit)
+ target.participants(note.project, note.author)
+ elsif target.respond_to?(:participants)
+ target.participants(note.author)
else
note.mentioned_users
end
diff --git a/app/services/projects/participants_service.rb b/app/services/projects/participants_service.rb
index ae6260bcdab..c2d8f48f6e4 100644
--- a/app/services/projects/participants_service.rb
+++ b/app/services/projects/participants_service.rb
@@ -13,19 +13,21 @@ module Projects
end
def participants_in(type, id)
- users = case type
- when "Issue"
- issue = project.issues.find_by_iid(id)
- issue ? issue.participants(current_user) : []
- when "MergeRequest"
- merge_request = project.merge_requests.find_by_iid(id)
- merge_request ? merge_request.participants(current_user) : []
- when "Commit"
- author_ids = Note.for_commit_id(id).pluck(:author_id).uniq
- User.where(id: author_ids)
- else
- []
- end
+ users =
+ case type
+ when "Issue"
+ issue = project.issues.find_by_iid(id)
+ issue.participants(current_user) if issue
+ when "MergeRequest"
+ merge_request = project.merge_requests.find_by_iid(id)
+ merge_request.participants(current_user) if merge_request
+ when "Commit"
+ commit = project.repository.commit(id)
+ commit.participants(project, current_user) if commit
+ end
+
+ return [] unless users
+
sorted(users)
end
diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml
index c6026f96804..8e1aaa4d051 100644
--- a/app/views/projects/commits/_commit.html.haml
+++ b/app/views/projects/commits/_commit.html.haml
@@ -12,7 +12,7 @@
- if @note_counts
- note_count = @note_counts.fetch(commit.id, 0)
- else
- - notes = project.notes.for_commit_id(commit.id)
+ - notes = commit.notes(project)
- note_count = notes.user.count
- if note_count > 0
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb
index bfca2c88264..6d2bc41c2b9 100644
--- a/spec/services/notification_service_spec.rb
+++ b/spec/services/notification_service_spec.rb
@@ -149,7 +149,7 @@ describe NotificationService do
before do
build_team(note.project)
- note.stub(:commit_author => @u_committer)
+ allow_any_instance_of(Commit).to receive(:author).and_return(@u_committer)
end
describe :new_note do