-
Notifications
You must be signed in to change notification settings - Fork 40
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
Print improvements: don't print unprintable filetypes, improve PDF conversion and mimetype detection #2166
Conversation
5562877
to
07bb841
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did a quick skim!
07bb841
to
5890ce4
Compare
I was hoping to have this all finished + green before tomorrow and to do a little more testing, but I'm a little short on time and still need to fix up one or two tests, but I'm taking it out of draft mode to invite more feedback and testing. So far I've tested the export component with locally-built packages, and printing and mime detection are working as expected. I will be back to address review feedback (such as #2166 (comment) and anything else that arises) and do test fixup on Wed. |
…E_DISCOVERY status enums to client and export.
Raise ExportException instead of trying to print file with unprintable mimetype. Parse mimetypes from LibreOffice .desktop files and try to convert files of any mimetype that LibreOffice supports to PDF before printing. This dramatically broadens the range of printable types. Use LibreOffice headless mode for PDF conversion rather than unoconv. In future, if batch printing is supported, consider unoserver instead. Use -M (magic bytes only) flag for mimeinfo detection.
Show error message in Print dialog when attempting to print unprintable filetype. Use CALLED_PROCESS_ERROR code for QProcess errors instead of generic print error code, and log error messages. Add message in Print Dialog if user tries to print non printable filetype.
…ency of libreoffice.
…op-viewer packages. This was previously not possible due to the necessary paxctl configuration not being available soon enough (see #205), but now that we install the grsec kernel and our configuration packages in a template and reboot it before provisioning the (shared) export/viewer template, the PaX conf file is in place and the installation will succeed. Include libfile-mimeinfo-perl package (installed by default) in secuedrop-export package depedencies.
parsing tests and update _needs_pdf_conversion and other print tests.
5890ce4
to
1bcf7d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excited for this, I've done a code review pass and now am going to actually test it.
client/securedrop_client/gui/conversation/export/print_dialog.py
Outdated
Show resolved
Hide resolved
client/securedrop_client/gui/conversation/export/print_dialog.py
Outdated
Show resolved
Hide resolved
export/tests/print/test_service.py
Outdated
# sample .desktop files in test directory, but the service checks /usr/share/applications | ||
testdir_libreoffice_desktop = Path(Path.cwd(), "tests", "files") | ||
supported = self.service._get_supported_mimetypes_libreoffice(testdir_libreoffice_desktop) | ||
assert len(supported) > 0, len(supported) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're testing against fixed sample files, can we assert the real number? Or even just the full list of mime types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test plan checks out, one note: I tried "one file with the wrong extension" by having a webp image with the .txt extension, it opened in the wrong application (text editor instead of eog), I don't think that's a regression here right?
Marking as requesting changes based on previous CR
I pushed 292b230 in a separate branch to show how we can install LibreOffice in CI and use it for integration tests; there could be others that run various files through headless libreoffice to see how the conversion goes and error handling instead of trying to mock it all out. Let me know if you'd like me to push it to this branch or submit it as a separate PR after this lands! (Or feel free to pull it in yourself :)) |
Hey, thank you for all the feedback and testing :) Realquick:
|
Ack, filed separately as #2171.
OK! I was going to spend some time today figuring that out but I can hold off for now then.
It definitely does blur the boundaries, but I think mixing is fine, if we end up having more we can split them out into separate files. |
0588432
to
fec5ed2
Compare
test are failing because it doesn't find any libreoffice .desktop mime types:
I suspect you (like me) have LibreOffice installed locally so it passes locally but the CI container doesn't have it, so it either needs to be mocked or we just install LibreOffice in CI and it works (which it will once my integration patch is in) |
58193af
to
706e94a
Compare
706e94a
to
e9228ce
Compare
(moving out of 'ready for review' until I pull in 292b230) |
raise ExportException(sdstatus=Status.ERROR_MIMETYPE_UNKNOWN) | ||
# Don't print "audio/*", "video/*", or archive mimetypes | ||
if ( | ||
any(mimetype.startswith(prefix) for prefix in MIMETYPE_UNPRINTABLE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A cool trick is that startswith
takes a tuple of strings, which allows you to do:
>>> 'audio/foo'.startswith(('audio/', 'video/'))
True
>>> 'text/foo'.startswith(('audio/', 'video/'))
False
…ss review feedback.
Install LibreOffice in the CI container and then we can test against the actual desktop files instead of copies of them.
libreoffice headless conversion against .odt file if libreoffice is installed.
ec47d11
to
3ac0af4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, in real testing, it all works too!
Status
Ready for review
Documentation changes tk as well
Description
Printer-focused UX improvements/support: (#918)
mimetype
instead of by file extension before printingBroadening printable filetype support: (#1725)
Dependency management:
no-install-recommends
flag, meaning Java (openjdk-17-jdk at present time) will be installed, which it currently is not. This is intentional; it will allow us to support viewing and converting more filetypes. When updated client packages have been released, we can remove the Salt logic that installs libreoffice: see Remove Salt logic installing libreoffice securedrop-workstation#1162Fixes #918
Fixes #1725 (although we will still want to look at an overall consistent way of handling file types in the client, and there have been a few suggestions)
Refs (probably fixes, but needs testing) #1731
Test Plan
Manual testing
Viewing
Printing
unprintable types
"audio/mp4", "audio/mpeg", "audio/x-vorbis", "audio/x-wav", "video/quicktime", "video/x-theora", "video/mp4", "video/webm", "video/x-msvideo", "video/x-ms-wmv", "application/vnd.djvu", "application/vnd.rar", "application/zip", "application/x-7z-compressed"Checklist
TK
If these changes modify code paths involving cryptography, the opening of files in VMs or network (via the RPC service) traffic, Qubes testing in the staging environment is required. For fine tuning of the graphical user interface, testing in any environment in Qubes is required. Please check as applicable:
If these changes add or remove files other than client code, the AppArmor profile may need to be updated. Please check as applicable:
If these changes modify the database schema, you should include a database migration. Please check as applicable:
main
and confirmed that the migration is self-contained and applies cleanlymain
and would like the reviewer to do so