Skip to content

Commit

Permalink
add seen_by field to draftreplies
Browse files Browse the repository at this point in the history
  • Loading branch information
Allie Crevier committed Nov 13, 2020
1 parent f53052a commit c589dd9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions securedrop_client/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,12 @@ def seen(self) -> bool:
"""
return True

def seen_by(self, journalist_id: int) -> bool:
"""
A draft reply is considered seen by everyone (we don't track who sees draft replies).
"""
return True


class ReplySendStatus(Base):

Expand Down
2 changes: 1 addition & 1 deletion tests/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ def DraftReply(**attrs):
global DRAFT_REPLY_COUNT
DRAFT_REPLY_COUNT += 1
defaults = dict(
uuid="draft-reply-uuid-{}".format(DRAFT_REPLY_COUNT),
timestamp=datetime.utcnow(),
source_id=1,
journalist_id=1,
file_counter=1,
uuid="draft-reply-uuid-{}".format(REPLY_COUNT),
content="content",
send_status_id=1,
)
Expand Down
24 changes: 23 additions & 1 deletion tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,13 @@ def test_SourceWidget_init_for_seen_source(mocker, session):
session.add(seen_message_for_another_user)
session.add(seen_reply_for_another_user)

draft_reply_from_current_user = factory.DraftReply(
source=source, journalist_id=controller.authenticated_user.id
)
draft_reply_from_another_user = factory.DraftReply(source=source, journalist_id=666)
session.add(draft_reply_from_current_user)
session.add(draft_reply_from_another_user)

session.commit()

session.add(db.SeenFile(file_id=seen_file.id, journalist_id=controller.authenticated_user.id))
Expand Down Expand Up @@ -1304,6 +1311,13 @@ def test_SourceWidget_init_for_unseen_source(mocker, session):
session.add(unseen_message)
session.add(unseen_reply)

draft_reply_from_current_user = factory.DraftReply(
source=source, journalist_id=controller.authenticated_user.id
)
draft_reply_from_another_user = factory.DraftReply(source=source, journalist_id=666)
session.add(draft_reply_from_current_user)
session.add(draft_reply_from_another_user)

session.commit()

session.add(db.SeenFile(file_id=seen_file.id, journalist_id=controller.authenticated_user.id))
Expand Down Expand Up @@ -1345,7 +1359,7 @@ def test_SourceWidget_html_init(mocker):
sw.name.setText.assert_called_once_with("foo <b>bar</b> baz")


def test_test_SourceWidget_update_styles_to_read(mocker):
def test_SourceWidget_update_styles_to_read(mocker):
"""
Ensure styles are updated so that the source widget appears read when seen is True.
"""
Expand Down Expand Up @@ -1419,6 +1433,7 @@ def test_SourceWidget__on_mark_seen(mocker, session):
unseen_file = factory.File(source=source)
unseen_message = factory.Message(source=source)
unseen_reply = factory.Reply(source=source)

session.add(unseen_file)
session.add(unseen_message)
session.add(unseen_reply)
Expand All @@ -1437,6 +1452,13 @@ def test_SourceWidget__on_mark_seen(mocker, session):
session.add(unseen_message_for_current_user)
session.add(unseen_reply_for_current_user)

draft_reply_from_current_user = factory.DraftReply(
source=source, journalist_id=controller.authenticated_user.id
)
draft_reply_from_another_user = factory.DraftReply(source=source, journalist_id=666)
session.add(draft_reply_from_current_user)
session.add(draft_reply_from_another_user)

session.commit()

session.add(db.SeenFile(file_id=seen_file.id, journalist_id=controller.authenticated_user.id))
Expand Down

0 comments on commit c589dd9

Please sign in to comment.