From d2bf9dbc284117a6f52e3be5d8329234bc7efa80 Mon Sep 17 00:00:00 2001 From: damau Date: Tue, 12 Mar 2013 18:04:22 +0000 Subject: [PATCH] merged with errbit/master --- app/models/#notification_service.rb# | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app/models/comment_observer.rb | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 app/models/#notification_service.rb# diff --git a/app/models/#notification_service.rb# b/app/models/#notification_service.rb# new file mode 100644 index 0000000..1939449 --- /dev/null +++ b/app/models/#notification_service.rb# @@ -0,0 +1,59 @@ +class NotificationService + include Mongoid::Document + + include Rails.application.routes.url_helpers + default_url_options[:host] = ActionMailer::Base.default_url_options[:host] + + field :room_id, :type => String + field :user_id, :type => String + field :service_url, :type => String + field :service, :type => String + field :api_token, :type => String + field :subdomain, :type => String + field :sender_name, :type => String + field :notify_at_notices, :type => Array, :default => Errbit::Config.notify_at_notices + + embedded_in :app, :inverse_of => :notification_service + + validate :check_params + + if Errbit::Config.per_app_notify_at_notices + Fields = [[:notify_at_notices, + { :placeholder => 'comma separated numbers or simply 0 for every notice', + :label => 'notify on errors (0 for all errors)' + } + ]] + else + Fields = [] + end + + def notify_at_notices + Errbit::Config.per_app_notify_at_notices ? super : Errbit::Config.notify_at_notices + end + + # Subclasses are responsible for overwriting this method. + def check_params; true; end + + def notification_description(problem) + "[#{ problem.environment }][#{ problem.where }] #{problem.message.to_s.truncate(100)}" + end + + # Allows us to set the issue tracker class from a single form. + def type; self._type; end + def type=(t); self._type=t; end + + def url; nil; end + + # Retrieve tracker label from either class or instance. + Label = '' + def self.label; self::Label; end + def label; self.class.label; end + + def configured? + api_token.present? + end + + def problem_url(problem) + "http://#{Errbit::Config.host}/apps/#{problem.app.id}/problems/#{problem.id}" + end +end diff --git a/app/models/comment_observer.rb b/app/models/comment_observer.rb index 4e59ba7..a9beadc 100644 --- a/app/models/comment_observer.rb +++ b/app/models/comment_observer.rb @@ -2,7 +2,7 @@ class CommentObserver < Mongoid::Observer observe :comment def after_create(comment) - Mailer.comment_notification(comment).deliver if comment.app.notifiable? + Mailer.comment_notification(comment).deliver if comment.app.emailable? end end -- libgit2 0.21.2