summaryrefslogtreecommitdiff
path: root/app/models/notification_setting.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/notification_setting.rb')
-rw-r--r--app/models/notification_setting.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb
index 38bd95e6a20..c8c1f47c182 100644
--- a/app/models/notification_setting.rb
+++ b/app/models/notification_setting.rb
@@ -14,6 +14,7 @@ class NotificationSetting < ApplicationRecord
validates :user_id, uniqueness: { scope: [:source_type, :source_id],
message: "already exists in source",
allow_nil: true }
+ validate :owns_notification_email, if: :notification_email_changed?
scope :for_groups, -> { where(source_type: 'Namespace') }
@@ -97,6 +98,13 @@ class NotificationSetting < ApplicationRecord
def event_enabled?(event)
respond_to?(event) && !!public_send(event) # rubocop:disable GitlabSecurity/PublicSend
end
+
+ def owns_notification_email
+ return if user.temp_oauth_email?
+ return if notification_email.empty?
+
+ errors.add(:notification_email, _("is not an email you own")) unless user.verified_emails.include?(notification_email)
+ end
end
NotificationSetting.prepend_if_ee('EE::NotificationSetting')