Skip to content

Commit

Permalink
feat: Add custom license expiration v2 fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
macdiesel committed Oct 31, 2024
1 parent e0d443c commit acb9a7f
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 5 deletions.
46 changes: 41 additions & 5 deletions license_manager/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ class MinimalCustomerAgreementSerializer(serializers.ModelSerializer):
"""

subscription_for_auto_applied_licenses = serializers.SerializerMethodField()
has_custom_license_expiration_messaging_v2 = serializers.SerializerMethodField()
modal_header_text_v2 = serializers.SerializerMethodField()
expired_subscription_modal_messaging_v2 = serializers.SerializerMethodField()
button_label_in_modal_v2 = serializers.SerializerMethodField()
url_for_button_in_modal_v2 = serializers.SerializerMethodField()

class Meta:
model = CustomerAgreement
Expand All @@ -355,17 +360,48 @@ class Meta:
'subscription_for_auto_applied_licenses',
'available_subscription_catalogs',
'enable_auto_applied_subscriptions_with_universal_link',
'has_custom_license_expiration_messaging',
'modal_header_text',
'expired_subscription_modal_messaging',
'button_label_in_modal',
'url_for_button_in_modal',
'has_custom_license_expiration_messaging_v2',
'modal_header_text_v2',
'expired_subscription_modal_messaging_v2',
'button_label_in_modal_v2',
'url_for_button_in_modal_v2',
]

def get_subscription_for_auto_applied_licenses(self, obj):
subscription_plan = obj.auto_applicable_subscription
return subscription_plan.uuid if subscription_plan else None

def has_custom_license_expiration_messaging_v2(self, obj):
custom_subscription_expiration_messaging = obj.custom_subscription_expiration_messaging
if custom_subscription_expiration_messaging:
return custom_subscription_expiration_messaging.has_custom_license_expiration_messaging
return None

def get_modal_header_text_v2(self, obj):
custom_subscription_expiration_messaging = obj.custom_subscription_expiration_messaging
if custom_subscription_expiration_messaging:
return custom_subscription_expiration_messaging.modal_header_text
return None


def expired_subscription_modal_messaging_v2(self, obj):
custom_subscription_expiration_messaging = obj.custom_subscription_expiration_messaging
if custom_subscription_expiration_messaging:
return custom_subscription_expiration_messaging.expired_subscription_modal_messaging
return None

def button_label_in_modal_v2(self, obj):
custom_subscription_expiration_messaging = obj.custom_subscription_expiration_messaging
if custom_subscription_expiration_messaging:
return custom_subscription_expiration_messaging.button_label_in_modal
return None

def url_for_button_in_modal_v2(self, obj):
custom_subscription_expiration_messaging = obj.custom_subscription_expiration_messaging
if custom_subscription_expiration_messaging:
return custom_subscription_expiration_messaging.url_for_button_in_modal
return None


class CustomerAgreementSerializer(MinimalCustomerAgreementSerializer):
"""
Expand Down
57 changes: 57 additions & 0 deletions license_manager/apps/subscriptions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,63 @@ def __str__(self):
)
)

class CustomSubscriptionExpirationMessaging(models.Model):
"""
Custom subscription expiration messaging
"""

customer_agreement = models.OneToOneField(
CustomerAgreement,
on_delete=models.CASCADE,
null=False,
related_name='custom_subscription_expiration_messaging',
unique=True,
)

has_custom_license_expiration_messaging = models.BooleanField(
default=False,
help_text=_(
"Indicates if the customer has a unique license expiration experience, instead of the standard one."
)
)

modal_header_text = models.CharField(
max_length=512,
blank=True,
null=True,
help_text=_(
"The bold text that will appear as the header in the expiration modal."
)
)

expired_subscription_modal_messaging = models.TextField(
blank=True,
null=True,
help_text=_(
"The content of a modal that will appear to learners upon subscription expiration. This text can be used "
"for custom guidance per customer."
)
)

button_label_in_modal = models.CharField(
max_length=255,
blank=True,
null=True,
help_text=_(
"The text that will appear as on the button in the expiration modal"
)
)

url_for_button_in_modal = models.CharField(
max_length=512,
blank=True,
null=True,
help_text=_(
"The URL that should underly the sole button in the expiration modal"
)
)

history = HistoricalRecords()

class PlanType(models.Model):
"""
Expand Down

0 comments on commit acb9a7f

Please sign in to comment.