Skip to content
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

Add print integration #631

Merged
merged 7 commits into from
Dec 5, 2019
Merged

Add print integration #631

merged 7 commits into from
Dec 5, 2019

Conversation

sssoleileraaa
Copy link
Contributor

@sssoleileraaa sssoleileraaa commented Nov 25, 2019

Description

Resolves #477
Resolves #632

Test Plan

If you have an HP LaserJet printer like me, then update the export script with this change: https://github.com/freedomofpress/securedrop-export/tree/laserjet-printers.

Test ERROR_PRINTER_NOT_FOUND:

  1. Do not attach the printer to the Export VM
  2. Print a document and see message to plug in printer

Test ERROR_PRINTER_NOT_SUPPORTED

  1. Plug in an unsupported printer or modify the export script to expect a dummy uri so that this check does not pass: https://github.com/freedomofpress/securedrop-export/blob/312f9f8ac5d8b2bdde66671d51ac4f075639885b/securedrop_export/export.py#L353
  2. Print a document and see error message to contact admin.

Test ERROR_PRINTER_DRIVER_UNAVAILABLE

  1. Move /usr/share/cups/drv/brlaser.drv to /usr/share/cups/drv/brlaser.drv.bak so it's not found
  2. Print a document and see error message to contact admin.

Test ERROR_PRINT

  1. Send a corrupt doc file to SD instance so that unoconv -o converted_path /tmp/tmp123/export_data/hello.doc.pdf /tmp/tmp123/export_data/hello.doc fails
  2. Print corrupt doc file and see error message to contact admin.

Checklist

  • I have tested these changes in the appropriate Qubes environment
  • I do not have an appropriate Qubes OS workstation set up (the reviewer will need to test these changes)
  • These changes should not need testing in Qubes

@sssoleileraaa
Copy link
Contributor Author

Resolves #632

@eloquence eloquence changed the title 477 print Add print integration Nov 26, 2019
Copy link
Contributor

@emkll emkll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @creviera !

I've managed to successfully print a few submissions 🎉
I've tested with pdf and {ms, libre}office documents, as follows:

  • Built securedrop-client on this branch, install in svs
  • Fix bug in securedrop-export script logging (see 1 below)
  • Switch back and forth between source panes (see 2 below)

Then, proceeded with your test plan, as follows:

  • ✔️ Test ERROR_PRINTER_NOT_FOUND: If no printer is connected, I get the expected message
  • 〰️ Test ERROR_PRINTER_NOT_SUPPORTED: I plugged in an HP printer (currently unsupported), I get the ERROR_PRINTER_NOT_FOUND message: this is because the printer is not exposed over USB but using this direct hp instead of usb <printer_url>. This is a very old HP inkjet printer so this might be the reason why.
  • ✔️ Test ERROR_PRINTER_DRIVER_UNAVAILABLE: I moved the file and see the expected error
  • ❌ Test ERROR_PRINT: Did not test, could you please clarify the steps
  1. There was a bug in the securedrop-export script, that was easily resolved (see https://github.com/freedomofpress/securedrop-export/compare/fix-print-for-477?expand=1). Have you seen this failure locally?

  2. On first download, the print button is not visible until one changes sources (and comes back to the source), this is probably resolved by showing the button on this line : https://github.com/freedomofpress/securedrop-client/pull/631/files#diff-16a175b4662541f3889b432ac9e7e0e8L1864

Once 2 is fixed (and I test the corrupt print) I am satisfied with the functionality as implemented, and good to merge from my perspective (though @redshiftzero said they wanted to review this one as well).

securedrop_client/logic.py Outdated Show resolved Hide resolved
@sssoleileraaa
Copy link
Contributor Author

  1. There was a bug in the securedrop-export script, that was easily resolved (see https://github.com/freedomofpress/securedrop-export/compare/fix-print-for-477?expand=1). Have you seen this failure locally?

Yes, I did have that fix in my export branch, maybe it didn't get pushed (will push that change and open an export pr against the branch I linked to above so we can start tracking changes.

  1. On first download, the print button is not visible until one changes sources (and comes back to the source), this is probably resolved by showing the button on this line : https://github.com/freedomofpress/securedrop-client/pull/631/files#diff-16a175b4662541f3889b432ac9e7e0e8L1864

Good find! I thought I fixed this.

❌ Test ERROR_PRINT: Did not test, could you please clarify the steps

I will clarify after fixing #2 and opening the export PR

Thanks for the review so far!

Copy link
Contributor

@redshiftzero redshiftzero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is looking good to me, minor comments inline (though i can't functionally test atm due to no printer)

securedrop_client/gui/widgets.py Show resolved Hide resolved
tests/gui/test_widgets.py Outdated Show resolved Hide resolved
tests/gui/test_widgets.py Outdated Show resolved Hide resolved
securedrop_client/logic.py Outdated Show resolved Hide resolved
@sssoleileraaa
Copy link
Contributor Author

pr comments addressed with regression test for showing print and export links immediately after file download and tests around refactored code to create and cleanup hardlinks when opening, exporting, and printing files (no cleanup yet for opening with the way it was designed -- a ticket should already exist for this).

to clarify how you would test the scenario where we would get back ERROR_PRINT, see https://github.com/freedomofpress/securedrop-export/blob/793f39cc320550fb8c0740987208808af959859a/securedrop_export/export.py#L327-L331 -- a forced timeout should do it.

@emkll
Copy link
Contributor

emkll commented Dec 4, 2019

Thanks @creviera, changes look good!

What changed from last week's review is that I am using Buster templates, and I've observed some errors with the printer tooling, and I have pushed a commit to the associated securedrop-export branch here: freedomofpress/securedrop-export#34

With those changes, everything works as expected 🎉

One last comment from me: as I was debugging the Buster compatibility this morning, I observed some strange Client behavior: a segfault occurred when I (manually) introduced an error in the securedrop-export code in sd-export-usb. I introduced a syntax error in the python code, and then accidentally double clicked on the print button. This should never happen in production as it will certainly get caught by the automated tests, but I am wondering if something can be done on the client side to improve resilience. It seems like it may be a race condition with the file copying, when copying the file multiple times? Do you think this could happen in other scenarios as well?

If it's an easy fix, let's include it as part of this PR, otherwise we can open a follow-up to track to see if others can reliably reproduce.

INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Traceback (most recent call last):
  File "/opt/venvs/securedrop-client/lib/python3.7/site-packages/securedrop_client/export.py", line 300, in print
    self._run_print(temp_dir, filepaths)
  File "/opt/venvs/securedrop-client/lib/python3.7/site-packages/securedrop_client/export.py", line 244, in _run_print
    archive_path = self._create_archive(archive_dir, self.PRINT_FN, metadata, filepaths)
  File "/opt/venvs/securedrop-client/lib/python3.7/site-packages/securedrop_client/export.py", line 151, in _create_archive
    cls._add_file_to_archive(archive, filepath)
  File "/opt/venvs/securedrop-client/lib/python3.7/site-packages/securedrop_client/export.py", line 184, in _add_file_to_archive
    archive.add(filepath, arcname=arcname, recursive=False)
  File "/opt/venvs/securedrop-client/lib/python3.7/tarfile.py", line 1928, in add
    tarinfo = self.gettarinfo(name, arcname)
  File "/opt/venvs/securedrop-client/lib/python3.7/tarfile.py", line 1807, in gettarinfo
    statres = os.lstat(name)
FileNotFoundError: [Errno 2] No such file or directory: '/home/user/.securedrop_client/data/Secret_Docs.docx'

QObject::~QObject: Timers cannot be stopped from another thread
Segmentation fault

@sssoleileraaa
Copy link
Contributor Author

So at the time I wrote this, we were building and testing for stretch. But now that securedrop-workstation has upgraded to buster, I need to run through testing this again.

Copy link
Contributor

@emkll emkll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested this again with the export script changes in freedomofpress/securedrop-export#34 , and everything works! Thanks for your hard work on this one @creviera

Opened #641 to track the issue I encountered but could not reproduce.

@emkll emkll merged commit 2e4cf25 into master Dec 5, 2019
@emkll emkll deleted the 477-print branch December 5, 2019 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

remove QApplication.processEvents call from FileWidget Add support for printing documents
3 participants