Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new content event signals #32599

Conversation

rpenido
Copy link
Contributor

@rpenido rpenido commented Jun 28, 2023

Description

Use the following OpenEdxPublicSignal events triggered by content creation and editing.

  • XBLOCK_CREATED and XBLOCK_UPDATED
  • COURSE_CREATED
  • CONTENT_LIBRARY_CREATED, CONTENT_LIBRARY_UPDATED and CONTENT_LIBRARY_DELETED
  • LIBRARY_BLOCK_CREATED, LIBRARY_BLOCK_UPDATED and LIBRARY_BLOCK_DELETED

These events will be used in the Content Tagging app for System-defined automatic tagging to trigger updates on any automatically-generated system taxonomy tags.

This PR introduces a breaking change because it changes the following events from django.Signal to OpenEdxPublicSignal:

  • CONTENT_LIBRARY_CREATED
  • CONTENT_LIBRARY_UPDATED
  • CONTENT_LIBRARY_DELETED
  • LIBRARY_BLOCK_CREATED
  • LIBRARY_BLOCK_UPDATED
  • LIBRARY_BLOCK_DELETED

Supporting information

Testing instructions

Get latest version of openedx-events:

  1. Clone openedx-events repository to ~/workspace/src/openedx-events
git clone [email protected]:openedx/openedx-events.git --branch 'v8.3.0'
  1. Install the develop package in lms and studio
./in lms pip install -e /edx/src/openedx-events
./in studio pip install -e /edx/src/openedx-events

Setup frontend-app-library-authoring if not done before:

  1. Add the following to a new cms/envs/private.py file.
from .devstack import FEATURES
FEATURES['ENABLE_LIBRARY_AUTHORING_MICROFRONTEND'] = True
BLOCKSTORE_API_AUTH_TOKEN = 'edxapp-insecure-devstack-key'
  1. Set up the blockstore to run in devstack (ref) by running the following from the studio shell (make studio-shell):
# Configure blockstore to run inside LMS/Studio (instead of as an external service)
./manage.py cms waffle_switch --create blockstore.use_blockstore_app_api on
./manage.py cms shell  # enter python code below

# Create a "Collection" that new content libraries / xblocks can be created within:
from blockstore.apps.bundles.models import Collection
coll, _ = Collection.objects.get_or_create(title='Devstack Content Collection', uuid='11111111-2111-4111-8111-111111111111')

# Create an "Organization":
from organizations.models import Organization
Organization.objects.get_or_create(short_name='DeveloperInc', defaults={'name': 'DeveloperInc', 'active': True})

Then:

  1. Start lms and studio using make dev.up.lms+studio+frontend-app-learning+frontend-app-library-authoring
  2. Add below snippet somewhere, for example in cms/djangoapps/contentstore/signals/handlers.py:
from openedx_events.content_authoring.signals import (
    XBLOCK_CREATED,
    XBLOCK_UPDATED,
    COURSE_CREATED,
    CONTENT_LIBRARY_CREATED,
    CONTENT_LIBRARY_UPDATED,
    CONTENT_LIBRARY_DELETED,
    LIBRARY_BLOCK_CREATED,
    LIBRARY_BLOCK_UPDATED,
    LIBRARY_BLOCK_DELETED,
)
XBLOCK_CREATED.connect(lambda **x: print("test_event: ", x))
XBLOCK_UPDATED.connect(lambda **x: print("test_event: ", x))
COURSE_CREATED.connect(lambda **x: print("test_event: ", x))
CONTENT_LIBRARY_CREATED.connect(lambda **x: print("test_event: ", x))
CONTENT_LIBRARY_UPDATED.connect(lambda **x: print("test_event: ", x))
CONTENT_LIBRARY_DELETED.connect(lambda **x: print("test_event: ", x))
LIBRARY_BLOCK_CREATED.connect(lambda **x: print("test_event: ", x))
LIBRARY_BLOCK_UPDATED.connect(lambda **x: print("test_event: ", x))
LIBRARY_BLOCK_DELETED.connect(lambda **x: print("test_event: ", x))
  1. Open studio in http://localhost:18010/ and login with [email protected] / edx
  2. Open studio logs monitoring:
make studio-logs | grep test_event:
  1. Create a course
    Check the log for COURSE_CREATED and the XBLOCK_UPDATED event data
  2. Create a section
    Check the log for XBLOCK_CREATED event data
  3. Create a subsection
    Check the log for XBLOCK_CREATED event data
  4. Edit a subsection name
    Check the log for XBLOCK_UPDATED event data
  5. Create a unit
    Check the log for XBLOCK_CREATED event data
  6. Visit the Libraries tab, it should take you to Content Libraries V2 MFE: http://localhost:3001
  7. Create a new library for the Org created on setup
    Check the log for CONTENT_LIBRARY_CREATED event data
  8. Edit the name of the library
    Check the log for CONTENT_LIBRARY_UPDATED event data
  9. Add a block to the library, e.g Text block
    Check the log for LIBRARY_BLOCK_CREATED event data
  10. Edit the name of the block
    Check the log for LIBRARY_BLOCK_UPDATED event data

Deadline

TBD

Other information

Depends on openedx/openedx-events#244

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jun 28, 2023
@openedx-webhooks
Copy link

openedx-webhooks commented Jun 28, 2023

Thanks for the pull request, @rpenido! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@rpenido rpenido force-pushed the rpenido/fal-3434-implement-content-event-signals branch from 5458929 to 048dc74 Compare July 3, 2023 23:44
@rpenido rpenido force-pushed the rpenido/fal-3434-implement-content-event-signals branch 2 times, most recently from 33f2816 to 8dafbc6 Compare July 4, 2023 21:09
Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good @rpenido ! We have an open discussion about the changed library events, and this suggestion plus these changes should fix the test failures.

Could you also please update this PR to give some more context on why we're making these changes? These signals will be used by the Content Tagging app, to trigger updates on any automatically-generated system taxonomy tags.

You can reference this openedx/modular-learning#61 in the More Info section too.

openedx/core/djangoapps/content_libraries/signals.py Outdated Show resolved Hide resolved
xmodule/modulestore/mixed.py Outdated Show resolved Hide resolved
openedx/core/djangoapps/content_libraries/api.py Outdated Show resolved Hide resolved
openedx/core/djangoapps/content_libraries/api.py Outdated Show resolved Hide resolved
openedx/core/djangoapps/content_libraries/api.py Outdated Show resolved Hide resolved
openedx/core/djangoapps/content_libraries/api.py Outdated Show resolved Hide resolved
openedx/core/djangoapps/content_libraries/api.py Outdated Show resolved Hide resolved
xmodule/modulestore/mixed.py Show resolved Hide resolved
@rpenido rpenido force-pushed the rpenido/fal-3434-implement-content-event-signals branch from 3a44f7f to ea01a63 Compare July 5, 2023 23:11
@rpenido rpenido force-pushed the rpenido/fal-3434-implement-content-event-signals branch 2 times, most recently from d3bd997 to d758871 Compare July 6, 2023 19:41
Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpenido This is working well and looking good. ☀️

There's a couple of minor changes to be made and one outstanding question:

Your instructions for testing block creation/updates worked exactly as described, and I was able to test the content libraries events using the steps below. Running the tests locally is also working for me. I'll approve once the changes/questions are resolved. 👍

Steps to enable and test content libraries:

  • Add frontend-app-library-authoring to the list of services you're running along with Studio et al

  • Add the following to a new cms/envs/private.py file (may need to restart studio to pick up these changes, using make studio-restart:

    from .devstack import FEATURES
    FEATURES['ENABLE_LIBRARY_AUTHORING_MICROFRONTEND'] = True
    BLOCKSTORE_API_AUTH_TOKEN = 'edxapp-insecure-devstack-key'
  • Set up the blockstore to run in devstack (ref) by running the following from the studio shell (make studio-shell):

    # Configure blockstore to run inside LMS/Studio (instead of as an external service)
    ./manage.py cms waffle_switch --create blockstore.use_blockstore_app_api on
    ./manage.py cms shell  # enter python code below
    
    # Create a "Collection" that new content libraries / xblocks can be created within:
    from blockstore.apps.bundles.models import Collection
    coll, _ = Collection.objects.get_or_create(title='Devstack Content Collection', uuid='11111111-2111-4111-8111-111111111111')
    
    # Create an "Organization":
    from organizations.models import Organization
    Organization.objects.get_or_create(short_name='DeveloperInc', defaults={'name': 'DeveloperInc', 'active': True})
  • Now, you can login to Studio, and visit the Libraries tab, it should take you to Content Libraries V2 MFE: http://localhost:3001
    (This is still very much WIP, and so it's not very nice to use yet.)

  • Create a new library for the Org created above, and watch the "library created" event happen in the Studio logs

  • Update the library, and watch for the event

  • Add a block to the library, e.g Text block, and watch for the "library block created" event

  • Update the block, and watch for the "library block updated" event

docs/guides/hooks/events.rst Outdated Show resolved Hide resolved
openedx/core/djangoapps/content_libraries/api.py Outdated Show resolved Hide resolved
Copy link
Contributor

@pomegranited pomegranited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This looks and works great @rpenido ! Ok to take it out of Draft to prepare for upstream review.

  • I tested this using the excellent PR test instructions
  • I read through the code
  • I checked for accessibility issues N/A
  • Includes documentation for the added signals.
  • Commit structure follows OEP-0051

Copy link
Contributor

@navinkarkera navinkarkera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpenido Nice work! Just added a suggestion regarding event handlers, everything else looks good. Please rebase and resolve the conflicts. Noting down few observations.

  • Noticed a weird behaviour when updating a vertical xblock. If you change the name and press enter, XBLOCK_UPDATED event is fired twice (probably the block is saved twice). If you change the name and click outside, the block is saved once and a single event is fired. Not sure if it has major effect but just wanted to bring this up.
  • XBLOCK_UPDATED as well as XBLOCK_PUBLISHED events are fired whenever an XBlock is published.

docs/guides/hooks/events.rst Outdated Show resolved Hide resolved
@rpenido rpenido force-pushed the rpenido/fal-3434-implement-content-event-signals branch from 6bbc3da to 0e4233e Compare July 20, 2023 20:50
@rpenido rpenido force-pushed the rpenido/fal-3434-implement-content-event-signals branch from 1ad5bc5 to d2f60df Compare July 20, 2023 22:21
@rpenido rpenido changed the title feat: add new content event signals [WIP] feat: add new content event signals Jul 20, 2023
@rpenido
Copy link
Contributor Author

rpenido commented Jul 20, 2023

@navinkarkera I think this is ready for review again!

@navinkarkera
Copy link
Contributor

@rpenido Please change the status from draft to ready if it is ready as well as rebase it.

@rpenido rpenido force-pushed the rpenido/fal-3434-implement-content-event-signals branch from 57142c2 to 41ab164 Compare July 24, 2023 17:53
@rpenido rpenido marked this pull request as ready for review July 24, 2023 17:54
@rpenido rpenido force-pushed the rpenido/fal-3434-implement-content-event-signals branch from c1c35b3 to 6a3cf9a Compare July 24, 2023 17:56
@rpenido
Copy link
Contributor Author

rpenido commented Jul 24, 2023

@rpenido Please change the status from draft to ready if it is ready as well as rebase it.

Done @navinkarkera !

Copy link
Contributor

@navinkarkera navinkarkera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

  • I tested this: emits events as expected
  • I read through the code
  • I checked for accessibility issues
  • Includes documentation
  • I made sure any change in configuration variables is reflected in the corresponding client's configuration-secure repository.

navinkarkera

This comment was marked as resolved.

@navinkarkera navinkarkera force-pushed the rpenido/fal-3434-implement-content-event-signals branch from 6a3cf9a to 900a49a Compare July 25, 2023 14:04
@navinkarkera navinkarkera force-pushed the rpenido/fal-3434-implement-content-event-signals branch from 900a49a to 2593d5a Compare July 25, 2023 14:10
@navinkarkera navinkarkera merged commit c540709 into openedx:master Jul 25, 2023
41 checks passed
@navinkarkera navinkarkera deleted the rpenido/fal-3434-implement-content-event-signals branch July 25, 2023 14:45
@openedx-webhooks
Copy link

@rpenido 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants