From cb1212fa8c9bcf1e0c98e21d29fdfa225d2b3a41 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 17 Feb 2012 18:06:50 +0800 Subject: [PATCH] Added user_info data to notices, to retrieve and display info about the currently logged in user. --- app/models/error_report.rb | 5 +++-- app/models/notice.rb | 1 + app/views/errs/show.html.haml | 7 ++++++- app/views/notices/_user_info.html.haml | 6 ++++++ lib/hoptoad/v2.rb | 3 ++- lib/tasks/errbit/demo.rake | 8 +++++++- 6 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 app/views/notices/_user_info.html.haml diff --git a/app/models/error_report.rb b/app/models/error_report.rb index 463ac29..bef568a 100644 --- a/app/models/error_report.rb +++ b/app/models/error_report.rb @@ -2,7 +2,7 @@ require 'digest/md5' require 'hoptoad_notifier' class ErrorReport - attr_reader :klass, :message, :backtrace, :request, :server_environment, :api_key, :notifier + attr_reader :klass, :message, :backtrace, :request, :server_environment, :api_key, :notifier, :user_info def initialize(xml_or_attributes) @attributes = (xml_or_attributes.is_a?(String) ? Hoptoad.parse_xml!(xml_or_attributes) : xml_or_attributes).with_indifferent_access @@ -35,7 +35,8 @@ class ErrorReport :backtrace => backtrace, :request => request, :server_environment => server_environment, - :notifier => notifier) + :notifier => notifier, + :user_info => user_info) err = app.find_or_create_err!( :klass => klass, diff --git a/app/models/notice.rb b/app/models/notice.rb index 09ea68b..6f8140d 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -10,6 +10,7 @@ class Notice field :server_environment, :type => Hash field :request, :type => Hash field :notifier, :type => Hash + field :user_info, :type => Hash field :klass belongs_to :err diff --git a/app/views/errs/show.html.haml b/app/views/errs/show.html.haml index 16a19b3..265a76f 100644 --- a/app/views/errs/show.html.haml +++ b/app/views/errs/show.html.haml @@ -50,6 +50,7 @@ %ul %li= link_to 'Summary', '#summary', :rel => 'summary', :class => 'button' %li= link_to 'Backtrace', '#backtrace', :rel => 'backtrace', :class => 'button' + %li= link_to 'Application User', '#user_info', :rel => 'user_info', :class => 'button' %li= link_to 'Environment', '#environment', :rel => 'environment', :class => 'button' %li= link_to 'Parameters', '#params', :rel => 'params', :class => 'button' %li= link_to 'Session', '#session', :rel => 'session', :class => 'button' @@ -63,6 +64,11 @@ %h3 Backtrace = render 'notices/backtrace', :lines => @notice.backtrace + - if @notice.user_info.present? + #user_info + %h3 User + = render 'notices/user_info', :user => @notice.user_info + #environment %h3 Environment = render 'notices/environment', :notice => @notice @@ -74,4 +80,3 @@ #session %h3 Session = render 'notices/session', :notice => @notice - diff --git a/app/views/notices/_user_info.html.haml b/app/views/notices/_user_info.html.haml new file mode 100644 index 0000000..3e1273a --- /dev/null +++ b/app/views/notices/_user_info.html.haml @@ -0,0 +1,6 @@ +.window + %table.user_info + - user.each do |user_key, user_value| + %tr + %th= user_key + %td= auto_link(user_value).html_safe diff --git a/lib/hoptoad/v2.rb b/lib/hoptoad/v2.rb index 6c09197..ad77409 100644 --- a/lib/hoptoad/v2.rb +++ b/lib/hoptoad/v2.rb @@ -58,7 +58,8 @@ module Hoptoad :server_environment => notice['server-environment'], :api_key => notice['api-key'], - :notifier => notice['notifier'] + :notifier => notice['notifier'], + :user_info => notice['user-info'] || {} } end end diff --git a/lib/tasks/errbit/demo.rake b/lib/tasks/errbit/demo.rake index a35451b..581ae7a 100644 --- a/lib/tasks/errbit/demo.rake +++ b/lib/tasks/errbit/demo.rake @@ -52,7 +52,13 @@ namespace :errbit do 'action' => 'error' }, :server_environment => {'environment-name' => Rails.env.to_s}, - :notifier => {:name => "seeds.rb"} + :notifier => {:name => "seeds.rb"}, + :app_user => { + :id => "1234", + :username => "jsmith", + :name => "John Smith", + :url => "http://www.example.com/users/jsmith" + } }) app.report_error!(error_report) -- libgit2 0.21.2