* Remove duplicated work display from header * Update work profile field handling * Update DUS + spec * Delegate more carefully * Update delegation guard * Adapt for removed delegation * Undo accidental schema changes * Fix seeds * Remove accidentaly change * Fix User#processed_website_url * Update guard clause * Update profile card content * Add Organization#profile * Be more conservative with profile fields * Spec fixes round 1 * Fix typo * Update spec * Limit number of header fields and update card content * Decorate correct model * Update factory * Update schema.rb * Fix validation * How bad could this possibly be? * Pretty bad, nevermind * Remove obsolete code * Reset profile fields during test runs * Move profile fields back to before(:suite) * Spec fixes * Remove accidentally re-added files * More spec fixes * Specs * Change User#tag_keywords_for_search * More spec fixes * Add comment * Undo accidental schema changes * Attempt spec fix * Remove fix attempt * Fix e2e test * Update spec * Remove guard clause * Remove outdated guard clause * Re-add validation * Update header field validation * Fix auto-complete fail
59 lines
1.9 KiB
Ruby
59 lines
1.9 KiB
Ruby
class Profile < ApplicationRecord
|
|
belongs_to :user
|
|
|
|
validates :user_id, uniqueness: true
|
|
validates :location, :website_url, length: { maximum: 100 }
|
|
validates :website_url, url: { allow_blank: true, no_local: true, schemes: %w[https http] }
|
|
validates_with ProfileValidator
|
|
|
|
# Static fields are columns on the profiles table; they have no relationship
|
|
# to a ProfileField record. These are columns we can safely assume exist for
|
|
# any profile on a given Forem.
|
|
STATIC_FIELDS = %w[summary location website_url].freeze
|
|
|
|
SPECIAL_DISPLAY_ATTRIBUTES = %w[summary location].freeze
|
|
|
|
# NOTE: @citizen428 This is a temporary mapping so we don't break DEV during
|
|
# profile migration/generalization work.
|
|
MAPPED_ATTRIBUTES = {
|
|
education: :education,
|
|
skills_languages: :mostly_work_with
|
|
}.with_indifferent_access.freeze
|
|
|
|
# Generates typed accessors for all currently defined profile fields.
|
|
def self.refresh_attributes!
|
|
return if ENV["ENV_AVAILABLE"] == "false"
|
|
return unless Database.table_available?("profiles")
|
|
|
|
ProfileField.find_each do |field|
|
|
# Don't generate accessors for static fields stored on the table.
|
|
# TODO: [@jacobherrington] Remove this when ProfileFields for the static
|
|
# fields are dropped from production and the associated data is removed.
|
|
# https://github.com/forem/forem/pull/13641#discussion_r637641185
|
|
next if STATIC_FIELDS.any?(field.attribute_name)
|
|
|
|
store_attribute :data, field.attribute_name.to_sym, field.type
|
|
end
|
|
end
|
|
|
|
# Set up all profile attributes when this class loads so all store_attribute
|
|
# accessors get defined immediately.
|
|
refresh_attributes!
|
|
|
|
# Returns an array of all currently defined `store_attribute`s on `data`.
|
|
def self.attributes
|
|
(stored_attributes[:data] || []).map(&:to_s)
|
|
end
|
|
|
|
def self.special_attributes
|
|
SPECIAL_DISPLAY_ATTRIBUTES
|
|
end
|
|
|
|
def self.static_fields
|
|
STATIC_FIELDS
|
|
end
|
|
|
|
def clear!
|
|
update(data: {})
|
|
end
|
|
end
|