diff --git a/README.md b/README.md index b3206174..9abc1e52 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ The code above will enable all of the Bullet notification systems: * `Bullet.slack`: add notifications to slack * `Bullet.raise`: raise errors, useful for making your specs fail unless they have optimized queries * `Bullet.always_append_html_body`: always append the html body even if no notifications are present. Note: `console` or `add_footer` must also be true. Useful for Single Page Applications where the initial page load might not have any notifications present. +* `Bullet.skip_user_in_notification`: exclude the OS user (`whoami`) from notifications. Bullet also allows you to disable any of its detectors. diff --git a/lib/bullet.rb b/lib/bullet.rb index a432963b..2b0b312d 100644 --- a/lib/bullet.rb +++ b/lib/bullet.rb @@ -40,7 +40,7 @@ class << self :stacktrace_excludes, :skip_html_injection attr_reader :safelist - attr_accessor :add_footer, :orm_patches_applied, :skip_http_headers, :always_append_html_body + attr_accessor :add_footer, :orm_patches_applied, :skip_http_headers, :always_append_html_body, :skip_user_in_notification available_notifiers = UniformNotifier::AVAILABLE_NOTIFIERS.select { |notifier| notifier != :raise } diff --git a/lib/bullet/notification/base.rb b/lib/bullet/notification/base.rb index f35f499d..d0b1da66 100644 --- a/lib/bullet/notification/base.rb +++ b/lib/bullet/notification/base.rb @@ -51,11 +51,22 @@ def notify_out_of_channel end def short_notice - [whoami.presence, url, title, body].compact.join(' ') + parts = [] + parts << whoami.presence unless Bullet.skip_user_in_notification + parts << url + parts << title + parts << body + + parts.compact.join(' ') end def notification_data - { user: whoami, url: url, title: title, body: body_with_caller } + hash = {} + hash[:user] = whoami unless Bullet.skip_user_in_notification + hash[:url] = url + hash[:title] = title + hash[:body] = body_with_caller + hash end def eql?(other) diff --git a/spec/bullet/notification/base_spec.rb b/spec/bullet/notification/base_spec.rb index 45176699..184cd061 100644 --- a/spec/bullet/notification/base_spec.rb +++ b/spec/bullet/notification/base_spec.rb @@ -70,6 +70,18 @@ def temp_env_variable(name, value) allow(subject).to receive(:body_with_caller).and_return('body_with_caller') expect(subject.notification_data).to eq(user: 'whoami', url: 'url', title: 'title', body: 'body_with_caller') end + + context 'when skip_user_in_notification is true' do + before { allow(Bullet).to receive(:skip_user_in_notification).and_return(true) } + + it 'should return notification data without user' do + allow(subject).to receive(:url).and_return('url') + allow(subject).to receive(:title).and_return('title') + allow(subject).to receive(:body_with_caller).and_return('body_with_caller') + + expect(subject.notification_data).to eq(url: 'url', title: 'title', body: 'body_with_caller') + end + end end context '#notify_inline' do