[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'
|
when 'Issue'
|
||||||
recipients = record.collect_recipient_ids
|
record.collect_recipients.each do |recipient|
|
||||||
recipients.each do |recipient_id|
|
UserMailer.new_issue_notification(record, recipient).deliver if recipient.notifier.can_notify && recipient.notifier.new_issue
|
||||||
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
|
|
||||||
ActivityFeed.create(
|
ActivityFeed.create(
|
||||||
:user => recipient,
|
:user => recipient,
|
||||||
:kind => 'new_issue_notification',
|
: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
|
options.merge!({:user_id => first_commiter.id, :user_name => first_commiter.name}) if first_commiter
|
||||||
end
|
end
|
||||||
|
|
||||||
record.project.owner_and_admin_ids.each do |recipient|
|
record.project.admins.each do |recipient|
|
||||||
ActivityFeed.create!(
|
ActivityFeed.create!(
|
||||||
:user => User.find(recipient),
|
:user => recipient,
|
||||||
:kind => kind,
|
:kind => kind,
|
||||||
:data => options
|
:data => options
|
||||||
)
|
)
|
||||||
|
@ -106,9 +104,9 @@ class ActivityFeedObserver < ActiveRecord::Observer
|
||||||
actor = User.find_by_uname! record[:actor_name]
|
actor = User.find_by_uname! record[:actor_name]
|
||||||
project = Project.find record[:project_id]
|
project = Project.find record[:project_id]
|
||||||
|
|
||||||
project.owner_and_admin_ids.each do |recipient|
|
project.admins.each do |recipient|
|
||||||
ActivityFeed.create!(
|
ActivityFeed.create!(
|
||||||
:user => User.find(recipient),#record.user,
|
:user => recipient,
|
||||||
:kind => 'wiki_new_commit_notification',
|
:kind => 'wiki_new_commit_notification',
|
||||||
:data => {:user_id => actor.id, :user_name => actor.name, :user_email => actor.email, :project_id => project.id,
|
: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}
|
: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,
|
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
|
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.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(
|
ActivityFeed.create(
|
||||||
:user => User.find(recipient),
|
:user => recipient,
|
||||||
:kind => 'build_list_notification',
|
:kind => 'build_list_notification',
|
||||||
:data => {:task_num => record.bs_id, :build_list_id => record.id, :status => record.status, :updated_at => record.updated_at,
|
: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,
|
: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?
|
if issue_comment?
|
||||||
commentable.subscribes.create(:user => user) if !commentable.subscribes.exists?(:user_id => user.id)
|
commentable.subscribes.create(:user => user) if !commentable.subscribes.exists?(:user_id => user.id)
|
||||||
elsif commit_comment?
|
elsif commit_comment?
|
||||||
recipients = project.relations.by_role('admin').where(:actor_type => 'User').map &:actor # admins
|
recipients = project.admins
|
||||||
recipients << user << User.where(:email => commentable.committer.email).first # commentor and committer
|
recipients << user << User.where(:email => commentable.try(:committer).try(:email)).first # commentor and committer
|
||||||
recipients << project.owner if project.owner_type == 'User' # project owner
|
|
||||||
recipients.compact.uniq.each do |user|
|
recipients.compact.uniq.each do |user|
|
||||||
options = {:project_id => project.id, :subscribeable_id => commentable_id, :subscribeable_type => commentable.class.name, :user_id => user.id}
|
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)
|
Subscribe.subscribe_to_commit(options) if Subscribe.subscribed_to_commit?(project, user, commentable)
|
||||||
|
|
|
@ -62,11 +62,9 @@ class Issue < ActiveRecord::Base
|
||||||
self.status = 'open'
|
self.status = 'open'
|
||||||
end
|
end
|
||||||
|
|
||||||
def collect_recipient_ids
|
def collect_recipients
|
||||||
recipients = self.project.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) }
|
recipients = self.project.admins
|
||||||
recipients = recipients | [self.assignee_id] if self.assignee_id
|
recipients = recipients | [self.assignee] if self.assignee
|
||||||
recipients = recipients | [self.project.owner_id] if self.project.owner_type == 'User'
|
|
||||||
|
|
||||||
recipients
|
recipients
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -78,10 +76,9 @@ class Issue < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def subscribe_users
|
def subscribe_users
|
||||||
recipients = collect_recipient_ids
|
collect_recipients.each do |recipient|
|
||||||
recipients.each do |recipient_id|
|
if recipient.notifier.new_comment && !self.subscribes.exists?(:user_id => 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)
|
||||||
ss = self.subscribes.create(:user_id => recipient_id)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -94,5 +91,4 @@ class Issue < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -103,10 +103,14 @@ class Project < ActiveRecord::Base
|
||||||
@platforms ||= repositories.map(&:platform).uniq
|
@platforms ||= repositories.map(&:platform).uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def owner_and_admin_ids
|
def admins
|
||||||
recipients = self.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) }
|
admins = self.collaborators.where("relations.role = 'admin'")
|
||||||
recipients = recipients | [self.owner_id] if self.owner_type == 'User'
|
grs = self.groups.where("relations.role = 'admin'")
|
||||||
recipients
|
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
|
end
|
||||||
|
|
||||||
def public?
|
def public?
|
||||||
|
|
Loading…
Reference in New Issue