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

[0.14.0] Truncate source list displayed in delete dialog #2293

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion client/securedrop_client/gui/source/delete/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
from securedrop_client.db import Source
from securedrop_client.gui.base import ModalDialog

# Maximum number of source names to display in delete dialog before
# truncation
MAX_DEL_DISP = 30


class DeleteSourceDialog(ModalDialog):
"""Used to confirm deletion of source accounts."""
Expand Down Expand Up @@ -71,9 +75,25 @@ def make_body_text(self, sources: list[Source]) -> str:
)

return "".join(message_tuple).format(
source_or_sources=f"<b>{self._get_source_names(sources)}</b>"
source_or_sources=f"<b>{self._get_source_names_truncated(sources, MAX_DEL_DISP)}</b>"
)

def _get_source_names_truncated(self, sources: list[Source], max_shown: int) -> str:
"""
Helper. Return a comma-separated list of journalist designations, truncated to avoid
text overflows. If the limit is N and there are N+2 sources, all N+2 are displayed.
If there are >N+2 sources, N sources and an additional message (approx 2 source names
long) is displayed.
"""
if len(sources) <= max_shown + 2:
return self._get_source_names(sources)
else:
shortlist = sources[:max_shown]
return _("{sources} ... plus {count} additional sources").format(
sources=", ".join([s.journalist_designation for s in shortlist]),
count=len(sources) - max_shown,
)

def _get_source_names(self, sources: list[Source]) -> str:
"""
Helper. Return a comma-separated list of journalist designations.
Expand Down
3 changes: 3 additions & 0 deletions client/securedrop_client/locale/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ msgstr ""
msgid "All files and messages from that source will also be destroyed."
msgstr ""

msgid "{sources} ... plus {count} additional sources"
msgstr ""

msgid "No sources have been selected."
msgstr ""