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

Add filter_publishable_entities to publishing API [FC-0062] #257

Merged

Conversation

ChrisChV
Copy link
Contributor

@ChrisChV ChrisChV commented Nov 8, 2024

Adds filter_publishable_entities() to openedx.apps.authoring.publishing.api
(and the public openedx.api.authoring package). This also bumps the
version to 0.18.0

The motivation for this change is so that other apps can filter their
PublishableEntity querysets without having to dig into the internals of
the "publishing" app's data model relations. For instance, the
"collections" app could already answer the question, "What Publishable
Entities are in this Collection?" But to answer the question of, "What
are the Publishable Entities in this Collection that have a published
version?" requires filtering on "published__version__isnull", which is
a level of detail that we don't want to burden other apps with.

With this commit, they could call something like this instead:

    published_entities = filter_publishable_entities(
        collection.entities(),
        has_published=True,
    )

It's possible that this could be done in a more natural way with custom
Managers/QuerySets. The main concern there would be to make sure that
those come across correctly in various RelatedManagers, e.g. to make
sure that something like "Collection.entities" returns the customized
version. This is something we can follow up on in the future.

Supporting information

Testing instructions

- Given a list of publishable entities returns current drafts. Not all entities may have current drafts.
- Given a list of publishable entities returns those who have a published version. Not all entities may have current published version.
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 8, 2024
@openedx-webhooks
Copy link

Thanks for the pull request, @ChrisChV!

What's next?

Please work through the following steps to get your changes ready for engineering review:

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @axim-engineering. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@ChrisChV ChrisChV changed the title feat: Get drafts and get published functions feat: Get drafts and get published functions [FC-0062] Nov 8, 2024
return Draft.objects.filter(
entity_id__in=entity_ids,
version__isnull=False,
).select_related("entity", "version")
Copy link
Contributor

@ormsbee ormsbee Nov 9, 2024

Choose a reason for hiding this comment

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

I was thinking about this more recently. The entity_id__in query is reasonable for what this does, but it does get expensive for larger queries. But I think even more importantly, the fact that we'd be passing back a QuerySet[Draft] makes it harder for callers to chain queries.

Maybe something like this instead?

def filter_publishable_entities(entities: QuerySet[PublishableEntity], has_draft=None, has_published=None) -> QuerySet[PublishableEntity]:
    if has_draft is not None:
        entities = entities.filter(draft__version__isnull=(not has_draft))
    if has_published is not None:
        entities = entities.filter(published__version__isnull=(not has_published))

    return entities

Copy link
Contributor

@ormsbee ormsbee Nov 9, 2024

Choose a reason for hiding this comment

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

With the calling code from https://github.com/openedx/edx-platform/pull/35734/files looking something like:

draft_num_children = authoring_api.filter_publishable_entities(collection.entities, has_draft=True).count()
published_num_children = authoring_api.filter_publishable_entities(collection.entities, has_published=True).count()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. Updated here: 19f542b

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.

👍 So clean @ChrisChV ! Really happy with this implementation :)

  • I tested this using the PR test instructions and checking test coverage
  • I read through the code
  • I checked for accessibility issues N/A
  • Includes documentation N/A
  • User-facing strings are extracted for translation N/A

@pomegranited pomegranited requested a review from ormsbee November 12, 2024 01:49
@ormsbee
Copy link
Contributor

ormsbee commented Nov 12, 2024

(I'm going to rewrite the commit message, but I need to step away for a bit. Please don't merge this yet.)

@ormsbee ormsbee merged commit 9d91976 into openedx:main Nov 12, 2024
9 checks passed
@ormsbee ormsbee changed the title feat: Get drafts and get published functions [FC-0062] Add filter_publishable_entities to publishing API [FC-0062] Nov 12, 2024
@ormsbee ormsbee changed the title Add filter_publishable_entities to publishing API [FC-0062] Add filter_publishable_entities to publishing API [FC-0062] Nov 12, 2024
@bradenmacdonald bradenmacdonald deleted the chris/FAL-3921-get-drafts-and-get-published branch November 12, 2024 18:19
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
None yet
Development

Successfully merging this pull request may close these issues.

4 participants