From 47b1c646aabacc831fc50fff171ea5ef30dae2df Mon Sep 17 00:00:00 2001 From: Alex Dusenbery Date: Thu, 21 Sep 2023 15:14:17 -0400 Subject: [PATCH] feat: optionally allow modifications of all spend limit fields in django admin ...regardless of policy type --- .gitignore | 5 ++- .../apps/subsidy_access_policy/admin.py | 45 ++++++++++++++++++- enterprise_access/settings/base.py | 3 ++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7be375f4..359e2509 100644 --- a/.gitignore +++ b/.gitignore @@ -146,4 +146,7 @@ dmypy.json .vscode # Generated docs not useful -docs/generated/ \ No newline at end of file +docs/generated/ + +# private django settings +enterprise_access/settings/private.py diff --git a/enterprise_access/apps/subsidy_access_policy/admin.py b/enterprise_access/apps/subsidy_access_policy/admin.py index a337d7d0..cca3c717 100644 --- a/enterprise_access/apps/subsidy_access_policy/admin.py +++ b/enterprise_access/apps/subsidy_access_policy/admin.py @@ -1,11 +1,24 @@ """ Admin configuration for subsidy_access_policy models. """ +from django.conf import settings from django.contrib import admin from django.utils.text import Truncator # for shortening a text from djangoql.admin import DjangoQLSearchMixin from enterprise_access.apps.subsidy_access_policy import constants, models +EVERY_SPEND_LIMIT_FIELD = [ + 'spend_limit', + 'policy_spend_limit_dollars', + 'per_learner_spend_limit', + 'per_learner_spend_limit_dollars', + 'per_learner_enrollment_limit', +] + + +def super_admin_enabled(): + return getattr(settings, 'DJANGO_ADMIN_POLICY_SUPER_ADMIN', False) + def cents_to_usd_string(cents): """ @@ -72,6 +85,34 @@ class PerLearnerEnrollmentCreditAccessPolicy(DjangoQLSearchMixin, BaseSubsidyAcc 'subsidy_uuid', ) + fieldsets = [ + ( + 'Base configuration', + { + 'fields': [ + 'enterprise_customer_uuid', + 'display_name', + 'description', + 'active', + 'catalog_uuid', + 'subsidy_uuid', + 'created', + 'modified', + ] + } + ), + ( + 'Spend limits', + { + 'fields': [ + 'spend_limit', + 'policy_spend_limit_dollars', + 'per_learner_enrollment_limit', + ] if not super_admin_enabled() else EVERY_SPEND_LIMIT_FIELD + } + ), + ] + @admin.register(models.PerLearnerSpendCreditAccessPolicy) class PerLearnerSpendCreditAccessPolicy(DjangoQLSearchMixin, BaseSubsidyAccessPolicyMixin): @@ -116,7 +157,7 @@ class PerLearnerSpendCreditAccessPolicy(DjangoQLSearchMixin, BaseSubsidyAccessPo 'policy_spend_limit_dollars', 'per_learner_spend_limit', 'per_learner_spend_limit_dollars', - ] + ] if not super_admin_enabled() else EVERY_SPEND_LIMIT_FIELD } ), ] @@ -164,7 +205,7 @@ class LearnerContentAssignmentAccessPolicy(DjangoQLSearchMixin, BaseSubsidyAcces 'fields': [ 'spend_limit', 'policy_spend_limit_dollars', - ] + ] if not super_admin_enabled() else EVERY_SPEND_LIMIT_FIELD } ), ] diff --git a/enterprise_access/settings/base.py b/enterprise_access/settings/base.py index 11039523..383b63e0 100644 --- a/enterprise_access/settings/base.py +++ b/enterprise_access/settings/base.py @@ -465,3 +465,6 @@ def root(*path_fragments): # Enterprise Subsidy API Client settings ENTERPRISE_SUBSIDY_API_CLIENT_VERSION = 2 + +# Allows broader modification of access policy records from django admin +DJANGO_ADMIN_POLICY_SUPER_ADMIN = False