Commit a769204f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improved commit author notification

parent adcfeae1
...@@ -27,8 +27,7 @@ class Notify < ActionMailer::Base ...@@ -27,8 +27,7 @@ class Notify < ActionMailer::Base
@user = user @user = user
@note = note @note = note
@project = note.project @project = note.project
@commit = @project.repo.commits(note.noteable_id).first @commit = @note.target
return unless ( note.notify or ( note.notify_author and @commit.author.email == @user.email ) )
mail(:to => @user.email, :subject => "gitlab | note for commit | #{@note.project.name} ") mail(:to => @user.email, :subject => "gitlab | note for commit | #{@note.project.name} ")
end end
......
...@@ -27,20 +27,25 @@ class MailerObserver < ActiveRecord::Observer ...@@ -27,20 +27,25 @@ class MailerObserver < ActiveRecord::Observer
end end
def new_note(note) def new_note(note)
return unless note.notify or note.notify_author # Notify whole team except author of note
note.project.users.reject { |u| u.id == current_user.id } .each do |u| if note.notify
case note.noteable_type note.project.users.reject { |u| u.id == current_user.id } .each do |u|
when "Commit" then case note.noteable_type
Notify.note_commit_email(u, note).deliver when "Commit" then
when "Issue" then Notify.note_commit_email(u, note).deliver
Notify.note_issue_email(u, note).deliver when "Issue" then
when "MergeRequest" then Notify.note_issue_email(u, note).deliver
Notify.note_merge_request_email(u, note).deliver when "MergeRequest" then
when "Snippet" Notify.note_merge_request_email(u, note).deliver
true when "Snippet"
else true
Notify.note_wall_email(u, note).deliver else
Notify.note_wall_email(u, note).deliver
end
end end
# Notify only author of resource
elsif note.notify_author
Notify.note_commit_email(note.commit_author, note).deliver
end end
end end
......
...@@ -57,6 +57,36 @@ class Note < ActiveRecord::Base ...@@ -57,6 +57,36 @@ class Note < ActiveRecord::Base
rescue rescue
nil nil
end end
# Check if we can notify commit author
# with email about our comment
#
# If commit author email exist in project
# and commit author is not passed user we can
# send email to him
#
# params:
# user - current user
#
# return:
# Boolean
#
def notify_only_author?(user)
commit? && commit_author &&
commit_author.email != user.email
end
def commit?
noteable_type == "Commit"
end
def commit_author
@commit_author ||=
project.users.find_by_email(target.author_email) ||
project.users.find_by_name(target.author_name)
rescue
nil
end
end end
# == Schema Information # == Schema Information
# #
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
= check_box_tag :notify, 1, @note.noteable_type != "Commit" = check_box_tag :notify, 1, @note.noteable_type != "Commit"
%span Project team %span Project team
-if @note.noteable_type == "Commit" - if @note.notify_only_author?(current_user)
= label_tag :notify_author do = label_tag :notify_author do
= check_box_tag :notify_author, 1 , @note.noteable_type == "Commit" = check_box_tag :notify_author, 1 , @note.noteable_type == "Commit"
%span Commit author %span Commit author
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment