From b52d8e931d2c92ea5dcc8640b8b1dd63d33b1226 Mon Sep 17 00:00:00 2001 From: Bolarinwa Balogun Date: Wed, 26 Jun 2019 08:56:07 -0400 Subject: [PATCH] Add Instagram URL to profile links (#3307) --- app/controllers/admin/users_controller.rb | 1 + app/dashboards/user_dashboard.rb | 2 ++ app/models/user.rb | 3 +++ app/policies/user_policy.rb | 1 + app/services/moderator/banish_user.rb | 2 +- app/views/users/_profile.html.erb | 4 ++++ app/views/users/_profile_header.html.erb | 5 +++++ app/views/users/show.html.erb | 5 +++++ .../20190626022355_add_instagram_url_to_users.rb | 5 +++++ db/schema.rb | 3 ++- spec/models/user_spec.rb | 12 ++++++++++++ 11 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20190626022355_add_instagram_url_to_users.rb diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 88ab65b94..d2f2fc1f3 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -50,6 +50,7 @@ module Admin gitlab_url linkedin_url twitch_url + instagram_url ] accessible << %i[password password_confirmation] if params[:user][:password].present? verify_usernames params.require(:user).permit(accessible) diff --git a/app/dashboards/user_dashboard.rb b/app/dashboards/user_dashboard.rb index fcddce779..0f5e8405a 100644 --- a/app/dashboards/user_dashboard.rb +++ b/app/dashboards/user_dashboard.rb @@ -37,6 +37,7 @@ class UserDashboard < Administrate::BaseDashboard dribbble_url: Field::String, medium_url: Field::String, gitlab_url: Field::String, + instagram_url: Field::String, linkedin_url: Field::String, twitch_url: Field::String, feed_admin_publish_permission: Field::Boolean, @@ -83,6 +84,7 @@ class UserDashboard < Administrate::BaseDashboard dribbble_url medium_url gitlab_url + instagram_url linkedin_url twitch_url bg_color_hex diff --git a/app/models/user.rb b/app/models/user.rb index 12bf39643..798bfcb3f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -91,6 +91,9 @@ class User < ApplicationRecord validates :gitlab_url, allow_blank: true, format: /\A(http(s)?:\/\/)?(www.gitlab.com|gitlab.com)\/.*\Z/ + validates :instagram_url, + allow_blank: true, + format: /\A(http(s)?:\/\/)?(www.instagram.com|instagram.com)\/[a-z\d_]{1,30}\Z/ validates :twitch_url, allow_blank: true, format: /\A(http(s)?:\/\/)?(www.twitch.tv|twitch.tv)\/.*\Z/ diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index 19ddfe5cd..0772ef18d 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -84,6 +84,7 @@ class UserPolicy < ApplicationPolicy feed_url gitlab_url inbox_guidelines + instagram_url linkedin_url location looking_for_work diff --git a/app/services/moderator/banish_user.rb b/app/services/moderator/banish_user.rb index 8bd6aeb98..4aaae6670 100644 --- a/app/services/moderator/banish_user.rb +++ b/app/services/moderator/banish_user.rb @@ -41,7 +41,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, twitch_url: nil + behance_url: nil, linkedin_url: nil, gitlab_url: nil, instagram_url: nil, mastodon_url: nil, twitch_url: nil ) user.update_columns(profile_image: "https://thepracticaldev.s3.amazonaws.com/i/99mvlsfu5tfj9m7ku25d.png") diff --git a/app/views/users/_profile.html.erb b/app/views/users/_profile.html.erb index 9df11d1df..e92e63df4 100644 --- a/app/views/users/_profile.html.erb +++ b/app/views/users/_profile.html.erb @@ -147,6 +147,10 @@ <%= f.label :gitlab_url, "GitLab URL" %> <%= f.url_field :gitlab_url %> +
+ <%= f.label :instagram_url, "Instagram URL" %> + <%= f.url_field :instagram_url %> +
<%= f.label :mastodon_url, "Mastodon URL" %> <%= f.url_field :mastodon_url %> diff --git a/app/views/users/_profile_header.html.erb b/app/views/users/_profile_header.html.erb index a2900069a..2b2d51353 100644 --- a/app/views/users/_profile_header.html.erb +++ b/app/views/users/_profile_header.html.erb @@ -82,6 +82,11 @@ <%= inline_svg("gitlab.svg", class: "icon-img", aria: true, title: "GitLab logo") %> + <% end %> + <% if @user.instagram_url.present? %> + + <%= inline_svg("instagram-logo.svg", class: "icon-img", aria: true, title: "Instagram logo") %> + <% end %> <% if @user.twitch_url.present? %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index bf81056b6..5f7391022 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -105,6 +105,11 @@ <%= inline_svg("gitlab.svg", class: "icon-img", aria: true, title: "GitLab logo") %> <% end %> + <% if @user.instagram_url? %> + + <%= inline_svg("instagram-logo.svg", class: "icon-img", aria: true, title: "Instagram logo") %> + + <% end %> <% if @user.twitch_username? %> <%= link_to twitch_live_stream_path(username: @user.username) do %> <%= inline_svg("twitch-logo.svg", class: "icon-img", id: "icon-twitch", aria: true, title: "Twitch logo") %> diff --git a/db/migrate/20190626022355_add_instagram_url_to_users.rb b/db/migrate/20190626022355_add_instagram_url_to_users.rb new file mode 100644 index 000000000..cfa44ad92 --- /dev/null +++ b/db/migrate/20190626022355_add_instagram_url_to_users.rb @@ -0,0 +1,5 @@ +class AddInstagramUrlToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :instagram_url, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index f65e89924..b3ac291de 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,7 +12,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_06_25_143841) do +ActiveRecord::Schema.define(version: 2019_06_26_022355) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -952,6 +952,7 @@ ActiveRecord::Schema.define(version: 2019_06_25_143841) do t.string "gitlab_url" t.string "inbox_guidelines" t.string "inbox_type", default: "private" + t.string "instagram_url" t.jsonb "language_settings", default: {}, null: false t.datetime "last_article_at", default: "2017-01-01 05:00:00" t.datetime "last_comment_at", default: "2017-01-01 05:00:00" diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d7e260016..cd00b7fca 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -257,6 +257,18 @@ RSpec.describe User, type: :model do expect(user).not_to be_valid end + it "does not accept invalid instagram url" do + user.instagram_url = "ben.com" + expect(user).not_to be_valid + end + + it "accepts valid instagram url" do + %w[jess je_ss].each do |username| + user.instagram_url = "https://instagram.com/#{username}" + expect(user).to be_valid + end + 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}"