From 03fe90c1b75664ccfd941d759248469dcf876ddf Mon Sep 17 00:00:00 2001
From: Lennard Strohmeyer <lennard.strohmeyer@digitallearning.gmbh>
Date: Tue, 21 Jan 2025 15:59:13 +0100
Subject: [PATCH] #109 fixed test case and added correct filter for consents

---
 src/consents/tests/tests_consent_operations.py | 8 +++++---
 src/xapi/views.py                              | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/consents/tests/tests_consent_operations.py b/src/consents/tests/tests_consent_operations.py
index efc7053..e9be69b 100644
--- a/src/consents/tests/tests_consent_operations.py
+++ b/src/consents/tests/tests_consent_operations.py
@@ -878,16 +878,18 @@ class TestUserConsentSaveUpdatedProviderSchema(BaseTestCase):
         )
         self.assertEqual(response.status_code, 200)
 
-        user_consents = UserConsents.objects.filter(user__email=self.test_user_email)
+        user_consents = UserConsents.objects.filter(user__email=self.test_user_email, active=True)
         self.assertEqual(len(user_consents), 2)
         self.assertTrue(
             UserConsents.objects.get(
-                verb="http://h5p.example.com/expapi/verbs/experienced"
+                verb="http://h5p.example.com/expapi/verbs/experienced",
+                active=True
             ).consented
         )
         self.assertTrue(
             UserConsents.objects.get(
-                verb="http://h5p.example.com/expapi/verbs/attempted"
+                verb="http://h5p.example.com/expapi/verbs/attempted",
+                active=True
             ).consented
         )
 
diff --git a/src/xapi/views.py b/src/xapi/views.py
index b20a46c..515ecf5 100644
--- a/src/xapi/views.py
+++ b/src/xapi/views.py
@@ -195,7 +195,7 @@ def process_statement(x_api_statement, provider, latest_schema):
         # has the user given consent to this verb?
         # maybe TODO: load correct provider schema pertaining to this user consent to validate the verb and objects fully
         user_consent = UserConsents.objects.filter(
-            user=user, provider=provider, verb=verb, consented=True, created__lte=timestamp
+            user=user, provider=provider, verb=verb, consented=True, created__lte=timestamp, active=True
         ).first()
 
         if not user_consent:
-- 
GitLab