2014-03-11 07:39:25 +00:00
|
|
|
module Feed::Issue
|
2013-06-27 14:06:42 +01:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2014-03-26 20:02:28 +00:00
|
|
|
after_commit :new_issue_notifications, on: :create
|
2013-07-04 15:08:07 +01:00
|
|
|
|
2014-03-26 20:02:28 +00:00
|
|
|
after_commit :send_assign_notifications, on: :create, if: ->(i) { i.assignee }
|
2014-03-17 20:18:46 +00:00
|
|
|
after_update -> { send_assign_notifications(:update) }
|
2013-07-04 15:08:07 +01:00
|
|
|
|
2014-03-26 20:02:28 +00:00
|
|
|
after_commit :send_hooks, on: :create
|
2014-03-17 20:18:46 +00:00
|
|
|
after_update -> { send_hooks(:update) }, if: ->(i) { i.previous_changes['status'].present? }
|
2013-06-27 14:06:42 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def new_issue_notifications
|
|
|
|
collect_recipients.each do |recipient|
|
|
|
|
next if user_id == recipient.id
|
2013-07-04 09:56:35 +01:00
|
|
|
if recipient.notifier.can_notify && recipient.notifier.new_issue && assignee_id != recipient.id
|
2014-06-18 19:32:17 +01:00
|
|
|
UserMailer.new_issue_notification(id, recipient.id).deliver
|
2013-07-04 09:56:35 +01:00
|
|
|
end
|
2013-06-27 14:06:42 +01:00
|
|
|
ActivityFeed.create(
|
2014-01-21 04:51:49 +00:00
|
|
|
user: recipient,
|
|
|
|
kind: 'new_issue_notification',
|
|
|
|
data: {
|
|
|
|
user_name: user.name,
|
|
|
|
user_email: user.email,
|
|
|
|
user_id: user_id,
|
|
|
|
issue_serial_id: serial_id,
|
|
|
|
issue_title: title,
|
|
|
|
project_id: project.id,
|
|
|
|
project_name: project.name,
|
|
|
|
project_owner: project.owner.uname
|
2013-06-27 14:06:42 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
2014-03-18 23:00:29 +00:00
|
|
|
::Comment.create_link_on_issues_from_item(self)
|
2013-06-27 14:06:42 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def send_assign_notifications(action = :create)
|
2013-07-10 18:44:18 +01:00
|
|
|
if(action == :create && assignee_id) || previous_changes['assignee_id'].present?
|
2013-06-27 14:06:42 +01:00
|
|
|
if assignee.notifier.issue_assign && assignee.notifier.can_notify
|
2013-07-04 08:48:30 +01:00
|
|
|
UserMailer.issue_assign_notification(self, assignee).deliver
|
2013-06-27 14:06:42 +01:00
|
|
|
end
|
|
|
|
ActivityFeed.create(
|
2014-01-21 04:51:49 +00:00
|
|
|
user: assignee,
|
|
|
|
kind: 'issue_assign_notification',
|
|
|
|
data: {
|
|
|
|
user_name: assignee.name,
|
|
|
|
user_email: assignee.email,
|
|
|
|
issue_serial_id: serial_id,
|
|
|
|
issue_title: title,
|
|
|
|
project_id: project.id,
|
|
|
|
project_name: project.name,
|
|
|
|
project_owner: project.owner.uname
|
2013-06-27 14:06:42 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
# dont remove outdated issues link
|
2014-03-18 23:00:29 +00:00
|
|
|
::Comment.create_link_on_issues_from_item(self) if previous_changes['title'].present? || previous_changes['body'].present?
|
2013-06-27 14:06:42 +01:00
|
|
|
end
|
|
|
|
|
2013-07-04 15:08:07 +01:00
|
|
|
def send_hooks(action = :create)
|
|
|
|
project.hooks.each{ |h| h.receive_issues(self, action) }
|
|
|
|
end
|
2013-07-09 20:57:49 +01:00
|
|
|
end
|