#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)
|
def build_list_notification(build_list, user)
|
||||||
I18n.locale = user.language if user.language
|
I18n.locale = user.language if user.language
|
||||||
@user = user
|
@user, @build_list = user, build_list
|
||||||
@build_list = build_list
|
|
||||||
|
|
||||||
subject = "[#{build_list.bs_id.present? ? build_list.bs_id : t("layout.build_lists.bs_id_not_set")}] "
|
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 << (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|
|
mail(:to => user.email, :subject => subject) do |format|
|
||||||
format.html
|
format.html
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,25 +25,20 @@ class BuildListObserver < ActiveRecord::Observer
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.notify_users(build_list)
|
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 = []
|
users = []
|
||||||
if build_list.project # find associated users
|
if build_list.project # find associated users
|
||||||
associated_users = build_list.project.members
|
users = build_list.project.all_members.
|
||||||
associated_users << (build_list.project.owner.is_a?(User) ?
|
|
||||||
build_list.project.owner : build_list.project.owner.members)
|
|
||||||
users = associated_users.flatten.uniq.
|
|
||||||
select{ |user| user.notifier.can_notify? && user.notifier.new_associated_build? }
|
select{ |user| user.notifier.can_notify? && user.notifier.new_associated_build? }
|
||||||
end
|
end
|
||||||
if build_list.user.notifier.can_notify? && build_list.user.notifier.new_build?
|
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
|
end
|
||||||
users.each do |user|
|
users.each do |user|
|
||||||
if (( build_list.auto_publish? &&
|
UserMailer.build_list_notification(build_list, user).deliver
|
||||||
PUBLICATION_STATUSES.include?(build_list.status) ) ||
|
|
||||||
( !build_list.auto_publish? && STATUSES.include?(build_list.status) ))
|
|
||||||
|
|
||||||
UserMailer.build_list_notification(build_list, user).deliver
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end # notify_users
|
end # notify_users
|
||||||
|
|
|
@ -76,8 +76,12 @@ class Project < ActiveRecord::Base
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def all_members
|
||||||
|
(members | (owner_type == 'User' ? [owner] : owner.members)).uniq
|
||||||
|
end
|
||||||
|
|
||||||
def members
|
def members
|
||||||
collaborators + groups.map(&:members).flatten
|
collaborators | groups.map(&:members).flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
def platforms
|
def platforms
|
||||||
|
|
Loading…
Reference in New Issue