alphagov/whitehall — pull request #297 by tekin (2013-03-01 15:54:30+00:00)
Title: Executable attachments

Pivotal: https://www.pivotaltracker.com/story/show/45184805

This story adds the ability to make file uploads more permissive for privileged users, primarily so we can manage the HMRC’s Basic PAYE Tools.

My initial pass at this attempted to hook into carrierwave in the same way that the zip file verification did, and delegate up to the owning model (AttachmentData) to see if the zip verification should be more permissive or not by adding a virtual attribute to it that gets set during mass-assignment by the controller code. The with this problem was that carrierwave's `before :cache` callbacks get fired during assignment of the file itself, which means that if you are mass-assigning the attributes on `AttachmentData`, the call backs fire before all the other parameters on `AttachmentData` have been set. Thus the virtual attribute is always nil.

The only sensible course of action was to pull the file content validation out of the carrierwave uploader and into the model where we have more control over when they get run. The added bonus of doing it this way is that we can now set sensible error messages for file attachment errors, rather than having to settle for the default carrierwave integrity error message.