diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-03-29 13:52:42 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2016-03-30 10:44:20 +0200 |
commit | 71e7b398431506c8bac2e8e6014b0f3891a41f95 (patch) | |
tree | 31d30ecd7d71de5614cc79e5213789cb3c5f7539 /app/models/notification_setting.rb | |
parent | 630c86a7a36cee36ed6b9c93644a6cb51e2b3b23 (diff) | |
download | gitlab-ce-71e7b398431506c8bac2e8e6014b0f3891a41f95.tar.gz |
Refactor creating notification setting with defaults
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/models/notification_setting.rb')
-rw-r--r-- | app/models/notification_setting.rb | 11 |
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 |