-
Notifications
You must be signed in to change notification settings - Fork 42
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
Refactor move DeleteSourceDialog to 'gui.source' namespace #1394
Merged
sssoleileraaa
merged 2 commits into
main
from
refactor-move-source-deletion-dialog-to-namespace
Jan 25, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Okay, so you are hiding the
dialog
module from the path so that you canfrom securedrop_client.gui.source.delete import DeleteSourceDialog
when you actually need to importDeleteSourceDialog
vsfrom securedrop_client.gui.source.delete.dialog import DeleteSourceDialog
. Either way works for me, but I tend to try to keep my__init__.py
empty and kind of prefer the simplicity and explicit-y when importing classes, functions, and variables from somewhere.