From eb4624ff691027341e721f01037ea28172796105 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Thu, 24 Jul 2014 20:58:11 +0200 Subject: [PATCH] set permissions on attachments so that users in same group can handle the attachments if you run MessageGateway under user mail and Tracks under user apache, you cannot delete attachments from the web ui since the default permissions is read-only. To delete an attachment, you need w permission on the directory containing the attachment --- app/models/attachment.rb | 6 +++++- app/models/message_gateway.rb | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index c33fdc22..d1ea3d4d 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -1,9 +1,13 @@ class Attachment < ActiveRecord::Base belongs_to :todo, touch: true + # enable write permissions on group, since MessageGateway could be run under different + # user than Tracks (i.e. apache versus mail) + has_attached_file :file, url: '/:class/:id/:basename.:extension', - path: ":rails_root/db/assets/#{Rails.env}/:class/:id/:basename.:extension" + path: ":rails_root/db/assets/#{Rails.env}/:class/:id/:basename.:extension", + override_file_permissions: 0660 do_not_validate_attachment_file_type :file # validates_attachment_content_type :file, :content_type => ["text/plain"] diff --git a/app/models/message_gateway.rb b/app/models/message_gateway.rb index 4106c2ae..194d1cc0 100644 --- a/app/models/message_gateway.rb +++ b/app/models/message_gateway.rb @@ -43,6 +43,11 @@ class MessageGateway < ActionMailer::Base tmp.close saved = attachment.save! + # enable write permissions on group, since MessageGateway could be run under different + # user than Tracks (i.e. apache versus mail) + dir = File.open(File.dirname(attachment.file.path)) + dir.chmod(0770) + # delete temp file tmp.unlink end