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

app: fix reply ordering #829

Merged
merged 2 commits into from
Feb 27, 2020
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
2 changes: 2 additions & 0 deletions securedrop_client/api_jobs/uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def call_api(self, api_client: API, session: Session) -> str:
# Delete draft, add reply to replies table.
session.add(reply_db_object)
session.delete(draft_reply_db_object)
source.interaction_count += 1
session.add(source)
session.commit()

return reply_db_object.uuid
Expand Down
18 changes: 17 additions & 1 deletion tests/api_jobs/test_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ def test_drafts_ordering(homedir, mocker, session, session_maker,
Check that if a reply is successful, drafts sent before and after
continue to appear in the same order.
'''
source = factory.Source(interaction_count=1)
initial_interaction_count = 1
source_uuid = 'foo'
source = factory.Source(uuid=source_uuid,
interaction_count=initial_interaction_count)
session.add(source)
msg_uuid = 'xyz456'

Expand Down Expand Up @@ -130,6 +133,19 @@ def test_drafts_ordering(homedir, mocker, session, session_maker,
reply = session.query(db.Reply).filter_by(uuid=msg_uuid).one()
assert reply.journalist_id == api_client.token_journalist_uuid

# We use the file_counter on each Reply, Message, File, and DraftReply
# object to order the conversation view. We expect a unique file_counter
# for Reply, Message, and File objects since they are retrieved from
# the server.
# For DraftReply, we don't have that unique constraint, and we instead expect
# the file_counter to be the interaction_count at the time of send.
# If we do not update the interaction_count after each successful reply send,
# future drafts will have an interaction_count that is too low, leading
# to incorrectly ordered drafts until a metadata sync completes (the metadata
# sync is the place where the source object is updated from the server).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helpful comment ❤️

source = session.query(db.Source).filter_by(uuid=source_uuid).one()
assert source.interaction_count == initial_interaction_count + 1

# Check the ordering displayed to the user
assert source.collection[0] == draft_reply_before
assert source.collection[1] == reply
Expand Down