diff --git a/license_manager/apps/api/serializers.py b/license_manager/apps/api/serializers.py index 2cf79e82..eb13d3bf 100644 --- a/license_manager/apps/api/serializers.py +++ b/license_manager/apps/api/serializers.py @@ -130,6 +130,7 @@ class Meta: 'disable_expiration_notifications', 'net_days_until_expiration', 'subscription_for_auto_applied_licenses', + 'available_subscription_catalogs', ] def get_subscription_for_auto_applied_licenses(self, obj): diff --git a/license_manager/apps/api/v1/tests/test_views.py b/license_manager/apps/api/v1/tests/test_views.py index f7a70ad0..1e9c0bc3 100644 --- a/license_manager/apps/api/v1/tests/test_views.py +++ b/license_manager/apps/api/v1/tests/test_views.py @@ -2724,8 +2724,19 @@ def test_endpoint_results_contains_customer_agreement(self): response = self._get_url_with_customer_uuid(self.enterprise_customer_uuid) assert response.status_code == status.HTTP_200_OK + customer_agreement_response = response.json().get('customer_agreement') + expected_days_until_expiration = self.customer_agreement.net_days_until_expiration + expected_disable_expire_notifications = self.customer_agreement.disable_expiration_notifications assert customer_agreement_response['uuid'] == str(self.customer_agreement.uuid) + assert customer_agreement_response['net_days_until_expiration'] == expected_days_until_expiration + assert customer_agreement_response['disable_expiration_notifications'] == expected_disable_expire_notifications + assert customer_agreement_response['subscription_for_auto_applied_licenses'] is None + + expected_available_catalog_uuids = [ + str(self.customer_agreement.subscriptions.first().enterprise_catalog_uuid) + ] + assert customer_agreement_response['available_subscription_catalogs'] == expected_available_catalog_uuids def test_endpoint_results_correctly_ordered(self): """ diff --git a/license_manager/apps/subscriptions/models.py b/license_manager/apps/subscriptions/models.py index b35984af..2e5a543b 100644 --- a/license_manager/apps/subscriptions/models.py +++ b/license_manager/apps/subscriptions/models.py @@ -152,6 +152,23 @@ def net_days_until_expiration(self): net_days = max(net_days, plan.days_until_expiration_including_renewals) return net_days + @property + def available_subscription_catalogs(self): + """ + Returns all the enterprise catalogs associated with the subscription plans + in this customer agreement. + """ + default_catalog_uuid = self.default_enterprise_catalog_uuid + available_catalog_uuids = set() + for plan in self.subscriptions.filter(is_active=True).prefetch_related('renewal'): + if plan.days_until_expiration_including_renewals > 0: + available_catalog_uuids.add( + str(plan.enterprise_catalog_uuid) + if plan.enterprise_catalog_uuid + else str(default_catalog_uuid) + ) + return list(available_catalog_uuids) + @property def auto_applicable_subscription(self): """