Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow apps to not include the user in a notification #698

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/bullet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
15 changes: 13 additions & 2 deletions lib/bullet/notification/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions spec/bullet/notification/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down