Skip to content

Commit

Permalink
emit failed reply to update GUI for drafts that fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Allie Crevier committed Feb 3, 2020
1 parent 2707ed6 commit e0a39b1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
3 changes: 3 additions & 0 deletions securedrop_client/api_jobs/uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def call_api(self, api_client: API, session: Session) -> str:
source = session.query(Source).filter_by(uuid=self.source_uuid).one()
session.commit()

import time
time.sleep(5)

encrypted_reply = self.gpg.encrypt_to_source(self.source_uuid, self.message)
interaction_count = source.interaction_count + 1
filename = '{}-{}-reply.gpg'.format(interaction_count,
Expand Down
11 changes: 8 additions & 3 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,16 +490,21 @@ def update_star(self, source_db_object, callback):

def logout(self):
"""
Call logout function in the API, reset the API object, and force the UI
to update into a logged out state.
If the token is not already invalid, make an api call to logout and invalidate the token.
Then mark all pending draft replies as failed, stop the queues, and show the user as logged
out in the GUI.
"""
if self.api is not None:
self.call_api(self.api.logout, self.on_logout_success, self.on_logout_failure)
self.invalidate_token()

storage.mark_all_pending_drafts_as_failed(self.session)
failed_replies = storage.mark_all_pending_drafts_as_failed(self.session)
for failed_reply in failed_replies:
self.reply_failed.emit(failed_reply.uuid)

self.api_job_queue.logout()
self.gui.logout()

self.is_authenticated = False

def invalidate_token(self):
Expand Down
4 changes: 0 additions & 4 deletions securedrop_client/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ def __init__(self, api_client: API, session_maker: scoped_session) -> None:
self.metadata_queue.pinged.connect(self.resume_queues)

def logout(self) -> None:
self.main_queue.api_client = None
self.download_file_queue.api_client = None
self.metadata_queue.api_client = None

if self.main_thread.isRunning():
logger.debug('Stopping main queue thread')
self.main_thread.quit()
Expand Down
11 changes: 5 additions & 6 deletions securedrop_client/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,20 +562,19 @@ def get_reply(session: Session, uuid: str) -> Reply:
return session.query(Reply).filter_by(uuid=uuid).one()


def mark_all_pending_drafts_as_failed(session: Session) -> None:
def mark_all_pending_drafts_as_failed(session: Session) -> List[DraftReply]:
"""
When we login (offline or online) or logout, we need to set all
the pending replies as failed.
When we login (offline or online) or logout, we need to set all the pending replies as failed.
"""
pending_status = session.query(ReplySendStatus).filter_by(
name=ReplySendStatusCodes.PENDING.value).one()
failed_status = session.query(ReplySendStatus).filter_by(
name=ReplySendStatusCodes.FAILED.value).one()

pending_drafts = session.query(DraftReply).filter_by(
send_status=pending_status
).all()
pending_drafts = session.query(DraftReply).filter_by(send_status=pending_status).all()
for pending_draft in pending_drafts:
pending_draft.send_status = failed_status

session.commit()

return pending_drafts

0 comments on commit e0a39b1

Please sign in to comment.