2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UserDetail < ApplicationRecord
|
2020-07-28 23:09:34 +05:30
|
|
|
extend ::Gitlab::Utils::Override
|
|
|
|
include CacheMarkdownField
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
validates :job_title, length: { maximum: 200 }
|
2020-07-28 23:09:34 +05:30
|
|
|
validates :bio, length: { maximum: 255 }, allow_blank: true
|
|
|
|
|
|
|
|
before_save :prevent_nil_bio
|
|
|
|
|
|
|
|
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-29 21:17:54 +05:30
|
|
|
# Here we disable writing the markdown cache when the `bio_html` column does not exist.
|
2020-07-28 23:09:34 +05:30
|
|
|
override :invalidated_markdown_cache?
|
|
|
|
def invalidated_markdown_cache?
|
|
|
|
self.class.column_names.include?('bio_html') && super
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def prevent_nil_bio
|
|
|
|
self.bio = '' if bio_changed? && bio.nil?
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
UserDetail.prepend_mod_with('UserDetail')
|