Skip to content

Instantly share code, notes, and snippets.

@edavis10
Created September 10, 2010 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edavis10/574541 to your computer and use it in GitHub Desktop.
Save edavis10/574541 to your computer and use it in GitHub Desktop.
# Returns the mail adresses of users that should be notified
def recipients
notified = project.notified_users
# Author and assignee are always notified unless they have been locked
notified << author if author && author.active? && author.notify_about?(self)
notified << entered_by if entered_by && entered_by.active? && entered_by.notify_about?(self)
notified << assigned_to if assigned_to && assigned_to.active? && assigned_to.notify_about?(self)
notified.uniq!
# Remove users that can not view the issue
notified.reject! {|user| !visible?(user)}
notified.collect(&:mail)
end
# Utility method to help check if a user should be notified about an
# event.
#
# TODO: only supports Issue events currently
def notify_about?(object)
case mail_notification.to_sym
when :all
true
when :selected
# Handled by the Project
when :none
false
when :only_my_events
if object.is_a?(Issue)&& (object.author == self || object.entered_by ==self || object.assigned_to == self)
true
else
false
end
when :only_assigned
if object.is_a?(Issue) && object.assigned_to == self
true
else
false
end
when :only_owner
if object.is_a?(Issue) && object.author == self
true
else
false
end
when :only_owner_or_creator
if object.is_a?(Issue) && (object.author == self || object.entered_by == self)
true
else
false
end
else
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment