Skip to content

Commit c6b4e47

Browse files
committed
feat: Add event for LTI Launches
1 parent f327edb commit c6b4e47

3 files changed

Lines changed: 133 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"name": "CloudEvent",
3+
"type": "record",
4+
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
5+
"fields": [
6+
{
7+
"name": "launch_data",
8+
"type": {
9+
"name": "LtiLaunchData",
10+
"type": "record",
11+
"fields": [
12+
{
13+
"name": "user",
14+
"type": {
15+
"name": "UserData",
16+
"type": "record",
17+
"fields": [
18+
{
19+
"name": "id",
20+
"type": "long"
21+
},
22+
{
23+
"name": "is_active",
24+
"type": "boolean"
25+
},
26+
{
27+
"name": "pii",
28+
"type": {
29+
"name": "UserPersonalData",
30+
"type": "record",
31+
"fields": [
32+
{
33+
"name": "username",
34+
"type": "string"
35+
},
36+
{
37+
"name": "email",
38+
"type": "string"
39+
},
40+
{
41+
"name": "name",
42+
"type": "string"
43+
}
44+
]
45+
}
46+
}
47+
]
48+
}
49+
},
50+
{
51+
"name": "course_key",
52+
"type": "string"
53+
},
54+
{
55+
"name": "usage_key",
56+
"type": "string"
57+
},
58+
{
59+
"name": "launch_params",
60+
"type": {
61+
"name": "LtiLaunchParamsData",
62+
"type": "record",
63+
"fields": [
64+
{
65+
"name": "roles",
66+
"type": "string"
67+
},
68+
{
69+
"name": "context_id",
70+
"type": "string"
71+
},
72+
{
73+
"name": "user_id",
74+
"type": "string"
75+
},
76+
{
77+
"name": "extra_data",
78+
"type": {
79+
"type": "map",
80+
"values": "string"
81+
}
82+
}
83+
]
84+
}
85+
}
86+
]
87+
}
88+
}
89+
],
90+
"namespace": "org.openedx.learning.lti_provider.launch.success.v1"
91+
}

openedx_events/learning/data.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,3 +656,30 @@ class ExternalGraderScoreData:
656656
module_id = attr.ib(type=str)
657657
queue_key = attr.ib(type=str)
658658
queue_name = attr.ib(type=str)
659+
660+
661+
@attr.s(frozen=True)
662+
class LtiLaunchParamsData:
663+
"""
664+
Data required for a successful LTI launch.
665+
666+
Attributes:
667+
roles (str): The roles (as per LTI Spec) of the User.
668+
context_id (str): An ID for the launch context of LTI content.
669+
user_id (str): User ID of user performing the launch.
670+
"""
671+
roles = attr.ib(type=str)
672+
context_id = attr.ib(type=str)
673+
user_id = attr.ib(type=str)
674+
extra_data = attr.ib(type=dict[str, str], factory=dict)
675+
676+
677+
@attr.s(frozen=True)
678+
class LtiLaunchData:
679+
"""
680+
Class that encapsulates LTI data for an LTI launch event.
681+
"""
682+
user = attr.ib(type=UserData)
683+
course_key = attr.ib(type=CourseKey)
684+
usage_key = attr.ib(type=UsageKey)
685+
launch_params = attr.ib(type=LtiLaunchParamsData)

openedx_events/learning/signals.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
DiscussionThreadData,
2222
ExamAttemptData,
2323
ExternalGraderScoreData,
24+
LtiLaunchData,
2425
ORASubmissionData,
2526
PersistentCourseGradeData,
2627
ProgramCertificateData,
@@ -504,3 +505,17 @@
504505
"score": ExternalGraderScoreData,
505506
}
506507
)
508+
509+
510+
# .. event_type: org.openedx.learning.lti_provider.launch.success.v1
511+
# .. event_name: LTI_PROVIDER_LAUNCH_SUCCESS
512+
# .. event_description: emitted when a student accesses learning content via LTI
513+
# .. event_warning: This event is currently incompatible with the event bus, list with complex types
514+
# like ``List[DiscussionTopicContext]`` cannot be serialized yet.
515+
# .. event_data: LtiLaunchData
516+
LTI_PROVIDER_LAUNCH_SUCCESS = OpenEdxPublicSignal(
517+
event_type="org.openedx.learning.lti_provider.launch.success.v1",
518+
data={
519+
"launch_data": LtiLaunchData,
520+
}
521+
)

0 commit comments

Comments
 (0)