Commit d2bf9dbc284117a6f52e3be5d8329234bc7efa80
1 parent
9523305a
Exists in
master
and in
1 other branch
merged with errbit/master
Showing
2 changed files
with
60 additions
and
1 deletions
Show diff stats
| @@ -0,0 +1,59 @@ | @@ -0,0 +1,59 @@ | ||
| 1 | +class NotificationService | ||
| 2 | + include Mongoid::Document | ||
| 3 | + | ||
| 4 | + include Rails.application.routes.url_helpers | ||
| 5 | + default_url_options[:host] = ActionMailer::Base.default_url_options[:host] | ||
| 6 | + | ||
| 7 | + field :room_id, :type => String | ||
| 8 | + field :user_id, :type => String | ||
| 9 | + field :service_url, :type => String | ||
| 10 | + field :service, :type => String | ||
| 11 | + field :api_token, :type => String | ||
| 12 | + field :subdomain, :type => String | ||
| 13 | + field :sender_name, :type => String | ||
| 14 | + field :notify_at_notices, :type => Array, :default => Errbit::Config.notify_at_notices | ||
| 15 | + | ||
| 16 | + embedded_in :app, :inverse_of => :notification_service | ||
| 17 | + | ||
| 18 | + validate :check_params | ||
| 19 | + | ||
| 20 | + if Errbit::Config.per_app_notify_at_notices | ||
| 21 | + Fields = [[:notify_at_notices, | ||
| 22 | + { :placeholder => 'comma separated numbers or simply 0 for every notice', | ||
| 23 | + :label => 'notify on errors (0 for all errors)' | ||
| 24 | + } | ||
| 25 | + ]] | ||
| 26 | + else | ||
| 27 | + Fields = [] | ||
| 28 | + end | ||
| 29 | + | ||
| 30 | + def notify_at_notices | ||
| 31 | + Errbit::Config.per_app_notify_at_notices ? super : Errbit::Config.notify_at_notices | ||
| 32 | + end | ||
| 33 | + | ||
| 34 | + # Subclasses are responsible for overwriting this method. | ||
| 35 | + def check_params; true; end | ||
| 36 | + | ||
| 37 | + def notification_description(problem) | ||
| 38 | + "[#{ problem.environment }][#{ problem.where }] #{problem.message.to_s.truncate(100)}" | ||
| 39 | + end | ||
| 40 | + | ||
| 41 | + # Allows us to set the issue tracker class from a single form. | ||
| 42 | + def type; self._type; end | ||
| 43 | + def type=(t); self._type=t; end | ||
| 44 | + | ||
| 45 | + def url; nil; end | ||
| 46 | + | ||
| 47 | + # Retrieve tracker label from either class or instance. | ||
| 48 | + Label = '' | ||
| 49 | + def self.label; self::Label; end | ||
| 50 | + def label; self.class.label; end | ||
| 51 | + | ||
| 52 | + def configured? | ||
| 53 | + api_token.present? | ||
| 54 | + end | ||
| 55 | + | ||
| 56 | + def problem_url(problem) | ||
| 57 | + "http://#{Errbit::Config.host}/apps/#{problem.app.id}/problems/#{problem.id}" | ||
| 58 | + end | ||
| 59 | +end |
app/models/comment_observer.rb
| @@ -2,7 +2,7 @@ class CommentObserver < Mongoid::Observer | @@ -2,7 +2,7 @@ class CommentObserver < Mongoid::Observer | ||
| 2 | observe :comment | 2 | observe :comment |
| 3 | 3 | ||
| 4 | def after_create(comment) | 4 | def after_create(comment) |
| 5 | - Mailer.comment_notification(comment).deliver if comment.app.notifiable? | 5 | + Mailer.comment_notification(comment).deliver if comment.app.emailable? |
| 6 | end | 6 | end |
| 7 | 7 | ||
| 8 | end | 8 | end |