Skip to content

Commit

Permalink
ENT-1289 | Removing enterprise entitlement logic from codebase (#590)
Browse files Browse the repository at this point in the history
Updating tests and a few other spots I missed

Adding back in some things I should not have taken out

Bumping version and changelog
  • Loading branch information
christopappas authored Oct 2, 2019
1 parent efe35de commit d4b488c
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 484 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Change Log
Unreleased
----------

[2.0.0] - 2019-10-02
---------------------

* Removing EnterpriseCustomerEntitlement code

[1.11.0] - 2019-10-02
---------------------

Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

from __future__ import absolute_import, unicode_literals

__version__ = "1.11.0"
__version__ = "2.0.0"

default_app_config = "enterprise.apps.EnterpriseConfig" # pylint: disable=invalid-name
44 changes: 0 additions & 44 deletions enterprise/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
EnterpriseCustomer,
EnterpriseCustomerBrandingConfiguration,
EnterpriseCustomerCatalog,
EnterpriseCustomerEntitlement,
EnterpriseCustomerIdentityProvider,
EnterpriseCustomerReportingConfiguration,
EnterpriseCustomerType,
Expand Down Expand Up @@ -87,35 +86,6 @@ class EnterpriseCustomerIdentityProviderInline(admin.StackedInline):
form = EnterpriseCustomerIdentityProviderAdminForm


class EnterpriseCustomerEntitlementInline(admin.StackedInline):
"""
Django admin model for EnterpriseCustomerEntitlement.
The admin interface has the ability to edit models on the same page as a parent model. These are called inlines.
https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.StackedInline
"""

model = EnterpriseCustomerEntitlement
extra = 0
can_delete = True
fields = ('enterprise_customer', 'entitlement_id', 'ecommerce_coupon_url',)

def ecommerce_coupon_url(self, instance):
"""
Instance is EnterpriseCustomer. Return e-commerce coupon urls.
"""
if not instance.entitlement_id:
return "N/A"

return format_html(
'<a href="{base_url}/coupons/{id}" target="_blank">View coupon "{id}" details</a>',
base_url=settings.ECOMMERCE_PUBLIC_URL_ROOT, id=instance.entitlement_id
)

readonly_fields = ('ecommerce_coupon_url',)
ecommerce_coupon_url.allow_tags = True
ecommerce_coupon_url.short_description = 'Seat Entitlement URL'


class EnterpriseCustomerCatalogInline(admin.TabularInline):
"""
Django admin model for EnterpriseCustomerCatalog.
Expand Down Expand Up @@ -165,7 +135,6 @@ class EnterpriseCustomerAdmin(DjangoObjectActions, SimpleHistoryAdmin):
'has_logo',
'enable_dsc',
'has_identity_provider',
'has_ecommerce_coupons',
'uuid',
)

Expand All @@ -175,7 +144,6 @@ class EnterpriseCustomerAdmin(DjangoObjectActions, SimpleHistoryAdmin):
inlines = [
EnterpriseCustomerBrandingConfigurationInline,
EnterpriseCustomerIdentityProviderInline,
EnterpriseCustomerEntitlementInline,
EnterpriseCustomerCatalogInline,
]

Expand All @@ -192,18 +160,6 @@ class EnterpriseCustomerAdmin(DjangoObjectActions, SimpleHistoryAdmin):
class Meta(object):
model = EnterpriseCustomer

def has_ecommerce_coupons(self, instance):
"""
Return True if provded enterprise customer has ecommerce coupons.
Arguments:
instance (enterprise.models.EnterpriseCustomer): `EnterpriseCustomer` model instance
"""
return instance.enterprise_customer_entitlements.exists()

has_ecommerce_coupons.boolean = True
has_ecommerce_coupons.short_description = 'Ecommerce coupons'

def get_form(self, request, obj=None, **kwargs):
"""
Retrieve the appropriate form to use, saving the request user
Expand Down
33 changes: 1 addition & 32 deletions enterprise/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,6 @@ def get_enterprise_slug(self, obj):
return obj.enterprise_customer.slug


class EnterpriseCustomerEntitlementSerializer(serializers.ModelSerializer):
"""
Serializer for EnterpriseCustomerEntitlement model.
"""

class Meta:
model = models.EnterpriseCustomerEntitlement
fields = (
'enterprise_customer', 'entitlement_id'
)


class EnterpriseCustomerSerializer(serializers.ModelSerializer):
"""
Serializer for EnterpriseCustomer model.
Expand All @@ -117,17 +105,14 @@ class Meta:
model = models.EnterpriseCustomer
fields = (
'uuid', 'name', 'slug', 'active', 'site', 'enable_data_sharing_consent',
'enforce_data_sharing_consent', 'branding_configuration', 'enterprise_customer_entitlements',
'enforce_data_sharing_consent', 'branding_configuration',
'identity_provider', 'enable_audit_enrollment', 'replace_sensitive_sso_username',
'enable_portal_code_management_screen', 'sync_learner_profile_data', 'enable_audit_data_reporting',
'enable_learner_portal', 'learner_portal_hostname', 'enable_portal_reporting_config_screen'
)

site = SiteSerializer()
branding_configuration = EnterpriseCustomerBrandingConfigurationSerializer()
enterprise_customer_entitlements = EnterpriseCustomerEntitlementSerializer( # pylint: disable=invalid-name
many=True,
)


class EnterpriseCustomerBasicSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -353,22 +338,6 @@ def save(self): # pylint: disable=arguments-differ
ecu.save()


class EnterpriseCustomerUserEntitlementSerializer(ImmutableStateSerializer):
"""
Serializer for the entitlements of EnterpriseCustomerUser.
This Serializer is for read only endpoint of enterprise learner's entitlements
It will ignore any state changing requests like POST, PUT and PATCH.
"""

entitlements = serializers.ListField(
child=serializers.DictField()
)

user = UserSerializer(read_only=True)
enterprise_customer = EnterpriseCustomerSerializer(read_only=True)


class CourseDetailSerializer(ImmutableStateSerializer):
"""
Serializer for course data retrieved from the discovery service course detail API endpoint.
Expand Down
5 changes: 0 additions & 5 deletions enterprise/api/v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
views.EnterpriseCustomerBrandingConfigurationViewSet,
'enterprise-customer-branding',
)
router.register(
"enterprise-customer-entitlement",
views.EnterpriseCustomerEntitlementViewSet,
'enterprise-customer-entitlement',
)
router.register(
"enterprise_customer_reporting",
views.EnterpriseCustomerReportingConfigurationViewSet,
Expand Down
35 changes: 0 additions & 35 deletions enterprise/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,25 +264,6 @@ def get_serializer_class(self):
return serializers.EnterpriseCustomerUserReadOnlySerializer
return serializers.EnterpriseCustomerUserWriteSerializer

@detail_route()
def entitlements(self, request, pk=None): # pylint: disable=invalid-name,unused-argument
"""
Retrieve the list of entitlements available to this learner.
Only those entitlements are returned that satisfy enterprise customer's data sharing setting.
Arguments:
request (HttpRequest): Reference to in-progress request instance.
pk (Int): Primary key value of the selected enterprise learner.
Returns:
(HttpResponse): Response object containing a list of learner's entitlements.
"""
enterprise_customer_user = self.get_object()
instance = {"entitlements": enterprise_customer_user.entitlements}
serializer = serializers.EnterpriseCustomerUserEntitlementSerializer(instance, context={'request': request})
return Response(serializer.data)


class EnterpriseCustomerBrandingConfigurationViewSet(EnterpriseReadOnlyModelViewSet):
"""
Expand All @@ -301,22 +282,6 @@ class EnterpriseCustomerBrandingConfigurationViewSet(EnterpriseReadOnlyModelView
lookup_field = 'enterprise_customer__slug'


class EnterpriseCustomerEntitlementViewSet(EnterpriseReadOnlyModelViewSet):
"""
API views for the ``enterprise-customer-entitlements`` API endpoint.
"""

queryset = models.EnterpriseCustomerEntitlement.objects.all()
serializer_class = serializers.EnterpriseCustomerEntitlementSerializer

USER_ID_FILTER = 'enterprise_customer__enterprise_customer_users__user_id'
FIELDS = (
'enterprise_customer', 'entitlement_id',
)
filter_fields = FIELDS
ordering_fields = FIELDS


class EnterpriseCustomerCatalogViewSet(EnterpriseReadOnlyModelViewSet):
"""
API Views for performing search through course discovery at the ``enterprise_catalogs`` API endpoint.
Expand Down
90 changes: 0 additions & 90 deletions enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,53 +664,6 @@ def username(self):
return self.user.username
return None

@property
def entitlements(self):
"""
Return entitlement ids available to the learner along-with consent data.
Returns an empty list if enterprise customer requires data sharing consent and learner does not agree.
Returns:
(list): A list of entitlements that learner can avail. Each item in the list is a dict with two
key-value pairs,
{
"requires_consent": True ,
"entitlement_id": 1
}
"requires_consent": True if learner must consent to data
sharing in order to get benefits of entitlement.
"entitlement_id: id of the entitlements available to the learner.
"""
# Check if Enterprise Learner consents to data sharing and store the boolean result
DataSharingConsent = apps.get_model('consent', 'DataSharingConsent') # pylint: disable=invalid-name
learner_consent_enabled = DataSharingConsent.objects.filter(
enterprise_customer=self.enterprise_customer,
username=self.username,
granted=True,
).exists()

entitlements = self.enterprise_customer.enterprise_customer_entitlements

# If Enterprise Customer requires account course specific consent then we return all entitlements
# including whether or not to acquire learner's consent.
if self.enterprise_customer.enforces_data_sharing_consent(EnterpriseCustomer.AT_ENROLLMENT):
return [
{
"entitlement_id": entitlement.entitlement_id,
"requires_consent": not learner_consent_enabled,
} for entitlement in entitlements.all()
]

# for all other cases learner is eligible to all entitlements.
return [
{
"entitlement_id": entitlement.entitlement_id,
"requires_consent": False,
} for entitlement in entitlements.all()
]

@property
def data_sharing_consent_records(self):
"""
Expand Down Expand Up @@ -1059,49 +1012,6 @@ def sync_learner_profile_data(self):
return identity_provider is not None and identity_provider.sync_learner_profile_data


@python_2_unicode_compatible
class EnterpriseCustomerEntitlement(TimeStampedModel):
"""
Enterprise Customer Entitlement is a relationship between and Enterprise customer and its entitlements.
Users associated with an Enterprise Customer could be eligible for these entitlements resulting in partial or full
discounts while taking paid courses on the edX platform.
.. no_pii:
"""

class Meta(object):
app_label = 'enterprise'
verbose_name = _("Enterprise Customer Entitlement")
verbose_name_plural = _("Enterprise Customer Entitlements")
ordering = ['created']

enterprise_customer = models.ForeignKey(EnterpriseCustomer, related_name="enterprise_customer_entitlements")
entitlement_id = models.PositiveIntegerField(
blank=False,
null=False,
unique=True,
help_text=_("Enterprise customer's entitlement id for relationship with e-commerce coupon."),
verbose_name=_('Seat Entitlement')
)
history = HistoricalRecords()

def __str__(self):
"""
Return human-readable string representation.
"""
return "<EnterpriseCustomerEntitlement {customer}: {id}>".format(
customer=self.enterprise_customer,
id=self.entitlement_id
)

def __repr__(self):
"""
Return uniquely identifying string representation.
"""
return self.__str__()


@python_2_unicode_compatible
class EnterpriseCourseEnrollment(TimeStampedModel):
"""
Expand Down
21 changes: 0 additions & 21 deletions test_utils/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
EnterpriseCustomer,
EnterpriseCustomerBrandingConfiguration,
EnterpriseCustomerCatalog,
EnterpriseCustomerEntitlement,
EnterpriseCustomerIdentityProvider,
EnterpriseCustomerReportingConfiguration,
EnterpriseCustomerUser,
Expand Down Expand Up @@ -211,26 +210,6 @@ class Meta(object):
cohort_name = None


class EnterpriseCustomerEntitlementFactory(factory.django.DjangoModelFactory):
"""
EnterpriseCustomerEntitlement factory.
Creates an instance of EnterpriseCustomerEntitlement with minimal boilerplate - uses this class' attributes as
default parameters for EnterpriseCustomerEntitlementFactory constructor.
"""

class Meta(object):
"""
Meta for EnterpriseCustomerEntitlementFactory.
"""

model = EnterpriseCustomerEntitlement

id = factory.LazyAttribute(lambda x: FAKER.random_int(min=1))
entitlement_id = factory.LazyAttribute(lambda x: FAKER.random_int(min=1))
enterprise_customer = factory.SubFactory(EnterpriseCustomerFactory)


class EnterpriseCustomerBrandingConfigurationFactory(factory.django.DjangoModelFactory):
"""
EnterpriseCustomerBrandingConfiguration factory.
Expand Down
Loading

0 comments on commit d4b488c

Please sign in to comment.