Skip to content

Commit

Permalink
fix: resolve issues with initdev command
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe committed Oct 24, 2024
1 parent 7fea8c7 commit 1891fb5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,19 @@ family:
metaData: *metadata-prototype
pedigree:
persons:
- familyId: {{ data_case }}
- familyId: {{ case_name }}
individualId: index
paternalId: father
maternalId: mother
sex: MALE
affectedStatus: AFFECTED
- familyId: {{ data_case }}
- familyId: {{ case_name }}
individualId: father
paternalId: "0"
maternalId: "0"
sex: MALE
affectedStatus: UNAFFECTED
- familyId: {{ data_case }}
- familyId: {{ case_name }}
individualId: mother
paternalId: "0"
maternalId: "0"
Expand Down
24 changes: 20 additions & 4 deletions backend/varfish/users/management/commands/initdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def handle(self, *args, **options):
data_release = options["data_release"]
data_case = options["data_case"]
data_create = options["data_create"]
reset_password = options["reset_password"]

job_pk: Optional[int] = None
with transaction.atomic():
Expand All @@ -98,6 +99,7 @@ def handle(self, *args, **options):
data_release=data_release,
data_case=data_case,
data_create=data_create,
reset_password=reset_password,
)
self.stderr.write(self.style.SUCCESS("-- comitting transaction --"))
if data_create == "job-create" and job_pk is not None:
Expand All @@ -119,6 +121,7 @@ def _handle(
data_release: Literal["grch37", "grch38"],
data_case: str,
data_create: Literal["disabled", "job-create", "job-run"],
reset_password: bool,
) -> Optional[int]:
"""Handle the actual initialization, called within ``transaction.atomic()``.
Expand All @@ -128,9 +131,13 @@ def _handle(
job_pk: Optional[int] = None
try:
self._setup_seqmeta()
self._create_user(username="root", is_superuser=True, is_staff=True)
self._create_user(username="devadmin", is_superuser=True, is_staff=True)
devuser = self._create_user(username="devuser")
self._create_user(
username="root", is_superuser=True, is_staff=True, reset_password=reset_password
)
self._create_user(
username="devadmin", is_superuser=True, is_staff=True, reset_password=reset_password
)
devuser = self._create_user(username="devuser", reset_password=reset_password)
category = self._create_project(
title=category_name, owner=devuser, project_type="CATEGORY"
)
Expand Down Expand Up @@ -211,13 +218,15 @@ def _create_user(
if created:
password = str(uuid4())
obj.set_password(password)
obj.save()
self.stderr.write(
self.style.SUCCESS(f"Created user {username}. Password is '{password}'")
)
else:
if reset_password:
password = str(uuid4())
obj.set_password(password)
obj.save()
self.stderr.write(
self.style.SUCCESS(
f"Reset password for user {username}. New password is '{password}'"
Expand Down Expand Up @@ -400,6 +409,8 @@ def _create_import_job(
Create an import job into the given ``project`` using the development
data with the given ``name``.
"""
# Check whether the case already exists.
case_exists = Case.objects.filter(project=project, name=case_name).exists()
# Read the phenopacket template and replace variables.
data_path = pathlib.Path(__file__).parent / "data"
with open(data_path / f"{data_case}.{data_release}.yaml.tpl") as f:
Expand All @@ -408,6 +419,7 @@ def _create_import_job(
pp_yaml = pp_yaml_tpl.render(
Context(
{
"case_name": case_name,
"data_case": data_case,
"data_path": str(data_path),
}
Expand All @@ -423,7 +435,11 @@ def _create_import_job(
job = CaseImportBackgroundJob.objects.create_full(
caseimportaction=CaseImportAction.objects.create(
project=project,
action=CaseImportAction.ACTION_CREATE,
action=(
CaseImportAction.ACTION_UPDATE
if case_exists
else CaseImportAction.ACTION_CREATE
),
payload=payload,
),
user=user,
Expand Down

0 comments on commit 1891fb5

Please sign in to comment.