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,7 +27,8 @@ class MailerObserver < ActiveRecord::Observer ...@@ -27,7 +27,8 @@ 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
if note.notify
note.project.users.reject { |u| u.id == current_user.id } .each do |u| note.project.users.reject { |u| u.id == current_user.id } .each do |u|
case note.noteable_type case note.noteable_type
when "Commit" then when "Commit" then
...@@ -42,6 +43,10 @@ class MailerObserver < ActiveRecord::Observer ...@@ -42,6 +43,10 @@ class MailerObserver < ActiveRecord::Observer
Notify.note_wall_email(u, note).deliver Notify.note_wall_email(u, note).deliver
end end
end end
# Notify only author of resource
elsif note.notify_author
Notify.note_commit_email(note.commit_author, note).deliver
end
end end
def new_merge_request(merge_request) def new_merge_request(merge_request)
......
...@@ -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