Skip to content
Snippets Groups Projects
Commit bf7c8998 authored by Nathaniel Kofalt's avatar Nathaniel Kofalt
Browse files

Merge pull request #120 from scitran/project-bugfix

Allow rule hierarchy walking on more container types
parents 84b182f4 b1d93a7f
No related branches found
No related tags found
No related merge requests found
...@@ -136,8 +136,7 @@ def create_jobs(db, container, container_type, file_): ...@@ -136,8 +136,7 @@ def create_jobs(db, container, container_type, file_):
job_list = [] job_list = []
# Get configured rules for this project # Get configured rules for this project
project = get_project_for_container(db, container) rules = get_rules_for_container(db, container)
rules = project.get('rules', [])
# Add hardcoded rules that cannot be removed or changed # Add hardcoded rules that cannot be removed or changed
for hardcoded_rule in HARDCODED_RULES: for hardcoded_rule in HARDCODED_RULES:
...@@ -153,14 +152,16 @@ def create_jobs(db, container, container_type, file_): ...@@ -153,14 +152,16 @@ def create_jobs(db, container, container_type, file_):
return job_list return job_list
# TODO: consider moving to a module that has a variety of hierarchy-management helper functions # TODO: consider moving to a module that has a variety of hierarchy-management helper functions
def get_project_for_container(db, container): def get_rules_for_container(db, container):
""" """
Recursively walk the hierarchy until the project object is found. Recursively walk the hierarchy until the project object is found.
""" """
if 'session' in container: if 'session' in container:
session = db.sessions.find_one({'_id': container['session']}) session = db.sessions.find_one({'_id': container['session']})
return get_project_for_container(db, session) return get_rules_for_container(db, session)
elif 'project' in container: elif 'project' in container:
project = db.projects.find_one({'_id': container['project']}) project = db.projects.find_one({'_id': container['project']})
return project return get_rules_for_container(db, project)
raise Exception('Hierarchy walking not implemented for container ' + str(container['_id'])) else:
# Assume container is a project, or a collection (which currently cannot have a rules property)
return container.get('rules', [])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment