summaryrefslogtreecommitdiff
path: root/app/models/user.rb
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-06-14 09:06:53 +0530
committerTimothy Andrew <mail@timothyandrew.net>2016-06-14 09:06:53 +0530
commitd0bcba1105686c2306414a402bf33c85a08a17a6 (patch)
tree2922086316008cf86e864e1dd8a251fd4878cb04 /app/models/user.rb
parentd754d99179f1ffe846fcc1d8e858163b39efc5dc (diff)
parentf34af6b83cc2663bb8a076f4df9c82047e5511ab (diff)
downloadgitlab-ce-d0bcba1105686c2306414a402bf33c85a08a17a6.tar.gz
Merge remote-tracking branch 'origin/master' into 2979-personal-access-tokens
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb21
1 files changed, 13 insertions, 8 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 3449544c170..65fe88e0287 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -10,6 +10,8 @@ class User < ActiveRecord::Base
include CaseSensitivity
include TokenAuthenticatable
+ DEFAULT_NOTIFICATION_LEVEL = :participating
+
add_authentication_token_field :authentication_token
default_value_for :admin, false
@@ -100,7 +102,6 @@ class User < ActiveRecord::Base
presence: true,
uniqueness: { case_sensitive: false }
- 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? }
@@ -134,13 +135,6 @@ 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.
- #
- # TODO: Add '_prefix: :notification' to enum when update to Rails 5. https://github.com/rails/rails/pull/19813
- # Because user.notification_disabled? is much better than user.disabled?
- enum notification_level: [:disabled, :participating, :watch, :global, :mention]
-
alias_attribute :private_token, :authentication_token
delegate :path, to: :namespace, allow_nil: true, prefix: true
@@ -801,6 +795,17 @@ class User < ActiveRecord::Base
notification_settings.find_or_initialize_by(source: source)
end
+ # Lazy load global notification setting
+ # Initializes User setting with Participating level if setting not persisted
+ def global_notification_setting
+ return @global_notification_setting if defined?(@global_notification_setting)
+
+ @global_notification_setting = notification_settings.find_or_initialize_by(source: nil)
+ @global_notification_setting.update_attributes(level: NotificationSetting.levels[DEFAULT_NOTIFICATION_LEVEL]) unless @global_notification_setting.persisted?
+
+ @global_notification_setting
+ end
+
def assigned_open_merge_request_count(force: false)
Rails.cache.fetch(['users', id, 'assigned_open_merge_request_count'], force: force) do
assigned_merge_requests.opened.count