Skip to content

Commit

Permalink
Merge pull request #249 from CLIMB-TRE/development
Browse files Browse the repository at this point in the history
`override` option in `project` command input JSON file
  • Loading branch information
tombch authored Jan 13, 2025
2 parents d1ed393 + 106f781 commit 1fabcf3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions onyx/data/management/commands/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ChoiceInfoConfig(BaseModel):
class ChoiceConfig(BaseModel):
field: str
options: List[str | ChoiceInfoConfig]
override: bool = False


class ChoiceConstraintConfig(BaseModel):
Expand Down Expand Up @@ -123,8 +124,8 @@ def set_project(
# Mapping of scope to permissions
groups = {}

# List of choices
choices = []
# Mapping of field to choice configurations
choice_configs = {}

# List of choice constraints
choice_constraints = []
Expand All @@ -145,7 +146,13 @@ def set_project(
groups.setdefault(group.scope, []).extend(group.permissions)

if content.choices:
choices.extend(content.choices)
for choice_config in content.choices:
if choice_config.override:
choice_configs[choice_config.field] = [choice_config]
else:
choice_configs.setdefault(
choice_config.field, []
).append(choice_config)

if content.choice_constraints:
choice_constraints.extend(content.choice_constraints)
Expand All @@ -159,7 +166,13 @@ def set_project(

self.set_groups(project, group_configs)

if choices:
if choice_configs:
# Convert field/ChoiceConfig mapping to list of ChoiceConfig objects
choices = [
choice_config
for choice_config_list in choice_configs.values()
for choice_config in choice_config_list
]
self.set_choices(project, choices)

if choice_constraints:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "onyx"
version = "0.18.5"
version = "0.18.6"
description = "API for pathogen metadata."
authors = ["Thomas Brier <[email protected]>"]
license = "LICENSE"
Expand Down

0 comments on commit 1fabcf3

Please sign in to comment.