Skip to content

Commit

Permalink
app, test: do not show drafts in preview
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Mar 25, 2020
1 parent bd94b7c commit 236d884
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
16 changes: 14 additions & 2 deletions securedrop_client/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def __repr__(self) -> str:

@property
def collection(self) -> List:
"""Return the list of submissions and replies for this source, sorted
in ascending order by the filename/interaction count."""
"""Return the list of submissions, replies, messages, and drafts for this
source, sorted in ascending order by the filename/interaction count."""
collection = [] # type: List
collection.extend(self.messages)
collection.extend(self.files)
Expand All @@ -63,6 +63,18 @@ def collection(self) -> List:
datetime.datetime(datetime.MINYEAR, 1, 1))))
return collection

@property
def server_collection(self) -> List:
"""Return the list of submissions, replies, and messages for this source.
These are the items that have been either successfully sent to the server,
or they have been retrieved from the server."""
collection = [] # type: List
collection.extend(self.messages)
collection.extend(self.files)
collection.extend(self.replies)
collection.sort(key=lambda x: x.file_counter)
return collection

@property
def journalist_filename(self) -> str:
valid_chars = 'abcdefghijklmnopqrstuvwxyz1234567890-_'
Expand Down
4 changes: 2 additions & 2 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,10 +1186,10 @@ def update(self):
self.timestamp.setText(_(arrow.get(self.source.last_updated).format('DD MMM')))
self.name.setText(self.source.journalist_designation)

if not self.source.collection:
if not self.source.server_collection:
self.set_snippet(self.source_uuid, '')
else:
last_collection_obj = self.source.collection[-1]
last_collection_obj = self.source.server_collection[-1]
self.set_snippet(self.source_uuid, str(last_collection_obj))

if self.source.document_count == 0:
Expand Down
19 changes: 19 additions & 0 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,25 @@ def test_SourceWidget_update_attachment_icon(mocker):
assert sw.paperclip.isHidden()


def test_SourceWidget_draft_only(mocker, session_maker, session, homedir):
"""
Snippets/previews do not include draft messages.
"""
mock_gui = mocker.MagicMock()
controller = logic.Controller('http://localhost', mock_gui, session_maker, homedir)
source = factory.Source(document_count=1)
f = factory.File(source=source)
reply = factory.DraftReply(source=source)
session.add(f)
session.add(source)
session.add(reply)
session.commit()

sw = SourceWidget(controller, source)
sw.set_snippet(source.uuid, f.filename)
assert sw.preview.text() == f.filename


def test_SourceWidget_set_snippet(mocker, session_maker, session, homedir):
"""
Snippets are set as expected.
Expand Down
27 changes: 27 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,33 @@ def test_source_collection():
assert source.collection[2] == message


def test_source_server_collection():
# Create some test submissions and replies
source = factory.Source()
file_ = File(source=source, uuid="test", size=123, filename="2-test.doc.gpg",
download_url='http://test/test')
message = Message(source=source, uuid="test", size=123, filename="3-test.doc.gpg",
download_url='http://test/test')
user = User(username='hehe')
reply = Reply(source=source, journalist=user, filename="1-reply.gpg",
size=1234, uuid='test')
draft_reply = DraftReply(source=source, journalist=user,
uuid='test',
timestamp=datetime.datetime(2002, 6, 6, 6, 0))
source.files = [file_]
source.messages = [message]
source.replies = [reply]
source.draftreplies = [draft_reply]

# Now these items should be in the source collection in the proper order
assert source.server_collection[0] == reply
assert source.server_collection[1] == file_
assert source.server_collection[2] == message

# Drafts do not appear in the server_collection, they are local only.
assert draft_reply not in source.server_collection


def test_source_collection_ordering_with_multiple_draft_replies():
# Create some test submissions, replies, and draft replies.
source = factory.Source()
Expand Down

0 comments on commit 236d884

Please sign in to comment.