feat: added user in support_details object

This commit is contained in:
Muhammad Zubair
2023-06-21 19:24:11 +05:00
committed by Phillip Shiu
parent a0d3c21295
commit a9afb4fb5b
2 changed files with 13 additions and 7 deletions

View File

@@ -9,7 +9,7 @@ from math import ceil
from textwrap import dedent
from django.core.management import BaseCommand
from django.contrib.auth.models import User
from common.djangoapps.entitlements.tasks import expire_and_create_entitlements
from common.djangoapps.entitlements.models import CourseEntitlement
@@ -62,6 +62,7 @@ class Command(BaseCommand):
logger.info('Looking for entitlements which may be expirable.')
support_user = User.objects.get(username='cbrash-edx')
current_date = date.today()
expiration_period = current_date - relativedelta(years=1)
exceptional_expiration_period = current_date - relativedelta(years=1, months=6)
@@ -89,6 +90,6 @@ class Command(BaseCommand):
for batch_num in range(num_batches):
start = batch_num * batch_size
end = min(start + batch_size, entitlements_to_expire)
expire_and_create_entitlements.delay(entitlements[start:end])
expire_and_create_entitlements.delay(entitlements[start:end], support_user)
logger.info('Done. Successfully enqueued %d tasks.', num_batches)

View File

@@ -1,9 +1,6 @@
"""
This file contains celery tasks for entitlements-related functionality.
"""
from datetime import date
from dateutil.relativedelta import relativedelta
from celery import shared_task
from celery.utils.log import get_task_logger
from django.conf import settings # lint-amnesty, pylint: disable=unused-import
@@ -67,7 +64,7 @@ def expire_old_entitlements(self, start, end, logid='...'):
@shared_task(bind=True, ignore_result=True)
@set_code_owner_attribute
def expire_and_create_entitlements(self, entitlements):
def expire_and_create_entitlements(self, entitlements, support_user):
"""
Expire entitlements older than one year.
@@ -91,7 +88,14 @@ def expire_and_create_entitlements(self, entitlements):
LOGGER.info('Started expiring entitlement with id %d', entitlement.id)
entitlement.expire_entitlement()
LOGGER.info('Expired entitlement with id %d as expiration period has reached', entitlement.id)
support_detail = {
'action': 'EXPIRED',
'comments': 'REV-3574',
'entitlement': entitlement,
'support_user': support_user,
}
CourseEntitlementSupportDetail.objects.create(**support_detail)
# Creating new entitlement with old entitlement's data
entitlement.pk = None
entitlement.id = None
@@ -105,6 +109,7 @@ def expire_and_create_entitlements(self, entitlements):
'action': 'CREATE',
'comments': 'REV-3574',
'entitlement': entitlement,
'support_user': support_user,
}
CourseEntitlementSupportDetail.objects.create(**support_detail)
LOGGER.info('created new entitlement with id %d in a correspondence of above expired entitlement', entitlement.id)