Skip to content

Commit

Permalink
do not hide draft replies after deletion succeeds
Browse files Browse the repository at this point in the history
Signed-off-by: Allie Crevier <allie@freedom.press>
  • Loading branch information
Allie Crevier committed Nov 25, 2021
1 parent 16b3d74 commit c505eac
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 7 deletions.
36 changes: 29 additions & 7 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3330,13 +3330,35 @@ def _on_sync_started(self, timestamp: datetime) -> None:

@pyqtSlot(str, datetime)
def _on_conversation_deletion_successful(self, source_uuid: str, timestamp: datetime) -> None:
if self.source_uuid == source_uuid:
self.deletion_scheduled_timestamp = timestamp
for message in self.current_messages.values():
message.hide()
self.scroll.hide()
self.deleted_conversation_items_marker.hide()
self.deleted_conversation_marker.show()
if self.source_uuid != source_uuid:
return

self.deletion_scheduled_timestamp = timestamp

# Now that we know the deletion is scheduled, hide conversation items until they are
# removed from the local database.
try:
draft_reply_exists = False
for item in self.source.collection:
if isinstance(item, DraftReply):
draft_reply_exists = True
continue
item_widget = self.current_messages.get(item.uuid)
if item_widget:
item_widget.hide()

# If a draft reply exists then show the tear pattern above the draft replies.
# Otherwise, show that the entire conversation is deleted.
if draft_reply_exists:
self.scroll.show()
self.deleted_conversation_items_marker.show()
self.deleted_conversation_marker.hide()
else:
self.scroll.hide()
self.deleted_conversation_items_marker.hide()
self.deleted_conversation_marker.show()
except sqlalchemy.exc.InvalidRequestError as e:
logger.debug(f"Could not update ConversationView: {e}")

def update_deletion_markers(self) -> None:
try:
Expand Down
49 changes: 49 additions & 0 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,10 @@ class DeletedSource(Mock):
def uuid(self):
raise sqlalchemy.exc.InvalidRequestError()

@property
def collection(self):
raise sqlalchemy.exc.InvalidRequestError()


def test_SourceList_initial_update_does_not_raise_exc_and_no_widget_created(mocker, qtbot):
"""
Expand Down Expand Up @@ -4546,6 +4550,51 @@ def test_ConversationView__on_conversation_deletion_successful(mocker, session):
assert cv.current_messages[message.uuid].isHidden()


def test_ConversationView__on_conversation_deletion_successful_with_mismatched_source_uuid(mocker):
"""
If the success signal was emitted for a different source, ensure the deletion markers are not
altered.
"""
source = factory.Source(uuid="abc123")
cv = ConversationView(source, mocker.MagicMock())
timestamp = datetime.now()

assert not cv.scroll.isHidden()
assert cv.deleted_conversation_items_marker.isHidden()
assert cv.deleted_conversation_marker.isHidden()

cv._on_conversation_deletion_successful("notabc123", datetime.now())

assert not cv.scroll.isHidden()
assert cv.deleted_conversation_items_marker.isHidden()
assert cv.deleted_conversation_marker.isHidden()


def test_ConversationView__on_conversation_deletion_successful_handles_exception(mocker, session):
cv = ConversationView(factory.Source(uuid="abc123"), mocker.MagicMock())
cv.source = DeletedSource()
cv._on_conversation_deletion_successful("abc123", datetime.now()) # does not raise exception


def test_ConversationView__on_conversation_deletion_successful_does_not_hide_draft(mocker, session):
source = factory.Source()
message = factory.Message(source=source)
draft_reply = factory.DraftReply(source=source, send_status=factory.ReplySendStatus())
session.add(draft_reply)
session.add(message)
session.add(source)
session.commit()
cv = ConversationView(source, mocker.MagicMock())

cv._on_conversation_deletion_successful(cv.source.uuid, datetime.now())

assert not cv.scroll.isHidden()
assert not cv.deleted_conversation_items_marker.isHidden()
assert cv.deleted_conversation_marker.isHidden()
assert cv.current_messages[message.uuid].isHidden()
assert not cv.current_messages[draft_reply.uuid].isHidden()


def test_ConversationView_update_conversation_skips_if_sync_is_stale(mocker):
"""
If the sync started before the source was scheduled for deletion, do not update the conversation
Expand Down

0 comments on commit c505eac

Please sign in to comment.