Commit a769204f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improved commit author notification

parent adcfeae1
......@@ -27,8 +27,7 @@ class Notify < ActionMailer::Base
@user = user
@note = note
@project = note.project
@commit = @project.repo.commits(note.noteable_id).first
return unless ( note.notify or ( note.notify_author and @commit.author.email == @user.email ) )
@commit = @note.target
mail(:to => @user.email, :subject => "gitlab | note for commit | #{@note.project.name} ")
end
......
......@@ -27,20 +27,25 @@ class MailerObserver < ActiveRecord::Observer
end
def new_note(note)
return unless note.notify or note.notify_author
note.project.users.reject { |u| u.id == current_user.id } .each do |u|
case note.noteable_type
when "Commit" then
Notify.note_commit_email(u, note).deliver
when "Issue" then
Notify.note_issue_email(u, note).deliver
when "MergeRequest" then
Notify.note_merge_request_email(u, note).deliver
when "Snippet"
true
else
Notify.note_wall_email(u, note).deliver
# Notify whole team except author of note
if note.notify
note.project.users.reject { |u| u.id == current_user.id } .each do |u|
case note.noteable_type
when "Commit" then
Notify.note_commit_email(u, note).deliver
when "Issue" then
Notify.note_issue_email(u, note).deliver
when "MergeRequest" then
Notify.note_merge_request_email(u, note).deliver
when "Snippet"
true
else
Notify.note_wall_email(u, note).deliver
end
end
# Notify only author of resource
elsif note.notify_author
Notify.note_commit_email(note.commit_author, note).deliver
end
end
......
......@@ -57,6 +57,36 @@ class Note < ActiveRecord::Base
rescue
nil
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
# == Schema Information
#
......
......@@ -17,7 +17,7 @@
= check_box_tag :notify, 1, @note.noteable_type != "Commit"
%span Project team
-if @note.noteable_type == "Commit"
- if @note.notify_only_author?(current_user)
= label_tag :notify_author do
= check_box_tag :notify_author, 1 , @note.noteable_type == "Commit"
%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