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 committed Jul 4, 2023
1 parent 37a84a7 commit 4d2d951
Show file tree
Hide file tree
Showing 18 changed files with 447 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-04
--------------------
Changed
~~~~~~~
* Added new XBLOCK_CREATED and XBLOCK_UPDATED events in content_authoring.
* Added new COURSE_CREATED and COURSE_UPDATED events 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"
41 changes: 41 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 (str): identifier of the Course object.
"""

course_key = attr.ib(type=CourseKey)


@attr.s(frozen=True)
Expand Down Expand Up @@ -136,3 +149,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)
113 changes: 112 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,91 @@
"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.course.updated.v1
# .. event_name: COURSE_UPDATED
# .. event_description: emitted when a course is created
# .. event_data: CourseData
COURSE_UPDATED = OpenEdxPublicSignal(
event_type="org.openedx.content_authoring.course.updated.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:
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:
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:
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:
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:
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:
LIBRARY_BLOCK_DELETED = OpenEdxPublicSignal(
event_type="org.openedx.content_authoring.library_block.deleted.v1",
data={
"library_block": LibraryBlockData,
}
)
44 changes: 43 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,45 @@ 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,16 @@
{
"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": []
}
}
],
"namespace": "org.openedx.content_authoring.content_library.created.v1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"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": []
}
}
],
"namespace": "org.openedx.content_authoring.content_library.deleted.v1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"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": []
}
}
],
"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"
}
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.updated.v1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "CloudEvent",
"type": "record",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
"fields": [
{
"name": "library_block",
"type": {
"name": "LibraryBlockData",
"type": "record",
"fields": []
}
}
],
"namespace": "org.openedx.content_authoring.library_block.created.v1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "CloudEvent",
"type": "record",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
"fields": [
{
"name": "library_block",
"type": {
"name": "LibraryBlockData",
"type": "record",
"fields": []
}
}
],
"namespace": "org.openedx.content_authoring.library_block.deleted.v1"
}
Loading

0 comments on commit 4d2d951

Please sign in to comment.