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

Add ralph for xAPI statements generation in backend #2582

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).

### Added

- Integrate `ralph-malph` library for xAPI statements generation
- Add scaleway storage configuration
- Add Peertube pipeline to VOD
- Celery task queue
Expand Down
3 changes: 3 additions & 0 deletions src/backend/marsha/core/api/xapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from marsha.core import permissions, serializers
from marsha.core.api.base import APIViewMixin
from marsha.core.defaults import XAPI_STATEMENT_ID_CACHE
from marsha.core.lti import LTI
from marsha.core.xapi import XAPI, get_xapi_statement


Expand All @@ -41,10 +42,12 @@ def _statement_from_lti(
xapi_logger = logging.getLogger(f"xapi.{consumer_site.domain}")

# xapi statement enriched with video and jwt_token information
lti = LTI(request, object_instance)
Copy link
Member

Choose a reason for hiding this comment

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

As you are not in a LTI request you will have no relevant information.
IMO if you need to have an information from the LTI request, you have to set it in the JWT token and then retrieve it in it when you need it.
And to add the origin_url in the jwt token you should add it here I think

token.payload.update(
{
"context_id": lti.context_id,
"consumer_site": str(lti.get_consumer_site().id),
}
)

xapi_statement = statement_class.from_lti(
object_instance,
partial_xapi_statement.validated_data,
request.resource.token,
lti.origin_url
)

# Log the statement in the xapi logger
Expand Down
2 changes: 1 addition & 1 deletion src/backend/marsha/core/lti/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, request, resource_id=None):
request : django.http.request.HttpRequest
The request that holds the LTI parameters
resource_id : uuid.uuid4
The primary key of the video targetted by the LTI query as a UUID.
The primary key of the video targeted by the LTI query as a UUID.

"""
self.resource_id = resource_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def test_xapi_statement_document_resource(self):

session_id = str(uuid.uuid4())
jwt_token = UserAccessTokenFactory()
print(jwt_token.__dict__)

data = {
"verb": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from logging_ldp.formatters import LDPGELFFormatter

from marsha.core.defaults import XAPI_STATEMENT_ID_CACHE
from marsha.core.factories import VideoFactory
from marsha.core.factories import VideoFactory, UserFactory
from marsha.core.simple_jwt.factories import UserAccessTokenFactory


Expand Down Expand Up @@ -199,7 +199,8 @@ def test_xapi_statement_with_two_same_event(self):
"""
video = VideoFactory()
jwt_token = UserAccessTokenFactory()

user=UserFactory(username="johndoe")
print(user)
data = {
"id": "7b18195e-e183-4bbf-b8ef-5145ef64ae19",
"verb": {
Expand Down
Loading