Skip to content

Commit

Permalink
add seen dev data
Browse files Browse the repository at this point in the history
  • Loading branch information
Allie Crevier committed Oct 15, 2020
1 parent b782ef4 commit abc54fc
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions securedrop/create-dev-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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(
Expand All @@ -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):
Expand All @@ -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()
Expand Down

0 comments on commit abc54fc

Please sign in to comment.