Commit c0b47d3245a15b12ebe7a6f4154f35ba91396c3c
1 parent
89a43543
Exists in
master
and in
4 other branches
Alert commit author on note
Allows to alert only the commit author when a new note is added on a commit, useful when gitlabhq is used for code reviews, allows less noise with mails...
Showing
5 changed files
with
13 additions
and
2 deletions
Show diff stats
app/controllers/notes_controller.rb
@@ -13,6 +13,7 @@ class NotesController < ApplicationController | @@ -13,6 +13,7 @@ class NotesController < ApplicationController | ||
13 | @note = @project.notes.new(params[:note]) | 13 | @note = @project.notes.new(params[:note]) |
14 | @note.author = current_user | 14 | @note.author = current_user |
15 | @note.notify = true if params[:notify] == '1' | 15 | @note.notify = true if params[:notify] == '1' |
16 | + @note.notify_author = true if params[:notify_author] == '1' | ||
16 | @note.save | 17 | @note.save |
17 | 18 | ||
18 | respond_to do |format| | 19 | respond_to do |format| |
app/mailers/notify.rb
@@ -28,6 +28,7 @@ class Notify < ActionMailer::Base | @@ -28,6 +28,7 @@ class Notify < ActionMailer::Base | ||
28 | @note = note | 28 | @note = note |
29 | @project = note.project | 29 | @project = note.project |
30 | @commit = @project.repo.commits(note.noteable_id).first | 30 | @commit = @project.repo.commits(note.noteable_id).first |
31 | + return unless ( note.notify or ( note.notify_author and @commit.author.email == @user.email ) ) | ||
31 | mail(:to => @user.email, :subject => "gitlab | #{@note.project.name} ") | 32 | mail(:to => @user.email, :subject => "gitlab | #{@note.project.name} ") |
32 | end | 33 | end |
33 | 34 |
app/models/mailer_observer.rb
@@ -27,7 +27,7 @@ class MailerObserver < ActiveRecord::Observer | @@ -27,7 +27,7 @@ class MailerObserver < ActiveRecord::Observer | ||
27 | end | 27 | end |
28 | 28 | ||
29 | def new_note(note) | 29 | def new_note(note) |
30 | - return unless note.notify | 30 | + return unless note.notify or note.notify_author |
31 | note.project.users.reject { |u| u.id == current_user.id } .each do |u| | 31 | note.project.users.reject { |u| u.id == current_user.id } .each do |u| |
32 | case note.noteable_type | 32 | case note.noteable_type |
33 | when "Commit" then | 33 | when "Commit" then |
app/models/note.rb
@@ -14,6 +14,7 @@ class Note < ActiveRecord::Base | @@ -14,6 +14,7 @@ class Note < ActiveRecord::Base | ||
14 | 14 | ||
15 | attr_protected :author, :author_id | 15 | attr_protected :author, :author_id |
16 | attr_accessor :notify | 16 | attr_accessor :notify |
17 | + attr_accessor :notify_author | ||
17 | 18 | ||
18 | validates_presence_of :project | 19 | validates_presence_of :project |
19 | 20 | ||
@@ -40,6 +41,10 @@ class Note < ActiveRecord::Base | @@ -40,6 +41,10 @@ class Note < ActiveRecord::Base | ||
40 | def notify | 41 | def notify |
41 | @notify ||= false | 42 | @notify ||= false |
42 | end | 43 | end |
44 | + | ||
45 | + def notify_author | ||
46 | + @notify_author ||= false | ||
47 | + end | ||
43 | end | 48 | end |
44 | # == Schema Information | 49 | # == Schema Information |
45 | # | 50 | # |
app/views/notes/_form.html.haml
@@ -23,9 +23,13 @@ | @@ -23,9 +23,13 @@ | ||
23 | %br | 23 | %br |
24 | = f.file_field :attachment | 24 | = f.file_field :attachment |
25 | 25 | ||
26 | - = check_box_tag :notify, 1, true | 26 | + = check_box_tag :notify, 1, @note.noteable_type != "Commit" |
27 | = label_tag :notify, "Notify project team about your note" | 27 | = label_tag :notify, "Notify project team about your note" |
28 | 28 | ||
29 | + -if @note.noteable_type == "Commit" | ||
30 | + = check_box_tag :notify_author, 1 , @note.noteable_type == "Commit" | ||
31 | + = label_tag :notify_author, "Notify commit author about your note" | ||
32 | + | ||
29 | .clear | 33 | .clear |
30 | %br | 34 | %br |
31 | = f.submit 'Add note', :class => "grey-button", :id => "submit_note" | 35 | = f.submit 'Add note', :class => "grey-button", :id => "submit_note" |