diff --git a/openedx/features/subscriptions/api/v1/serializers.py b/openedx/features/subscriptions/api/v1/serializers.py index aaf9db54b49c..91901efa3ac9 100644 --- a/openedx/features/subscriptions/api/v1/serializers.py +++ b/openedx/features/subscriptions/api/v1/serializers.py @@ -15,7 +15,7 @@ class UserSubscriptionSerializer(serializers.ModelSerializer): class Meta: model = UserSubscription - fields = ['subscription_id', 'subscription_type', 'expiration_date', 'course_enrollments', 'max_allowed_courses', 'user'] + fields = ['subscription_id', 'subscription_type', 'description', 'expiration_date', 'course_enrollments', 'max_allowed_courses', 'user'] def to_internal_value(self, data): """ diff --git a/openedx/features/subscriptions/api/v1/tests/factories.py b/openedx/features/subscriptions/api/v1/tests/factories.py index 351742ae4d8b..2ceb7a85bb94 100644 --- a/openedx/features/subscriptions/api/v1/tests/factories.py +++ b/openedx/features/subscriptions/api/v1/tests/factories.py @@ -1,7 +1,7 @@ from datetime import date import factory from factory import SubFactory -from factory.fuzzy import FuzzyDate, FuzzyInteger +from factory.fuzzy import FuzzyDate, FuzzyInteger, FuzzyText from factory.django import DjangoModelFactory from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory @@ -22,6 +22,7 @@ class Meta(object): expiration_date = FuzzyDate(start_date=date.today(), end_date=date.today()) subscription_type = UserSubscription.LIMITED_ACCESS site = SubFactory(SiteFactory) + description = FuzzyText(length=50) @factory.post_generation def course_enrollments(self, create, extracted, **kwargs): diff --git a/openedx/features/subscriptions/api/v1/tests/test_models.py b/openedx/features/subscriptions/api/v1/tests/test_models.py index d83407b74450..69adba99c821 100644 --- a/openedx/features/subscriptions/api/v1/tests/test_models.py +++ b/openedx/features/subscriptions/api/v1/tests/test_models.py @@ -49,7 +49,7 @@ def setUp(self): # Lifetime access subscription (None, None, UserSubscription.LIFETIME_ACCESS, 1, None, True), ) - def test_is_active(self, max_allowed_courses, expiration_date, subscription_type, subscription_id, number_of_enrollments, expected_value): + def test_is_active(self, max_allowed_courses, expiration_date, subscription_type, subscription_id, number_of_enrollments, expected_value, description): """ Verify the method properly maps mode slugs to display names. """ @@ -59,7 +59,8 @@ def test_is_active(self, max_allowed_courses, expiration_date, subscription_type subscription_type=subscription_type, subscription_id=subscription_id, user=self.user, - site=self.site + site=self.site, + description=description ) if number_of_enrollments: course_enrollments = _get_course_enrollments(number_of_enrollments, self.user) @@ -84,7 +85,7 @@ def test_is_active(self, max_allowed_courses, expiration_date, subscription_type # Lifetime access subscription (None, None, UserSubscription.LIFETIME_ACCESS, 1, None, True), ) - def test_is_valid(self, max_allowed_courses, expiration_date, subscription_type, subscription_id, number_of_enrollments, expected_value): + def test_is_valid(self, max_allowed_courses, expiration_date, subscription_type, subscription_id, number_of_enrollments, expected_value, description): """ Verify the method returns the slug if it has no known mapping. """ @@ -93,7 +94,8 @@ def test_is_valid(self, max_allowed_courses, expiration_date, subscription_type, expiration_date=expiration_date, subscription_type=subscription_type, subscription_id=subscription_id, - user=self.user + user=self.user, + description=description ) if number_of_enrollments: course_enrollments = _get_course_enrollments(number_of_enrollments, self.user) @@ -118,7 +120,7 @@ def test_is_valid(self, max_allowed_courses, expiration_date, subscription_type, # Lifetime access subscription (None, None, UserSubscription.LIFETIME_ACCESS, 1, None, True), ) - def test_get_valid_subscription(self, max_allowed_courses, expiration_date, subscription_type, subscription_id, number_of_enrollments, expected_value): + def test_get_valid_subscription(self, max_allowed_courses, expiration_date, subscription_type, subscription_id, number_of_enrollments, expected_value, description): """ Verify that get_valid_subscription returns valid subscription correctly. """ @@ -128,7 +130,8 @@ def test_get_valid_subscription(self, max_allowed_courses, expiration_date, subs subscription_type=subscription_type, subscription_id=subscription_id, user=self.user, - site=self.site + site=self.site, + description=description ) if number_of_enrollments: course_enrollments = _get_course_enrollments(number_of_enrollments, self.user) @@ -152,7 +155,8 @@ def test_user_subscription_post_update_receiver(self): subscription_type=UserSubscription.LIMITED_ACCESS, subscription_id=1, user=self.user, - site=self.site + site=self.site, + description=description ) user_subscription_history = UserSubscriptionHistory.objects.filter( site=user_subscription.site, diff --git a/openedx/features/subscriptions/api/v1/tests/test_serializers.py b/openedx/features/subscriptions/api/v1/tests/test_serializers.py index 06a1987ad38c..04b77148bc7b 100644 --- a/openedx/features/subscriptions/api/v1/tests/test_serializers.py +++ b/openedx/features/subscriptions/api/v1/tests/test_serializers.py @@ -24,5 +24,6 @@ def test_user_subscription_seriaizer(self): 'subscription_type': user_subscription.subscription_type, 'user': user_subscription.user.id, 'course_enrollments': [], + 'description': user_subscription.description, } ) diff --git a/openedx/features/subscriptions/migrations/0004_usersubscription_description.py b/openedx/features/subscriptions/migrations/0004_usersubscription_description.py new file mode 100644 index 000000000000..72971f04149f --- /dev/null +++ b/openedx/features/subscriptions/migrations/0004_usersubscription_description.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.29 on 2020-12-01 13:36 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('subscriptions', '0003_add_user_subscription_history_model'), + ] + + operations = [ + migrations.AddField( + model_name='usersubscription', + name='description', + field=models.TextField(blank=True, verbose_name='Description'), + ), + ] diff --git a/openedx/features/subscriptions/migrations/0005_usersubscriptionhistory_description.py b/openedx/features/subscriptions/migrations/0005_usersubscriptionhistory_description.py new file mode 100644 index 000000000000..f6f211352d85 --- /dev/null +++ b/openedx/features/subscriptions/migrations/0005_usersubscriptionhistory_description.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.29 on 2020-12-02 10:43 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('subscriptions', '0004_usersubscription_description'), + ] + + operations = [ + migrations.AddField( + model_name='usersubscriptionhistory', + name='description', + field=models.TextField(blank=True, verbose_name='Description'), + ), + ] diff --git a/openedx/features/subscriptions/models.py b/openedx/features/subscriptions/models.py index eb5c49955cdc..282d4f047720 100644 --- a/openedx/features/subscriptions/models.py +++ b/openedx/features/subscriptions/models.py @@ -22,7 +22,8 @@ class UserSubscription(TimeStampedModel): user = models.ForeignKey(User, on_delete=models.CASCADE) subscription_id = models.PositiveIntegerField(db_index=True) expiration_date = models.DateField(default=None, null=True, blank=True) - + description = models.TextField(_('Description'), blank=True) + LIMITED_ACCESS = 'limited-access' FULL_ACCESS_COURSES = 'full-access-courses' FULL_ACCESS_TIME_PERIOD = 'full-access-time-period' @@ -117,6 +118,7 @@ class UserSubscriptionHistory(TimeStampedModel): user = models.ForeignKey(User, on_delete=models.CASCADE) subscription_id = models.PositiveIntegerField() expiration_date = models.DateField(default=None, null=True, blank=True) + description = models.TextField(_('Description'), blank=True) LIMITED_ACCESS = 'limited-access' FULL_ACCESS_COURSES = 'full-access-courses' @@ -167,7 +169,8 @@ def update_user_subscription_history(sender, instance, **kwargs): # pylint: dis subscription_id=instance.subscription_id, expiration_date=instance.expiration_date, subscription_type=instance.subscription_type, - max_allowed_courses=instance.max_allowed_courses + max_allowed_courses=instance.max_allowed_courses, + description=instance.description ) for course_enrollment in instance.course_enrollments.all(): user_subscription_history.course_enrollments.add(course_enrollment)