make NotificationRecipient a little more customizable
This commit is contained in:
parent
1c874f71e3
commit
7e7f602d29
|
@ -5,12 +5,18 @@ class NotificationRecipient
|
|||
custom_action: nil,
|
||||
target: nil,
|
||||
acting_user: nil,
|
||||
project: nil
|
||||
project: nil,
|
||||
group: nil
|
||||
)
|
||||
unless NotificationSetting.levels.key?(type) || type == :subscription
|
||||
raise ArgumentError, "invalid type: #{type.inspect}"
|
||||
end
|
||||
|
||||
@custom_action = custom_action
|
||||
@acting_user = acting_user
|
||||
@target = target
|
||||
@project = project || @target&.project
|
||||
@project = project || default_project
|
||||
@group = group || @project&.group
|
||||
@user = user
|
||||
@type = type
|
||||
end
|
||||
|
@ -111,12 +117,18 @@ class NotificationRecipient
|
|||
end
|
||||
end
|
||||
|
||||
def default_project
|
||||
return nil if @target.nil?
|
||||
return @target if @target.is_a?(Project)
|
||||
return @target.project if @target.respond_to?(:project)
|
||||
end
|
||||
|
||||
def find_notification_setting
|
||||
project_setting = @project && user.notification_settings_for(@project)
|
||||
|
||||
return project_setting unless project_setting.nil? || project_setting.global?
|
||||
|
||||
group_setting = @project&.group && user.notification_settings_for(@project.group)
|
||||
group_setting = @group && user.notification_settings_for(@group)
|
||||
|
||||
return group_setting unless group_setting.nil? || group_setting.global?
|
||||
|
||||
|
|
Loading…
Reference in New Issue