diff --git a/app/assets/images/gitlab.svg b/app/assets/images/gitlab.svg new file mode 100644 index 000000000..36faeca30 --- /dev/null +++ b/app/assets/images/gitlab.svg @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/app/controllers/internal/users_controller.rb b/app/controllers/internal/users_controller.rb index ad2d176a2..edfe0203a 100644 --- a/app/controllers/internal/users_controller.rb +++ b/app/controllers/internal/users_controller.rb @@ -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. diff --git a/app/models/user.rb b/app/models/user.rb index 15a1a1e7d..bae79df53 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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, diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index 9b371512d..54dbfde79 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -76,6 +76,7 @@ class UserPolicy < ApplicationPolicy feed_admin_publish_permission feed_mark_canonical feed_url + gitlab_url linkedin_url location looking_for_work diff --git a/app/views/articles/index.html.erb b/app/views/articles/index.html.erb index f40d208e3..353846f45 100644 --- a/app/views/articles/index.html.erb +++ b/app/views/articles/index.html.erb @@ -164,6 +164,11 @@ <%= inline_svg("medium_icon.svg", class:"icon-img") %> <% end %> + <% if @user.gitlab_url.present? %> + + <%= inline_svg("gitlab.svg", class:"icon-img") %> + + <% end %> <% if @user.website_url.present? %> <%= inline_svg("external-link-logo.svg", class:"icon-img") %> diff --git a/app/views/users/_profile.html.erb b/app/views/users/_profile.html.erb index 22082bad2..3416fba78 100644 --- a/app/views/users/_profile.html.erb +++ b/app/views/users/_profile.html.erb @@ -138,6 +138,10 @@ <%= f.label :medium_url %> <%= f.url_field :medium_url %> +
+ <%= f.label :gitlab_url %> + <%= f.url_field :gitlab_url %> +
<%= f.hidden_field :tab, value: @tab %> diff --git a/db/migrate/20181111040732_add_gitlab_url_to_users.rb b/db/migrate/20181111040732_add_gitlab_url_to_users.rb new file mode 100644 index 000000000..73dfccec7 --- /dev/null +++ b/db/migrate/20181111040732_add_gitlab_url_to_users.rb @@ -0,0 +1,5 @@ +class AddGitlabUrlToUsers < ActiveRecord::Migration[5.1] + def change + add_column :users, :gitlab_url, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 44779ac25..b33c6c097 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d9a8d287f..cfa5ad2c6 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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)}"