Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/notification_setting.rb')
-rw-r--r--app/models/notification_setting.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb
index 287862a01bc..13a8995b036 100644
--- a/app/models/notification_setting.rb
+++ b/app/models/notification_setting.rb
@@ -15,6 +15,17 @@ class NotificationSetting < ActiveRecord::Base
scope :for_groups, -> { where(source_type: 'Namespace') }
scope :for_projects, -> { where(source_type: 'Project') }
+ def self.find_or_create_for(source)
+ setting = find_or_initialize_by(source: source)
+
+ unless setting.persisted?
+ setting.set_defaults
+ setting.save
+ end
+
+ setting
+ end
+
def set_defaults
self.level = :global
end