Skip to content

Commit

Permalink
fix: check for active, current license
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Nov 25, 2024
1 parent 98ed6ec commit 8bf0d08
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions enterprise_access/apps/bffs/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,19 @@ def transform_subscriptions_result(self, subscriptions_result):
'subscription_licenses_by_status': subscription_licenses_by_status,
}

def check_has_activated_license(self):
@property
def current_active_license(self):
"""
Check if the user has an activated license.
Returns:
bool: True if the user has an activated license, False otherwise.
Returns an activated license for the user iff the related subscription plan is current,
otherwise returns None.
"""
return bool(self.subscription_licenses_by_status.get('activated'))
current_active_licenses = [
_license for _license in self.subscription_licenses_by_status.get('activated', [])
if _license['subscription_plan']['is_current']
]
if current_active_licenses:
return current_active_licenses[0]
return None

def process_subscription_licenses(self):
"""
Expand All @@ -248,7 +253,7 @@ def process_subscription_licenses(self):
This method is called after `load_subscription_licenses` to handle further actions based
on the loaded data.
"""
if not (self.subscriptions or self.check_has_activated_license()):
if not self.subscriptions or self.current_active_license:
# Skip processing if:
# - there is no subscriptions data
# - user already has an activated license
Expand Down Expand Up @@ -345,7 +350,7 @@ def check_and_auto_apply_license(self):
subscription_licenses_by_status = self.subscription_licenses_by_status
assigned_licenses = subscription_licenses_by_status.get('assigned', [])

if assigned_licenses or self.check_has_activated_license():
if assigned_licenses or self.current_active_license:
# Skip auto-apply if user already has assigned license(s) or an already-activated license
return

Expand Down

0 comments on commit 8bf0d08

Please sign in to comment.