Skip to content

Commit

Permalink
feat: optionally allow modifications of all spend limit fields in dja…
Browse files Browse the repository at this point in the history
…ngo admin

...regardless of policy type
  • Loading branch information
iloveagent57 committed Sep 21, 2023
1 parent 01aac35 commit 47b1c64
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,7 @@ dmypy.json
.vscode

# Generated docs not useful
docs/generated/
docs/generated/

# private django settings
enterprise_access/settings/private.py
45 changes: 43 additions & 2 deletions enterprise_access/apps/subsidy_access_policy/admin.py
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
}
),
]
Expand Down Expand Up @@ -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
}
),
]
3 changes: 3 additions & 0 deletions enterprise_access/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 47b1c64

Please sign in to comment.