Fix crashes in SuspendAccountService/UnsuspendAccountService (#15100)

* Fix crashes in SuspendAccountService/UnsuspendAccountService

* Catch filesystem errors
lolsob-rspec
ThibG 2020-11-07 13:16:54 +01:00 committed by GitHub
parent c11e8737dd
commit d41433f651
2 changed files with 12 additions and 4 deletions

View File

@ -39,11 +39,15 @@ class SuspendAccountService < BaseService
styles.each do |style|
case Paperclip::Attachment.default_options[:storage]
when :s3
attachment.s3_object(style).acl.put(:private)
attachment.s3_object(style).acl.put(acl: 'private')
when :fog
# Not supported
when :filesystem
FileUtils.chmod(0o600 & ~File.umask, attachment.path(style))
begin
FileUtils.chmod(0o600 & ~File.umask, attachment.path(style)) unless attachment.path(style).nil?
rescue Errno::ENOENT
Rails.logger.warn "Tried to change permission on non-existent file #{attachment.path(style)}"
end
end
end
end

View File

@ -39,11 +39,15 @@ class UnsuspendAccountService < BaseService
styles.each do |style|
case Paperclip::Attachment.default_options[:storage]
when :s3
attachment.s3_object(style).acl.put(Paperclip::Attachment.default_options[:s3_permissions])
attachment.s3_object(style).acl.put(acl: Paperclip::Attachment.default_options[:s3_permissions])
when :fog
# Not supported
when :filesystem
FileUtils.chmod(0o666 & ~File.umask, attachment.path(style))
begin
FileUtils.chmod(0o666 & ~File.umask, attachment.path(style)) unless attachment.path(style).nil?
rescue Errno::ENOENT
Rails.logger.warn "Tried to change permission on non-existent file #{attachment.path(style)}"
end
end
end
end