From 44abfbfec259cda49c787d5268760a40bda21e61 Mon Sep 17 00:00:00 2001 From: Brian Scorcia Date: Thu, 11 Nov 2021 15:44:37 -0500 Subject: [PATCH] #294: Created new ColdFront config vars that allow users to decide whether or not to allow allocation change requests by default and to customize the list of days users can request allocation extensions --- coldfront/config/core.py | 2 ++ coldfront/core/allocation/forms.py | 7 ++++++- coldfront/core/allocation/views.py | 3 +++ docs/pages/config.md | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/coldfront/config/core.py b/coldfront/config/core.py index 2823494fb..3c68dfaa2 100644 --- a/coldfront/config/core.py +++ b/coldfront/config/core.py @@ -21,6 +21,8 @@ #------------------------------------------------------------------------------ # Allocation related #------------------------------------------------------------------------------ +ALLOCATION_ENABLE_CHANGE_REQUESTS_BY_DEFAULT = ENV.bool('ALLOCATION_ENABLE_CHANGE_REQUESTS', default=True) +ALLOCATION_CHANGE_REQUEST_EXTENSION_DAYS = ENV.list('ALLOCATION_CHANGE_REQUEST_EXTENSION_DAYS', cast=int, default=[30, 60, 90]) ALLOCATION_ENABLE_ALLOCATION_RENEWAL = ENV.bool('ALLOCATION_ENABLE_ALLOCATION_RENEWAL', default=True) ALLOCATION_FUNCS_ON_EXPIRE = ['coldfront.core.allocation.utils.test_allocation_function', ] diff --git a/coldfront/core/allocation/forms.py b/coldfront/core/allocation/forms.py index 5ed1fcc68..4165c38de 100644 --- a/coldfront/core/allocation/forms.py +++ b/coldfront/core/allocation/forms.py @@ -12,6 +12,8 @@ ALLOCATION_ACCOUNT_ENABLED = import_from_settings( 'ALLOCATION_ACCOUNT_ENABLED', False) +ALLOCATION_CHANGE_REQUEST_EXTENSION_DAYS = import_from_settings( + 'ALLOCATION_CHANGE_REQUEST_EXTENSION_DAYS', []) class AllocationForm(forms.Form): @@ -198,8 +200,11 @@ def clean(self): class AllocationChangeForm(forms.Form): EXTENSION_CHOICES = [ - (0, "----"), (30, "30 days"), (60, "60 days"), (90, "90 days") + (0, "----") ] + for choice in ALLOCATION_CHANGE_REQUEST_EXTENSION_DAYS: + EXTENSION_CHOICES.append((choice, "{} days".format(choice))) + end_date_extension = forms.TypedChoiceField( label='Request End Date Extension', choices = EXTENSION_CHOICES, diff --git a/coldfront/core/allocation/views.py b/coldfront/core/allocation/views.py index e8232f3de..8d73e79bb 100644 --- a/coldfront/core/allocation/views.py +++ b/coldfront/core/allocation/views.py @@ -62,6 +62,8 @@ 'ALLOCATION_ENABLE_ALLOCATION_RENEWAL', True) ALLOCATION_DEFAULT_ALLOCATION_LENGTH = import_from_settings( 'ALLOCATION_DEFAULT_ALLOCATION_LENGTH', 365) +ALLOCATION_ENABLE_CHANGE_REQUESTS_BY_DEFAULT = import_from_settings( + 'ALLOCATION_ENABLE_CHANGE_REQUESTS_BY_DEFAULT', True) EMAIL_ENABLED = import_from_settings('EMAIL_ENABLED', False) if EMAIL_ENABLED: @@ -1060,6 +1062,7 @@ def get(self, request, pk): allocation_obj.status = allocation_status_active_obj allocation_obj.start_date = start_date allocation_obj.end_date = end_date + if ALLOCATION_ENABLE_CHANGE_REQUESTS_BY_DEFAULT: allocation_obj.is_changeable = True allocation_obj.save() messages.success(request, 'Allocation to {} has been ACTIVATED for {} {} ({})'.format( diff --git a/docs/pages/config.md b/docs/pages/config.md index 997983293..f2300f7ed 100644 --- a/docs/pages/config.md +++ b/docs/pages/config.md @@ -86,6 +86,8 @@ The following settings are ColdFront specific settings related to the core appli | PROJECT_ENABLE_PROJECT_REVIEW | Enable or disable project reviews. Default True| | ALLOCATION_ENABLE_ALLOCATION_RENEWAL | Enable or disable allocation renewals. Default True | | ALLOCATION_DEFAULT_ALLOCATION_LENGTH | Default number of days an allocation is active for. Default 365 | +| ALLOCATION_ENABLE_CHANGE_REQUESTS_BY_DEFAULT | Enable or disable allocation change requests. Default True | +| ALLOCATION_CHANGE_REQUEST_EXTENSION_DAYS | List of days users can request extensions in an allocation change request. Default 30,60,90 | | ALLOCATION_ACCOUNT_ENABLED | Allow user to select account name for allocation. Default False | | INVOICE_ENABLED | Enable or disable invoices. Default True | | ONDEMAND_URL | The URL to your Open OnDemand installation |