From ed9323043f05f760ba0fb2263679034c303c249f Mon Sep 17 00:00:00 2001
From: Sam Saffron <sam.saffron@gmail.com>
Date: Fri, 28 Aug 2020 12:28:41 +1000
Subject: [PATCH] DEV: Allow all uploads when fixing missing s3

If we do not do this we can not properly re-download files
---
 lib/tasks/uploads.rake | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake
index 9d6155e3ae6..013f9a9e9a1 100644
--- a/lib/tasks/uploads.rake
+++ b/lib/tasks/uploads.rake
@@ -1138,7 +1138,7 @@ def fix_missing_s3
       end
 
       if fix_error
-        puts "Failed to fix upload #{e}"
+        puts "Failed to fix upload #{fix_error}"
       else
         # we do not fix sha, it may be wrong for arbitrary reasons, if we correct it
         # we may end up breaking posts
@@ -1181,12 +1181,20 @@ def fix_missing_s3
   puts
 end
 
+def allow_all_uploads
+  old_staff_extension = SiteSetting.authorized_extensions_for_staff
+  SiteSetting.authorized_extensions_for_staff = "*"
+  yield
+ensure
+  SiteSetting.authorized_extensions_for_staff = old_staff_extension
+end
+
 task "uploads:fix_missing_s3" => :environment do
   if RailsMultisite::ConnectionManagement.current_db != "default"
-    fix_missing_s3
+    allow_all_uploads { fix_missing_s3 }
   else
     RailsMultisite::ConnectionManagement.each_connection do
-      fix_missing_s3
+      allow_all_uploads { fix_missing_s3 }
     end
   end
 end