Skip to content

Commit

Permalink
allow apps to not include the user in a notification
Browse files Browse the repository at this point in the history
While some may find the current OS user helpful, in other contexts, that user is randomly assigned and not material to the notification itself. Consider a deployment enviroment like Heroku, which will use a different OS user for each deployable, and each deploy.

It may also cause grouping issues in services like Sentry, which use the exception / notification content to determine whether the situation has occurred already.

This does not change the default behavior, but rather introduces a new option to skip including that information in notifications, for those who want to.
  • Loading branch information
agrobbin committed Jan 15, 2024
1 parent eff5b01 commit 905352b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
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
8 changes: 8 additions & 0 deletions spec/bullet/notification/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ 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
expect(subject.notification_data.keys).not_to include(:user)
end
end
end

context '#notify_inline' do
Expand Down

0 comments on commit 905352b

Please sign in to comment.