summaryrefslogtreecommitdiff
path: root/app/models/notification_recipient.rb
diff options
context:
space:
mode:
authorPatrick Bajao <ebajao@gitlab.com>2019-04-16 17:26:49 -0800
committerPatrick Bajao <ebajao@gitlab.com>2019-04-16 17:26:49 +0800
commit199337103ba4db2af303bcdd481f97e7611aafe9 (patch)
treedaf0f851941e08350b4cf72a346e9d8806febca9 /app/models/notification_recipient.rb
parentdc8848794bfd2f06345d4dbba8a918aa09ee07a8 (diff)
downloadgitlab-ce-199337103ba4db2af303bcdd481f97e7611aafe9.tar.gz
Stop sending emails to users who can't read commit
This is to ensure that only users will be able receive an email if they can read a commit from the repository even if they are watching the activity of it.
Diffstat (limited to 'app/models/notification_recipient.rb')
-rw-r--r--app/models/notification_recipient.rb20
1 files changed, 12 insertions, 8 deletions
diff --git a/app/models/notification_recipient.rb b/app/models/notification_recipient.rb
index 793cce191fa..292e8a58028 100644
--- a/app/models/notification_recipient.rb
+++ b/app/models/notification_recipient.rb
@@ -123,15 +123,19 @@ class NotificationRecipient
return @read_ability if instance_variable_defined?(:@read_ability)
@read_ability =
- case @target
- when Issuable
- :"read_#{@target.to_ability_name}"
- when Ci::Pipeline
+ if @target.is_a?(Ci::Pipeline)
:read_build # We have build trace in pipeline emails
- when ActiveRecord::Base
- :"read_#{@target.class.model_name.name.underscore}"
- else
- nil
+ elsif default_ability_for_target
+ :"read_#{default_ability_for_target}"
+ end
+ end
+
+ def default_ability_for_target
+ @default_ability_for_target ||=
+ if @target.respond_to?(:to_ability_name)
+ @target.to_ability_name
+ elsif @target.class.respond_to?(:model_name)
+ @target.class.model_name.name.underscore
end
end