Skip to content

Commit

Permalink
feat: add new content authoring event signals
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido authored and navinkarkera committed Jul 20, 2023
1 parent 6ae52b1 commit c0eb4ba
Show file tree
Hide file tree
Showing 17 changed files with 475 additions and 3 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ Change Log
Unreleased
----------

[8.3.0] - 2023-07-10
--------------------
Changed
~~~~~~~
* Added new XBLOCK_CREATED and XBLOCK_UPDATED events in content_authoring.
* Added new COURSE_CREATED event in content_authoring.
* Added new CONTENT_LIBRARY_CREATED, CONTENT_LIBRARY_UPDATED and CONTENT_LIBRARY_DELETED events in content_authoring.
* Added new LIBRARY_BLOCK_CREATED, LIBRARY_BLOCK_UPDATED and LIBRARY_BLOCK_DELETED events in content_authoring.

[8.2.0] - 2023-06-08
--------------------
Changed
Expand Down
2 changes: 1 addition & 1 deletion openedx_events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
more information about the project.
"""

__version__ = "8.2.0"
__version__ = "8.3.0"
44 changes: 44 additions & 0 deletions openedx_events/content_authoring/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@

import attr
from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.locator import LibraryLocatorV2, LibraryUsageLocatorV2


@attr.s(frozen=True)
class CourseData:
"""
Attributes defined for Open edX Course object.
Arguments:
course_key (CourseKey): identifier of the Course object.
"""

course_key = attr.ib(type=CourseKey)


@attr.s(frozen=True)
Expand Down Expand Up @@ -65,10 +78,13 @@ class XBlockData:
Arguments:
usage_key (UsageKey): identifier of the XBlock object.
block_type (str): type of block.
version (UsageKey): identifier of the XBlock object with branch and version data (optional). This
could be used to get the exact version of the XBlock object.
"""

usage_key = attr.ib(type=UsageKey)
block_type = attr.ib(type=str)
version = attr.ib(type=UsageKey, default=None, kw_only=True)


@attr.s(frozen=True)
Expand Down Expand Up @@ -136,3 +152,31 @@ class CertificateConfigData:
title = attr.ib(type=str)
signatories = attr.ib(type=List[CertificateSignatoryData], factory=list)
is_active = attr.ib(type=bool, default=False)


@attr.s(frozen=True)
class ContentLibraryData:
"""
Data about changed ContentLibrary.
Arguments:
library_key (LibraryLocatorV2): a key that represents a Blockstore-based content library.
update_blocks (bool): flag that indicates whether the content library blocks indexes should be updated
"""

library_key = attr.ib(type=LibraryLocatorV2)
update_blocks = attr.ib(type=bool, default=False)


@attr.s(frozen=True)
class LibraryBlockData:
"""
Data about changed LibraryBlock.
Arguments:
library_key (LibraryLocatorV2): a key that represents a Blockstore-based content library.
usage_key (LibraryUsageLocatorV2): a key that represents a XBlock in a Blockstore-based content library.
"""

library_key = attr.ib(type=LibraryLocatorV2)
usage_key = attr.ib(type=LibraryUsageLocatorV2)
102 changes: 101 additions & 1 deletion openedx_events/content_authoring/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
They also must comply with the payload definition specified in
docs/decisions/0003-events-payload.rst
"""

from openedx_events.content_authoring.data import (
CertificateConfigData,
ContentLibraryData,
CourseCatalogData,
CourseData,
DuplicatedXBlockData,
LibraryBlockData,
XBlockData,
)
from openedx_events.tooling import OpenEdxPublicSignal
Expand All @@ -27,6 +29,27 @@
}
)

# .. event_type: org.openedx.content_authoring.xblock.created.v1
# .. event_name: XBLOCK_CREATED
# .. event_description: Fired when an XBlock is created.
# .. event_data: XBlockData
XBLOCK_CREATED = OpenEdxPublicSignal(
event_type="org.openedx.content_authoring.xblock.created.v1",
data={
"xblock_info": XBlockData,
}
)

# .. event_type: org.openedx.content_authoring.xblock.updated.v1
# .. event_name: XBLOCK_UPDATED
# .. event_description: Fired when an XBlock is updated.
# .. event_data: XBlockData
XBLOCK_UPDATED = OpenEdxPublicSignal(
event_type="org.openedx.content_authoring.xblock.updated.v1",
data={
"xblock_info": XBlockData,
}
)

# .. event_type: org.openedx.content_authoring.xblock.published.v1
# .. event_name: XBLOCK_PUBLISHED
Expand Down Expand Up @@ -92,3 +115,80 @@
"certificate_config": CertificateConfigData,
}
)

# .. event_type: org.openedx.content_authoring.course.created.v1
# .. event_name: COURSE_CREATED
# .. event_description: emitted when a course is created
# .. event_data: CourseData
COURSE_CREATED = OpenEdxPublicSignal(
event_type="org.openedx.content_authoring.course.created.v1",
data={
"course": CourseData,
}
)

# .. event_type: org.openedx.content_authoring.content_library.created.v1
# .. event_name: CONTENT_LIBRARY_CREATED
# .. event_description: emitted when a content library is created
# .. event_data: ContentLibraryData
CONTENT_LIBRARY_CREATED = OpenEdxPublicSignal(
event_type="org.openedx.content_authoring.content_library.created.v1",
data={
"content_library": ContentLibraryData,
}
)

# .. event_type: org.openedx.content_authoring.content_library.updated.v1
# .. event_name: CONTENT_LIBRARY_UPDATED
# .. event_description: emitted when a content library is updated
# .. event_data: ContentLibraryData
CONTENT_LIBRARY_UPDATED = OpenEdxPublicSignal(
event_type="org.openedx.content_authoring.content_library.updated.v1",
data={
"content_library": ContentLibraryData,
}
)

# .. event_type: org.openedx.content_authoring.content_library.deleted.v1
# .. event_name: CONTENT_LIBRARY_DELETED
# .. event_description: emitted when a content library is deleted
# .. event_data: ContentLibraryData
CONTENT_LIBRARY_DELETED = OpenEdxPublicSignal(
event_type="org.openedx.content_authoring.content_library.deleted.v1",
data={
"content_library": ContentLibraryData,
}
)

# .. event_type: org.openedx.content_authoring.library_block.created.v1
# .. event_name: LIBRARY_BLOCK_CREATED
# .. event_description: emitted when a library block is created
# .. event_data: LibraryBlockData
LIBRARY_BLOCK_CREATED = OpenEdxPublicSignal(
event_type="org.openedx.content_authoring.library_block.created.v1",
data={
"library_block": LibraryBlockData,
}
)

# .. event_type: org.openedx.content_authoring.library_block.updated.v1
# .. event_name: LIBRARY_BLOCK_UPDATED
# .. event_description: emitted when a library block is updated
# .. event_data: LibraryBlockData
LIBRARY_BLOCK_UPDATED = OpenEdxPublicSignal(
event_type="org.openedx.content_authoring.library_block.updated.v1",
data={
"library_block": LibraryBlockData,
}
)

# .. event_type: org.openedx.content_authoring.library_block.deleted.v1
# .. event_name: LIBRARY_BLOCK_DELETED
# .. event_description: emitted when a library block is deleted
# .. event_data: LibraryBlockData
LIBRARY_BLOCK_DELETED = OpenEdxPublicSignal(
event_type="org.openedx.content_authoring.library_block.deleted.v1",
data={
"library_block": LibraryBlockData,
}
)
47 changes: 46 additions & 1 deletion openedx_events/event_bus/avro/custom_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from datetime import datetime

from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.locator import LibraryLocatorV2, LibraryUsageLocatorV2

from openedx_events.event_bus.avro.types import PYTHON_TYPE_TO_AVRO_MAPPING

Expand Down Expand Up @@ -90,4 +91,48 @@ def deserialize(data: str):
return UsageKey.from_string(data)


DEFAULT_CUSTOM_SERIALIZERS = [CourseKeyAvroSerializer, DatetimeAvroSerializer, UsageKeyAvroSerializer]
class LibraryLocatorV2AvroSerializer(BaseCustomTypeAvroSerializer):
"""
CustomTypeAvroSerializer for LibraryLocatorV2 class.
"""

cls = LibraryLocatorV2
field_type = PYTHON_TYPE_TO_AVRO_MAPPING[str]

@staticmethod
def serialize(obj) -> str:
"""Serialize obj into string."""
return str(obj)

@staticmethod
def deserialize(data: str):
"""Deserialize string into obj."""
return LibraryLocatorV2.from_string(data)


class LibraryUsageLocatorV2AvroSerializer(BaseCustomTypeAvroSerializer):
"""
CustomTypeAvroSerializer for LibraryUsageLocatorV2 class.
"""

cls = LibraryUsageLocatorV2
field_type = PYTHON_TYPE_TO_AVRO_MAPPING[str]

@staticmethod
def serialize(obj) -> str:
"""Serialize obj into string."""
return str(obj)

@staticmethod
def deserialize(data: str):
"""Deserialize string into obj."""
return LibraryUsageLocatorV2.from_string(data)


DEFAULT_CUSTOM_SERIALIZERS = [
CourseKeyAvroSerializer,
DatetimeAvroSerializer,
LibraryLocatorV2AvroSerializer,
LibraryUsageLocatorV2AvroSerializer,
UsageKeyAvroSerializer,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "CloudEvent",
"type": "record",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
"fields": [
{
"name": "content_library",
"type": {
"name": "ContentLibraryData",
"type": "record",
"fields": [
{
"name": "library_key",
"type": "string"
},
{
"name": "update_blocks",
"type": "boolean"
}
]
}
}
],
"namespace": "org.openedx.content_authoring.content_library.created.v1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "CloudEvent",
"type": "record",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
"fields": [
{
"name": "content_library",
"type": {
"name": "ContentLibraryData",
"type": "record",
"fields": [
{
"name": "library_key",
"type": "string"
},
{
"name": "update_blocks",
"type": "boolean"
}
]
}
}
],
"namespace": "org.openedx.content_authoring.content_library.deleted.v1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "CloudEvent",
"type": "record",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
"fields": [
{
"name": "content_library",
"type": {
"name": "ContentLibraryData",
"type": "record",
"fields": [
{
"name": "library_key",
"type": "string"
},
{
"name": "update_blocks",
"type": "boolean"
}
]
}
}
],
"namespace": "org.openedx.content_authoring.content_library.updated.v1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "CloudEvent",
"type": "record",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
"fields": [
{
"name": "course",
"type": {
"name": "CourseData",
"type": "record",
"fields": [
{
"name": "course_key",
"type": "string"
}
]
}
}
],
"namespace": "org.openedx.content_authoring.course.created.v1"
}
Loading

0 comments on commit c0eb4ba

Please sign in to comment.