[refs #777] fix for group owned project
This commit is contained in:
parent
87cf300c39
commit
519886fecd
|
@ -12,10 +12,8 @@ class ActivityFeedObserver < ActiveRecord::Observer
|
|||
)
|
||||
|
||||
when 'Issue'
|
||||
recipients = record.collect_recipient_ids
|
||||
recipients.each do |recipient_id|
|
||||
recipient = User.find(recipient_id)
|
||||
UserMailer.new_issue_notification(record, recipient).deliver if User.find(recipient).notifier.can_notify && User.find(recipient).notifier.new_issue
|
||||
record.collect_recipients.each do |recipient|
|
||||
UserMailer.new_issue_notification(record, recipient).deliver if recipient.notifier.can_notify && recipient.notifier.new_issue
|
||||
ActivityFeed.create(
|
||||
:user => recipient,
|
||||
:kind => 'new_issue_notification',
|
||||
|
@ -94,9 +92,9 @@ class ActivityFeedObserver < ActiveRecord::Observer
|
|||
options.merge!({:user_id => first_commiter.id, :user_name => first_commiter.name}) if first_commiter
|
||||
end
|
||||
|
||||
record.project.owner_and_admin_ids.each do |recipient|
|
||||
record.project.admins.each do |recipient|
|
||||
ActivityFeed.create!(
|
||||
:user => User.find(recipient),
|
||||
:user => recipient,
|
||||
:kind => kind,
|
||||
:data => options
|
||||
)
|
||||
|
@ -106,9 +104,9 @@ class ActivityFeedObserver < ActiveRecord::Observer
|
|||
actor = User.find_by_uname! record[:actor_name]
|
||||
project = Project.find record[:project_id]
|
||||
|
||||
project.owner_and_admin_ids.each do |recipient|
|
||||
project.admins.each do |recipient|
|
||||
ActivityFeed.create!(
|
||||
:user => User.find(recipient),#record.user,
|
||||
:user => recipient,
|
||||
:kind => 'wiki_new_commit_notification',
|
||||
:data => {:user_id => actor.id, :user_name => actor.name, :user_email => actor.email, :project_id => project.id,
|
||||
:project_name => project.name, :commit_sha => record[:commit_sha], :project_owner => project.owner.uname}
|
||||
|
@ -134,9 +132,9 @@ class ActivityFeedObserver < ActiveRecord::Observer
|
|||
if [BuildList::BUILD_PUBLISHED, BuildServer::SUCCESS, BuildServer::BUILD_ERROR, BuildServer::PLATFORM_NOT_FOUND,
|
||||
BuildServer::PROJECT_NOT_FOUND, BuildServer::PROJECT_VERSION_NOT_FOUND, BuildList::FAILED_PUBLISH].include? record.status or
|
||||
(record.status == BuildList::BUILD_PENDING && record.bs_id_changed?)
|
||||
record.project.owner_and_admin_ids.each do |recipient|
|
||||
record.project.admins.each do |recipient|
|
||||
ActivityFeed.create(
|
||||
:user => User.find(recipient),
|
||||
:user => recipient,
|
||||
:kind => 'build_list_notification',
|
||||
:data => {:task_num => record.bs_id, :build_list_id => record.id, :status => record.status, :updated_at => record.updated_at,
|
||||
:project_id => record.project_id, :project_name => record.project.name, :project_owner => record.project.owner.uname,
|
||||
|
|
|
@ -138,9 +138,8 @@ class Comment < ActiveRecord::Base
|
|||
if issue_comment?
|
||||
commentable.subscribes.create(:user => user) if !commentable.subscribes.exists?(:user_id => user.id)
|
||||
elsif commit_comment?
|
||||
recipients = project.relations.by_role('admin').where(:actor_type => 'User').map &:actor # admins
|
||||
recipients << user << User.where(:email => commentable.committer.email).first # commentor and committer
|
||||
recipients << project.owner if project.owner_type == 'User' # project owner
|
||||
recipients = project.admins
|
||||
recipients << user << User.where(:email => commentable.try(:committer).try(:email)).first # commentor and committer
|
||||
recipients.compact.uniq.each do |user|
|
||||
options = {:project_id => project.id, :subscribeable_id => commentable_id, :subscribeable_type => commentable.class.name, :user_id => user.id}
|
||||
Subscribe.subscribe_to_commit(options) if Subscribe.subscribed_to_commit?(project, user, commentable)
|
||||
|
|
|
@ -62,11 +62,9 @@ class Issue < ActiveRecord::Base
|
|||
self.status = 'open'
|
||||
end
|
||||
|
||||
def collect_recipient_ids
|
||||
recipients = self.project.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) }
|
||||
recipients = recipients | [self.assignee_id] if self.assignee_id
|
||||
recipients = recipients | [self.project.owner_id] if self.project.owner_type == 'User'
|
||||
|
||||
def collect_recipients
|
||||
recipients = self.project.admins
|
||||
recipients = recipients | [self.assignee] if self.assignee
|
||||
recipients
|
||||
end
|
||||
|
||||
|
@ -78,10 +76,9 @@ class Issue < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def subscribe_users
|
||||
recipients = collect_recipient_ids
|
||||
recipients.each do |recipient_id|
|
||||
if User.find(recipient_id).notifier.new_comment && !self.subscribes.exists?(:user_id => recipient_id)
|
||||
ss = self.subscribes.create(:user_id => recipient_id)
|
||||
collect_recipients.each do |recipient|
|
||||
if recipient.notifier.new_comment && !self.subscribes.exists?(:user_id => recipient.id)
|
||||
ss = self.subscribes.create(:user_id => recipient.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -94,5 +91,4 @@ class Issue < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -103,10 +103,14 @@ class Project < ActiveRecord::Base
|
|||
@platforms ||= repositories.map(&:platform).uniq
|
||||
end
|
||||
|
||||
def owner_and_admin_ids
|
||||
recipients = self.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) }
|
||||
recipients = recipients | [self.owner_id] if self.owner_type == 'User'
|
||||
recipients
|
||||
def admins
|
||||
admins = self.collaborators.where("relations.role = 'admin'")
|
||||
grs = self.groups.where("relations.role = 'admin'")
|
||||
if self.owner.is_a? Group
|
||||
grs = grs.where("relations.actor_id != ?", self.owner.id)
|
||||
admins = admins | owner.members.where("relations.role = 'admin'")
|
||||
end
|
||||
admins = admins | grs.map(&:members).flatten # member of the admin group is admin
|
||||
end
|
||||
|
||||
def public?
|
||||
|
|
Loading…
Reference in New Issue