From 67749eaf0b6691bcedf2cb0a6a33c1e5b0784c8e Mon Sep 17 00:00:00 2001 From: Allie Crevier Date: Mon, 20 Jan 2020 23:56:06 -0800 Subject: [PATCH] show when an export is successful in the client --- securedrop_client/gui/widgets.py | 50 +++++++++++------ tests/gui/test_widgets.py | 93 +++++++++++++++++++++++++++----- 2 files changed, 116 insertions(+), 27 deletions(-) diff --git a/securedrop_client/gui/widgets.py b/securedrop_client/gui/widgets.py index 6769d83ae3..812b2322f6 100644 --- a/securedrop_client/gui/widgets.py +++ b/securedrop_client/gui/widgets.py @@ -2155,15 +2155,15 @@ def __init__(self): window_buttons.setObjectName('window_buttons') button_layout = QVBoxLayout() window_buttons.setLayout(button_layout) - cancel_button = QPushButton(_('CANCEL')) - cancel_button.setAutoDefault(False) - cancel_button.clicked.connect(self.close) + self.cancel_button = QPushButton(_('CANCEL')) + self.cancel_button.setAutoDefault(False) + self.cancel_button.clicked.connect(self.close) self.continue_button = QPushButton(_('CONTINUE')) self.continue_button.setObjectName('primary_button') self.continue_button.setDefault(True) button_box = QDialogButtonBox(Qt.Horizontal) button_box.setObjectName('button_box') - button_box.addButton(cancel_button, QDialogButtonBox.ActionRole) + button_box.addButton(self.cancel_button, QDialogButtonBox.ActionRole) button_box.addButton(self.continue_button, QDialogButtonBox.ActionRole) button_layout.addWidget(button_box, alignment=Qt.AlignRight) content_layout.addWidget(header_container) @@ -2349,6 +2349,7 @@ def __init__(self, controller: Controller, file_uuid: str, file_name: str): '{}'.format(self.file_name)) self.insert_usb_header = _('Insert encrypted USB drive') self.passphrase_header = _('Enter passphrase for USB drive') + self.success_header = _('Export successful') self.error_header = _('Unable to export') self.starting_message = _( '

Proceed with caution when exporting files

' @@ -2374,6 +2375,8 @@ def __init__(self, controller: Controller, file_uuid: str, file_name: str): self.generic_error_message = _('See your administrator for help.') self.continue_disabled_message = _( 'The CONTINUE button will be disabled until the Export VM is ready') + self.success_message = _( + 'Remember to be careful when working with files outside of your Workstation machine.') # Passphrase Form self.passphrase_form = QWidget() @@ -2415,45 +2418,61 @@ def _show_starting_instructions(self): def _show_passphrase_request_message(self): self.continue_button.clicked.connect(self._export_file) self.header.setText(self.passphrase_header) + self.continue_button.setText('SUBMIT') self.header_line.hide() self.error_details.hide() - self.body.hide() self.passphrase_form.show() - self.continue_button.setText('SUBMIT') + self.body.hide() self.adjustSize() self.center_dialog() def _show_passphrase_request_message_again(self): self.continue_button.clicked.connect(self._export_file) self.header.setText(self.passphrase_header) - self.header_line.hide() self.error_details.setText(self.passphrase_error_message) + self.continue_button.setText('SUBMIT') + self.header_line.hide() self.error_details.show() - self.body.hide() self.passphrase_form.show() - self.continue_button.setText('SUBMIT') + self.body.hide() + self.adjustSize() + self.center_dialog() + + def _show_success_message(self): + self.continue_button.clicked.connect(self.close) + self.header.setText('\n{}'.format(self.success_header)) + self.continue_button.setText('DONE') + self.body.setText(self.success_message) + self.cancel_button.hide() + self.header_line.show() + self.error_details.hide() + self.passphrase_form.hide() + self.body.show() self.adjustSize() self.center_dialog() def _show_insert_usb_message(self): self.continue_button.clicked.connect(self._run_preflight) self.header.setText(self.insert_usb_header) - self.header_line.show() + self.continue_button.setText('CONTINUE') self.body.setText(self.insert_usb_message) + self.header_line.show() self.error_details.hide() self.passphrase_form.hide() - self.continue_button.setText('CONTINUE') + self.body.show() self.adjustSize() self.center_dialog() def _show_insert_encrypted_usb_message(self): self.continue_button.clicked.connect(self._run_preflight) self.header.setText(self.insert_usb_header) - self.header_line.show() self.error_details.setText(self.usb_error_message) + self.continue_button.setText('CONTINUE') self.body.setText(self.insert_usb_message) + self.header_line.show() + self.error_details.show() self.passphrase_form.hide() - self.continue_button.setText('CONTINUE') + self.body.show() self.adjustSize() self.center_dialog() @@ -2461,10 +2480,11 @@ def _show_generic_error_message(self): self.continue_button.clicked.connect(self.close) self.continue_button.setText('DONE') self.header.setText(self.error_header) + self.body.setText('{}: {}'.format(self.error_status, self.generic_error_message)) self.header_line.show() self.error_details.hide() - self.body.setText('{}: {}'.format(self.error_status, self.generic_error_message)) self.passphrase_form.hide() + self.body.show() self.adjustSize() self.center_dialog() @@ -2492,7 +2512,7 @@ def _on_preflight_failure(self, error: ExportError): @pyqtSlot() def _on_export_success(self): - self.close() + self._show_success_message() @pyqtSlot(object) def _on_export_failure(self, error: ExportError): diff --git a/tests/gui/test_widgets.py b/tests/gui/test_widgets.py index f49fac2078..22c87cbfed 100644 --- a/tests/gui/test_widgets.py +++ b/tests/gui/test_widgets.py @@ -1621,12 +1621,12 @@ def test_ExportDialog_close(mocker): dialog.modal_closing = mocker.MagicMock() dialog.modal_closing.emit = mocker.MagicMock() - assert dialog.isHidden() is False + assert not dialog.isHidden() dialog.close() dialog.modal_closing.emit.assert_called_once_with() - assert dialog.isHidden() is True + assert dialog.isHidden() def test_ExportDialog__show_starting_instructions(mocker): @@ -1636,7 +1636,6 @@ def test_ExportDialog__show_starting_instructions(mocker): dialog._show_starting_instructions() - assert dialog.passphrase_form.isHidden() assert dialog.header.text() == \ 'Preparing to export:' \ '
' \ @@ -1655,6 +1654,13 @@ def test_ExportDialog__show_starting_instructions(mocker): 'Documents submitted by sources may contain information or hidden metadata that ' \ 'identifies who they are. To protect your sources, please consider redacting documents ' \ 'before working with them on network-connected computers.' + assert not dialog.header.isHidden() + assert not dialog.header_line.isHidden() + assert dialog.error_details.isHidden() + assert not dialog.body.isHidden() + assert dialog.passphrase_form.isHidden() + assert not dialog.continue_button.isHidden() + assert not dialog.cancel_button.isHidden() def test_ExportDialog___show_passphrase_request_message(mocker): @@ -1664,9 +1670,14 @@ def test_ExportDialog___show_passphrase_request_message(mocker): dialog._show_passphrase_request_message() - assert not dialog.passphrase_form.isHidden() assert dialog.header.text() == 'Enter passphrase for USB drive' + assert not dialog.header.isHidden() + assert dialog.header_line.isHidden() + assert dialog.error_details.isHidden() assert dialog.body.isHidden() + assert not dialog.passphrase_form.isHidden() + assert not dialog.continue_button.isHidden() + assert not dialog.cancel_button.isHidden() def test_ExportDialog__show_passphrase_request_message_again(mocker): @@ -1674,15 +1685,37 @@ def test_ExportDialog__show_passphrase_request_message_again(mocker): 'securedrop_client.gui.widgets.QApplication.activeWindow', return_value=QMainWindow()) dialog = ExportDialog(mocker.MagicMock(), 'mock_uuid', 'mock.jpg') - assert dialog.error_details.isHidden() is True - dialog._show_passphrase_request_message_again() - assert dialog.error_details.isHidden() is False - assert not dialog.passphrase_form.isHidden() assert dialog.header.text() == 'Enter passphrase for USB drive' assert dialog.error_details.text() == 'The passphrase provided did not work. Please try again.' assert dialog.body.isHidden() + assert not dialog.header.isHidden() + assert dialog.header_line.isHidden() + assert not dialog.error_details.isHidden() + assert dialog.body.isHidden() + assert not dialog.passphrase_form.isHidden() + assert not dialog.continue_button.isHidden() + assert not dialog.cancel_button.isHidden() + + +def test_ExportDialog__show_success_message(mocker): + mocker.patch( + 'securedrop_client.gui.widgets.QApplication.activeWindow', return_value=QMainWindow()) + dialog = ExportDialog(mocker.MagicMock(), 'mock_uuid', 'mock.jpg') + + dialog._show_success_message() + + assert dialog.header.text() == '\nExport successful' + assert dialog.body.text() == \ + 'Remember to be careful when working with files outside of your Workstation machine.' + assert not dialog.header.isHidden() + assert not dialog.header_line.isHidden() + assert dialog.error_details.isHidden() + assert not dialog.body.isHidden() + assert dialog.passphrase_form.isHidden() + assert not dialog.continue_button.isHidden() + assert dialog.cancel_button.isHidden() def test_ExportDialog__show_insert_usb_message(mocker): @@ -1696,7 +1729,13 @@ def test_ExportDialog__show_insert_usb_message(mocker): assert dialog.body.text() == \ 'Please insert one of the export drives provisioned specifically ' \ 'for the SecureDrop Workstation.' + assert not dialog.header.isHidden() + assert not dialog.header_line.isHidden() + assert dialog.error_details.isHidden() + assert not dialog.body.isHidden() assert dialog.passphrase_form.isHidden() + assert not dialog.continue_button.isHidden() + assert not dialog.cancel_button.isHidden() def test_ExportDialog__show_insert_encrypted_usb_message(mocker): @@ -1712,7 +1751,13 @@ def test_ExportDialog__show_insert_encrypted_usb_message(mocker): assert dialog.body.text() == \ 'Please insert one of the export drives provisioned specifically for the SecureDrop ' \ 'Workstation.' + assert not dialog.header.isHidden() + assert not dialog.header_line.isHidden() + assert not dialog.error_details.isHidden() + assert not dialog.body.isHidden() assert dialog.passphrase_form.isHidden() + assert not dialog.continue_button.isHidden() + assert not dialog.cancel_button.isHidden() def test_ExportDialog__show_generic_error_message(mocker): @@ -1723,10 +1768,15 @@ def test_ExportDialog__show_generic_error_message(mocker): dialog._show_generic_error_message() - assert dialog.passphrase_form.isHidden() assert dialog.header.text() == 'Unable to export' - assert dialog.error_details.isHidden() assert dialog.body.text() == 'mock_error_status: See your administrator for help.' + assert not dialog.header.isHidden() + assert not dialog.header_line.isHidden() + assert dialog.error_details.isHidden() + assert not dialog.body.isHidden() + assert dialog.passphrase_form.isHidden() + assert not dialog.continue_button.isHidden() + assert not dialog.cancel_button.isHidden() def test_ExportDialog__export_file(mocker): @@ -1804,11 +1854,11 @@ def test_ExportDialog__on_export_success(mocker): mocker.patch( 'securedrop_client.gui.widgets.QApplication.activeWindow', return_value=QMainWindow()) dialog = ExportDialog(mocker.MagicMock(), 'mock_uuid', 'mock.jpg') - dialog.close = mocker.MagicMock() + dialog._show_success_message = mocker.MagicMock() dialog._on_export_success() - dialog.close.assert_called_once_with() + dialog._show_success_message.assert_called_once_with() def test_ExportDialog__on_export_failure(mocker): @@ -1905,6 +1955,7 @@ def test_ExportDialog__update_dialog_when_status_is_CALLED_PROCESS_ERROR(mocker) dialog._show_generic_error_message.assert_called_once_with() assert dialog.error_status == ExportStatus.CALLED_PROCESS_ERROR.value + def test_ExportDialog__update_dialog_when_status_is_unknown(mocker): mocker.patch( 'securedrop_client.gui.widgets.QApplication.activeWindow', return_value=QMainWindow()) @@ -1963,6 +2014,12 @@ def test_PrintDialog__show_starting_instructions(mocker): 'Any part of a printed page may contain identifying information ' \ 'invisible to the naked eye, such as printer dots. Please carefully ' \ 'consider this risk when working with or publishing scanned printouts.' + assert not dialog.header.isHidden() + assert not dialog.header_line.isHidden() + assert dialog.error_details.isHidden() + assert not dialog.body.isHidden() + assert not dialog.continue_button.isHidden() + assert not dialog.cancel_button.isHidden() def test_PrintDialog__show_insert_usb_message(mocker): @@ -1974,6 +2031,12 @@ def test_PrintDialog__show_insert_usb_message(mocker): assert dialog.header.text() == 'Insert USB printer' assert dialog.body.text() == 'Please connect your printer to a USB port.' + assert not dialog.header.isHidden() + assert not dialog.header_line.isHidden() + assert dialog.error_details.isHidden() + assert not dialog.body.isHidden() + assert not dialog.continue_button.isHidden() + assert not dialog.cancel_button.isHidden() def test_PrintDialog__show_generic_error_message(mocker): @@ -1986,6 +2049,12 @@ def test_PrintDialog__show_generic_error_message(mocker): assert dialog.header.text() == 'Unable to print' assert dialog.body.text() == 'mock_error_status: See your administrator for help.' + assert not dialog.header.isHidden() + assert not dialog.header_line.isHidden() + assert dialog.error_details.isHidden() + assert not dialog.body.isHidden() + assert not dialog.continue_button.isHidden() + assert not dialog.cancel_button.isHidden() def test_PrintDialog__print_file(mocker):