* Prepare to drop profile columns from user * Update code and factory * Also remove unused constant * Move validation from user to profile * Remove Profiles::ExtractData service object * Add more comments * Simplify sameAs attribute generation * Obey me machine, I am your master * Fix condition order in guard clause * Temporarily disable callback * Fix specs * Reduce usage of Profile#refresh_attributes! * Remove leftover comment * Handle social media links differently * More spec fixes * Fix specs for admin profile fields controller * Fix specs after merge * Fix remaining specs * Update user show request spec * Add comment for follow_hiring_tag * Only save profile when user is valid * Fix seeds.rb for profile fields * Switch from before_save to after_save * Undo unrelated formattin change * Update spec/fixtures/files/profile_fields.csv Co-authored-by: Molly Struve <mollylbs@gmail.com> * Remove data update script and spec * Fix spec * Fix typo in comment * Fix typo in comment * Move article resave logic to service object * Move profile field creation to before(:suite) * Refactor error handling in Profiles::Update * Fix Profiles::Update specs and refactor * Temporarily disable spec * Add ProfileValidator * Clean up * Move DB ready check into app/lib * Refresh attributes after importing from CSV * Fix specs * Remove unused file * A girl has no name. A profile neither. * Fix specs * Add responds_to? check * Spec fix * Add name to user fields in profile settings page Co-authored-by: Molly Struve <mollylbs@gmail.com>
52 lines
1.6 KiB
Ruby
52 lines
1.6 KiB
Ruby
class Profile < ApplicationRecord
|
|
belongs_to :user
|
|
|
|
validates :data, presence: true
|
|
validates :user_id, uniqueness: true
|
|
validates_with ProfileValidator
|
|
|
|
has_many :custom_profile_fields, dependent: :destroy
|
|
|
|
store_attribute :data, :custom_attributes, :json, default: {}
|
|
|
|
# NOTE: @citizen428 This is a temporary mapping so we don't break DEV during
|
|
# profile migration/generalization work.
|
|
MAPPED_ATTRIBUTES = {
|
|
brand_color1: :bg_color_hex,
|
|
brand_color2: :text_color_hex,
|
|
display_email_on_profile: :email_public,
|
|
display_looking_for_work_on_profile: :looking_for_work_publicly,
|
|
git_lab_url: :gitlab_url,
|
|
linked_in_url: :linkedin_url,
|
|
recruiters_can_contact_me_about_job_opportunities: :contact_consent,
|
|
skills_languages: :mostly_work_with,
|
|
stack_overflow_url: :stackoverflow_url
|
|
}.with_indifferent_access.freeze
|
|
|
|
# Generates typed accessors for all currently defined profile fields.
|
|
def self.refresh_attributes!
|
|
return unless Database.table_exists?("profiles")
|
|
|
|
ProfileField.find_each do |field|
|
|
store_attribute :data, field.attribute_name.to_sym, field.type
|
|
end
|
|
end
|
|
|
|
# Returns an array of all currently defined `store_attribute`s on `data`.
|
|
def self.attributes
|
|
(stored_attributes[:data] || []).map(&:to_s)
|
|
end
|
|
|
|
def custom_profile_attributes
|
|
custom_profile_fields.pluck(:attribute_name)
|
|
end
|
|
|
|
def clear!
|
|
update(data: {})
|
|
end
|
|
|
|
# NOTE: @citizen428 We want to have a current list of profile attributes the
|
|
# moment the application loads. I wish Rails had a hook for code to run after
|
|
# the app started...
|
|
refresh_attributes!
|
|
end
|