Class: NotificationSetting
Constant Summary
collapse
- EMAIL_EVENTS =
NOTE: Applicable unfound_translations.rb also needs to be updated when below events are changed.
[
:new_release,
:new_note,
:new_issue,
:reopen_issue,
:close_issue,
:reassign_issue,
:issue_due,
:new_merge_request,
:push_to_merge_request,
:reopen_merge_request,
:close_merge_request,
:reassign_merge_request,
:change_reviewer_merge_request,
:merge_merge_request,
:failed_pipeline,
:fixed_pipeline,
:success_pipeline,
:moved_project,
:merge_when_pipeline_succeeds
].freeze
- EXCLUDED_WATCHER_EVENTS =
[
:push_to_merge_request,
:issue_due,
:success_pipeline,
:approver
].freeze
ApplicationRecord::MAX_PLUCK
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
ResetOnColumnErrors::MAX_RESET_PERIOD
Class Method Summary
collapse
Instance Method Summary
collapse
===, cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, nullable_column?, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#reset_on_union_error, #reset_on_unknown_attribute_error
#serializable_hash
Class Method Details
.allowed_fields(source = nil) ⇒ Object
64
65
66
|
# File 'app/models/notification_setting.rb', line 64
def self.allowed_fields(source = nil)
NotificationSetting.email_events(source).dup + %i[level notification_email]
end
|
.email_events(source = nil) ⇒ Object
60
61
62
|
# File 'app/models/notification_setting.rb', line 60
def self.email_events(source = nil)
EMAIL_EVENTS
end
|
.find_or_create_for(source) ⇒ Object
79
80
81
82
83
84
85
86
87
|
# File 'app/models/notification_setting.rb', line 79
def self.find_or_create_for(source)
setting = find_or_initialize_by(source: source)
unless setting.persisted?
setting.save
end
setting
end
|
.reset_email_for_user!(email) ⇒ Object
89
90
91
92
93
94
95
96
|
# File 'app/models/notification_setting.rb', line 89
def self.reset_email_for_user!(email)
where(
user_id: email.user_id,
notification_email: email.email
).each_batch(of: 500) do |relation|
relation.update_all(notification_email: nil)
end
end
|
Instance Method Details
#email_events ⇒ Object
68
69
70
|
# File 'app/models/notification_setting.rb', line 68
def email_events
self.class.email_events(source)
end
|
#event_enabled?(event) ⇒ Boolean
115
116
117
118
119
120
121
|
# File 'app/models/notification_setting.rb', line 115
def event_enabled?(event)
return failed_pipeline if event.to_sym == :failed_pipeline
return fixed_pipeline if event.to_sym == :fixed_pipeline
has_attribute?(event) && !!read_attribute(event)
end
|
#failed_pipeline ⇒ Object
Also known as:
failed_pipeline?
Allow people to receive both failed pipeline/fixed pipeline notifications if they already have custom notifications enabled, as these are more like mentions than the other custom settings.
101
102
103
104
105
|
# File 'app/models/notification_setting.rb', line 101
def failed_pipeline
bool = super
bool.nil? || bool
end
|
#fixed_pipeline ⇒ Object
Also known as:
fixed_pipeline?
108
109
110
111
112
|
# File 'app/models/notification_setting.rb', line 108
def fixed_pipeline
bool = super
bool.nil? || bool
end
|
#notification_email_verified ⇒ Object
123
124
125
126
127
128
|
# File 'app/models/notification_setting.rb', line 123
def notification_email_verified
return if user.temp_oauth_email?
return if notification_email.blank?
errors.add(:notification_email, _("must be an email you have verified")) unless user.verified_emails.include?(notification_email)
end
|