-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ [FEAT] Add in TinyMCE Areas possibility for the user to upload a local file #277
base: master
Are you sure you want to change the base?
Conversation
…cal file The local media will be imported into MEDIA_ROOT folder and automatically added to the text area.
Codecov ReportPatch coverage:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #277 +/- ##
==========================================
- Coverage 89.08% 88.80% -0.28%
==========================================
Files 31 31
Lines 2373 2386 +13
==========================================
+ Hits 2114 2119 +5
- Misses 259 267 +8
☔ View full report in Codecov by Sentry. |
filename = f"tinymce/{uuid4()}/{str(file)}" | ||
path = f"{settings.MEDIA_URL}{filename}" | ||
location = f"{settings.MEDIA_ROOT}/{filename}" | ||
os.makedirs(os.path.dirname(location), exist_ok=True) |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
path = f"{settings.MEDIA_URL}{filename}" | ||
location = f"{settings.MEDIA_ROOT}/{filename}" | ||
os.makedirs(os.path.dirname(location), exist_ok=True) | ||
with open(location, "wb+") as destination: |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
Nice. |
Better way to achieve this is to create an attachment to keep naming / categorization logic and possibility to delete it if required |
To me there will be just a few images uploaded in the WYSIWYG, so it is not crucial to have an orphan deletion mechanism. In classical CMS, there are thousands of images uploaded in articles and no automatic system to delete unused ones. So in our case it is secondary as most images are uploaded as objects attachments, and it shouldn't block this PR in my opinion. |
The use of Attachment model to support the TinyMCE image upload should be considered for the following reasons:
But using Attachment is not straightforward as an instance ID is needed to create an Attachment so we cannot create it when an image is uploaded on the form to create a new entity. We could create temporary files/attachments in the Another concern is the absolute URLs which are inserted in the tinymce HTML content. When GTA server configuration changes (for instance with a new domain) all those URLs will be broken. |
Demonstration of the feature :
mapentity.webm
The local media will be imported into MEDIA_ROOT folder and automatically added to the text area.
Files are store in the media folder and then into the following path :
/tinymce/<generated-uuid>/file.ext
. The generated uuid allow to avoid conflicts if multiple files with the same name are uploaded.Everything seems to be working fine.
By default TinyMCE stored a relative path for the uploaded files. I ensure the URL stored for local files are absolute urls therefore GTR3 and others services can exploit data without having to rebuild URLs and API V2 from Geotrek needs no modification either.
One important element not done in this PR: The uploaded files are stored into media but there is no method to delete them if there not used anymore. I'd like some help to find the best strategy to find and remove unused uploaded file. A command that users will need to run ? An asynchrone task ? How can we determine which files are not used ?