Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/openedx/edx-enterprise in…
Browse files Browse the repository at this point in the history
…to ENT-8018/create-api-log-model
  • Loading branch information
hamzawaleed01 committed Jan 15, 2024
2 parents 62367cf + a8c4a60 commit a507c96
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 59 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ Change Log
Unreleased
----------

[4.9.3]
[4.9.4]
--------

feat: Add model for integrated channel API request log table (ENT-8018)

[4.9.3]
--------

fix: Remove SAP debug logs

[4.9.2]
--------

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

__version__ = "4.9.3"
__version__ = "4.9.4"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.23 on 2024-01-12 07:24
# Generated by Django 3.2.23 on 2024-01-15 07:54

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -17,7 +17,7 @@ class Migration(migrations.Migration):
fields=[
('integratedchannelapirequestlogs_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='integrated_channel.integratedchannelapirequestlogs')),
('user_agent', models.CharField(max_length=255)),
('user_ip', models.GenericIPAddressField()),
('user_ip', models.GenericIPAddressField(blank=True, null=True)),
],
bases=('integrated_channel.integratedchannelapirequestlogs',),
),
Expand Down
3 changes: 1 addition & 2 deletions integrated_channels/cornerstone/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class CornerstoneAPIRequestLogs(IntegratedChannelAPIRequestLogs):
A model to track basic information about every API call we make from the integrated channels.
"""
user_agent = models.CharField(max_length=255)
user_ip = models.GenericIPAddressField(blank=False, null=False)
user_ip = models.GenericIPAddressField(blank=True, null=True)

class Meta:
app_label = 'cornerstone'
Expand All @@ -340,7 +340,6 @@ def __str__(self):
f' for enterprise customer {self.enterprise_customer}, '
f', enterprise_customer_configuration_id: {self.enterprise_customer_configuration_id}>'
f', endpoint: {self.endpoint}'
f', payload: {self.payload}'
f', time_taken: {self.time_taken}'
f', user_agent: {self.user_agent}'
f', user_ip: {self.user_ip}'
Expand Down
51 changes: 1 addition & 50 deletions integrated_channels/integrated_channel/exporters/learner_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,6 @@ def export(self, **kwargs):
)
enrollment_ids_to_export = [enrollment.id for enrollment in enrollments_permitted]

LOGGER.info(
f"[Debug-SAP]: course_run_id:{course_run_id}, channel_name: {channel_name}"
f"lms_user_for_filter:{lms_user_for_filter}, grade:{grade} "
f"enrollment_ids_to_export: {enrollment_ids_to_export}"
)
for enterprise_enrollment in enrollments_permitted:
lms_user_id = enterprise_enrollment.enterprise_customer_user.user_id
user_email = enterprise_enrollment.enterprise_customer_user.user_email
Expand Down Expand Up @@ -460,18 +455,7 @@ def export(self, **kwargs):
course_completed=_is_course_completed,
grade_percent=grade_percent,
)
LOGGER.info(
generate_formatted_log(
channel_name,
enterprise_customer_uuid,
lms_user_id,
course_id,
f", [Debug-SAP]: _is_course_completed: {_is_course_completed}, progress_status:{progress_status}"
f",completed_date_from_api: {completed_date_from_api}, grade_from_api:{grade_from_api}"
f"is_passing_from_api: {is_passing_from_api}, grade_percent:{grade_percent}"
f"passed_timestamp:{passed_timestamp}, records: {records}",
)
)

if records:
# There are some cases where we won't receive a record from the above
# method; right now, that should only happen if we have an Enterprise-linked
Expand All @@ -489,12 +473,6 @@ def export(self, **kwargs):

yield record

LOGGER.info(generate_formatted_log(
channel_name, None, lms_user_for_filter, course_run_id,
f'[Debug-SAP]: export finished. Did not export records for EnterpriseCourseEnrollment objects: '
f' {enrollment_ids_to_export}.'
))

def _filter_out_pre_transmitted_enrollments(
self,
enrollments_to_process,
Expand Down Expand Up @@ -546,42 +524,15 @@ def get_enrollments_to_process(self, lms_user_for_filter, course_run_id, channel
enterprise_customer_user__active=True,
)
if lms_user_for_filter and course_run_id:
LOGGER.info(
generate_formatted_log(
channel_name,
self.enterprise_customer.uuid,
lms_user_for_filter,
course_run_id,
f"[Debug-SAP]: enrollments to process before filtering: {list(enrollment_queryset)}",
)
)
enrollment_queryset = enrollment_queryset.filter(
course_id=course_run_id,
enterprise_customer_user__user_id=lms_user_for_filter.id,
)
LOGGER.info(
generate_formatted_log(
channel_name,
self.enterprise_customer.uuid,
lms_user_for_filter,
course_run_id,
f"[Debug-SAP]: enrollments to process after filtering: {list(enrollment_queryset)}",
)
)
LOGGER.info(generate_formatted_log(
channel_name, self.enterprise_customer.uuid, lms_user_for_filter, course_run_id,
'get_enrollments_to_process run for single learner and course.'))
enrollment_queryset = enrollment_queryset.order_by('course_id')
# return resolved list instead of queryset
LOGGER.info(
generate_formatted_log(
channel_name,
self.enterprise_customer.uuid,
lms_user_for_filter,
course_run_id,
f"[Debug-SAP]: enrollments to process: {list(enrollment_queryset)}",
)
)
return list(enrollment_queryset)

def get_learner_assessment_data_records(
Expand Down
1 change: 0 additions & 1 deletion integrated_channels/integrated_channel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,6 @@ def __str__(self):
f' for enterprise customer {self.enterprise_customer}, '
f', enterprise_customer_configuration_id: {self.enterprise_customer_configuration_id}>'
f', endpoint: {self.endpoint}'
f', payload: {self.payload}'
f', time_taken: {self.time_taken}'
f', api_record.body: {self.api_record.body}'
f', api_record.status_code: {self.api_record.status_code}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def test_offset_naive_error(self):
self.config.update_content_synced_at(first_timestamp, True)
assert self.config.last_sync_attempted_at == first_timestamp


@mark.django_db
class TestIntegratedChannelAPIRequestLogs(unittest.TestCase, EnterpriseMockMixin):
"""
Expand Down Expand Up @@ -287,12 +288,11 @@ def test_content_meta_data_string_representation(self):
f' for enterprise customer {self.enterprise_customer}, '
f', enterprise_customer_configuration_id: {self.enterprise_customer_configuration_id}>'
f', endpoint: {self.endpoint}'
f', payload: {self.payload}'
f', time_taken: {self.time_taken}'
f', api_record.body: {self.api_record.body}'
f', api_record.status_code: {self.api_record.status_code}'
)

request_log = IntegratedChannelAPIRequestLogs(
id=1,
enterprise_customer=self.enterprise_customer,
Expand Down

0 comments on commit a507c96

Please sign in to comment.