Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add button to retransmit courses metadata #1776

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ Change Log

Unreleased
----------

[3.67.2]
--------
fix: fixing name of table used by model fetching method

[3.67.1]
--------
chore: more orphaned content transmission logging

[3.67.0]
--------
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Your project description goes here.
"""

__version__ = "3.67.0"
__version__ = "3.67.2"

default_app_config = "enterprise.apps.EnterpriseConfig"
30 changes: 28 additions & 2 deletions integrated_channels/blackboard/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
"""
from config_models.admin import ConfigurationModelAdmin

from django.contrib import admin
from django.contrib import admin, messages
from django.http import HttpResponseRedirect
from django_object_actions import DjangoObjectActions
from django.utils.html import format_html
import inspect

from integrated_channels.blackboard.models import (
BlackboardEnterpriseCustomerConfiguration,
Expand All @@ -29,7 +32,7 @@ class Meta:


@admin.register(BlackboardEnterpriseCustomerConfiguration)
class BlackboardEnterpriseCustomerConfigurationAdmin(admin.ModelAdmin):
class BlackboardEnterpriseCustomerConfigurationAdmin(DjangoObjectActions, admin.ModelAdmin):
"""
Django admin model for BlackEnterpriseCustomerConfiguration.
"""
Expand All @@ -51,6 +54,7 @@ class BlackboardEnterpriseCustomerConfigurationAdmin(admin.ModelAdmin):
)

search_fields = ("enterprise_customer_name",)
change_actions = ('update_modified_time',)

class Meta:
model = BlackboardEnterpriseCustomerConfiguration
Expand Down Expand Up @@ -78,6 +82,28 @@ def customer_oauth_authorization_url(self, obj):
else:
return None

def update_modified_time(self, request, obj):
"""
Updates the modified time of the customer record to retransmit courses metadata
and redirects to configuration view with success or error message.
"""
try:
obj.enterprise_customer.save()
messages.success(
request,
'The blackboard enterprise customer modified time '
'“<BlackboardEnterpriseCustomerConfiguration for Enterprise {enterprise_name}>” '
'was saved successfully.'.format(enterprise_name=obj.enterprise_customer.name))
except:
messages.error(
request,
'The blackboard enterprise customer modified time '
'“<BlackboardEnterpriseCustomerConfiguration for Enterprise {enterprise_name}>” '
'was not saved successfully.'.format(enterprise_name=obj.enterprise_customer.name))
return HttpResponseRedirect('/admin/blackboard/blackboardenterprisecustomerconfiguration')
update_modified_time.label = 'Update Customer Modified Time'
update_modified_time.short_description = 'Update modified time for this Enterprise Customer to retransmit courses metadata'


@admin.register(BlackboardLearnerDataTransmissionAudit)
class BlackboardLearnerDataTransmissionAuditAdmin(BaseLearnerDataTransmissionAuditAdmin):
Expand Down
30 changes: 28 additions & 2 deletions integrated_channels/canvas/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
Admin integration for configuring Canvas app to communicate with Canvas systems.
"""

from django.contrib import admin
from django.contrib import admin, messages
from django.http import HttpResponseRedirect
from django_object_actions import DjangoObjectActions
from django.utils.html import format_html

from integrated_channels.canvas.models import CanvasEnterpriseCustomerConfiguration, CanvasLearnerDataTransmissionAudit
from integrated_channels.integrated_channel.admin import BaseLearnerDataTransmissionAuditAdmin


@admin.register(CanvasEnterpriseCustomerConfiguration)
class CanvasEnterpriseCustomerConfigurationAdmin(admin.ModelAdmin):
class CanvasEnterpriseCustomerConfigurationAdmin(DjangoObjectActions, admin.ModelAdmin):
"""
Django admin model for CanvasEnterpriseCustomerConfiguration.
"""
Expand All @@ -36,6 +38,8 @@ class CanvasEnterpriseCustomerConfigurationAdmin(admin.ModelAdmin):

search_fields = ("enterprise_customer_name",)

change_actions = ('update_modified_time',)

class Meta:
model = CanvasEnterpriseCustomerConfiguration

Expand All @@ -62,6 +66,28 @@ def customer_oauth_authorization_url(self, obj):
else:
return None

def update_modified_time(self, request, obj):
"""
Updates the modified time of the customer record to retransmit courses metadata
and redirects to configuration view with success or error message.
"""
try:
obj.enterprise_customer.save()
messages.success(
request,
'The canvas enterprise customer modified time '
'“<CanvasEnterpriseCustomerConfiguration for Enterprise {enterprise_name}>” '
'was saved successfully.'.format(enterprise_name=obj.enterprise_customer.name))
except:
messages.error(
request,
'The canvas enterprise customer modified time '
'“<CanvasEnterpriseCustomerConfiguration for Enterprise {enterprise_name}>” '
'was not saved successfully.'.format(enterprise_name=obj.enterprise_customer.name))
return HttpResponseRedirect('/admin/canvas/canvasenterprisecustomerconfiguration')
update_modified_time.label = 'Update Customer Modified Time'
update_modified_time.short_description = 'Update modified time for this Enterprise Customer to retransmit courses metadata'


@admin.register(CanvasLearnerDataTransmissionAudit)
class CanvasLearnerDataTransmissionAuditAdmin(BaseLearnerDataTransmissionAuditAdmin):
Expand Down
30 changes: 27 additions & 3 deletions integrated_channels/cornerstone/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

from config_models.admin import ConfigurationModelAdmin

from django.contrib import admin
from django.contrib import admin, messages
from django.http import HttpResponseRedirect
from django_object_actions import DjangoObjectActions

from integrated_channels.cornerstone.models import (
CornerstoneEnterpriseCustomerConfiguration,
Expand All @@ -31,7 +33,7 @@ class Meta:


@admin.register(CornerstoneEnterpriseCustomerConfiguration)
class CornerstoneEnterpriseCustomerConfigurationAdmin(admin.ModelAdmin):
class CornerstoneEnterpriseCustomerConfigurationAdmin(DjangoObjectActions, admin.ModelAdmin):
"""
Django admin model for CornerstoneEnterpriseCustomerConfiguration.
"""
Expand All @@ -53,8 +55,8 @@ class CornerstoneEnterpriseCustomerConfigurationAdmin(admin.ModelAdmin):
)

list_filter = ("active",)

search_fields = ("enterprise_customer_name",)
change_actions = ('update_modified_time',)

class Meta:
model = CornerstoneEnterpriseCustomerConfiguration
Expand All @@ -69,6 +71,28 @@ def enterprise_customer_name(self, obj):
"""
return obj.enterprise_customer.name

def update_modified_time(self, request, obj):
"""
Updates the modified time of the customer record to retransmit courses metadata
and redirects to configuration view with success or error message.
"""
try:
obj.enterprise_customer.save()
messages.success(
request,
'The cornerstone enterprise customer modified time '
'“<CornerstoneEnterpriseCustomerConfiguration for Enterprise {enterprise_name}>” '
'was saved successfully.'.format(enterprise_name=obj.enterprise_customer.name))
except:
messages.error(
request,
'The cornerstone enterprise customer modified time '
'“<CornerstoneEnterpriseCustomerConfiguration for Enterprise {enterprise_name}>” '
'was not saved successfully.'.format(enterprise_name=obj.enterprise_customer.name))
return HttpResponseRedirect('/admin/cornerstone/cornerstoneenterprisecustomerconfiguration')
update_modified_time.label = 'Update Customer Modified Time'
update_modified_time.short_description = 'Update modified time for this Enterprise Customer to retransmit courses metadata'


@admin.register(CornerstoneLearnerDataTransmissionAudit)
class CornerstoneLearnerDataTransmissionAuditAdmin(BaseLearnerDataTransmissionAuditAdmin):
Expand Down
28 changes: 26 additions & 2 deletions integrated_channels/degreed/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

from config_models.admin import ConfigurationModelAdmin

from django.contrib import admin
from django.contrib import admin, messages
from django.http import HttpResponseRedirect
from django_object_actions import DjangoObjectActions

from integrated_channels.degreed.models import (
DegreedEnterpriseCustomerConfiguration,
Expand All @@ -31,7 +33,7 @@ class Meta:


@admin.register(DegreedEnterpriseCustomerConfiguration)
class DegreedEnterpriseCustomerConfigurationAdmin(admin.ModelAdmin):
class DegreedEnterpriseCustomerConfigurationAdmin(DjangoObjectActions, admin.ModelAdmin):
"""
Django admin model for DegreedEnterpriseCustomerConfiguration.
"""
Expand All @@ -58,6 +60,7 @@ class DegreedEnterpriseCustomerConfigurationAdmin(admin.ModelAdmin):

list_filter = ("active",)
search_fields = ("enterprise_customer_name",)
change_actions = ('update_modified_time',)

class Meta:
model = DegreedEnterpriseCustomerConfiguration
Expand All @@ -72,6 +75,27 @@ def enterprise_customer_name(self, obj):
"""
return obj.enterprise_customer.name

def update_modified_time(self, request, obj):
"""
Updates the modified time of the customer record to retransmit courses metadata
and redirects to configuration view with success or error message.
"""
try:
obj.enterprise_customer.save()
messages.success(
request,
'The degreed enterprise customer modified time '
'“<DegreedEnterpriseCustomerConfiguration for Enterprise {enterprise_name}>” '
'was saved successfully.'.format(enterprise_name=obj.enterprise_customer.name))
except:
messages.error(
request,
'The degreed enterprise customer modified time '
'“<DegreedEnterpriseCustomerConfiguration for Enterprise {enterprise_name}>” '
'was not saved successfully.'.format(enterprise_name=obj.enterprise_customer.name))
return HttpResponseRedirect('/admin/degreed/degreedenterprisecustomerconfiguration')
update_modified_time.label = 'Update Customer Modified Time'
update_modified_time.short_description = 'Update modified time for this Enterprise Customer to retransmit courses metadata'

@admin.register(DegreedLearnerDataTransmissionAudit)
class DegreedLearnerDataTransmissionAuditAdmin(BaseLearnerDataTransmissionAuditAdmin):
Expand Down
29 changes: 27 additions & 2 deletions integrated_channels/degreed2/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Django admin integration for configuring degreed app to communicate with Degreed systems.
"""

from django.contrib import admin
from django.contrib import admin, messages
from django.http import HttpResponseRedirect
from django_object_actions import DjangoObjectActions

from integrated_channels.degreed2.models import (
Degreed2EnterpriseCustomerConfiguration,
Expand All @@ -13,7 +15,7 @@


@admin.register(Degreed2EnterpriseCustomerConfiguration)
class Degreed2EnterpriseCustomerConfigurationAdmin(admin.ModelAdmin):
class Degreed2EnterpriseCustomerConfigurationAdmin(DjangoObjectActions, admin.ModelAdmin):
"""
Django admin model for Degreed2EnterpriseCustomerConfiguration.
"""
Expand All @@ -37,6 +39,7 @@ class Degreed2EnterpriseCustomerConfigurationAdmin(admin.ModelAdmin):

list_filter = ("active",)
search_fields = ("enterprise_customer_name",)
change_actions = ('update_modified_time',)

class Meta:
model = Degreed2EnterpriseCustomerConfiguration
Expand All @@ -51,6 +54,28 @@ def enterprise_customer_name(self, obj):
"""
return obj.enterprise_customer.name

def update_modified_time(self, request, obj):
"""
Updates the modified time of the customer record to retransmit courses metadata
and redirects to configuration view with success or error message.
"""
try:
obj.enterprise_customer.save()
messages.success(
request,
'The degreed2 enterprise customer modified time '
'“<Degreed2EnterpriseCustomerConfiguration for Enterprise {enterprise_name}>” '
'was saved successfully.'.format(enterprise_name=obj.enterprise_customer.name))
except:
messages.error(
request,
'The degreed2 enterprise customer modified time '
'“<Degreed2EnterpriseCustomerConfiguration for Enterprise {enterprise_name}>” '
'was not saved successfully.'.format(enterprise_name=obj.enterprise_customer.name))
return HttpResponseRedirect('/admin/degreed2/degreed2enterprisecustomerconfiguration')
update_modified_time.label = 'Update Customer Modified Time'
update_modified_time.short_description = 'Update modified time for this Enterprise Customer to retransmit courses metadata'


@admin.register(Degreed2LearnerDataTransmissionAudit)
class Degreed2LearnerDataTransmissionAuditAdmin(BaseLearnerDataTransmissionAuditAdmin):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ def _get_catalog_diff(
# 2) swap the catalog uuid of the transmission audit associated with the orphaned record, and 3) mark the
# orphaned record resolved
if orphaned_content:
ContentMetadataTransmissionAudit = apps.get_model(
ContentMetadataItemTransmission = apps.get_model(
'integrated_channel',
'ContentMetadataTransmissionAudit'
'ContentMetadataItemTransmission',
)
ContentMetadataTransmissionAudit.objects.filter(
ContentMetadataItemTransmission.objects.filter(
integrated_channel_code=self.enterprise_configuration.channel_code(),
plugin_configuration_id=self.enterprise_configuration.id,
content_id=content_key
Expand Down Expand Up @@ -436,8 +436,16 @@ def _get_customer_config_orphaned_content(self, max_set_count, content_key=None)
) & content_query

# Grab orphaned content metadata items for the customer, ordered by oldest to newest
return OrphanedContentTransmissions.objects.filter(base_query).order_by('created')[:max_set_count]
orphaned_content = OrphanedContentTransmissions.objects.filter(base_query)
num_records = len(orphaned_content)
self._log_info(
f'Found {num_records} orphaned content records for customer: '
f'{self.enterprise_customer.uuid}. Returning {min(max_set_count, num_records)} records.'
)
ordered_and_chunked_orphaned_content = orphaned_content.order_by('created')[:max_set_count]
return ordered_and_chunked_orphaned_content

# pylint: disable=too-many-statements
def export(self, **kwargs):
"""
Export transformed content metadata if there has been an update to the consumer's catalogs
Expand Down Expand Up @@ -529,8 +537,20 @@ def export(self, **kwargs):
delete_payload[key] = item

# If we're not at the max payload count, we can check for orphaned content and shove it in the delete payload
current_payload_count = len(items_to_create) + len(items_to_update) + len(items_to_delete)
current_payload_count = len(create_payload) + len(update_payload) + len(delete_payload)

self._log_info(
f'Exporter finished iterating over catalogs for customer: {self.enterprise_customer.uuid},'
f'with a current payload count of: {current_payload_count}. Is there room for orphaned content'
f'in the exporter payload?: {current_payload_count < max_payload_count}'
)

if current_payload_count < max_payload_count:
self._log_info(
f'Exporter has {max_payload_count - current_payload_count} slots left in the payload for customer: '
f'{self.enterprise_customer.uuid}, searching for orphaned content to append'
)

space_left_in_payload = max_payload_count - current_payload_count
orphaned_content_to_delete = self._get_customer_config_orphaned_content(
max_set_count=space_left_in_payload,
Expand Down
Loading