diff options
author | http://jneen.net/ <jneen@jneen.net> | 2017-08-02 14:14:53 -0700 |
---|---|---|
committer | http://jneen.net/ <jneen@jneen.net> | 2017-08-03 09:07:18 -0700 |
commit | eaa503d679e3c2a1396091efebda49a91637cb02 (patch) | |
tree | 2c66a9d55be1bed171852712eea0d041e90cba94 /app/models | |
parent | 56a40a2b6548d57c2c2a32b34a76c157ae5fdeab (diff) | |
download | gitlab-ce-eaa503d679e3c2a1396091efebda49a91637cb02.tar.gz |
move the read_ability logic into NotificationRecipient
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/notification_recipient.rb | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/app/models/notification_recipient.rb b/app/models/notification_recipient.rb index c307f0ad5b6..418b42d8f1d 100644 --- a/app/models/notification_recipient.rb +++ b/app/models/notification_recipient.rb @@ -5,12 +5,10 @@ class NotificationRecipient custom_action: nil, target: nil, acting_user: nil, - read_ability: nil, project: nil ) @custom_action = custom_action @acting_user = acting_user - @read_ability = read_ability @target = target @project = project || @target&.project @user = user @@ -81,10 +79,10 @@ class NotificationRecipient return false unless user.can?(:receive_notifications) return false if @project && !user.can?(:read_project, @project) - return true unless @read_ability + return true unless read_ability return true unless DeclarativePolicy.has_policy?(@target) - user.can?(@read_ability, @target) + user.can?(read_ability, @target) end end @@ -97,6 +95,22 @@ class NotificationRecipient private + def read_ability + return @read_ability if instance_variable_defined?(:@read_ability) + + @read_ability = + case @target + when Issuable + :"read_#{@target.to_ability_name}" + when Ci::Pipeline + :read_build # We have build trace in pipeline emails + when ActiveRecord::Base + :"read_#{@target.class.model_name.name.underscore}" + else + nil + end + end + def find_notification_setting project_setting = @project && user.notification_settings_for(@project) |