-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1394 from freedomofpress/refactor-move-source-del…
…etion-dialog-to-namespace Refactor move DeleteSourceDialog to 'gui.source' namespace
- Loading branch information
Showing
9 changed files
with
205 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
A source who interacts with journalists. | ||
Copyright (C) 2021 The Freedom of the Press Foundation. | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
# Import classes here to make possible to import them from securedrop_client.gui.source | ||
from securedrop_client.gui.source.delete import DeleteSourceDialog # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
Everything necessary for a journalist to delete a source. | ||
Copyright (C) 2021 The Freedom of the Press Foundation. | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
# Import classes here to make possible to import them from securedrop_client.gui.source.delete | ||
from securedrop_client.gui.source.delete.dialog import DeleteSourceDialog # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
Source deletion dialog. | ||
Copyright (C) 2021 The Freedom of the Press Foundation. | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
from gettext import gettext as _ | ||
|
||
from PyQt5.QtCore import pyqtSlot | ||
|
||
from securedrop_client.db import Source | ||
from securedrop_client.gui.base import ModalDialog | ||
from securedrop_client.logic import Controller | ||
|
||
|
||
class DeleteSourceDialog(ModalDialog): | ||
"""Used to confirm deletion of source accounts.""" | ||
|
||
def __init__(self, source: Source, controller: Controller) -> None: | ||
super().__init__(show_header=False, dangerous=True) | ||
|
||
self.source = source | ||
self.controller = controller | ||
|
||
self.body.setText(self.make_body_text()) | ||
|
||
self.continue_button.setText(_("YES, DELETE ENTIRE SOURCE ACCOUNT")) | ||
self.continue_button.clicked.connect(self.delete_source) | ||
|
||
self.confirmation_label.setText(_("Are you sure this is what you want?")) | ||
|
||
self.adjustSize() | ||
|
||
def make_body_text(self) -> str: | ||
message_tuple = ( | ||
"<style>", | ||
"p {{white-space: nowrap;}}", | ||
"</style>", | ||
"<p><b>", | ||
_("When the entire account for a source is deleted:"), | ||
"</b></p>", | ||
"<p><b>\u2219</b> ", | ||
_("The source will not be able to log in with their codename again."), | ||
"</p>", | ||
"<p><b>\u2219</b> ", | ||
_("Your organization will not be able to send them replies."), | ||
"</p>", | ||
"<p><b>\u2219</b> ", | ||
_("All files and messages from that source will also be destroyed."), | ||
"</p>", | ||
"<p> </p>", | ||
) | ||
|
||
return "".join(message_tuple).format( | ||
source="<b>{}</b>".format(self.source.journalist_designation) | ||
) | ||
|
||
@pyqtSlot() | ||
def delete_source(self) -> None: | ||
self.controller.delete_source(self.source) | ||
self.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from gettext import gettext as _ | ||
|
||
from PyQt5.QtWidgets import QApplication | ||
|
||
from securedrop_client.gui.source import DeleteSourceDialog | ||
from tests import factory | ||
|
||
app = QApplication([]) | ||
|
||
|
||
def test_DeleteSourceDialog_init(mocker, source): | ||
mock_controller = mocker.MagicMock() | ||
DeleteSourceDialog(source["source"], mock_controller) | ||
|
||
|
||
def test_DeleteSourceDialog_cancel(mocker, source): | ||
source = source["source"] # to get the Source object | ||
|
||
mock_controller = mocker.MagicMock() | ||
delete_source_dialog = DeleteSourceDialog(source, mock_controller) | ||
delete_source_dialog.cancel_button.click() | ||
mock_controller.delete_source.assert_not_called() | ||
|
||
|
||
def test_DeleteSourceDialog_continue(mocker, source, session): | ||
source = source["source"] # to get the Source object | ||
|
||
mock_controller = mocker.MagicMock() | ||
delete_source_dialog = DeleteSourceDialog(source, mock_controller) | ||
delete_source_dialog.continue_button.click() | ||
mock_controller.delete_source.assert_called_once_with(source) | ||
|
||
|
||
def test_DeleteSourceDialog_make_body_text(mocker, source, session): | ||
source = source["source"] # to get the Source object | ||
file_ = factory.File(source=source) | ||
session.add(file_) | ||
message = factory.Message(source=source) | ||
session.add(message) | ||
message = factory.Message(source=source) | ||
session.add(message) | ||
reply = factory.Reply(source=source) | ||
session.add(reply) | ||
session.commit() | ||
|
||
mock_controller = mocker.MagicMock() | ||
|
||
delete_source_message_box = DeleteSourceDialog(source, mock_controller) | ||
|
||
message = delete_source_message_box.make_body_text() | ||
|
||
expected_message = "".join( | ||
( | ||
"<style>", | ||
"p {{white-space: nowrap;}}", | ||
"</style>", | ||
"<p><b>", | ||
_("When the entire account for a source is deleted:"), | ||
"</b></p>", | ||
"<p><b>\u2219</b> ", | ||
_("The source will not be able to log in with their codename again."), | ||
"</p>", | ||
"<p><b>\u2219</b> ", | ||
_("Your organization will not be able to send them replies."), | ||
"</p>", | ||
"<p><b>\u2219</b> ", | ||
_("All files and messages from that source will also be destroyed."), | ||
"</p>", | ||
"<p> </p>", | ||
) | ||
).format(source=source.journalist_designation) | ||
assert message == expected_message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters