diff --git a/src/backend/settings.py b/src/backend/settings.py index 50e6f0a04234638470f58e86439ffd37d3a5c173..e020fd45ac9df4d3b3409425a5cda6054c3b0e39 100644 --- a/src/backend/settings.py +++ b/src/backend/settings.py @@ -44,6 +44,7 @@ ANALYTICS_RESULTS_RETENTION = env("ANALYTICS_RESULTS_RETENTION", default=31) ALLOWED_HOSTS = ["*"] IDP_ENABLED = env("IDP_ENABLED") +SHOW_XAPI_STATEMENTS = env("SHOW_XAPI_STATEMENTS", default=False) # Application definition diff --git a/src/static/xapi_statement.schema.json b/src/static/xapi_statement.schema.json index 72577fd22d2ea8f16a00719665556d252c2357b5..7632ae4109b5f01c507b432ae79ba3d1345736ab 100644 --- a/src/static/xapi_statement.schema.json +++ b/src/static/xapi_statement.schema.json @@ -234,13 +234,7 @@ "$ref": "#/$defs/group" }, "contextActivities": { - "type": "object", - "properties": { - "parent": { "type": "array", "items": { "$ref": "#/$defs/activity" } }, - "category": { "type": "array", "items": { "$ref": "#/$defs/activity" } }, - "grouping": { "type": "array", "items": { "$ref": "#/$defs/activity" } }, - "other": { "type": "array", "items": { "$ref": "#/$defs/activity" } } - } + "type": "object" }, "revision": { "type": "string" diff --git a/src/xapi/views.py b/src/xapi/views.py index 31a7f138295c3d236e5f7bf67e485678102994d2..851a136b2c1931b27a55fc16edacdfda9f9acf4e 100644 --- a/src/xapi/views.py +++ b/src/xapi/views.py @@ -126,7 +126,8 @@ def process_statement(x_api_statement, provider, latest_schema): # has the user given consent to the object at hand? object_consent = False verb_objects = json.loads(user_consent.object) - if not verb_objects: # no objects defined, "consent" by default + object_statement = x_api_statement["object"]["definition"] + if not verb_objects or len(verb_objects) == 0: # no objects defined, "consent" by default object_consent = True else: for obj in verb_objects: @@ -154,7 +155,7 @@ def process_statement(x_api_statement, provider, latest_schema): return { "valid": True, "accepted": False, - "reason": "User has not given consent to this object", + "reason": f"User has not given consent to this object: {object_statement} for verb {verb}", } return {"valid": True, "accepted": True} @@ -241,10 +242,11 @@ class CreateStatement(APIView): ) # TODO remove this actor override - # for stmt in x_api_statements: - # stmt["actor"]["account"]["name"] = "user1@polaris.com" + for stmt in x_api_statements: + stmt["actor"]["account"]["name"] = "user1@polaris.com" - #print(x_api_statements) + if settings.SHOW_XAPI_STATEMENTS: + print(x_api_statements) result = [ process_statement(stmt, provider, latest_schema) @@ -254,7 +256,10 @@ class CreateStatement(APIView): invalid_or_not_consented = ( len([e for e in result if e["valid"] == False or e["accepted"] == False]) > 0 - ) + ) + + if settings.SHOW_XAPI_STATEMENTS: + print(result) if invalid_or_not_consented: return JsonResponse(