Uploads do not store their mount points
Note: this is a follow-up to !3867 (merged)
Uploaders that include RecordsUploads::Concern create a record in the uploads table, but do not track the current CarrierWave::Uploader#mounted_as value. This represents the name of the method used in the model to retrieve the file (via an uploader instance).
class Theme
mount :song, SongUploader # mounted_as == :song
end
This information is important to build back an uploader from an upload model. Without this, the upload model lacks information it needs to build a complete uploader.
Why is this needed?
The mounted_as attribute is used in multiple uploaders and is a part of the final storage directory.
Right now the uploader interface is fragmented between mounted uploaders and FileUploader-based uploaders. Both can create an Upload to track the file, but retrieval is not trivial. In all cases, one should be able to use Upload#build_uploader to have a fully functional GitlabUploader.
Solutions
- Add a column in the
Uploadmodel to trackCarrierWave::Uploader#mounted_as - Use reflection to find out the mount by searching into
CarrierWave::Extension::Mount#uploaderfor a matching uploader type. This will fail if a model mount 2 uploaders of the same class. - Add a
upload=hook in the mounted uploaders to extract the:mounted_asfrom the path (it is included)
Related issues
#4702 (closed) - to add an after_destroy hook
#4704 (closed) - to add an after_create hook
#4215 (closed) - to remove the need for the mounted_as parameter