Skip to content

Commit

Permalink
Remove references to social link profile fields (#13252)
Browse files Browse the repository at this point in the history
* Remove references to social link profile fields

* Add some dummy data

* Remove special display social links

* Remove unnecessary tests

* Add tests for profile social icons

* PR feedback

* Remove nil check from erb

* Move view method into helper

* Don't render links in user settings
  • Loading branch information
jacobherrington committed May 3, 2021
1 parent 393ba00 commit bb9780f
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 97 deletions.
2 changes: 2 additions & 0 deletions app/controllers/stories_controller.rb
@@ -1,4 +1,6 @@
class StoriesController < ApplicationController
helper ProfileHelper

DEFAULT_HOME_FEED_ATTRIBUTES_FOR_SERIALIZATION = {
only: %i[
title path id user_id comments_count public_reactions_count organization_id
Expand Down
16 changes: 16 additions & 0 deletions app/helpers/profile_helper.rb
@@ -0,0 +1,16 @@
module ProfileHelper
def social_authentication_links_for(user)
# Returns a Hash containing URLs for social authentication providers
# Currently supported: GitHub, Twitter, Facebook
user_identities = user.identities_enabled
return {} if user_identities.blank?

urls = user_identities.pluck(:auth_data_dump).each_with_object({}) do |data, hash|
if (data_urls = data.dig(:info, :urls))
hash.merge!(data_urls)
end
end

{ github: urls["GitHub"], twitter: urls["Twitter"], facebook: urls["Facebook"] }.compact
end
end
28 changes: 2 additions & 26 deletions app/models/profile.rb
Expand Up @@ -17,34 +17,14 @@ class Profile < ApplicationRecord
location
].freeze

SPECIAL_SOCIAL_LINK_ATTRIBUTES = %w[
twitter_url
github_url
facebook_url
linkedin_url
youtube_url
instagram_url
behance_url
medium_url
stackoverflow_url
gitlab_url
twitch_url
mastodon_url
website_url
dribbble_url
].freeze

# 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,
education: :education,
git_lab_url: :gitlab_url,
linked_in_url: :linkedin_url,
skills_languages: :mostly_work_with,
stack_overflow_url: :stackoverflow_url
skills_languages: :mostly_work_with
}.with_indifferent_access.freeze

# Generates typed accessors for all currently defined profile fields.
Expand All @@ -67,11 +47,7 @@ def self.attributes
end

def self.special_attributes
SPECIAL_DISPLAY_ATTRIBUTES + SPECIAL_SOCIAL_LINK_ATTRIBUTES
end

def self.special_social_link_attributes
SPECIAL_SOCIAL_LINK_ATTRIBUTES.freeze
SPECIAL_DISPLAY_ATTRIBUTES
end

def custom_profile_attributes
Expand Down
12 changes: 1 addition & 11 deletions app/policies/user_policy.rb
Expand Up @@ -2,7 +2,6 @@ class UserPolicy < ApplicationPolicy
PERMITTED_ATTRIBUTES = %i[
reaction_notifications
available_for
behance_url
bg_color_hex
config_font
config_theme
Expand All @@ -11,7 +10,7 @@ class UserPolicy < ApplicationPolicy
currently_hacking_on
currently_learning
display_announcements
display_sponsors dribbble_url
display_sponsors
editor_version education email
email_badge_notifications
email_comment_notifications
Expand All @@ -29,19 +28,12 @@ class UserPolicy < ApplicationPolicy
employment_title
experience_level
export_requested
facebook_url
youtube_url
feed_mark_canonical
feed_referential_link
feed_url
gitlab_url
inbox_guidelines
inbox_type
instagram_url
linkedin_url
location
mastodon_url
medium_url
mobile_comment_notifications
mod_roundrobin_notifications
welcome_notifications
Expand All @@ -52,10 +44,8 @@ class UserPolicy < ApplicationPolicy
payment_pointer
permit_adjacent_sponsors
profile_image
stackoverflow_url
summary
text_color_hex
twitch_url
username
website_url
].freeze
Expand Down
1 change: 1 addition & 0 deletions app/views/users/_profile.html.erb
Expand Up @@ -48,6 +48,7 @@
</div>

<% ProfileFieldGroup.non_empty_groups.each do |group| %>
<% next if group.name == "Links" # TODO: [@jacobherrington] Remove this when we drop social links %>
<div class="crayons-card crayons-card--content-rows">
<h2><%= group.name %></h2>
<% if group.description.present? %>
Expand Down
22 changes: 13 additions & 9 deletions app/views/users/show.html.erb
Expand Up @@ -82,15 +82,19 @@
<%= @user.email %>
</a>
<% end %>
<span class="profile-header__meta__item -ml-1">
<% Profile.special_social_link_attributes.each do |attribute| %>
<% if @user.public_send(attribute).present? %>
<a href="<%= @user.public_send(attribute) %>" target="_blank" rel="noopener me" class="px-1 align-middle inline-block">
<%= inline_svg_tag("#{attribute.gsub('_url', '')}.svg", class: "crayons-icon", aria: true, title: "#{attribute.split('_').first.titleize} logo") %>
</a>
<% end %>
<% end %>
</span>
<% if @user.website_url.present? %>
<a href="<%= @user.website_url %>" target="_blank" rel="noopener me" class="profile-header__meta__item">
<%= inline_svg_tag("link-external.svg", class: "crayons-icon mr-2 shrink-0", aria: true, title: "Personal website") %>
<%= @user.website_url %>
</a>
<% end %>
<% social_authentication_links_for(@user).each do |provider_name, url| %>
<a href="<%= url %>" target="_blank" rel="noopener me" class="profile-header__meta__item p-1">
<%= inline_svg_tag("#{provider_name}.svg", class: "crayons-icon shrink-0", aria: true, title: "#{provider_name} website") %>
</a>
<% end %>
</div>
</div>

Expand Down
11 changes: 0 additions & 11 deletions lib/data/dev_profile_fields.csv
Expand Up @@ -2,17 +2,6 @@ Display email on profile,check_box,,,Basic,settings_only,false
Website URL,text_field,https://yoursite.com,,Basic,settings_only,true
Summary,text_area,A short bio...,,Basic,settings_only,true
Location,text_field,"Halifax, Nova Scotia",,Basic,header,true
Facebook URL,text_field,https://facebook.com/...,,Links,settings_only,false
Youtube URL,text_field,https://www.youtube.com/channel/...,,Links,settings_only,false
StackOverflow URL,text_field,https://stackoverflow.com/users/...,,Links,settings_only,false
LinkedIn URL,text_field,https://www.linkedin.com/in/...,,Links,settings_only,false
Behance URL,text_field,https://www.behance.net/...,,Links,settings_only,false
Dribbble URL,text_field,https://dribbble.com/...,,Links,settings_only,false
Medium URL,text_field,https://medium.com/@...,,Links,settings_only,false
GitLab URL,text_field,https://gitlab.com/...,,Links,settings_only,false
Instagram URL,text_field,https://www.instagram.com/...,,Links,settings_only,false
Mastodon URL,text_field,https://...,,Links,settings_only,false
Twitch URL,text_field,https://www.twitch.tv/...,,Links,settings_only,false
Education,text_field,,,Work,header,false
Employer name,text_field,Acme Inc.,,Work,header,false
Employer URL,text_field,https://dev.com,,Work,header,false
Expand Down
10 changes: 0 additions & 10 deletions spec/factories/profiles.rb
Expand Up @@ -6,23 +6,13 @@
trait :with_DEV_info do
data do
{
behance_url: "www.behance.net/#{user.username}",
currently_hacking_on: "JSON-LD",
currently_learning: "Preact",
dribbble_url: "www.dribbble.com/example",
education: "DEV University",
employer_name: "DEV",
employer_url: "http://dev.to",
employment_title: "Software Engineer",
facebook_url: "www.facebook.com/example",
gitlab_url: "www.gitlab.com/example",
instagram_url: "www.instagram.com/example",
linkedin_url: "www.linkedin.com/company/example",
mastodon_url: "https://mastodon.social/@test",
medium_url: "www.medium.com/example",
skills_languages: "Ruby",
stackoverflow_url: "www.stackoverflow.com/example",
youtube_url: "https://youtube.com/example",
summary: "I do things with computers",
website_url: "http://example.com"
}
Expand Down
61 changes: 61 additions & 0 deletions spec/helpers/profile_helper_spec.rb
@@ -0,0 +1,61 @@
require "rails_helper"

describe ProfileHelper do
before do
allow(Settings::Authentication).to receive(:providers).and_return(Authentication::Providers.available)
end

describe "social_authentication_links_for" do
let(:user) do
create(:user)
end
let(:actual) { helper.social_authentication_links_for(user) }

context "when a user has no social authentication providers linked" do
it "does not return any links for a user without social authentication providers" do
expect(actual).to eq({})
end
end

context "when a user has one social authentication provider linked" do
let(:user) do
omniauth_mock_github_payload
create(:user, :with_identity, identities: ["github"])
end

it "returns a link to the social authentication provider's link" do
expect(actual).to eq({ github: "https://example.com" })
end
end

context "when a user has multiple social authentication providers linked" do
let(:user) do
omniauth_mock_github_payload
omniauth_mock_twitter_payload
omniauth_mock_facebook_payload
omniauth_mock_apple_payload
create(:user, :with_identity, identities: %w[github twitter facebook apple])
end

it "returns all supported links" do
expected = { github: "https://example.com", twitter: "https://example.com", facebook: "https://example.com" }
expect(actual).to eq(expected)
end
end

context "when third party authentication providers are not enabled" do
let(:user) do
omniauth_mock_github_payload
create(:user, :with_identity, identities: ["github"])
end

before do
allow(Settings::Authentication).to receive(:providers).and_return([])
end

it "returns a link to the social authentication provider's link" do
expect(actual).to eq({})
end
end
end
end
4 changes: 2 additions & 2 deletions spec/lib/data_update_scripts/create_profile_fields_spec.rb
Expand Up @@ -15,7 +15,7 @@ def profile_field_and_group_count
it "creates all profile fields and groups" do
expect do
described_class.new.run
end.to change { profile_field_and_group_count }.from([0, 0]).to([25, 5])
end.to change { profile_field_and_group_count }.from([0, 0]).to([14, 4])
end
end

Expand All @@ -29,7 +29,7 @@ def profile_field_and_group_count
expect do
described_class.new.run
end.not_to change { profile_field_and_group_count }
expect(profile_field_and_group_count).to eq [25, 5]
expect(profile_field_and_group_count).to eq [14, 4]
end
end
end
14 changes: 0 additions & 14 deletions spec/lib/data_update_scripts/fix_profile_field_edge_cases_spec.rb

This file was deleted.

Expand Up @@ -7,8 +7,6 @@
it "migrates profile fields to proper areas" do
# Run the script
described_class.new.run
expect(ProfileField.find_by(attribute_name: "instagram_url").display_area)
.to eq("settings_only")
expect(ProfileField.find_by(attribute_name: "education").display_area).to eq("header")
expect(ProfileField.find_by(attribute_name: "currently_learning").display_area).to eq("left_sidebar")
end
Expand Down
11 changes: 0 additions & 11 deletions spec/requests/user/user_profile_spec.rb
Expand Up @@ -114,17 +114,6 @@
expect(response.body).to include "M18.364 17.364L12 23.728l-6.364-6.364a9 9 0 1112.728 0zM12 13a2 2 0 100-4 2 2 0"
end

it "does not render special display social link elements naively" do
user.instagram_url = "https://instagram.com/whoa"
user.save
get "/#{user.username}"
# Does not include the word, but does include the SVG
expect(response.body).not_to include "<p>Instagram"
expect(response.body).to include "Instagram logo</title>"
expect(response.body).to include user.instagram_url
expect(response.body).to include "M12 2c2.717 0 3.056.01 4.122.06 1.065.05 1.79.217 2.428.465.66.254"
end

context "when organization" do
it "renders organization page if org" do
get organization.path
Expand Down
5 changes: 4 additions & 1 deletion spec/support/omniauth_helpers.rb
Expand Up @@ -49,7 +49,8 @@ module OmniauthHelpers
info: {
email: "markz@thefacebook.com",
name: "fname lname",
image: "https://dummyimage.com/400x400.jpg"
image: "https://dummyimage.com/400x400.jpg",
urls: { "Facebook" => "https://example.com" }
},
credentials: {
token: SecureRandom.hex,
Expand Down Expand Up @@ -169,6 +170,7 @@ def omniauth_mock_apple_payload
def omniauth_mock_github_payload
info = OMNIAUTH_BASIC_INFO[:info].merge(
image: "https://dummyimage.com/400x400.jpg",
urls: { "GitHub" => "https://example.com" },
)

OmniAuth.config.mock_auth[:github] = OmniAuth::AuthHash.new(
Expand All @@ -182,6 +184,7 @@ def omniauth_mock_github_payload
def omniauth_mock_twitter_payload
info = OMNIAUTH_BASIC_INFO[:info].merge(
image: "https://dummyimage.com/400x400_normal.jpg",
urls: { "Twitter" => "https://example.com" },
)

extra = OMNIAUTH_BASIC_INFO[:extra].merge(
Expand Down
9 changes: 9 additions & 0 deletions spec/system/authentication/user_logs_in_with_facebook_spec.rb
Expand Up @@ -220,6 +220,15 @@

expect(page).to have_current_path("/?signin=true")
end

it "renders the facebook icon on the profile" do
sign_in user
visit user_facebook_omniauth_authorize_path

visit user_profile_path(user.username)

expect(page).to have_css("svg.crayons-icon.shrink-0", text: "facebook website")
end
end
end

Expand Down
9 changes: 9 additions & 0 deletions spec/system/authentication/user_logs_in_with_github_spec.rb
Expand Up @@ -177,6 +177,15 @@

expect(page).to have_current_path("/?signin=true")
end

it "renders the github icon on the profile" do
sign_in user
visit user_github_omniauth_authorize_path

visit user_profile_path(user.username)

expect(page).to have_css("svg.crayons-icon.shrink-0", text: "github website")
end
end

context "when already signed in" do
Expand Down
9 changes: 9 additions & 0 deletions spec/system/authentication/user_logs_in_with_twitter_spec.rb
Expand Up @@ -178,6 +178,15 @@

expect(page).to have_current_path("/?signin=true")
end

it "renders the twitter icon on the profile" do
sign_in user
visit user_twitter_omniauth_authorize_path

visit user_profile_path(user.username)

expect(page).to have_css("svg.crayons-icon.shrink-0", text: "twitter website")
end
end
end

Expand Down

0 comments on commit bb9780f

Please sign in to comment.