diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 0fd7b25f7..58022f89d 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -353,9 +353,7 @@ class StoriesController < ApplicationController image: Images::Profile.call(@user.profile_image_url, length: 320), name: @user.name, email: @user.setting.display_email_on_profile ? @user.email : nil, - jobTitle: @user.employment_title.presence, - description: @user.summary.presence || "404 bio not found", - worksFor: [user_works_for].compact, + description: @user.profile.summary.presence || "404 bio not found", alumniOf: @user.education.presence }.reject { |_, v| v.blank? } end @@ -421,25 +419,13 @@ class StoriesController < ApplicationController } end - def user_works_for - # For further examples of the worksFor properties, please refer to this - # link: https://jsonld.com/person/ - return unless @user.employer_name.presence || @user.employer_url.presence - - { - "@type": "Organization", - name: @user.employer_name, - url: @user.employer_url - }.reject { |_, v| v.blank? } - end - def user_same_as # For further information on the sameAs property, please refer to this link: # https://schema.org/sameAs [ @user.twitter_username.present? ? "https://twitter.com/#{@user.twitter_username}" : nil, @user.github_username.present? ? "https://github.com/#{@user.github_username}" : nil, - @user.website_url, + @user.profile.website_url, ].reject(&:blank?) end diff --git a/app/models/organization.rb b/app/models/organization.rb index 2164152cd..83051975a 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -120,6 +120,12 @@ class Organization < ApplicationRecord organization_memberships.count == 1 && articles.count.zero? && credits.count.zero? end + # NOTE: We use Organization and User objects interchangeably. Since the former + # don't have profiles we return self instead. + def profile + self + end + private def evaluate_markdown diff --git a/app/models/profile.rb b/app/models/profile.rb index c42a1cfb9..6eede755b 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -11,13 +11,7 @@ class Profile < ApplicationRecord # any profile on a given Forem. STATIC_FIELDS = %w[summary location website_url].freeze - SPECIAL_DISPLAY_ATTRIBUTES = %w[ - summary - employment_title - employer_name - employer_url - location - ].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. diff --git a/app/models/profile_field.rb b/app/models/profile_field.rb index c9d67ba84..26390f289 100644 --- a/app/models/profile_field.rb +++ b/app/models/profile_field.rb @@ -1,6 +1,9 @@ class ProfileField < ApplicationRecord WORD_REGEX = /\b\w+\b/.freeze + HEADER_FIELD_LIMIT = 3 + HEADER_LIMIT_MESSAGE = "maximum number of header fields (#{HEADER_FIELD_LIMIT}) exceeded".freeze + # Key names follow the Rails form helpers enum input_type: { text_field: 0, @@ -21,6 +24,7 @@ class ProfileField < ApplicationRecord validates :input_type, presence: true validates :label, presence: true, uniqueness: { case_sensitive: false } validates :show_in_onboarding, inclusion: { in: [true, false] } + validate :maximum_header_field_count before_create :generate_attribute_name @@ -35,4 +39,20 @@ class ProfileField < ApplicationRecord def generate_attribute_name self.attribute_name = label.titleize.scan(WORD_REGEX).join.underscore end + + def maximum_header_field_count + return unless header? + + header_field_count = self.class.header.count + + # We need to have less than the maximum number so we can still create one. + if new_record? || display_area_was == "left_sidebar" + return if header_field_count < HEADER_FIELD_LIMIT + # We can change existing fields or update them as long as we're within the limit. + elsif header_field_count <= HEADER_FIELD_LIMIT + return + end + + errors.add(:display_area, HEADER_LIMIT_MESSAGE) + end end diff --git a/app/models/user.rb b/app/models/user.rb index 78e493f11..1a0760441 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -351,7 +351,7 @@ class User < ApplicationRecord end def processed_website_url - website_url.to_s.strip if website_url.present? + profile.website_url.to_s.strip if profile.website_url.present? end def remember_me @@ -636,8 +636,12 @@ class User < ApplicationRecord Users::BustCacheWorker.perform_async(id) end + # TODO: @citizen428 I don't want to completely remove this method yet, as we + # have similar methods in other models. But the previous implementation used + # three profile fields that we can't guarantee to exist across all Forems. So + # for now this method will just return an empty string. def tag_keywords_for_search - "#{employer_name}#{mostly_work_with}#{available_for}" + "" end # TODO: this can be removed once we migrate away from ES diff --git a/app/serializers/search/user_serializer.rb b/app/serializers/search/user_serializer.rb index 27bc9f22c..8b08a1030 100644 --- a/app/serializers/search/user_serializer.rb +++ b/app/serializers/search/user_serializer.rb @@ -3,13 +3,10 @@ module Search HASH_TRANSFORM = ->(key, value) { { name: key, value: value } } attributes :id, - :available_for, :comments_count, :badge_achievements_count, - :employer_name, :hotness_score, :last_comment_at, - :mostly_work_with, :name, :path, :public_reactions_count, diff --git a/app/views/profile_preview_cards/show.json.jbuilder b/app/views/profile_preview_cards/show.json.jbuilder index f3b1ac9f4..65ae4763f 100644 --- a/app/views/profile_preview_cards/show.json.jbuilder +++ b/app/views/profile_preview_cards/show.json.jbuilder @@ -1,6 +1,8 @@ +# TODO: @citizen428 - We shouldn't use education and work directly here, since +# we can't guarantee that these profile fields will exist on all Forems. json.extract!( @user.profile, - :summary, :employment_title, :employer_name, :employer_url, :location, :education + :summary, :location, :education, :work ) json.card_color( diff --git a/app/views/shared/_profile_card_content.html.erb b/app/views/shared/_profile_card_content.html.erb index 191103739..512d7e640 100644 --- a/app/views/shared/_profile_card_content.html.erb +++ b/app/views/shared/_profile_card_content.html.erb @@ -29,24 +29,6 @@ <% end %> - <% if actor.employment_title.present? %> -
- <%= @user.employment_title %> - <% if @user.employer_name.present? %> - at - <% if @user.employer_url.present? %> - <%= @user.employer_name %> - <% else %> - <%= @user.employer_name %> - <% end %> - <% end %> -
-<%= @user.summary.presence || ["404 bio not found"].sample %>
+<%= @user.profile.summary.presence || ["404 bio not found"].sample %>