Add Mastodon URL to profile (#1137)

This commit is contained in:
Michael Kohl 2018-12-04 23:54:53 +05:30 committed by Ben Halpern
parent 7d79b29b6c
commit ffd24f791e
10 changed files with 93 additions and 0 deletions

View file

@ -0,0 +1 @@
<svg role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><title>Mastodon icon</title><path d="M23.193 7.879c0-5.206-3.411-6.732-3.411-6.732C18.062.357 15.108.025 12.041 0h-.076c-3.068.025-6.02.357-7.74 1.147 0 0-3.411 1.526-3.411 6.732 0 1.192-.023 2.618.015 4.129.124 5.092.934 10.109 5.641 11.355 2.17.574 4.034.695 5.535.612 2.722-.15 4.25-.972 4.25-.972l-.09-1.975s-1.945.613-4.129.539c-2.165-.074-4.449-.233-4.799-2.891a5.499 5.499 0 0 1-.048-.745s2.125.52 4.817.643c1.646.075 3.19-.097 4.758-.283 3.007-.359 5.625-2.212 5.954-3.905.517-2.665.475-6.507.475-6.507zm-4.024 6.709h-2.497V8.469c0-1.29-.543-1.944-1.628-1.944-1.2 0-1.802.776-1.802 2.312v3.349h-2.483v-3.35c0-1.536-.602-2.312-1.802-2.312-1.085 0-1.628.655-1.628 1.944v6.119H4.832V8.284c0-1.289.328-2.313.987-3.07.68-.758 1.569-1.146 2.674-1.146 1.278 0 2.246.491 2.886 1.474L12 6.585l.622-1.043c.64-.983 1.608-1.474 2.886-1.474 1.104 0 1.994.388 2.674 1.146.658.757.986 1.781.986 3.07v6.304z"/></svg>

After

Width:  |  Height:  |  Size: 979 B

View file

@ -128,6 +128,7 @@ class Internal::UsersController < Internal::ApplicationController
user.behance_url = nil
user.linkedin_url = nil
user.gitlab_url = nil
user.mastodon_url = nil
user.add_role :banned
unless user.notes.where(reason: "banned").any?
user.notes.

51
app/lib/constants.rb Normal file
View file

@ -0,0 +1,51 @@
module Constants
MASTODON_INSTANCE_WHITELIST = [
"acg.mn",
"bitcoinhackers.org",
"cmx.im",
"framapiaf.org",
"friends.nico",
"hearthtodon.com",
"hex.bz",
"horiedon.com",
"hostux.social",
"imastodon.net",
"kirakiratter.com",
"knzk.me",
"lou.lt",
"mamot.fr",
"mao.daizhige.org",
"mastodon.art",
"mastodon.at",
"mastodon.blue",
"mastodon.cloud",
"mastodon.gamedev.place",
"mastodon.host",
"mastodon.sdf.org",
"mastodon.social",
"mastodon.technology",
"mastodon.xyz",
"mathtod.online",
"mimumedon.com",
"misskey.xyz",
"mstdn-workers.com",
"mstdn.guru",
"mstdn.io",
"mstdn.jp",
"mstdn.tokyocameraclub.com",
"mstdn18.jp",
"music.pawoo.net",
"niu.moe",
"noagendasocial.com",
"octodon.social",
"otajodon.com",
"pawoo.net",
"qiitadon.com",
"ro-mastodon.puyo.jp",
"social.targaryen.house",
"social.tchncs.de",
"switter.at",
"todon.nl",
"wikitetas.club"
].freeze
end

View file

@ -112,6 +112,7 @@ class User < ApplicationRecord
validates :website_url, url: { allow_blank: true, no_local: true, schemes: ["https", "http"] }
validates :website_url, :employer_name, :employer_url,
length: { maximum: 100 }
validates :mastodon_url, url: { allow_blank: true, no_local: true, schemes: ["https", "http"] }
validates :employment_title, :education, :location,
length: { maximum: 100 }
validates :mostly_work_with, :currently_learning,
@ -120,6 +121,7 @@ class User < ApplicationRecord
validates :mentee_description, :mentor_description,
length: { maximum: 1000 }
validate :conditionally_validate_summary
validate :mastodon_url_whitelist
validate :validate_feed_url
validate :unique_including_orgs
@ -471,6 +473,13 @@ class User < ApplicationRecord
errors.add(:feed_url, "is not a valid rss feed") unless RssReader.new.valid_feed_url?(feed_url)
end
def mastodon_url_whitelist
return unless mastodon_url.present?
uri = URI.parse(mastodon_url)
return if uri.host&.in?(Constants::MASTODON_INSTANCE_WHITELIST)
errors.add(:mastodon_url, "is not a whitelisted Mastodon instance")
end
def title
name
end

View file

@ -82,6 +82,7 @@ class UserPolicy < ApplicationPolicy
location
looking_for_work
looking_for_work_publicly
mastodon_url
medium_url
mentee_description
mentee_form_updated_at

View file

@ -134,6 +134,11 @@
</a>
<% end %>
<% if @user.class.name == "User" %>
<% if @user.mastodon_url.present? %>
<a href="<%= @user.mastodon_url %>" target="_blank" rel="noopener">
<%= inline_svg("mastodon-logo.svg", class:"icon-img") %>
</a>
<% end %>
<% if @user.facebook_url.present? %>
<a href="<%= @user.facebook_url %>" target="_blank" rel="noopener me">
<%= inline_svg("facebook-logo.svg", class:"icon-img") %>

View file

@ -142,6 +142,10 @@
<%= f.label :gitlab_url %>
<%= f.url_field :gitlab_url %>
</div>
<div class="field">
<%= f.label :mastodon_url %>
<%= f.url_field :mastodon_url %>
</div>
<div class="field">
<label></label>
<%= f.hidden_field :tab, value: @tab %>

View file

@ -0,0 +1,5 @@
class AddMastodonUrlToUsers < ActiveRecord::Migration[5.1]
def change
add_column :users, :mastodon_url, :string
end
end

View file

@ -800,6 +800,7 @@ ActiveRecord::Schema.define(version: 20181129222416) do
t.string "username"
t.string "website_url"
t.datetime "workshop_expiration"
t.string "mastodon_url"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["language_settings"], name: "index_users_on_language_settings", using: :gin
t.index ["organization_id"], name: "index_users_on_organization_id"

View file

@ -59,6 +59,21 @@ RSpec.describe User, type: :model do
expect(user).not_to be_valid
end
it "accepts valid https mastodon url" do
user.mastodon_url = "https://mastodon.social/@test"
expect(user).to be_valid
end
it "does not accept a non whitelisted mastodon instance" do
user.mastodon_url = "https://SpammyMcSpamface.com/"
expect(user).not_to be_valid
end
it "does not accept invalid mastodon url" do
user.mastodon_url = "mastodon.social/@test"
expect(user).not_to be_valid
end
it "accepts valid http website url" do
user.website_url = "http://ben.com"
expect(user).to be_valid