protect against nil project/group/setting

This commit is contained in:
http://jneen.net/ 2017-07-20 11:58:30 -07:00
parent b188e1b9e6
commit 9cd46811d3

View file

@ -5,13 +5,13 @@ class NotificationRecipientService
attr_reader :project attr_reader :project
def self.notification_setting_for_user_project(user, project) def self.notification_setting_for_user_project(user, project)
project_setting = user.notification_settings_for(project) project_setting = project && user.notification_settings_for(project)
return project_setting unless project_setting.global? return project_setting unless project_setting.nil? || project_setting.global?
group_setting = user.notification_settings_for(project.group) group_setting = project&.group && user.notification_settings_for(project.group)
return group_setting unless group_setting.global? return group_setting unless group_setting.nil? || group_setting.global?
user.global_notification_setting user.global_notification_setting
end end