summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/notification.rb4
-rw-r--r--app/models/notification_setting.rb7
-rw-r--r--app/models/user.rb7
3 files changed, 15 insertions, 3 deletions
diff --git a/app/models/notification.rb b/app/models/notification.rb
index 171b8df45c2..379f041969b 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -57,7 +57,7 @@ class Notification
def level
target.notification_level
end
-
+
def to_s
case level
when N_DISABLED
@@ -71,7 +71,7 @@ class Notification
when N_GLOBAL
'Global'
else
- # do nothing
+ # do nothing
end
end
end
diff --git a/app/models/notification_setting.rb b/app/models/notification_setting.rb
index 0dce146b7a9..287862a01bc 100644
--- a/app/models/notification_setting.rb
+++ b/app/models/notification_setting.rb
@@ -11,4 +11,11 @@ class NotificationSetting < ActiveRecord::Base
# Notification level
# Note: When adding an option, it MUST go on the end of the array.
enum level: [:disabled, :participating, :watch, :global, :mention]
+
+ scope :for_groups, -> { where(source_type: 'Namespace') }
+ scope :for_projects, -> { where(source_type: 'Project') }
+
+ def set_defaults
+ self.level = :global
+ end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 128ddc2a694..59493e6f90c 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -143,6 +143,7 @@ class User < ActiveRecord::Base
has_many :spam_logs, dependent: :destroy
has_many :builds, dependent: :nullify, class_name: 'Ci::Build'
has_many :todos, dependent: :destroy
+ has_many :notification_settings, dependent: :destroy
#
# Validations
@@ -157,7 +158,7 @@ class User < ActiveRecord::Base
presence: true,
uniqueness: { case_sensitive: false }
- validates :notification_level, inclusion: { in: Notification.notification_levels }, presence: true
+ validates :notification_level, presence: true
validate :namespace_uniq, if: ->(user) { user.username_changed? }
validate :avatar_type, if: ->(user) { user.avatar.present? && user.avatar_changed? }
validate :unique_email, if: ->(user) { user.email_changed? }
@@ -190,6 +191,10 @@ class User < ActiveRecord::Base
# Note: When adding an option, it MUST go on the end of the array.
enum project_view: [:readme, :activity, :files]
+ # Notification level
+ # Note: When adding an option, it MUST go on the end of the array.
+ enum notification_level: [:disabled, :participating, :watch, :global, :mention]
+
alias_attribute :private_token, :authentication_token
delegate :path, to: :namespace, allow_nil: true, prefix: true