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
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
REGISTRATION_OBJECTIVE_PAIRS = { basics: 0, move_repository: 1, code_storage: 2, exploring: 3, ci: 4, other: 5, joining_team: 6 }.freeze
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
belongs_to :user
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
validates :pronouns, length: { maximum: 50 }
|
2021-10-27 15:23:28 +05:30
|
|
|
validates :pronunciation, length: { maximum: 255 }
|
2020-04-08 14:13:33 +05:30
|
|
|
validates :job_title, length: { maximum: 200 }
|
2020-07-28 23:09:34 +05:30
|
|
|
validates :bio, length: { maximum: 255 }, allow_blank: true
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
DEFAULT_FIELD_LENGTH = 500
|
|
|
|
|
|
|
|
validates :linkedin, length: { maximum: DEFAULT_FIELD_LENGTH }, allow_blank: true
|
|
|
|
validates :twitter, length: { maximum: DEFAULT_FIELD_LENGTH }, allow_blank: true
|
|
|
|
validates :skype, length: { maximum: DEFAULT_FIELD_LENGTH }, allow_blank: true
|
|
|
|
validates :location, length: { maximum: DEFAULT_FIELD_LENGTH }, allow_blank: true
|
|
|
|
validates :organization, length: { maximum: DEFAULT_FIELD_LENGTH }, allow_blank: true
|
2023-03-04 22:38:38 +05:30
|
|
|
validates :website_url, length: { maximum: DEFAULT_FIELD_LENGTH }, url: true, allow_blank: true, if: :website_url_changed?
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
before_validation :sanitize_attrs
|
2023-03-17 16:20:25 +05:30
|
|
|
before_save :prevent_nil_fields
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
enum registration_objective: REGISTRATION_OBJECTIVE_PAIRS, _suffix: true
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
def sanitize_attrs
|
|
|
|
%i[linkedin skype twitter website_url].each do |attr|
|
|
|
|
value = self[attr]
|
|
|
|
self[attr] = Sanitize.clean(value) if value.present?
|
|
|
|
end
|
|
|
|
%i[location organization].each do |attr|
|
|
|
|
value = self[attr]
|
|
|
|
self[attr] = Sanitize.clean(value).gsub('&', '&') if value.present?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
private
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
def prevent_nil_fields
|
|
|
|
self.bio = '' if bio.nil?
|
|
|
|
self.linkedin = '' if linkedin.nil?
|
|
|
|
self.twitter = '' if twitter.nil?
|
|
|
|
self.skype = '' if skype.nil?
|
|
|
|
self.location = '' if location.nil?
|
|
|
|
self.organization = '' if organization.nil?
|
|
|
|
self.website_url = '' if website_url.nil?
|
2022-11-25 23:54:43 +05:30
|
|
|
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')
|