Skip to content

Commit

Permalink
Refactor: list[Source] instead of set[Source] of selectedItems
Browse files Browse the repository at this point in the history
  • Loading branch information
rocodes committed Oct 25, 2024
1 parent 5e83f07 commit 41b4299
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions client/securedrop_client/gui/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(
source: Source,
parent: QMenu,
controller: Controller,
confirmation_dialog: Callable[[set[Source]], QDialog],
confirmation_dialog: Callable[[list[Source]], QDialog],
) -> None:
self.source = source
self.controller = controller
Expand All @@ -91,9 +91,9 @@ def __init__(

# DeleteSource Dialog can accept more than one source (bulk delete),
# but when triggered from this menu, only applies to one source
self._confirmation_dialog = confirmation_dialog(set([self.source]))
self._confirmation_dialog = confirmation_dialog([self.source])
self._confirmation_dialog.accepted.connect(
lambda: self.controller.delete_sources(set([self.source]))
lambda: self.controller.delete_sources([self.source])
)
self.triggered.connect(self.trigger)

Expand Down
6 changes: 3 additions & 3 deletions client/securedrop_client/gui/source/delete/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class DeleteSourceDialog(ModalDialog):
"""Used to confirm deletion of source accounts."""

def __init__(self, sources: set[Source]) -> None:
def __init__(self, sources: list[Source]) -> None:
super().__init__(show_header=False, dangerous=True)
self.sources = sources

Expand All @@ -50,7 +50,7 @@ def __init__(self, sources: set[Source]) -> None:
self.confirmation_label.setText(_("Are you sure this is what you want?"))
self.adjustSize()

def make_body_text(self, sources: set[Source]) -> str:
def make_body_text(self, sources: list[Source]) -> str:
message_tuple = (
"<p>",
_("Delete entire account for: {source_or_sources}?"),
Expand All @@ -74,7 +74,7 @@ def make_body_text(self, sources: set[Source]) -> str:
source_or_sources=f"<b>{self._get_source_names(sources)}</b>"
)

def _get_source_names(self, sources: set[Source]) -> str:
def _get_source_names(self, sources: list[Source]) -> str:
"""
Helper. Return a comma-separated list of journalist designations.
"""
Expand Down
4 changes: 2 additions & 2 deletions client/securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ class SourceList(QListWidget):
source_selection_cleared = pyqtSignal()

# Bulk-context signal (toolbar)
selected_sources = pyqtSignal(object) # set[Source]
selected_sources = pyqtSignal(object) # list[Source]

NUM_SOURCES_TO_ADD_AT_A_TIME = 32
INITIAL_UPDATE_SCROLLBAR_WIDTH = 20
Expand Down Expand Up @@ -1365,7 +1365,7 @@ def _on_item_selection_changed(self) -> None:
self.source_selection_cleared.emit()

# Update listeners (action toolbar) with current selection
self.selected_sources.emit(set(selected))
self.selected_sources.emit(selected)


class SourcePreview(SecureQLabel):
Expand Down
8 changes: 4 additions & 4 deletions client/securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def __init__( # type: ignore[no-untyped-def]
os.chmod(self.last_sync_filepath, 0o600)

# Store currently-selected sources
self._selected_sources: set[db.Source] | None = None
self._selected_sources: list[db.Source] | None = None

@pyqtSlot(int)
def _on_main_queue_updated(self, num_items: int) -> None:
Expand Down Expand Up @@ -1050,7 +1050,7 @@ def on_delete_source_failure(self, e: Exception) -> None:
self.source_deletion_failed.emit(e.source_uuid)

@login_required
def delete_sources(self, sources: set[db.Source]) -> None:
def delete_sources(self, sources: list[db.Source]) -> None:
"""
Performs a delete operation on one or more source records.
Expand Down Expand Up @@ -1192,8 +1192,8 @@ def update_failed_replies(self) -> None:
self.reply_failed.emit(failed_reply.uuid)

@pyqtSlot(object)
def on_receive_selected_sources(self, sources: set[db.Source]) -> None:
def on_receive_selected_sources(self, sources: list[db.Source]) -> None:
self._selected_sources = sources

def get_selected_sources(self) -> set[db.Source] | None:
def get_selected_sources(self) -> list[db.Source] | None:
return self._selected_sources
2 changes: 1 addition & 1 deletion client/tests/functional/test_delete_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def check_for_conversation():
# Note: The qtbot object cannot interact with QAction items (as used in the delete button/menu)
# so we programatically delete the source rather than using the GUI via qtbot
source_count = gui.main_view.source_list.count()
controller.delete_sources(set([conversation.conversation_title_bar.source]))
controller.delete_sources([conversation.conversation_title_bar.source])

def check_source_list():
assert gui.main_view.source_list.count() == source_count - 1
Expand Down
2 changes: 1 addition & 1 deletion client/tests/functional/test_offline_delete_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def check_for_conversation():
# Attempt to delete the selected source
# Note: The qtbot object cannot interact with QAction items (as used in the delete button/menu)
# so we programatically attempt to delete the source rather than using the GUI via qtbot
controller.delete_sources(set([conversation.conversation_title_bar.source]))
controller.delete_sources([conversation.conversation_title_bar.source])

def check_for_error():
msg = gui.bottom_pane.error_status_bar.status_bar.currentMessage()
Expand Down
8 changes: 4 additions & 4 deletions client/tests/gui/source/delete/test_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


@pytest.fixture(
params=[set(), set([factory.Source()]), set([factory.Source(), factory.Source()])],
params=[[], [factory.Source()], [factory.Source(), factory.Source()]],
)
def dialog(request):
"""
Expand All @@ -22,7 +22,7 @@ def dialog(request):
class TestDeleteSourceDialog:
def test_dialog_setup(self, dialog):
assert type(dialog) is DeleteSourceDialog
assert type(dialog.sources) is set
assert type(dialog.sources) is list
assert dialog.dangerous

def test_default_button_is_safer_choice(self, dialog):
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_correct_format_body_text(self):
For n > 1 sources, ensure the warning text includes
all the journalist desginators.
"""
sources = set()
sources = []
names = [
"source one",
"source two",
Expand All @@ -82,7 +82,7 @@ def test_correct_format_body_text(self):

for item in names:
source = factory.Source(journalist_designation=item)
sources.update([source])
sources.append(source)

dialog = DeleteSourceDialog(sources)

Expand Down
4 changes: 2 additions & 2 deletions client/tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,7 @@ def test_Controller_delete_source_not_logged_in(homedir, config, mocker, session
source_db_object = mocker.MagicMock()
co.on_action_requiring_login = mocker.MagicMock()
co.api = None
co.delete_sources(set([source_db_object]))
co.delete_sources([source_db_object])
co.on_action_requiring_login.assert_called_with()


Expand All @@ -1945,7 +1945,7 @@ def test_Controller_delete_source(homedir, config, mocker, session_maker, sessio
session.add(source)
session.commit()

co.delete_sources(set([source]))
co.delete_sources([source])

assert len(source_deleted_emissions) == 1
assert source_deleted_emissions[0] == [source.uuid]
Expand Down

0 comments on commit 41b4299

Please sign in to comment.