Add Twitch to Profile Links (#2557)

This commit is contained in:
Bolarinwa Balogun 2019-04-25 16:14:28 -04:00 committed by Ben Halpern
parent 3f92ac4919
commit 1578befdf1
11 changed files with 38 additions and 3 deletions

View file

@ -49,6 +49,7 @@ module Admin
medium_url
gitlab_url
linkedin_url
twitch_url
]
accessible << %i[password password_confirmation] if params[:user][:password].present?
verify_usernames params.require(:user).permit(accessible)

View file

@ -38,6 +38,7 @@ class UserDashboard < Administrate::BaseDashboard
medium_url: Field::String,
gitlab_url: Field::String,
linkedin_url: Field::String,
twitch_url: Field::String,
feed_admin_publish_permission: Field::Boolean,
feed_mark_canonical: Field::Boolean,
saw_onboarding: Field::Boolean,
@ -83,6 +84,7 @@ class UserDashboard < Administrate::BaseDashboard
medium_url
gitlab_url
linkedin_url
twitch_url
bg_color_hex
text_color_hex
reputation_modifier

View file

@ -92,6 +92,9 @@ class User < ApplicationRecord
validates :gitlab_url,
allow_blank: true,
format: /\A(http(s)?:\/\/)?(www.gitlab.com|gitlab.com)\/.*\Z/
validates :twitch_url,
allow_blank: true,
format: /\A(http(s)?:\/\/)?(www.twitch.tv|twitch.tv)\/.*\Z/
validates :shirt_gender,
inclusion: { in: %w[unisex womens],
message: "%{value} is not a valid shirt style" },

View file

@ -116,6 +116,7 @@ class UserPolicy < ApplicationPolicy
stackoverflow_url
summary
text_color_hex
twitch_url
username
website_url
export_requested]

View file

@ -50,7 +50,7 @@ module Moderator
location: "", education: "", employer_name: "", employer_url: "", employment_title: "",
mostly_work_with: "", currently_learning: "", currently_hacking_on: "", available_for: "",
email_public: false, facebook_url: nil, dribbble_url: nil, medium_url: nil, stackoverflow_url: nil,
behance_url: nil, linkedin_url: nil, gitlab_url: nil, mastodon_url: nil
behance_url: nil, linkedin_url: nil, gitlab_url: nil, mastodon_url: nil, twitch_url: nil
)
user.update_columns(profile_image: "https://thepracticaldev.s3.amazonaws.com/i/99mvlsfu5tfj9m7ku25d.png")

View file

@ -103,7 +103,7 @@
</div>
<div class="field">
<%= f.label :currently_learning, "I'm getting into" %>
<%= f.text_area :currently_learning, placeholder: "What are you learning right now? what are the new tools and languages you're picking up in #{Time.new.year}?", maxlength: 500 %>
<%= f.text_area :currently_learning, placeholder: "What are you learning right now? what are the new tools and languages you're picking up in #{Time.zone.now.year}?", maxlength: 500 %>
</div>
<div class="field">
<%= f.label :currently_hacking_on, "My projects and hacks" %>
@ -145,6 +145,10 @@
<div class="field">
<%= f.label :mastodon_url, "Mastodon URL" %>
<%= f.url_field :mastodon_url %>
</div>
<div class="field">
<%= f.label :twitch_url, "Twitch URL" %>
<%= f.url_field :twitch_url %>
</div>
<div class="field">
<label></label>

View file

@ -24,7 +24,7 @@
</span>
</h1>
<p class="profile-description" itemprop="description">
<%= @user.summary.present? ? @user.summary : ["404 bio not found"].sample %>
<%= @user.summary.presence || ["404 bio not found"].sample %>
</p>
<style>
.profile-details .social .icon-img path {
@ -83,6 +83,11 @@
<%= inline_svg("gitlab.svg", class: "icon-img") %>
</a>
<% end %>
<% if @user.twitch_url.present? %>
<a href="<%= @user.twitch_url %>" target="_blank" rel="noopener nofollow me">
<%= inline_svg("twitch-logo.svg", class: "icon-img") %>
</a>
<% end %>
<% if @user.website_url.present? %>
<a href="<%= @user.website_url %>" target="_blank" rel="noopener nofollow me">
<%= inline_svg("external-link-logo.svg", class: "icon-img") %>

View file

@ -105,6 +105,11 @@
<%= inline_svg("gitlab.svg", class: "icon-img") %>
</a>
<% end %>
<% if @user.twitch_url? %>
<a href="<%= @user.twitch_url %>" target="_blank" rel="noopener nofollow me">
<%= inline_svg("twitch-logo.svg", class: "icon-img") %>
</a>
<% end %>
<% if @user.website_url? %>
<a href="<%= @user.website_url %>" target="_blank" rel="noopener nofollow me">
<%= inline_svg("external-link-logo.svg", class: "icon-img") %>

View file

@ -5,5 +5,6 @@ class AddSocialIconsToUser < ActiveRecord::Migration[5.1]
add_column :users, :linkedin_url, :string
add_column :users, :behance_url, :string
add_column :users, :dribbble_url, :string
add_column :users, :twitch_url, :string
end
end

View file

@ -919,6 +919,7 @@ ActiveRecord::Schema.define(version: 2019_04_17_171020) do
t.string "text_color_hex"
t.string "text_only_name"
t.string "top_languages"
t.string "twitch_url"
t.datetime "twitter_created_at"
t.integer "twitter_followers_count"
t.integer "twitter_following_count"

View file

@ -142,6 +142,18 @@ RSpec.describe User, type: :model do
expect(user).not_to be_valid
end
it "does not accept invalid twitch url" do
user.twitch_url = "ben.com"
expect(user).not_to be_valid
end
it "accepts valid https twitch url" do
%w[pandyzhao pandyzhao/ PandyZhao_ pandy_Zhao].each do |username|
user.twitch_url = "https://twitch.tv/#{username}"
expect(user).to be_valid
end
end
it "accepts valid https stackoverflow url" do
%w[pandyzhao pandyzhao/ pandy-zhao].each do |username|
user.stackoverflow_url = "https://stackoverflow.com/users/7381391/#{username}"