From 665f5aac0faa065f2158b6800cce3a35df65a950 Mon Sep 17 00:00:00 2001 From: Sebastien Date: Fri, 7 Feb 2020 08:56:16 -0500 Subject: [PATCH] Refactor ProfileImage (#5803) --- app/controllers/async_info_controller.rb | 2 +- app/controllers/comments_controller.rb | 2 +- app/controllers/live_articles_controller.rb | 4 ++-- app/controllers/messages_controller.rb | 2 +- app/labor/profile_image.rb | 2 +- app/models/article.rb | 6 +++--- app/models/chat_channel.rb | 2 +- app/models/chat_channel_membership.rb | 2 +- app/models/classified_listing.rb | 2 +- app/models/comment.rb | 4 ++-- app/models/message.rb | 4 ++-- app/models/organization.rb | 2 +- app/models/podcast.rb | 2 +- app/models/podcast_episode.rb | 2 +- app/models/user.rb | 2 +- app/serializers/webhook/user_serializer.rb | 4 ++-- .../_article_content_area.html.erb | 2 +- .../_article_followable_area.html.erb | 2 +- app/views/api/v0/articles/onboarding.json.jbuilder | 2 +- app/views/api/v0/shared/_follows.json.jbuilder | 2 +- app/views/api/v0/shared/_organization.json.jbuilder | 4 ++-- app/views/api/v0/shared/_user.json.jbuilder | 4 ++-- app/views/api/v0/users/index.json.jbuilder | 2 +- app/views/api/v0/users/show.json.jbuilder | 2 +- app/views/articles/_about_author.html.erb | 2 +- app/views/articles/_liquid.html.erb | 2 +- app/views/articles/_single_story.html.erb | 2 +- app/views/articles/_special_sidebar.html.erb | 2 +- app/views/articles/_sticky_nav.html.erb | 6 +++--- app/views/articles/index.html.erb | 2 +- app/views/articles/show.html.erb | 4 ++-- app/views/articles/tags/_sidebar.html.erb | 2 +- app/views/chat_channels/show.json.jbuilder | 2 +- app/views/comments/_comment_proper.html.erb | 2 +- app/views/comments/_liquid.html.erb | 2 +- .../comments/deleted_commentable_comment.html.erb | 2 +- app/views/dashboards/followers.html.erb | 2 +- app/views/dashboards/following_organizations.html.erb | 2 +- app/views/dashboards/following_users.html.erb | 2 +- app/views/internal/comments/index.html.erb | 2 +- app/views/moderations/index.html.erb | 2 +- app/views/organizations/_liquid.html.erb | 2 +- app/views/organizations/_sidebar_additional.html.erb | 2 +- app/views/pages/shecoded.html.erb | 4 ++-- app/views/partnerships/_form.html.erb | 10 +++++----- app/views/social_previews/article.html.erb | 2 +- app/views/social_previews/comment.html.erb | 2 +- app/views/social_previews/shecoded.html.erb | 2 +- app/views/social_previews/user.html.erb | 2 +- app/views/users/_liquid.html.erb | 2 +- app/views/users/_organizations_area.html.erb | 2 +- app/views/users/_profile.html.erb | 2 +- app/views/users/_profile_header.html.erb | 2 +- app/views/users/show.html.erb | 2 +- spec/liquid_tags/link_tag_spec.rb | 2 +- spec/requests/api/v0/chat_channels_spec.rb | 2 +- spec/requests/api/v0/followers_spec.rb | 4 ++-- spec/requests/api/v0/followings_spec.rb | 6 +++--- spec/requests/api/v0/users_spec.rb | 6 +++--- spec/requests/api/v0/webhooks_spec.rb | 4 ++-- 60 files changed, 82 insertions(+), 82 deletions(-) diff --git a/app/controllers/async_info_controller.rb b/app/controllers/async_info_controller.rb index 8020c121c..e9c35b6ef 100644 --- a/app/controllers/async_info_controller.rb +++ b/app/controllers/async_info_controller.rb @@ -43,7 +43,7 @@ class AsyncInfoController < ApplicationController id: @user.id, name: @user.name, username: @user.username, - profile_image_90: ProfileImage.new(@user).get(90), + profile_image_90: ProfileImage.new(@user).get(width: 90), followed_tag_names: @user.cached_followed_tag_names, followed_tags: @user.cached_followed_tags.to_json(only: %i[id name bg_color_hex text_color_hex hotness_score], methods: [:points]), followed_user_ids: @user.cached_following_users_ids, diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 84a257916..3fca99186 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -91,7 +91,7 @@ class CommentsController < ApplicationController id: current_user.id, username: current_user.username, name: current_user.name, - profile_pic: ProfileImage.new(current_user).get(50), + profile_pic: ProfileImage.new(current_user).get(width: 50), twitter_username: current_user.twitter_username, github_username: current_user.github_username } diff --git a/app/controllers/live_articles_controller.rb b/app/controllers/live_articles_controller.rb index 443c2c72b..322945e58 100644 --- a/app/controllers/live_articles_controller.rb +++ b/app/controllers/live_articles_controller.rb @@ -14,7 +14,7 @@ class LiveArticlesController < ApplicationController tag_list: [], user: { name: @event.host_name, - profile_pic: ProfileImage.new(@event).get(50) + profile_pic: ProfileImage.new(@event).get(width: 50) } } elsif @article @@ -26,7 +26,7 @@ class LiveArticlesController < ApplicationController tag_list: @article.tag_list, user: { name: @article.user.name, - profile_pic: ProfileImage.new(@article.user).get(50) + profile_pic: ProfileImage.new(@article.user).get(width: 50) } } else diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index d127948fd..4273ddd47 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -88,7 +88,7 @@ class MessagesController < ApplicationController chat_channel_adjusted_slug: new_message.chat_channel.adjusted_slug(current_user, "sender"), channel_type: new_message.chat_channel.channel_type, username: new_message.user.username, - profile_image_url: ProfileImage.new(new_message.user).get(90), + profile_image_url: ProfileImage.new(new_message.user).get(width: 90), message: new_message.message_html, markdown: new_message.message_markdown, edited_at: new_message.edited_at, diff --git a/app/labor/profile_image.rb b/app/labor/profile_image.rb index efcf65375..76c8f865d 100644 --- a/app/labor/profile_image.rb +++ b/app/labor/profile_image.rb @@ -8,7 +8,7 @@ class ProfileImage @backup_link = "https://thepracticaldev.s3.amazonaws.com/i/99mvlsfu5tfj9m7ku25d.png" end - def get(width = 120) + def get(width: 120) cl_image_path(get_link, type: "fetch", crop: "fill", diff --git a/app/models/article.rb b/app/models/article.rb index 686814014..924152403 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -150,7 +150,7 @@ class Article < ApplicationRecord :body_text, :tag_keywords_for_search, :search_score, :readable_publish_date, :flare_tag attribute :user do { username: user.username, name: user.name, - profile_image_90: ProfileImage.new(user).get(90), pro: user.pro? } + profile_image_90: ProfileImage.new(user).get(width: 90), pro: user.pro? } end tags do [tag_list, @@ -180,13 +180,13 @@ class Article < ApplicationRecord attribute :user do { username: user.username, name: user.name, - profile_image_90: ProfileImage.new(user).get(90) } + profile_image_90: ProfileImage.new(user).get(width: 90) } end attribute :organization do if organization { slug: organization.slug, name: organization.name, - profile_image_90: ProfileImage.new(organization).get(90) } + profile_image_90: ProfileImage.new(organization).get(width: 90) } end end tags do diff --git a/app/models/chat_channel.rb b/app/models/chat_channel.rb index 289cbbbcd..c233d3332 100644 --- a/app/models/chat_channel.rb +++ b/app/models/chat_channel.rb @@ -171,7 +171,7 @@ class ChatChannel < ApplicationRecord def user_obj(membership) { - profile_image: ProfileImage.new(membership.user).get(90), + profile_image: ProfileImage.new(membership.user).get(width: 90), darker_color: membership.user.decorate.darker_color, name: membership.user.name, last_opened_at: membership.last_opened_at, diff --git a/app/models/chat_channel_membership.rb b/app/models/chat_channel_membership.rb index 98464a7fe..d3f4df542 100644 --- a/app/models/chat_channel_membership.rb +++ b/app/models/chat_channel_membership.rb @@ -46,7 +46,7 @@ class ChatChannelMembership < ApplicationRecord def channel_image if chat_channel.channel_type == "direct" - ProfileImage.new(other_user).get(90) + ProfileImage.new(other_user).get(width: 90) else ActionController::Base.helpers.asset_path("organization.svg") end diff --git a/app/models/classified_listing.rb b/app/models/classified_listing.rb index 38fbcb746..5e1ededf4 100644 --- a/app/models/classified_listing.rb +++ b/app/models/classified_listing.rb @@ -42,7 +42,7 @@ class ClassifiedListing < ApplicationRecord attribute :author do { username: author.username, name: author.name, - profile_image_90: ProfileImage.new(author).get(90) } + profile_image_90: ProfileImage.new(author).get(width: 90) } end tags do [tag_list, diff --git a/app/models/comment.rb b/app/models/comment.rb index 98c77b594..b38ffb186 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -74,8 +74,8 @@ class Comment < ApplicationRecord username: user.username, name: user.name, id: user.id, - profile_pic: ProfileImage.new(user).get(90), - profile_image_90: ProfileImage.new(user).get(90), + profile_pic: ProfileImage.new(user).get(width: 90), + profile_image_90: ProfileImage.new(user).get(width: 90), github_username: user.github_username, twitter_username: user.twitter_username } diff --git a/app/models/message.rb b/app/models/message.rb index ec5586c62..43952400a 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -100,7 +100,7 @@ class Message < ApplicationRecord target='_blank' data-content='sidecar-article'> #{"
" if article.main_image.present?}

#{article.title}

-

#{article.cached_user.name}・#{article.readable_publish_date || 'Draft Post'}

+

#{article.cached_user.name}・#{article.readable_publish_date || 'Draft Post'}

".html_safe elsif (tag = rich_link_tag(anchor)) html += "

- + #{user.name}

".html_safe diff --git a/app/models/organization.rb b/app/models/organization.rb index a54875c1b..ca2ef463c 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -89,7 +89,7 @@ class Organization < ApplicationRecord end def profile_image_90 - ProfileImage.new(self).get(90) + ProfileImage.new(self).get(width: 90) end def enough_credits?(num_credits_needed) diff --git a/app/models/podcast.rb b/app/models/podcast.rb index 65f45dd3e..3d52f9fa2 100644 --- a/app/models/podcast.rb +++ b/app/models/podcast.rb @@ -40,7 +40,7 @@ class Podcast < ApplicationRecord end def image_90 - ProfileImage.new(self).get(90) + ProfileImage.new(self).get(width: 90) end private diff --git a/app/models/podcast_episode.rb b/app/models/podcast_episode.rb index c9829b9d5..5f1a2910c 100644 --- a/app/models/podcast_episode.rb +++ b/app/models/podcast_episode.rb @@ -42,7 +42,7 @@ class PodcastEpisode < ApplicationRecord attribute :user do { name: podcast.name, username: user_username, - profile_image_90: ProfileImage.new(user).get(90) } + profile_image_90: ProfileImage.new(user).get(width: 90) } end searchableAttributes ["unordered(title)", "body_text", diff --git a/app/models/user.rb b/app/models/user.rb index 825bc115e..76dfb368c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -445,7 +445,7 @@ class User < ApplicationRecord end def profile_image_90 - ProfileImage.new(self).get(90) + ProfileImage.new(self).get(width: 90) end def remove_from_algolia_index diff --git a/app/serializers/webhook/user_serializer.rb b/app/serializers/webhook/user_serializer.rb index 81268bc0c..c2359750c 100644 --- a/app/serializers/webhook/user_serializer.rb +++ b/app/serializers/webhook/user_serializer.rb @@ -5,10 +5,10 @@ module Webhook attributes :name, :username, :twitter_username, :github_username attribute :website_url, &:processed_website_url attribute :profile_image do |user| - ProfileImage.new(user).get(640) + ProfileImage.new(user).get(width: 640) end attribute :profile_image_90 do |user| - ProfileImage.new(user).get(90) + ProfileImage.new(user).get(width: 90) end end end diff --git a/app/views/additional_content_boxes/_article_content_area.html.erb b/app/views/additional_content_boxes/_article_content_area.html.erb index b6e428722..66640bcf8 100644 --- a/app/views/additional_content_boxes/_article_content_area.html.erb +++ b/app/views/additional_content_boxes/_article_content_area.html.erb @@ -3,7 +3,7 @@
- <%= article.user.username %> profile image + <%= article.user.username %> profile image <%= article.user.name %> <%= render "shared/pro_checkmark" if article.user.pro? %> diff --git a/app/views/additional_content_boxes/_article_followable_area.html.erb b/app/views/additional_content_boxes/_article_followable_area.html.erb index b8aa20391..2b3ff0e97 100644 --- a/app/views/additional_content_boxes/_article_followable_area.html.erb +++ b/app/views/additional_content_boxes/_article_followable_area.html.erb @@ -20,7 +20,7 @@ class="<%= "partner-link" if classification == "boosted" %>" data-details="<%= followable&.slug if classification == "boosted" %>__PROFILE"> <%= followable.name %> profile image__PROFILE" diff --git a/app/views/api/v0/articles/onboarding.json.jbuilder b/app/views/api/v0/articles/onboarding.json.jbuilder index e0814a0c1..da4fd6129 100644 --- a/app/views/api/v0/articles/onboarding.json.jbuilder +++ b/app/views/api/v0/articles/onboarding.json.jbuilder @@ -9,6 +9,6 @@ json.array! @articles do |article| json.user do json.name article.user.name - json.profile_image_url ProfileImage.new(article.user).get(90) + json.profile_image_url ProfileImage.new(article.user).get(width: 90) end end diff --git a/app/views/api/v0/shared/_follows.json.jbuilder b/app/views/api/v0/shared/_follows.json.jbuilder index 2ed41761d..5c7cec2f1 100644 --- a/app/views/api/v0/shared/_follows.json.jbuilder +++ b/app/views/api/v0/shared/_follows.json.jbuilder @@ -1,4 +1,4 @@ json.name user.name json.path "/" + user.path.delete_prefix("/") json.username user.try(:username) || user.name -json.profile_image ProfileImage.new(user).get(60) +json.profile_image ProfileImage.new(user).get(width: 60) diff --git a/app/views/api/v0/shared/_organization.json.jbuilder b/app/views/api/v0/shared/_organization.json.jbuilder index 44febb787..90fbc4cc8 100644 --- a/app/views/api/v0/shared/_organization.json.jbuilder +++ b/app/views/api/v0/shared/_organization.json.jbuilder @@ -4,6 +4,6 @@ json.organization do json.name organization.name json.username organization.username json.slug organization.slug - json.profile_image organization_profile_image.get(640) - json.profile_image_90 organization_profile_image.get(90) + json.profile_image organization_profile_image.get(width: 640) + json.profile_image_90 organization_profile_image.get(width: 90) end diff --git a/app/views/api/v0/shared/_user.json.jbuilder b/app/views/api/v0/shared/_user.json.jbuilder index 01493b390..0c435c100 100644 --- a/app/views/api/v0/shared/_user.json.jbuilder +++ b/app/views/api/v0/shared/_user.json.jbuilder @@ -6,6 +6,6 @@ json.user do json.twitter_username user.twitter_username json.github_username user.github_username json.website_url user.processed_website_url - json.profile_image user_profile_image.get(640) - json.profile_image_90 user_profile_image.get(90) + json.profile_image user_profile_image.get(width: 640) + json.profile_image_90 user_profile_image.get(width: 90) end diff --git a/app/views/api/v0/users/index.json.jbuilder b/app/views/api/v0/users/index.json.jbuilder index 00f629e79..00d0ecc06 100644 --- a/app/views/api/v0/users/index.json.jbuilder +++ b/app/views/api/v0/users/index.json.jbuilder @@ -3,6 +3,6 @@ json.array! @users.each do |user| json.name user.name json.username user.username json.summary truncate(user.summary.presence || "Active DEV author", length: 100) - json.profile_image_url ProfileImage.new(user).get(90) + json.profile_image_url ProfileImage.new(user).get(width: 90) json.following false end diff --git a/app/views/api/v0/users/show.json.jbuilder b/app/views/api/v0/users/show.json.jbuilder index 7dfe48eb1..6e25b11e1 100644 --- a/app/views/api/v0/users/show.json.jbuilder +++ b/app/views/api/v0/users/show.json.jbuilder @@ -8,4 +8,4 @@ json.github_username @user.github_username json.website_url @user.website_url json.location @user.location json.joined_at @user.created_at.strftime("%b %e, %Y") -json.profile_image ProfileImage.new(@user).get(320) +json.profile_image ProfileImage.new(@user).get(width: 320) diff --git a/app/views/articles/_about_author.html.erb b/app/views/articles/_about_author.html.erb index dc4e0a53d..5211f4f78 100644 --- a/app/views/articles/_about_author.html.erb +++ b/app/views/articles/_about_author.html.erb @@ -1,7 +1,7 @@
diff --git a/app/views/articles/_liquid.html.erb b/app/views/articles/_liquid.html.erb index d29c4afe8..3c9d1a5e9 100644 --- a/app/views/articles/_liquid.html.erb +++ b/app/views/articles/_liquid.html.erb @@ -8,7 +8,7 @@ <% end %> diff --git a/app/views/articles/_single_story.html.erb b/app/views/articles/_single_story.html.erb index e38c7b281..ae8a1303f 100644 --- a/app/views/articles/_single_story.html.erb +++ b/app/views/articles/_single_story.html.erb @@ -16,7 +16,7 @@ <% end %>
- <%= story.cached_user.username %> profile + <%= story.cached_user.username %> profile
diff --git a/app/views/articles/_special_sidebar.html.erb b/app/views/articles/_special_sidebar.html.erb index 0be250bad..92d39ef55 100644 --- a/app/views/articles/_special_sidebar.html.erb +++ b/app/views/articles/_special_sidebar.html.erb @@ -10,7 +10,7 @@

💪 <%= article.title %>

- <%= article.user.username %> + <%= article.user.username %>
<% end %> diff --git a/app/views/articles/_sticky_nav.html.erb b/app/views/articles/_sticky_nav.html.erb index 95c6d50ed..d5bdceb1d 100644 --- a/app/views/articles/_sticky_nav.html.erb +++ b/app/views/articles/_sticky_nav.html.erb @@ -36,7 +36,7 @@
- <%= @actor.name %> profile image + <%= @actor.name %> profile image
<% end %> - <%= article.user.name %> profile image + <%= article.user.name %> profile image <%= article.title %>
<% article.decorate.cached_tag_list_array.each do |tag| %> @@ -120,7 +120,7 @@
<% end %>
- <%= article.user.name %> profile image + <%= article.user.name %> profile image <%= article.title %>
<% article.decorate.cached_tag_list_array.each do |tag| %> diff --git a/app/views/articles/index.html.erb b/app/views/articles/index.html.erb index 7d272806f..ce16e1fa5 100644 --- a/app/views/articles/index.html.erb +++ b/app/views/articles/index.html.erb @@ -100,7 +100,7 @@
- <%= @featured_story.title %> + <%= @featured_story.title %>