Fix for nonstandard file rename with supporter accounts

This commit is contained in:
Kyle Drake 2021-09-09 17:51:47 -05:00
parent fea2ec55f9
commit f5613d2776
2 changed files with 15 additions and 1 deletions

View file

@ -56,7 +56,9 @@ class SiteFile < Sequel::Model
mime_type = Magic.guess_file_mime_type site.files_path(self.path) mime_type = Magic.guess_file_mime_type site.files_path(self.path)
extname = File.extname new_path extname = File.extname new_path
return false, 'unsupported file type' unless site.class.valid_file_mime_type_and_ext?(mime_type, extname) unless site.supporter? || site.class.valid_file_mime_type_and_ext?(mime_type, extname)
return false, 'unsupported file type'
end
end end
begin begin

View file

@ -51,6 +51,18 @@ describe 'site_files' do
@site.site_files_dataset.where(path: 'test.jpg').first.wont_equal nil @site.site_files_dataset.where(path: 'test.jpg').first.wont_equal nil
end end
it 'renames nonstandard file type for supporters' do
no_file_restriction_plans = Site::PLAN_FEATURES.select {|p,v| v[:no_file_restrictions] == true}
no_file_restriction_plans.each do |plan_type,hash|
@site = Fabricate :site, plan_type: plan_type
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav')
testfile = @site.site_files_dataset.where(path: 'flowercrime.wav').first
res = testfile.rename('flowercrime.exe')
res.first.must_equal true
File.exists?(@site.files_path('flowercrime.exe')).must_equal true
@site.site_files_dataset.where(path: 'flowercrime.exe').first.wont_equal nil
end
end
it 'works for directory' do it 'works for directory' do
@site.create_directory 'dirone' @site.create_directory 'dirone'