Add GitLab URL field to user profile (#1121)

* Add SVG file of GitLab icon

* Add gitlab_url column to users table

* Add gitlab_url to user model, controller and policy

* Add gitlab_url to views

* Add tests for gitlab_url
This commit is contained in:
sidemt 2018-11-16 06:09:35 +09:00 committed by Ben Halpern
parent b10747dbac
commit 62d8a33111
9 changed files with 43 additions and 6 deletions

View file

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M29.782 199.732L256 493.714 8.074 309.699c-6.856-5.142-9.712-13.996-7.141-21.993l28.849-87.974zm75.405-174.806c-3.142-8.854-15.709-8.854-18.851 0L29.782 199.732h131.961L105.187 24.926zm56.556 174.806L256 493.714l94.257-293.982H161.743zm349.324 87.974l-28.849-87.974L256 493.714l247.926-184.015c6.855-5.142 9.711-13.996 7.141-21.993zm-85.404-262.78c-3.142-8.854-15.709-8.854-18.851 0l-56.555 174.806h131.961L425.663 24.926z"/></svg>
<!--
Font Awesome Free 5.5.0 by @fontawesome - https://fontawesome.com
License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
-->

After

Width:  |  Height:  |  Size: 682 B

View file

@ -17,11 +17,11 @@ class Internal::UsersController < Internal::ApplicationController
end
def show
if params[:id] == "unmatched_mentee"
@user = MentorRelationship.unmatched_mentees.order("RANDOM()").first
else
@user = User.find(params[:id])
end
@user = if params[:id] == "unmatched_mentee"
MentorRelationship.unmatched_mentees.order("RANDOM()").first
else
User.find(params[:id])
end
@user_mentee_relationships = MentorRelationship.where(mentor_id: @user.id)
@user_mentor_relationships = MentorRelationship.where(mentee_id: @user.id)
end
@ -126,6 +126,7 @@ class Internal::UsersController < Internal::ApplicationController
user.stackoverflow_url = nil
user.behance_url = nil
user.linkedin_url = nil
user.gitlab_url = nil
user.add_role :banned
unless user.notes.where(reason: "banned").any?
user.notes.

View file

@ -86,6 +86,9 @@ class User < ApplicationRecord
validates :medium_url,
allow_blank: true,
format: /\Ahttps:\/\/(www.medium.com|medium.com)\/([a-zA-Z0-9\-\_\@\.]{2,32})\/?\Z/
validates :gitlab_url,
allow_blank: true,
format: /\Ahttps:\/\/(www.gitlab.com|gitlab.com)\/([a-zA-Z0-9_\-\.]{1,100})\/?\Z/
# rubocop:enable Metrics/LineLength
validates :employer_url, url: { allow_blank: true, no_local: true, schemes: ["https", "http"] }
validates :shirt_gender,

View file

@ -76,6 +76,7 @@ class UserPolicy < ApplicationPolicy
feed_admin_publish_permission
feed_mark_canonical
feed_url
gitlab_url
linkedin_url
location
looking_for_work

View file

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

View file

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

View file

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

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20181020195954) do
ActiveRecord::Schema.define(version: 20181111040732) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -712,6 +712,7 @@ ActiveRecord::Schema.define(version: 20181020195954) do
t.integer "following_users_count", default: 0, null: false
t.datetime "github_created_at"
t.string "github_username"
t.string "gitlab_url"
t.jsonb "language_settings", default: {}, null: false
t.datetime "last_followed_at"
t.datetime "last_moderation_notification", default: "2017-01-01 05:00:00"

View file

@ -156,6 +156,18 @@ RSpec.describe User, type: :model do
expect(user).not_to be_valid
end
it "accepts valid https gitlab url" do
%w(jess jess/ je-ss je_ss).each do |username|
user.gitlab_url = "https://gitlab.com/#{username}"
expect(user).to be_valid
end
end
it "does not accept invalid gitlab url" do
user.gitlab_url = "ben.com"
expect(user).not_to be_valid
end
it "changes old_username if old_old_username properly if username changes" do
old_username = user.username
random_new_username = "username_#{rand(100000000)}"