From abc54fccf0e7c1b59201684024a4da8de58afb76 Mon Sep 17 00:00:00 2001 From: Allie Crevier Date: Thu, 15 Oct 2020 13:05:44 -0700 Subject: [PATCH] add seen dev data --- securedrop/create-dev-data.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/securedrop/create-dev-data.py b/securedrop/create-dev-data.py index d082c9bf176..6100b7a9de8 100755 --- a/securedrop/create-dev-data.py +++ b/securedrop/create-dev-data.py @@ -16,7 +16,7 @@ from sdconfig import config from db import db -from models import Journalist, Reply, SeenReply, Source, Submission +from models import Journalist, Reply, SeenFile, SeenMessage, SeenReply, Source, Submission from specialstrings import strings @@ -65,7 +65,14 @@ def main(staging=False): i, num_sources, journalist_who_replied=journalist_tobe_deleted ) continue - create_dev_data(i, num_sources) + + # Mark a third of sources as "seen", a third as "semi-seen", and a third as "unseen" + if i % 3 == 0: + create_dev_data(i, num_sources, seen_files=2, seen_messages=2) + elif i % 3 == 1: + create_dev_data(i, num_sources, seen_files=1, seen_messages=1) + else: + create_dev_data(i, num_sources) # Now let us delete one journalist db.session.delete(journalist_tobe_deleted) @@ -98,6 +105,8 @@ def create_dev_data( num_files=2, num_messages=2, num_replies=2, + seen_files=0, + seen_messages=0, journalist_who_replied=None # noqa: W605, E501 ): # Store source in database @@ -113,7 +122,14 @@ def create_dev_data( os.mkdir(current_app.storage.path(source.filesystem_id)) current_app.crypto_util.genkeypair(source.filesystem_id, codename) + # TODO: Add variety for journalists who make replies and journalists who "see" submissions + if not journalist_who_replied: + journalist = Journalist.query.first() + else: + journalist = journalist_who_replied + # Generate some test messages + seen_messages_count = 0 for _ in range(num_messages): source.interaction_count += 1 submission_text = next(messages) @@ -126,8 +142,13 @@ def create_dev_data( source.last_updated = datetime.datetime.utcnow() submission = Submission(source, fpath) db.session.add(submission) + if seen_messages_count < seen_messages: + seen_messages_count = seen_messages_count + 1 + seen_message = SeenMessage(message_id=submission.id, journalist_id=journalist.id) + db.session.add(seen_message) # Generate some test files + seen_files_count = 0 for _ in range(num_files): source.interaction_count += 1 fpath = current_app.storage.save_file_submission( @@ -140,6 +161,10 @@ def create_dev_data( source.last_updated = datetime.datetime.utcnow() submission = Submission(source, fpath) db.session.add(submission) + if seen_files_count < seen_files: + seen_files_count = seen_files_count + 1 + seen_file = SeenFile(file_id=submission.id, journalist_id=journalist.id) + db.session.add(seen_file) # Generate some test replies for _ in range(num_replies): @@ -152,10 +177,6 @@ def create_dev_data( config.JOURNALIST_KEY], current_app.storage.path(source.filesystem_id, fname)) - if not journalist_who_replied: - journalist = Journalist.query.first() - else: - journalist = journalist_who_replied reply = Reply(journalist, source, fname) db.session.add(reply) db.session.flush()