Skip to content

feat: libraries v2 support for studio perms XBlock service - #39074

Open
Kelketek wants to merge 3 commits into
openedx:masterfrom
open-craft:fox/studio-permissions-universality
Open

Kelketek wants to merge 3 commits into
openedx:masterfrom
open-craft:fox/studio-permissions-universality

Conversation

@Kelketek

@Kelketek Kelketek commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Description

This Pull Request makes the studio permissions service more consistently available, and adds support for Libraries v2 to it.

Supporting information

Internal ticket: https://tasks.opencraft.com/browse/BB-11135

Testing instructions

  1. Switch your devstack to this branch
  2. Install this version of XBlocks-core
  3. Follow the instructions there to test the revised service capabilities

Other information

To check: Does this change make the service available in the LMS? Do we care if so?

@openedx-webhooks

openedx-webhooks commented Sep 2, 2026

Copy link
Copy Markdown

Thanks for the pull request, @Kelketek!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform-oncall.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are 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.

Details
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.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Sep 2, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Sep 2, 2026
@Kelketek Kelketek changed the title feat: libraries v2 support for studio perms feat: libraries v2 support for studio perms XBlock service Sep 3, 2026
@Kelketek
Kelketek force-pushed the fox/studio-permissions-universality branch 16 times, most recently from d1b890f to 702805f Compare September 9, 2026 18:18
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Sep 9, 2026
@Kelketek
Kelketek force-pushed the fox/studio-permissions-universality branch 2 times, most recently from 5dbbc5b to a12c7d7 Compare September 10, 2026 23:55
@Kelketek
Kelketek marked this pull request as ready for review September 11, 2026 00:35
@Kelketek
Kelketek requested a review from a team as a code owner September 11, 2026 00:35
@Kelketek

Copy link
Copy Markdown
Contributor Author

@pkulkark This is ready for you.

def can_read(self, context_key):
""" Does the user have read access to the given course/library? """
if isinstance(context_key, LibraryLocatorV2):
return authz_api.is_user_allowed(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not use the [user_has_permission_across_lib_authz_systems](https://github.com/openedx/openedx-platform/blob/master/openedx/core/djangoapps/content_libraries/api/libraries.py#L842) method? That seems to handle both legacy as well as authz grants and additional checks via the bridgekeeper rules behind has_perm.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@pkulkark I tried that, but it violates the import linting rules. You are not permitted to import higher-level packages from lower-level ones.

I also had to move the service because the LMS isn't permitted to import from the CMS.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see. Perhaps we could directly add user.is_authenticated and user.is_active and user.is_staff in that case? Both are plain attribute checks in the bridgekeeper rules. Adding them to the library branch would close the gap where an inactive user with an authz role passes here, and the one where global staff get write on a course but not on a library through the same method.

As for the legacy grants, if we can't add an exception (like this example), could we atleast note in the docstring that this service does not see legacy grants?

@Kelketek Kelketek Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@pkulkark We don't have to worry about the legacy grants, as all of the grant info has been copied over by now and the legacy checks are just pending removal.

The staff check shouldn't be needed, as someone can be non-global staff and still have library access.

The anonymous check isn't necessary-- authz will return False. I've tested this:

In [1]: import openedx_authz.api as authz_api

In [2]: from django.contrib.auth.models import AnonymousUser

In [3]: user = AnonymousUser()

In [4]: from openedx_authz.constants.permissions import EDIT_LIBRARY_CONTENT, VIEW_LIBRARY

In [5]: authz_api.is_user_allowed(user, VIEW_LIBRARY.identifier, 'lib:Test:TL100')

is_active isn't checked by authz, and while in most cases it would probably be checked by the calling code during the request process, I've gone ahead and added a check to be safe.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fair enough. Thanks @Kelketek

Comment thread openedx/core/djangoapps/xblock/runtime/runtime.py
@pkulkark

Copy link
Copy Markdown
Contributor

Note: This PR is what makes the permission check in openedx/xblocks-core#291 work in v2 libraries. Since xblocks-contrib is a pip package that operators can bump independently of a platform upgrade, an operator could install the PDF conversion block on a platform that does not yet carry this change. In that state the check falls back to the Django staff flag, which blocks real library authors and lets any staff user write assets into libraries they can only view. Worth saying explicitly on both PRs which one has to land first.

@Kelketek

Copy link
Copy Markdown
Contributor Author

@pkulkark

In that state the check falls back to the Django staff flag, which blocks real library authors and lets any staff user write assets into libraries they can only view. Worth saying explicitly on both PRs which one has to land first.

This has changed now that I made the permissions service more available. Now it requires the permissions service and no longer falls back.

@Kelketek
Kelketek force-pushed the fox/studio-permissions-universality branch 4 times, most recently from 54a33ba to 14899bf Compare September 11, 2026 19:19

@pkulkark pkulkark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍

"""
Service that can provide information about a user's permissions.

Deprecated. To be replaced by a more general authorization service.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"Hmm, this StudioPermissionsService is marked as Deprecated, and now this PR is un-deprecating it. I wonder who marked it as deprecated and what the replacement is."

(looks at git blame)

Oh.

Comment on lines +21 to +39
def can_read(self, context_key):
""" Does the user have read access to the given course/library? """
if isinstance(context_key, LibraryLocatorV2):
return self._user.is_active and authz_api.is_user_allowed(
self._user,
VIEW_LIBRARY.identifier,
str(context_key),
)
return has_studio_read_access(self._user, context_key)

def can_write(self, context_key):
""" Does the user have write access to the given course/library? """
if isinstance(context_key, LibraryLocatorV2):
return self._user.is_active and authz_api.is_user_allowed(
self._user,
EDIT_LIBRARY_CONTENT.identifier,
str(context_key),
)
return has_studio_write_access(self._user, context_key)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess we need can_read and can_write for backwards compatibility, but we have much more fine-grained permissions now. Should we update the permissions service to support those fine-grained permissions instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bradenmacdonald I've pushed a change here that includes much more fine-grained permissions. I'm about to start adding tests for it now. Is this what you had in mind?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Kelketek Yes, that's what I had in mind :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bradenmacdonald Cool-- I've cleaned it up a bit and added some tests. There was one hitch here-- it looks like the AuthZ perms for courses aren't actually added yet. So I put in a decorator shim to perform fallback behavior until they're working right.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, am I missing something? We've been merging a whole bunch of PRs like this which use the new course authoring permissions to make parts of the Studio UI read-only. And I tested those PRs, and they were working as expected, so I thought the fine-grained Studio permissions were implemented.


def create_library(
org: str,
org: Organization,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a little concerning that mypy hadn't flagged any error here ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bradenmacdonald Yes, it is. And after playing with it for a bit, I can't seem to make it fail. I don't want to detour too far here, but something's up. I tried changing mypy's file includes to globs just to make sure the directory paths weren't insufficient, and I tried switching the types back and forth, but despite the fact I know some files that call this function are in the includes, they aren't considered wrong whether I set it to Organization or string, and whether I comment out the assert below or not.

@Kelketek
Kelketek force-pushed the fox/studio-permissions-universality branch 2 times, most recently from 18d2f1f to 4d4a7ac Compare September 21, 2026 19:29
@Kelketek

Copy link
Copy Markdown
Contributor Author

@bradenmacdonald Ready for another pass. Thanks!

@Kelketek
Kelketek force-pushed the fox/studio-permissions-universality branch from 4d4a7ac to 9dbbef4 Compare September 21, 2026 19:38
@Kelketek
Kelketek force-pushed the fox/studio-permissions-universality branch from 9dbbef4 to d05ddf1 Compare September 23, 2026 00:23

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

5 participants