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 XApiBaseEnrollmentFilter #108

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

andrey-canon
Copy link
Collaborator

Description

This filter allows to implement the required object structure by the NELC team https://edunext.atlassian.net/browse/FUTUREX-251

Testing instructions

  1. Use this version of event routing feat: implement XAPI openedx filters nelc/event-routing-backends#5
  2. add the settings
        OPEN_EDX_FILTERS_CONFIG = {
            "event_routing_backends.processors.xapi.enrollment_events.base_enrollment.get_object": {
                "pipeline": ["eox_nelp.openedx_filters.xapi.filters.XApiBaseEnrollmentFilter"],
                "fail_silently": False,
            },
        }
  1. This uses the language and the short_description studio fields, set them
  2. Perform an enrollment or unenrollment event
  3. Check the result, in my case I'm using aspects, so I can check that in the superset panel

Before

image

After

image

Additional information

Include anything else that will help reviewers and consumers understand the change.

  • Does this change depend on other changes elsewhere?
  • Any special concerns or limitations? For example: deprecations, migrations, security, or accessibility.
  • Link to other information about the change, such as Jira issues, GitHub issues, or Discourse discussions.

Checklist for Merge

  • Tested in a remote environment
  • Updated documentation
  • Rebased master/main
  • Squashed commits

NATIONAL_ID_REGEX = r"^[1-2]\d{9}$"
COURSE_ID_REGEX = r'(course-v1:[^/+]+(/|\+)[^/+]+(/|\+)[^/?]+)'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where was extracted this Regex?
It seems a little different than
https://github.com/openedx/edx-platform/blob/master/openedx/core/constants.py#L12

>>> from django.conf import settings
>>> settings.COURSE_KEY_REGEX
'(?:[^/+]+(/|\\+)[^/+]+(/|\\+)[^/?]+)'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from that place the modification is the course-v1:

Course
"""
course_key = CourseKey.from_string(course_id)
course_overviews = CourseOverview.get_from_ids([course_key])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why if the methods is called get_course_from_id (from one id), you use a method for multiple ids instead of the method for one??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is a copy of this which implements this line course_overviews = get_course_overviews([course_key]) however I made a mistake and I copied the logic from the method get_course_overviews_from_ids instead of the get_course_overviews method

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is a copy of this which implements this line course_overviews = get_course_overviews([course_key]) however I made a mistake and I copied the logic from the method get_course_overviews_from_ids instead of the get_course_overviews method

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the logic because we already have the CourseOverview model and was easier however the other logic requires a backend, so it will be easier to implement new api backend

if course_overviews:
return course_overviews[0]

raise ValueError(f"Course with id {course_id} does not exist.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you prefer the raise of an exception instead a None return as the CourseOverview do ?
https://github.com/openedx/edx-platform/blob/master/openedx/core/djangoapps/content/course_overviews/models.py#L415

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a copy of this

course_overviews = CourseOverview.get_from_ids([course_key])

if course_overviews:
return course_overviews[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I was testing and found like an error
Peek 2023-11-17 16-33

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this seem not return a list...
image

Copy link
Collaborator

@johanseto johanseto Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

@andrey-canon andrey-canon Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to implement the right method

@andrey-canon
Copy link
Collaborator Author

@johanv26 I have already applied some changes and tested that by making an enrollment in the about page, could please you try again :D

@andrey-canon andrey-canon force-pushed the and/add_xapi_enrollment_object_filter branch from 83b1d4e to 8cf8feb Compare November 18, 2023 00:07
Copy link
Collaborator

@johanseto johanseto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested again and passed last error, with course_overviews using a list of ordered_dict. But after passing that I had an error with course_language being None

course_language = course['language']

# Create new attributes based on the course properties
definition_name = LanguageMap(**({course_language: display_name} if display_name is not None else {}))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are validating display_name is not None, but also is possible that course_language is empty None
Peek 2023-11-20 13-18

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johanv26 How did you set the course language to None since that option is not available on studio ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually is a very good question.
I tried to defined here, but is not working
image

But on the other hand my course_overview record of that object is empty.
From admin is difficult to change.
Peek 2023-11-20 16-41

Myabe there is a mismatch of mongo and mysql course_overview...

@johanseto johanseto self-requested a review November 20, 2023 21:47
Copy link
Collaborator

@johanseto johanseto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrey-canon
Copy link
Collaborator Author

andrey-canon commented Nov 20, 2023

Still I wonder how did you set to None the language, I couldn't do that I just considered that case, how did you create that course ?

This filter allows to implement the required object structure by the NELC team
https://edunext.atlassian.net/browse/FUTUREX-251
@andrey-canon andrey-canon force-pushed the and/add_xapi_enrollment_object_filter branch from dacc260 to 5247237 Compare November 20, 2023 22:26
@andrey-canon andrey-canon merged commit cd9de65 into master Nov 20, 2023
7 checks passed
@johanseto
Copy link
Collaborator

Still I wonder how did you set to None the language, I couldn't do that I just considered that case, how did you create that course ?

@andrey-canon I was reseaching a little and I found that seems this backend use the mysql course_overview as source.

From studio is possible to set with - and that saves in mongo with "". By the way, the mysql course_overview record is not updated. But in mongo and what we see in studio yes.

Peek 2023-11-20 18-13

Here I also share you how in my local env I set arabic language, then using modulestore, yes my course language is ar but with the method of course_overview is None.
Peek 2023-11-20 18-21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants