Commit Graph

6 Commits

Author SHA1 Message Date
Javi Martín
507fa7c5f5 Remove duplication in attachable fields components
These classes were almost identical.
2021-09-11 17:05:00 +02:00
Javi Martín
930bb753c5 Use a rake task to delete cached attachments
Our previous system to delete cached attachments didn't work for
documents because the `custom_hash_data` is different for files created
from a file and files created from cached attachments.

When creating a document attachment, the name of the file is taken into
account to calculate the hash. Let's say the original file name is
"logo.pdf", and the generated hash is "123456". The cached attachment
will be "123456.pdf", so the generated hash using the cached attachment
will be something different, like "28af3". So the file that will be
removed will be "28af3.pdf", and not "123456.pdf", which will still be
present.

Furthermore, there are times where users choose a file and then they
close the browser or go to a different page. In those cases, we weren't
deleting the cached attachments either.

So we're adding a rake task to delete these files once a day. This way
we can simplify the logic we were using to destroy cached attachments.

Note there's related a bug in documents: when editing a record (for
example, a proposal), if the title of the document changes, its hash
changes, and so it will be impossible to generate a link to that
document. Changing the way this hash is generated is not an option
because it would break links to existing files. We'll try to fix it when
moving to Active Storage.
2021-07-30 17:30:11 +02:00
Javi Martín
367d3f9d14 Remove condition for non-nested case
We don't use these input fields inside a non-nested context since commit
2993ef870.
2021-07-13 16:58:22 +02:00
Javi Martín
21fee9cff5 Simplify method names in image/document fields
We were using long, unique names because these methods used to be helper
methods. Helper methods should have unique names because otherwise one
method would overwrite the other.

Now that we're using components, we can omit the `image_` and
`document_` prefixes.
2021-07-13 16:58:13 +02:00
Javi Martín
5cf96ba03d Extract methods to get objects in attachment forms 2021-07-13 16:58:13 +02:00
Javi Martín
810814486c Move document fields partial to a component 2021-07-13 16:58:13 +02:00