From f291da19cb5dce76277ba8d5935f971e0108176f Mon Sep 17 00:00:00 2001 From: rutvikrj26 Date: Wed, 13 Mar 2024 12:08:42 -0400 Subject: [PATCH 1/2] Updated forms and added an environment variable for managing allowed access policies --- physionet-django/physionet/settings/base.py | 5 +++++ physionet-django/project/forms.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/physionet-django/physionet/settings/base.py b/physionet-django/physionet/settings/base.py index 9afa819d0f..2c829ab572 100644 --- a/physionet-django/physionet/settings/base.py +++ b/physionet-django/physionet/settings/base.py @@ -644,3 +644,8 @@ class StorageTypes: # Emails PROJECT_EDITOR_EMAIL = config('PROJECT_EDITOR_EMAIL', default='') + +ALLOWED_ACCESS_POLICIES = os.environ.get( + 'ALLOWED_ACCESS_POLICIES', + 'OPEN,RESTRICTED,CREDENTIALED,CONTRIBUTOR_REVIEW' +).split(',') diff --git a/physionet-django/project/forms.py b/physionet-django/project/forms.py index 22ee0839a1..3c82cfd637 100644 --- a/physionet-django/project/forms.py +++ b/physionet-django/project/forms.py @@ -876,6 +876,13 @@ def __init__(self, *args, **kwargs): if not settings.ENABLE_FILE_DOWNLOADS_OPTION: del self.fields['allow_file_downloads'] + allowed_policies = [] + for policy in AccessPolicy: + if policy.name in settings.ALLOWED_ACCESS_POLICIES: + allowed_policies.append((policy.value, policy.name.replace("_", " ").title())) + + self.fields['access_policy'].choices = tuple(allowed_policies) + if self.access_policy is None: self.access_policy = self.instance.access_policy From 3aef7b429d3854339f06ae0b25fe29435f4f3a4d Mon Sep 17 00:00:00 2001 From: rutvikrj26 Date: Tue, 19 Mar 2024 09:29:07 -0400 Subject: [PATCH 2/2] Addressing comments - replaced os.get with config and the form values --- physionet-django/physionet/settings/base.py | 4 ++-- physionet-django/project/forms.py | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/physionet-django/physionet/settings/base.py b/physionet-django/physionet/settings/base.py index 2c829ab572..aa14b2fb0b 100644 --- a/physionet-django/physionet/settings/base.py +++ b/physionet-django/physionet/settings/base.py @@ -645,7 +645,7 @@ class StorageTypes: # Emails PROJECT_EDITOR_EMAIL = config('PROJECT_EDITOR_EMAIL', default='') -ALLOWED_ACCESS_POLICIES = os.environ.get( +ALLOWED_ACCESS_POLICIES = config( 'ALLOWED_ACCESS_POLICIES', - 'OPEN,RESTRICTED,CREDENTIALED,CONTRIBUTOR_REVIEW' + default='OPEN,RESTRICTED,CREDENTIALED,CONTRIBUTOR_REVIEW' ).split(',') diff --git a/physionet-django/project/forms.py b/physionet-django/project/forms.py index 3c82cfd637..89804bd803 100644 --- a/physionet-django/project/forms.py +++ b/physionet-django/project/forms.py @@ -876,12 +876,11 @@ def __init__(self, *args, **kwargs): if not settings.ENABLE_FILE_DOWNLOADS_OPTION: del self.fields['allow_file_downloads'] - allowed_policies = [] - for policy in AccessPolicy: - if policy.name in settings.ALLOWED_ACCESS_POLICIES: - allowed_policies.append((policy.value, policy.name.replace("_", " ").title())) - - self.fields['access_policy'].choices = tuple(allowed_policies) + if settings.ALLOWED_ACCESS_POLICIES: + self.fields['access_policy'].choices = [ + (value, label) for (value, label) in AccessPolicy.choices() + if AccessPolicy(value).name in settings.ALLOWED_ACCESS_POLICIES + ] if self.access_policy is None: self.access_policy = self.instance.access_policy