Skip to content

Commit

Permalink
truncate source list displayed in delete dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
zenmonkeykstop committed Nov 14, 2024
1 parent a6e2140 commit 0ed4c5c
Showing 1 changed file with 21 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

0 comments on commit 0ed4c5c

Please sign in to comment.