diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 59bcc3c70..408625765 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -38,13 +38,11 @@ class UserMailer < ActionMailer::Base def build_list_notification(build_list, user) I18n.locale = user.language if user.language - @user = user - @build_list = build_list + @user, @build_list = user, build_list subject = "[#{build_list.bs_id.present? ? build_list.bs_id : t("layout.build_lists.bs_id_not_set")}] " subject << (build_list.project ? build_list.project.name_with_owner : t("layout.projects.unexisted_project")) - subject << " - " - subject << build_list.human_status + subject << " - #{build_list.human_status}" mail(:to => user.email, :subject => subject) do |format| format.html end diff --git a/app/models/build_list_observer.rb b/app/models/build_list_observer.rb index b02a445db..a41f17512 100644 --- a/app/models/build_list_observer.rb +++ b/app/models/build_list_observer.rb @@ -25,25 +25,20 @@ class BuildListObserver < ActiveRecord::Observer private def self.notify_users(build_list) - unless build_list.mass_build_id + if !build_list.mass_build_id && + ( (build_list.auto_publish? && PUBLICATION_STATUSES.include?(build_list.status)) || + (!build_list.auto_publish? && STATUSES.include?(build_list.status)) ) + users = [] if build_list.project # find associated users - associated_users = build_list.project.members - associated_users << (build_list.project.owner.is_a?(User) ? - build_list.project.owner : build_list.project.owner.members) - users = associated_users.flatten.uniq. + users = build_list.project.all_members. select{ |user| user.notifier.can_notify? && user.notifier.new_associated_build? } end if build_list.user.notifier.can_notify? && build_list.user.notifier.new_build? - users << build_list.user unless users.include?(build_list.user) + users | [build_list.user] end users.each do |user| - if (( build_list.auto_publish? && - PUBLICATION_STATUSES.include?(build_list.status) ) || - ( !build_list.auto_publish? && STATUSES.include?(build_list.status) )) - - UserMailer.build_list_notification(build_list, user).deliver - end + UserMailer.build_list_notification(build_list, user).deliver end end end # notify_users diff --git a/app/models/project.rb b/app/models/project.rb index c8744cb08..906c26a89 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -76,8 +76,12 @@ class Project < ActiveRecord::Base name end + def all_members + (members | (owner_type == 'User' ? [owner] : owner.members)).uniq + end + def members - collaborators + groups.map(&:members).flatten + collaborators | groups.map(&:members).flatten end def platforms