Class: UserPreference

Inherits:
ApplicationRecord show all
Includes:
IgnorableColumns, SafelyChangeColumnDefault
Defined in:
app/models/user_preference.rb

Constant Summary collapse

NOTES_FILTERS =

We could use enums, but Rails 4 doesn’t support multiple enum options with same name for multiple fields, also it creates extra methods that aren’t really needed here.

{ all_notes: 0, only_comments: 1, only_activity: 2 }.freeze
TIME_DISPLAY_FORMATS =
{ system: 0, non_iso_format: 1, iso_format: 2 }.freeze

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from Organizations::Sharding

#sharding_organization

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.notes_filtersObject



70
71
72
73
74
75
76
# File 'app/models/user_preference.rb', line 70

def notes_filters
  {
    s_('Notes|Show all activity') => NOTES_FILTERS[:all_notes],
    s_('Notes|Show comments only') => NOTES_FILTERS[:only_comments],
    s_('Notes|Show history only') => NOTES_FILTERS[:only_activity]
  }
end

.time_display_formatsObject



98
99
100
101
102
103
104
# File 'app/models/user_preference.rb', line 98

def time_display_formats
  {
    s_('Time Display|System') => TIME_DISPLAY_FORMATS[:system],
    s_('Time Display|12-hour: 2:34 PM') => TIME_DISPLAY_FORMATS[:non_iso_format],
    s_('Time Display|24-hour: 14:34') => TIME_DISPLAY_FORMATS[:iso_format]
  }
end

Instance Method Details

#default_text_editor_enabledObject



129
130
131
# File 'app/models/user_preference.rb', line 129

def default_text_editor_enabled
  text_editor == "rich_text_editor" || text_editor == "plain_text_editor"
end

#default_text_editor_enabled=(value) ⇒ Object



133
134
135
# File 'app/models/user_preference.rb', line 133

def default_text_editor_enabled=(value)
  self.text_editor = value ? "rich_text_editor" : "not_set"
end

#dpop_enabled=(value) ⇒ Object



112
113
114
115
116
117
118
119
# File 'app/models/user_preference.rb', line 112

def dpop_enabled=(value)
  if value.nil?
    default = self.class.column_defaults['dpop_enabled']
    super(default)
  else
    super(value)
  end
end

#extensions_marketplace_opt_in_urlObject



107
108
109
110
# File 'app/models/user_preference.rb', line 107

def extensions_marketplace_opt_in_url
  # To support existing records, this can be `nil` and it defaults to `https://open-vsx.org`
  super || 'https://open-vsx.org'
end

#notes_filter_for(resource) ⇒ Object

Returns the current discussion filter for a given issuable or issuable type.



93
94
95
# File 'app/models/user_preference.rb', line 93

def notes_filter_for(resource)
  self[notes_filter_field_for(resource)]
end

#set_notes_filter(filter_id, issuable) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'app/models/user_preference.rb', line 79

def set_notes_filter(filter_id, issuable)
  # No need to update the column if the value is already set.
  if filter_id && NOTES_FILTERS.value?(filter_id)
    field = notes_filter_field_for(issuable)
    self[field] = filter_id

    save if attribute_changed?(field)
  end

  notes_filter_for(issuable)
end

#text_editorObject



121
122
123
# File 'app/models/user_preference.rb', line 121

def text_editor
  text_editor_type
end

#text_editor=(value) ⇒ Object



125
126
127
# File 'app/models/user_preference.rb', line 125

def text_editor=(value)
  self.text_editor_type = value
end

#timezone=(value) ⇒ Object



137
138
139
140
141
# File 'app/models/user_preference.rb', line 137

def timezone=(value)
  value = nil if value == ''

  super(value)
end