From f5bdbd347e7e5b5885a3a4190cda535b9043c1c2 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 6 May 2020 11:28:02 -0400 Subject: [PATCH] Revert "FIX: Discobot has not been created with our custom avatar." This reverts commit 1062dbc3e9cbf9370803c0acea55eb3c054060ca. Looks like it's causing some errors on migration. ``` /var/www/discourse/lib/image_sizer.rb:6:in `resize' /var/www/discourse/lib/upload_creator.rb:120:in `block in create_for' /var/www/discourse/lib/distributed_mutex.rb:33:in `block in synchronize' /var/www/discourse/lib/distributed_mutex.rb:29:in `synchronize' /var/www/discourse/lib/distributed_mutex.rb:29:in `synchronize' /var/www/discourse/lib/distributed_mutex.rb:14:in `synchronize' /var/www/discourse/lib/upload_creator.rb:37:in `create_for' ``` --- app/models/user_avatar.rb | 28 +++++-------- .../assets/images/discobot.png | Bin 10343 -> 0 bytes .../db/fixtures/001_discobot.rb | 38 ++++++++++-------- 3 files changed, 31 insertions(+), 35 deletions(-) delete mode 100644 plugins/discourse-narrative-bot/assets/images/discobot.png diff --git a/app/models/user_avatar.rb b/app/models/user_avatar.rb index e2b7f44dc6b..f6dbf133126 100644 --- a/app/models/user_avatar.rb +++ b/app/models/user_avatar.rb @@ -96,31 +96,16 @@ class UserAvatar < ActiveRecord::Base return unless tempfile - create_custom_avatar( - user, - tempfile, - override_gravatar: options&.dig(:override_gravatar), - origin: avatar_url - ) - rescue Net::ReadTimeout, OpenURI::HTTPError - # skip saving, we are not connected to the net - ensure - tempfile.close! if tempfile && tempfile.respond_to?(:close!) - end + ext = FastImage.type(tempfile).to_s + tempfile.rewind - def self.create_custom_avatar(user, file, override_gravatar: false, origin: nil) - ext = FastImage.type(file).to_s - file.rewind - - upload = UploadCreator.new(file, "external-avatar.#{ext}", - origin: origin, - type: "avatar" - ).create_for(user.id) + upload = UploadCreator.new(tempfile, "external-avatar." + ext, origin: avatar_url, type: "avatar").create_for(user.id) user.create_user_avatar! unless user.user_avatar if !user.user_avatar.contains_upload?(upload.id) user.user_avatar.update!(custom_upload_id: upload.id) + override_gravatar = !options || options[:override_gravatar] if user.uploaded_avatar_id.nil? || !user.user_avatar.contains_upload?(user.uploaded_avatar_id) || @@ -129,6 +114,11 @@ class UserAvatar < ActiveRecord::Base user.update!(uploaded_avatar_id: upload.id) end end + + rescue Net::ReadTimeout, OpenURI::HTTPError + # skip saving, we are not connected to the net + ensure + tempfile.close! if tempfile && tempfile.respond_to?(:close!) end def self.ensure_consistency! diff --git a/plugins/discourse-narrative-bot/assets/images/discobot.png b/plugins/discourse-narrative-bot/assets/images/discobot.png deleted file mode 100644 index b6c711304241edfc3e23d08a463cb4fbffcb7e7d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10343 zcma)iWlS8gov zmKfs39v--Jv#&VbbMwy)amN_!LkMxbcskd~�LjRvhh880vUakWL@sOX2T%hqyu@ zo>;>C-;Ve46=uDi?6a*b?B1B6^Y!3JjuvgGP#EoULEJNk_%ekD&_LXr5jXS!URv-$ z+nXc$U?0WNZdxCAxO1m<# za=v>0^XKtQwy)Kpx)?av?ukGEf7Vh3c=6_@s%9lwlov2Z1fjXwFP#4F+L)mU^oitUBrG=^X8{F{!; zTacl*IH^24Bp&afn(iW>?3UX0X>ncq^7wsupULabfgCBZt&;}zBOu4G;Jz7s%k$mJ znZe_I4eP6eu4#i?#HGeWzZU}GT4Bo>5&V9%`}XC+8FB5}#UY4<#P;f)B2d?7`6O>e zlXQh)a3%SW3J2X&HG(C>l!Gib^Bu^Z^h+N!j78b$RWNYnYZ*She?4o2c3r zW5abq?wQPu2?dKL3>pSw24m6Sgh642K{VhGegf3PhaVrA;qukeopt;Lssm2}ZEt(t zkC4PXS0Ur{8yhwD6rh1fh@%-~xKzI?-`w;JH744nM$8bK2R;+eGemzT9zG1G$g6KF zoi2(RpG3gsW7aEWw#gxdpFik)QPDo=usEqY3QQVU-X8}i867nj5a+!C$4s@?r-^#= zKl!^!1X3~h+yq_a^=D4fP5f0FZ5zL<#elNUfF9c~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ARf6CgD`g<2RKkdlB+Y?7&#Ro4t$m;=B?{!GjLkviLM| z8tc3t(|)xmM|-FF?**S76J7cx%)qIy^!G$~wX!{$9VeXXemQviC>($3zS9(GcfA`r zqaEA3R+a8z0-$ZI=-^r5#kS|pQ84HNgc8;DQXkV!@5C^+fN~v{+knkkuezk45XV=NdI>AFaSaPr#$MwzQ?B`Yb$n ze)~H;MfI7r&i_`>xJCx@?4EUN<^dNMYm*_nYlEM~AD?s{4kc;(9gOkD=Kop?W) zD{}y%NrcJNNjqGB*6?rsiRv1+@>aQ;^XIVfzWnr?X z%mvE5(?2Hn6!^?sWbt&DYx(vS3fk2hvWu*Psuv6tGVV3y3rH!i#X$x#^jP?X%z)2O zI1!C}u-XAd7Yf()v3J)cjU3p?)2hv`1+|<<)G5JL*;NjfCiwkgz$Ii?i6u+4hk*!O z%J#tR8s)C@(iN&7wz#c~{R#jN{ZAqV@c(3e_yilYl0~9iqVj>`?3^Za?K;)4Qou4) z-Gg0NJ{|5ZQ-q+N+Si=5Ss`&{JXGeGz<_1|GjNk>f9Qyw!!i2R+dr^LBh4^9&ERQ2 q2CW1AI+)S_=lj29($Jq7Nk<}ac!Dbx{w)w9y?d*nSR?-_?Ee9}YZMXy diff --git a/plugins/discourse-narrative-bot/db/fixtures/001_discobot.rb b/plugins/discourse-narrative-bot/db/fixtures/001_discobot.rb index f30861e89ae..3972a350fbf 100644 --- a/plugins/discourse-narrative-bot/db/fixtures/001_discobot.rb +++ b/plugins/discourse-narrative-bot/db/fixtures/001_discobot.rb @@ -1,24 +1,23 @@ # frozen_string_literal: true discobot_username = 'discobot' -discobot_user_id = -2 -def seed_primary_email(user_id) +def seed_primary_email UserEmail.seed do |ue| - ue.id = user_id + ue.id = -2 ue.email = "discobot_email" ue.primary = true - ue.user_id = user_id + ue.user_id = -2 end end -unless user = User.find_by(id: discobot_user_id) +unless user = User.find_by(id: -2) suggested_username = UserNameSuggester.suggest(discobot_username) - seed_primary_email(discobot_user_id) + seed_primary_email User.seed do |u| - u.id = discobot_user_id + u.id = -2 u.name = discobot_username u.username = suggested_username u.username_lower = suggested_username.downcase @@ -27,13 +26,26 @@ unless user = User.find_by(id: discobot_user_id) u.approved = true u.trust_level = TrustLevel[4] end + + # TODO Pull the user avatar from that thread for now. In the future, pull it from a local file or from some central discobot repo. + if !Rails.env.test? + begin + UserAvatar.import_url_for_user( + "https://cdn.discourse.org/dev/uploads/default/original/2X/e/edb63d57a720838a7ce6a68f02ba4618787f2299.png", + User.find(-2), + override_gravatar: true + ) + rescue + # In case the avatar can't be downloaded, don't fail seed + end + end end -bot = User.find(discobot_user_id) +bot = User.find(-2) # ensure discobot has a primary email unless bot.primary_email - seed_primary_email(discobot_user_id) + seed_primary_email bot.reload end @@ -50,10 +62,4 @@ if !bot.user_profile.bio_raw ) end -if !Rails.env.test? && (bot.user_avatar&.custom_upload_id.blank?) - File.open(Rails.root.join("plugins", "discourse-narrative-bot", "assets", "images", "discobot.png"), 'r') do |file| - UserAvatar.create_custom_avatar(bot, file, override_gravatar: true) - end -end - -Group.user_trust_level_change!(discobot_user_id, TrustLevel[4]) +Group.user_trust_level_change!(-2, TrustLevel[4])