Fix crashes in SuspendAccountService/UnsuspendAccountService (#15100)

* Fix crashes in SuspendAccountService/UnsuspendAccountService

* Catch filesystem errors
master
ThibG 4 years ago committed by GitHub
parent f84239ecab
commit ee8cf246cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/services/suspend_account_service.rb
  2. 8
      app/services/unsuspend_account_service.rb

@ -39,11 +39,15 @@ class SuspendAccountService < BaseService
styles.each do |style| styles.each do |style|
case Paperclip::Attachment.default_options[:storage] case Paperclip::Attachment.default_options[:storage]
when :s3 when :s3
attachment.s3_object(style).acl.put(:private) attachment.s3_object(style).acl.put(acl: 'private')
when :fog when :fog
# Not supported # Not supported
when :filesystem 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 end
end end

@ -39,11 +39,15 @@ class UnsuspendAccountService < BaseService
styles.each do |style| styles.each do |style|
case Paperclip::Attachment.default_options[:storage] case Paperclip::Attachment.default_options[:storage]
when :s3 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 when :fog
# Not supported # Not supported
when :filesystem 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 end
end end

Loading…
Cancel
Save