#575: did some refactoring according to comments
This commit is contained in:
parent
8788db12c0
commit
6b62615a3e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue