Skip to content

Instantly share code, notes, and snippets.

@nisanthchunduru
Last active August 29, 2015 14:02
Show Gist options
  • Save nisanthchunduru/3d9d98b23f68fa590a24 to your computer and use it in GitHub Desktop.
Save nisanthchunduru/3d9d98b23f68fa590a24 to your computer and use it in GitHub Desktop.
class CommentCreated < Action
include WatchersToBeNotified
watchers_to_be_notified {
ticket_attr_reader :ticket
categories {
agents to_be_notified_if: :all_comments
user_assignees to_be_notified_if: :comment_assignment
group_assignees to_be_notified_if: :comment_group_assignment
}
blacklist_if { |watcher| watcher.user == @comment.author }
}
watchers_to_be_notified {
agents to_be_notified_if: :all_comments
user_assignees to_be_notified_if: :comment_assignment
group_assignees to_be_notified_if: :comment_group_assignment
inputs {
ticket_attr_reader :ticket
blacklist_if { |watcher| watcher.user == @comment.author }
}
}
watchers_to_be_notified {
agents to_be_notified_if: :all_comments
user_assignees to_be_notified_if: :comment_assignment
group_assignees to_be_notified_if: :comment_group_assignment
blacklist_if { |watcher| watcher.user == @comment.author }
inputs {
ticket_attr_reader :ticket
}
}
recipients :watchers_to_be_notified
recipients :mentioned_users
# Global blacklist
blacklist_recipient_if :system_user?, :app_user?
# mail_renderer :mail_renderer
mail_renderer { |recipient| TicketNotifications.comment(@comment, recipient) }
attr_reader :comment
def initialize(@comment)
@comment = comment
end
def mentioned_users
@comment.mentioned_users
end
def system_user?(user)
user.system?
end
def app_user(user)
user.app?
end
end
class Action
def send_notifications
recipients.uniq.each(&:notify)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment