2020-03-03 04:07:54 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UserDetail < ApplicationRecord
|
2020-07-09 20:09:13 -04:00
|
|
|
extend ::Gitlab::Utils::Override
|
|
|
|
include CacheMarkdownField
|
|
|
|
|
2020-03-03 04:07:54 -05:00
|
|
|
belongs_to :user
|
|
|
|
|
2021-06-07 17:10:00 -04:00
|
|
|
validates :pronouns, length: { maximum: 50 }
|
2020-03-04 16:07:54 -05:00
|
|
|
validates :job_title, length: { maximum: 200 }
|
2020-07-09 20:09:13 -04:00
|
|
|
validates :bio, length: { maximum: 255 }, allow_blank: true
|
|
|
|
|
2020-07-13 08:09:18 -04:00
|
|
|
before_save :prevent_nil_bio
|
|
|
|
|
2020-07-09 20:09:13 -04:00
|
|
|
cache_markdown_field :bio
|
|
|
|
|
|
|
|
def bio_html
|
|
|
|
read_attribute(:bio_html) || bio
|
|
|
|
end
|
|
|
|
|
|
|
|
# For backward compatibility.
|
|
|
|
# Older migrations (and their tests) reference the `User.migration_bot` where the `bio` attribute is set.
|
2021-04-06 02:09:00 -04:00
|
|
|
# Here we disable writing the markdown cache when the `bio_html` column does not exist.
|
2020-07-09 20:09:13 -04:00
|
|
|
override :invalidated_markdown_cache?
|
|
|
|
def invalidated_markdown_cache?
|
|
|
|
self.class.column_names.include?('bio_html') && super
|
|
|
|
end
|
2020-07-13 08:09:18 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def prevent_nil_bio
|
|
|
|
self.bio = '' if bio_changed? && bio.nil?
|
|
|
|
end
|
2020-03-03 04:07:54 -05:00
|
|
|
end
|
2020-12-03 13:10:10 -05:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
UserDetail.prepend_mod_with('UserDetail')
|