diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index b6fce9cbe..decfc44eb 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -333,6 +333,7 @@ class StoriesController < ApplicationController def set_user_json_ld # For more info on structuring data with JSON-LD, # please refer to this link: https://moz.com/blog/json-ld-for-beginners + decorated_user = @user.decorate @user_json_ld = { "@context": "http://schema.org", "@type": "Person", @@ -344,9 +345,8 @@ class StoriesController < ApplicationController sameAs: user_same_as, image: Images::Profile.call(@user.profile_image_url, length: 320), name: @user.name, - email: @user.setting.display_email_on_profile ? @user.email : nil, - description: @user.profile.summary.presence || "404 bio not found", - alumniOf: @user.education.presence + email: decorated_user.profile_email, + description: decorated_user.profile_summary }.reject { |_, v| v.blank? } end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 01acd4297..fcb5d4923 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -46,9 +46,7 @@ class UsersController < ApplicationController set_current_tab(params["user"]["tab"]) set_users_setting_and_notification_setting - @user.assign_attributes(permitted_attributes(@user)) - - if @user.save + if @user.update(permitted_attributes(@user)) # NOTE: [@rhymes] this queues a job to fetch the feed each time the profile is updated, regardless if the user # explicitly requested "Feed fetch now" or simply updated any other field import_articles_from_feed(@user) @@ -170,6 +168,7 @@ class UsersController < ApplicationController def onboarding_update authorize User + user_params = { saw_onboarding: true } if params[:user] @@ -181,7 +180,7 @@ class UsersController < ApplicationController user_params.merge!(params[:user].permit(ALLOWED_USER_PARAMS)) end - update_result = Profiles::Update.call(current_user, { user: user_params, profile: profile_params }) + update_result = Profiles::Update.call(current_user, user: user_params, profile: profile_params) render_update_response(update_result.success?, update_result.errors_as_sentence) end @@ -381,7 +380,7 @@ class UsersController < ApplicationController end def profile_params - params[:profile] ? params[:profile].permit(Profile.attributes) : nil + params[:profile] ? params[:profile].permit(Profile.static_fields + Profile.attributes) : nil end def password_params diff --git a/app/decorators/user_decorator.rb b/app/decorators/user_decorator.rb index b68bd35c8..b364c1759 100644 --- a/app/decorators/user_decorator.rb +++ b/app/decorators/user_decorator.rb @@ -18,6 +18,8 @@ class UserDecorator < ApplicationDecorator }, ].freeze + DEFAULT_PROFILE_SUMMARY = "404 bio not found".freeze + def cached_followed_tags follows_map = Rails.cache.fetch("user-#{id}-#{following_tags_count}-#{last_followed_at&.rfc3339}/followed_tags", expires_in: 20.hours) do @@ -110,6 +112,19 @@ class UserDecorator < ApplicationDecorator created_at.after?(min_days.days.ago) end + # Returns the user's public email if it is set and the display_email_on_profile + # settings is set to true. + def profile_email + return unless setting.display_email_on_profile? + + email + end + + # Returns the users profile summary or a placeholder text + def profile_summary + profile.summary.presence || DEFAULT_PROFILE_SUMMARY + end + delegate :display_sponsors, to: :setting delegate :display_announcements, to: :setting diff --git a/app/models/profile.rb b/app/models/profile.rb index 6eede755b..cc55cec91 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -11,15 +11,6 @@ class Profile < ApplicationRecord # 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" @@ -30,7 +21,7 @@ class Profile < ApplicationRecord # 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) + next if field.attribute_name.in?(STATIC_FIELDS) store_attribute :data, field.attribute_name.to_sym, field.type end @@ -45,10 +36,6 @@ class Profile < ApplicationRecord (stored_attributes[:data] || []).map(&:to_s) end - def self.special_attributes - SPECIAL_DISPLAY_ATTRIBUTES - end - def self.static_fields STATIC_FIELDS end diff --git a/app/models/profile_field.rb b/app/models/profile_field.rb index 26390f289..33f1629cd 100644 --- a/app/models/profile_field.rb +++ b/app/models/profile_field.rb @@ -13,8 +13,7 @@ class ProfileField < ApplicationRecord enum display_area: { header: 0, - left_sidebar: 1, - settings_only: 2 + left_sidebar: 1 } belongs_to :profile_field_group, optional: true diff --git a/app/models/user.rb b/app/models/user.rb index 238c935e5..4c2fb821c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,7 +12,6 @@ class User < ApplicationRecord bg_color_hex currently_hacking_on currently_learning - currently_streaming_on dribbble_url education email_public @@ -58,19 +57,12 @@ class User < ApplicationRecord after_create_commit -> { Profile.create(user: self) }, unless: :_skip_creating_profile # Getters and setters for unmapped profile attributes - (PROFILE_COLUMNS - Profile::MAPPED_ATTRIBUTES.values).each do |column| + PROFILE_COLUMNS.each do |column| next if INACTIVE_PROFILE_COLUMNS.include?(column) + next unless column.in?(Profile.attributes) delegate column, "#{column}=", to: :profile, allow_nil: true end - - # Getters and setters for mapped profile attributes - Profile::MAPPED_ATTRIBUTES.each do |profile_attribute, user_attribute| - define_method(user_attribute) { profile&.public_send(profile_attribute) } - define_method("#{user_attribute}=") do |value| - profile&.public_send("#{profile_attribute}=", value) - end - end end end @@ -289,7 +281,7 @@ class User < ApplicationRecord end def tag_line - summary + profile.summary end def twitter_url diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index 280771ede..5758f6afe 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -20,7 +20,8 @@ class UserPolicy < ApplicationPolicy email_follower_notifications email_membership_newsletter email_mention_notifications - email_newsletter email_public + email_newsletter + email_public email_tag_mod_newsletter email_unread_notifications employer_name @@ -33,21 +34,17 @@ class UserPolicy < ApplicationPolicy feed_url inbox_guidelines inbox_type - location mobile_comment_notifications mod_roundrobin_notifications welcome_notifications - mostly_work_with name password password_confirmation payment_pointer permit_adjacent_sponsors profile_image - summary text_color_hex username - website_url ].freeze def edit? diff --git a/app/services/profiles/update.rb b/app/services/profiles/update.rb index 0dd66e899..f511b8e89 100644 --- a/app/services/profiles/update.rb +++ b/app/services/profiles/update.rb @@ -1,3 +1,5 @@ +# TODO: This should probably become `Users::Update` as we're dealing with core +# user attributes, profile attributes and user settings. module Profiles # Deals with updates that affect fields on +Profile+ and/or +User+ in a transparent way. class Update diff --git a/app/services/users/suggest_for_sidebar.rb b/app/services/users/suggest_for_sidebar.rb index f5390230b..1803a524e 100644 --- a/app/services/users/suggest_for_sidebar.rb +++ b/app/services/users/suggest_for_sidebar.rb @@ -16,7 +16,7 @@ module Users suggested_user_ids = Rails.cache.fetch(generate_cache_name, expires_in: 120.hours) do (reputable_user_ids + random_user_ids).uniq end - User.select(:id, :name, :username, :profile_image, :summary).where(id: suggested_user_ids) + User.select(:id, :name, :username, :profile_image).where(id: suggested_user_ids) end private diff --git a/app/views/api/v0/shared/_user_show.json.jbuilder b/app/views/api/v0/shared/_user_show.json.jbuilder index 7c01a27bd..7f2a57d5c 100644 --- a/app/views/api/v0/shared/_user_show.json.jbuilder +++ b/app/views/api/v0/shared/_user_show.json.jbuilder @@ -5,12 +5,13 @@ json.extract!( :id, :username, :name, - :summary, :twitter_username, :github_username, - :website_url, - :location, ) +Profile.static_fields.each do |attr| + json.set! attr, user.profile.public_send(attr) +end + json.joined_at user.created_at.strftime("%b %e, %Y") json.profile_image Images::Profile.call(user.profile_image_url, length: 320) diff --git a/app/views/articles/feed.rss.builder b/app/views/articles/feed.rss.builder index c3bd52e11..270dc1cc1 100644 --- a/app/views/articles/feed.rss.builder +++ b/app/views/articles/feed.rss.builder @@ -7,7 +7,7 @@ xml.rss version: "2.0" do xml.channel do xml.title user ? user.name : community_name xml.author user ? user.name : community_name - xml.description user ? user.summary : Settings::Community.community_description + xml.description user ? user.tag_line : Settings::Community.community_description xml.link user ? app_url(user.path) : app_url xml.language "en" if user diff --git a/app/views/organizations/_header.html.erb b/app/views/organizations/_header.html.erb index 20b8005d8..a7629b58f 100644 --- a/app/views/organizations/_header.html.erb +++ b/app/views/organizations/_header.html.erb @@ -53,8 +53,8 @@ <%= inline_svg_tag("github.svg", class: "crayons-icon", aria: true, title: "GitHub logo") %> <% end %> - <% if @user.website_url.present? %> - + <% if @user.profile.website_url.present? %> + <%= inline_svg_tag("external.svg", class: "crayons-icon", aria: true, title: "External link icon") %> <% end %> diff --git a/app/views/shared/_profile_card_content.html.erb b/app/views/shared/_profile_card_content.html.erb index 90cb15529..6a0b3d1cd 100644 --- a/app/views/shared/_profile_card_content.html.erb +++ b/app/views/shared/_profile_card_content.html.erb @@ -29,19 +29,18 @@ <% end %> - <% if actor.location.present? %> + <% if actor.profile.location.present? %>
<%= @user.profile.summary.presence || ["404 bio not found"].sample %>
+<%= @user.tag_line.presence || ["404 bio not found"].sample %>