Skip to content

Commit

Permalink
Merge pull request #532 from biocore/master-overhaul
Browse files Browse the repository at this point in the history
Merge Master-overhaul into Master
  • Loading branch information
cassidysymons authored Aug 30, 2023
2 parents bf07af1 + 4498566 commit 8ccb2be
Show file tree
Hide file tree
Showing 86 changed files with 17,720 additions and 1,261 deletions.
2 changes: 1 addition & 1 deletion ci/conda_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ psycopg2
flask
natsort
pycryptodome
pandas
pandas < 2.0.0
3 changes: 1 addition & 2 deletions microsetta_private_api/LEGACY/locale_data/english_gut.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,9 @@
'TEXT_I_HAVE_READ_SIMPLIFIED': 'Yes, you will be in this research study.',
'PERSON_ATTAINING_ASSENT': 'Signature Of Person Obtaining Assent',
'TEXT_ASSENT_WITNESS': 'In my judgment, the participant is voluntarily and knowingly giving assent and possesses the legal capacity to give assent to participate in the study.',
'OBTAINER_NAME': 'Name of person obtaining assent',
'ASSENT_OBTAINER': 'Name of person obtaining assent',
'TEXT_I_HAVE_READ_PARENT': 'I have read (or someone has read to me) this form. I am aware that I am being asked to provide consent for my child to be in a research study. I voluntarily agree to allow my child to participate in this study. I understand how my child’s personal data will be processed, my related rights, and that I consent to the processing of my child’s sample and data as provided in this document.',
'PARTICIPANT_NAME': 'Participant name',
'PARTICIPANT_EMAIL': 'Participant email',
'PARTICIPANT_PARENT_1': 'Parent/Guardian name',
'PARTICIPANT_PARENT_2': 'Parent/Guardian name of second parent',
'PARTICIPANT_DECEASED_PARENTS': 'One parent/guardian is deceased or unable to consent',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
'TEXT_I_HAVE_READ_SIMPLIFIED': 'Sí, estarás en este estudio de investigación.',
'PERSON_ATTAINING_ASSENT': 'Firma de la persona que obtiene el consentimiento',
'TEXT_ASSENT_WITNESS': 'A mi juicio, el participante está dando su consentimiento voluntaria y conscientemente y posee la capacidad legal de dar su consentimiento para participar en el estudio.',
'OBTAINER_NAME': 'Nombre de la persona que obtiene el consentimiento',
'ASSENT_OBTAINER': 'Nombre de la persona que obtiene el consentimiento',
'TEXT_I_HAVE_READ_PARENT': 'He leído (o alguien me ha leído) este formulario. Soy consciente de que se le está pidiendo a mi hijo que participe en un estudio de investigación. Acepto voluntariamente que mi hijo participe en este estudio',
'PARTICIPANT_NAME': 'Nombre del participante',
'PARTICIPANT_EMAIL': 'Correo electrónico del participante',
Expand Down
3 changes: 1 addition & 2 deletions microsetta_private_api/LEGACY/locale_data/spanish_gut.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@
'TEXT_I_HAVE_READ_SIMPLIFIED': 'Sí, estarás en este estudio de investigación.',
'PERSON_ATTAINING_ASSENT': 'Firma de la persona que obtiene el consentimiento',
'TEXT_ASSENT_WITNESS': 'A mi juicio, el participante está dando su consentimiento voluntaria y conscientemente y posee la capacidad legal de dar su consentimiento para participar en el estudio.',
'OBTAINER_NAME': 'Nombre de la persona que obtiene el consentimiento',
'ASSENT_OBTAINER': 'Nombre de la persona que obtiene el consentimiento',
'TEXT_I_HAVE_READ_PARENT': 'He leído (o alguien me ha leído) este formulario. Soy consciente de que se le está pidiendo a mi hijo que participe en un estudio de investigación. Acepto voluntariamente que mi hijo participe en este estudio',
'PARTICIPANT_NAME': 'Nombre del participante',
'PARTICIPANT_EMAIL': 'Correo electrónico del participante',
'PARTICIPANT_PARENT_1': 'Nombre del Padre de Familia / Guardian',
'PARTICIPANT_PARENT_2': 'Nombre del padre / tutor del segundo padre',
'PARTICIPANT_DECEASED_PARENTS': 'Uno de los padres / tutor ha fallecido o no puede dar su consentimiento',
Expand Down
117 changes: 82 additions & 35 deletions microsetta_private_api/admin/admin_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from werkzeug.exceptions import Unauthorized
from microsetta_private_api.qiita import qclient
from microsetta_private_api.repo.interested_user_repo import InterestedUserRepo
from microsetta_private_api.repo.removal_queue_repo import RemovalQueueRepo


def search_barcode(token_info, sample_barcode):
Expand Down Expand Up @@ -542,6 +543,21 @@ def create_daklapack_orders(body, token_info):
return response


# We need an internal wrapper to create orders based on contributions coming
# from Fundrazr without authenticating an admin user.
# Do NOT expose an API endpoint for this.
def create_daklapack_order_internal(order_dict):
# Since we've established the consent dummy as a stable account across
# dev, staging, and production, we'll continue to use that internally
with Transaction() as t:
account_repo = AccountRepo(t)
order_dict[SUBMITTER_ACCT_KEY] = account_repo.get_account(
SERVER_CONFIG['fulfillment_account_id'])

result = _create_daklapack_order(order_dict)
return result


def _create_daklapack_order(order_dict):
order_dict[ORDER_ID_KEY] = str(uuid.uuid4())

Expand Down Expand Up @@ -614,6 +630,15 @@ def list_campaigns(token_info):
return jsonify(campaigns), 200


def list_removal_queue(token_info):
validate_admin_access(token_info)

with Transaction() as t:
repo = RemovalQueueRepo(t)
requests = repo.get_all_account_removal_requests()
return jsonify(requests), 200


def post_campaign_information(body, token_info):
validate_admin_access(token_info)

Expand Down Expand Up @@ -656,6 +681,20 @@ def generate_activation_codes(body, token_info):
return jsonify(results), 200


def generate_ffq_codes(body, token_info):
validate_admin_access(token_info)

quantity = body.get("code_quantity", 1)
with Transaction() as t:
admin_repo = AdminRepo(t)
code_list = []
for i in range(quantity):
code_list.append(admin_repo.create_ffq_code())
t.commit()

return jsonify(code_list), 200


def list_barcode_query_fields(token_info):
validate_admin_access(token_info)

Expand Down Expand Up @@ -796,7 +835,6 @@ def delete_account(account_id, token_info):
src_repo = SourceRepo(t)
samp_repo = SampleRepo(t)
sar_repo = SurveyAnswersRepo(t)
template_repo = SurveyTemplateRepo(t)

acct = acct_repo.get_account(account_id)
if acct is None:
Expand All @@ -806,8 +844,6 @@ def delete_account(account_id, token_info):
if acct.account_type == 'deleted':
return None, 204

sample_count = 0
account_has_external = False
sources = src_repo.get_sources_in_account(
account_id,
allow_revoked=True
Expand All @@ -820,50 +856,61 @@ def delete_account(account_id, token_info):
allow_revoked=True
)

has_samples = len(samples) > 0
sample_count += len(samples)
has_external = template_repo.has_external_surveys(account_id,
source.id)

if has_external:
account_has_external = True

for sample in samples:
# we scrub rather than disassociate in the event that the
# sample is in our freezers but not with an up-to-date scan
samp_repo.scrub(account_id, source.id, sample.id)

surveys = sar_repo.list_answered_surveys(account_id, source.id)
if has_samples or has_external:
# if we have samples or external surveys, we need to scrub
# survey / source free text
for survey_id in surveys:
sar_repo.scrub(account_id, source.id, survey_id)

# We're including scrubbed sources to detect external surveys
# so we need to make sure the source isn't already scrubbed
if source.source_data.date_revoked is None:
src_repo.scrub(account_id, source.id)

if not has_samples and not has_external:
# if we do not have associated samples, or external surveys,
# then the source is safe to delete
for survey_id in surveys:
sar_repo.delete_answered_survey(account_id, survey_id)
src_repo.delete_source(account_id, source.id)

# an account is safe to delete if there are no associated samples
# and does not have external surveys
if sample_count > 0 or account_has_external:
acct_repo.scrub(account_id)
else:
acct_repo.delete_account(account_id)
for survey_id in surveys:
sar_repo.scrub(account_id, source.id, survey_id)

# We're including scrubbed sources to detect external surveys
# so we need to make sure the source isn't already scrubbed
if source.source_data.date_revoked is None:
src_repo.scrub(account_id, source.id)

acct_repo.scrub(account_id)

t.commit()

return None, 204


def ignore_removal_request(account_id, token_info):
validate_admin_access(token_info)

with Transaction() as t:
rq_repo = RemovalQueueRepo(t)
try:
# remove the user from the queue, noting the admin who allowed it
# and the time the action was performed.
rq_repo.update_queue(account_id, token_info['email'], 'ignored')
t.commit()
except RepoException as e:
raise e

return None, 204


def allow_removal_request(account_id, token_info):
validate_admin_access(token_info)

with Transaction() as t:
rq_repo = RemovalQueueRepo(t)

try:
# remove the user from the queue, noting the admin who allowed it
# and the time the action was performed.
rq_repo.update_queue(account_id, token_info['email'], 'deleted')
t.commit()
except RepoException as e:
raise e

# delete the user
return delete_account(account_id, token_info)


def get_vioscreen_sample_to_user(token_info):
validate_admin_access(token_info)
with Transaction() as t:
Expand Down
32 changes: 32 additions & 0 deletions microsetta_private_api/admin/email_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,38 @@ class EmailMessage(Enum):
EventType.EMAIL,
EventSubtype.EMAIL_SUBMIT_INTEREST_CONFIRMATION
)
thank_you_with_kit = (
gettext(
"Registration code & kit update!"),
"email/thank_you_with_kit.jinja2",
("first_name", "registration_code", "interface_endpoint"),
EventType.EMAIL,
EventSubtype.EMAIL_THANK_YOU_WITH_KIT
)
thank_you_no_kit = (
gettext(
"Your questionnaire is ready!"),
"email/thank_you_no_kit.jinja2",
("first_name", "registration_code", "interface_endpoint"),
EventType.EMAIL,
EventSubtype.EMAIL_THANK_YOU_NO_KIT
)
kit_tracking_number = (
gettext(
"Your kit is on its way!"),
"email/kit_tracking_number.jinja2",
("first_name", "tracking_number"),
EventType.EMAIL,
EventSubtype.EMAIL_KIT_TRACKING_NUMBER
)
subscription_ffq_code = (
gettext(
"Registration code & kit update!"),
"email/subscription_ffq_code.jinja2",
("first_name", "tracking_number", "interface_endpoint"),
EventType.EMAIL,
EventSubtype.EMAIL_SUBSCRIPTION_FFQ_CODE
)

def __init__(self, subject, html, required, event_type, event_sub):
self.subject = subject
Expand Down
3 changes: 0 additions & 3 deletions microsetta_private_api/admin/sample_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ def per_sample(project, barcodes, strip_sampleid):
source = diag['source']

account_email = None if account is None else account.email
source_email = None
source_type = None if source is None else source.source_type
vio_id = None

if source is not None and source_type == Source.SOURCE_TYPE_HUMAN:
source_email = source.source_data.email

vio_id = template_repo.get_vioscreen_id_if_exists(account.id,
source.id,
Expand Down Expand Up @@ -75,7 +73,6 @@ def per_sample(project, barcodes, strip_sampleid):
"project": project,
"source-type": source_type,
"site-sampled": sample_site,
"source-email": source_email,
"account-email": account_email,
"vioscreen_username": vio_id,
"ffq-taken": ffq_taken,
Expand Down
Loading

0 comments on commit 8ccb2be

Please sign in to comment.