Skip to content

Commit

Permalink
Merge pull request #2293 from freedomofpress/2284-truncated-source-list
Browse files Browse the repository at this point in the history
[0.14.0] Truncate source list displayed in delete dialog
  • Loading branch information
deeplow authored Nov 14, 2024
2 parents a6e2140 + 4fd8dcb commit 5ddbedc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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 ""

0 comments on commit 5ddbedc

Please sign in to comment.