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 | 13 | @note = @project.notes.new(params[:note]) |
14 | 14 | @note.author = current_user |
15 | 15 | @note.notify = true if params[:notify] == '1' |
16 | + @note.notify_author = true if params[:notify_author] == '1' | |
16 | 17 | @note.save |
17 | 18 | |
18 | 19 | respond_to do |format| | ... | ... |
app/mailers/notify.rb
... | ... | @@ -28,6 +28,7 @@ class Notify < ActionMailer::Base |
28 | 28 | @note = note |
29 | 29 | @project = note.project |
30 | 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 | 32 | mail(:to => @user.email, :subject => "gitlab | #{@note.project.name} ") |
32 | 33 | end |
33 | 34 | ... | ... |
app/models/mailer_observer.rb
... | ... | @@ -27,7 +27,7 @@ class MailerObserver < ActiveRecord::Observer |
27 | 27 | end |
28 | 28 | |
29 | 29 | def new_note(note) |
30 | - return unless note.notify | |
30 | + return unless note.notify or note.notify_author | |
31 | 31 | note.project.users.reject { |u| u.id == current_user.id } .each do |u| |
32 | 32 | case note.noteable_type |
33 | 33 | when "Commit" then | ... | ... |
app/models/note.rb
... | ... | @@ -14,6 +14,7 @@ class Note < ActiveRecord::Base |
14 | 14 | |
15 | 15 | attr_protected :author, :author_id |
16 | 16 | attr_accessor :notify |
17 | + attr_accessor :notify_author | |
17 | 18 | |
18 | 19 | validates_presence_of :project |
19 | 20 | |
... | ... | @@ -40,6 +41,10 @@ class Note < ActiveRecord::Base |
40 | 41 | def notify |
41 | 42 | @notify ||= false |
42 | 43 | end |
44 | + | |
45 | + def notify_author | |
46 | + @notify_author ||= false | |
47 | + end | |
43 | 48 | end |
44 | 49 | # == Schema Information |
45 | 50 | # | ... | ... |
app/views/notes/_form.html.haml
... | ... | @@ -23,9 +23,13 @@ |
23 | 23 | %br |
24 | 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 | 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 | 33 | .clear |
30 | 34 | %br |
31 | 35 | = f.submit 'Add note', :class => "grey-button", :id => "submit_note" | ... | ... |