Make IssueObserver handle issus, not MailerObserver

This commit is contained in:
Robb Kidd 2012-05-21 13:30:53 -04:00
parent 356430c3c0
commit 6617eaaf9b
6 changed files with 64 additions and 21 deletions

View file

@ -68,6 +68,10 @@ class Issue < ActiveRecord::Base
def is_being_closed?
closed_changed? && closed
end
def is_being_reopened?
closed_changed? && !closed
end
end
# == Schema Information
#

View file

@ -5,9 +5,10 @@ class IssueObserver < ActiveRecord::Observer
Notify.new_issue_email(issue.id) if issue.assignee != current_user
end
def after_change(issue)
def after_update(issue)
send_reassigned_email(issue) if issue.is_being_reassigned?
Note.create_status_change_note(issue, current_user, 'closed') if issue.is_being_closed?
Note.create_status_change_note(issue, current_user, 'reopened') if issue.is_being_reopened?
end
def send_reassigned_email(issue)

View file

@ -3,7 +3,6 @@ class MailerObserver < ActiveRecord::Observer
cattr_accessor :current_user
def after_create(model)
new_issue(model) if model.kind_of?(Issue)
new_user(model) if model.kind_of?(User)
new_note(model) if model.kind_of?(Note)
new_merge_request(model) if model.kind_of?(MergeRequest)
@ -11,17 +10,10 @@ class MailerObserver < ActiveRecord::Observer
def after_update(model)
changed_merge_request(model) if model.kind_of?(MergeRequest)
changed_issue(model) if model.kind_of?(Issue)
end
protected
def new_issue(issue)
if issue.assignee != current_user
Notify.new_issue_email(issue.id).deliver
end
end
def new_user(user)
Notify.new_user_email(user.id, user.password).deliver
end
@ -65,12 +57,8 @@ class MailerObserver < ActiveRecord::Observer
status_notify_and_comment merge_request, :reassigned_merge_request_email
end
def changed_issue(issue)
status_notify_and_comment issue, :reassigned_issue_email
end
# This method used for Issues & Merge Requests
#
#
# It create a comment for Issue or MR if someone close/reopen.
# It also notify via email if assignee was changed
#