feat: authorize advanced settings endpoints via openedx-authz when fl…#38009
feat: authorize advanced settings endpoints via openedx-authz when fl…#38009wgu-taylor-payne wants to merge 2 commits intoopenedx:masterfrom
Conversation
|
Thanks for the pull request, @wgu-taylor-payne! This repository is currently maintained by 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 approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo 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:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere 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:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
6861d86 to
007be04
Compare
…when flag enabled
| bool: True if user has permission, False otherwise | ||
| """ | ||
| if core_toggles.AUTHZ_COURSE_AUTHORING_FLAG.is_enabled(course_key): | ||
| return authz_api.is_user_allowed(user.username, MANAGE_ADVANCED_SETTINGS.identifier, str(course_key)) |
There was a problem hiding this comment.
The previous version of this check also checked whether the DISABLE_ADVANCED_SETTINGS feature flag was set. Is that no longer necessary?
There was a problem hiding this comment.
The only path that checks this feature flag is when the proctoring errors view calls has_studio_advanced_settings_access. This path still executes, as I've wrapped has_studio_advanced_settings_access in the new function I introduced, check_course_advanced_settings_access.
So, the check still happens if the AUTHZ_COURSE_AUTHORING_FLAG is not enabled. But, you bring up a good point that to keep existing functionality for the proctoring errors view, I would need to check DISABLE_ADVANCED_SETTINGS even if AUTHZ_COURSE_AUTHORING_FLAG is enabled.
There was a problem hiding this comment.
I'm thinking through the permission check for the proctoring errors view. Right now this is how the permission check works:
has_studio_advanced_settings_access
|---------------------------+-------+---------------------------------------|
| DISABLE_ADVANCED_SETTINGS | not | result |
|---------------------------+-------+---------------------------------------|
| True | False | Only authorized if staff or superuser |
| False | True | Authorized - no staff/superuser check |
|---------------------------+-------+---------------------------------------|
The first thing to note here is that if DISABLE_ADVANCED_SETTINGS is False we don't do any further checks. I assume we would want to convert this scenario to check for the MANAGE_ADVANCED_SETTINGS permission, even though this wouldn't match current behavior?
Secondly, if DISABLE_ADVANCED_SETTINGS is True the current behavior is to make sure the user is staff or superuser to grant permission. If we migrate this check from solely staff/superuser to staff/superuser + role, then this changes behavior, as DISABLE_ADVANCED_SETTINGS is described as granting advanced settings access solely to staff/superusers.
new approach with openedx-authz
|---------------------------+--------------------------------------------|
| DISABLE_ADVANCED_SETTINGS | result |
|---------------------------+--------------------------------------------|
| True | Check MANAGE_ADVANCED_SETTINGS permission? |
| False | Check MANAGE_ADVANCED_SETTINGS permission? |
|---------------------------+--------------------------------------------|
There was a problem hiding this comment.
Mmm so the idea is that with MANAGE_ADVANCED_SETTINGS, we should be able to have the granularity to enable or disable advanced settings for specific users, so DISABLE_ADVANCED_SETTINGS won't be necessary anymore. I would vote then to only check for MANAGE_ADVANCED_SETTINGS if the flag is enabled.
| ) | ||
|
|
||
|
|
||
| def check_course_advanced_settings_access(user, course_key, access_type='read'): |
There was a problem hiding this comment.
It seems like this is being used for more than just advanced settings checks, should it be renamed?
There was a problem hiding this comment.
For the advanced settings page, the frontend calls the AdvancedCourseSettingsView (get/patch) and the ProctoringErrorsView (get). I wrapped all of those checks into this function. Since they are all advanced settings related, and since the ProctoringErrorsView check already called a function with "advanced settings" in the name, I thought this would be appropriate.
My first approach was to replace the current checks with something like:
if core_toggles.AUTHZ_COURSE_AUTHORING_FLAG.is_enabled(course_key):
if not authz_api.is_user_allowed(user.username, MANAGE_ADVANCED_SETTINGS.identifier, str(course_key)):
return self.permission_denied(request)
elif not { current permission check }:
return self.permission_denied(request)but I didn't love the repetition, nesting, and having to import everything needed in both modules, so I wrapped all the checks.
| access_type: Type of access to check. Options: | ||
| - 'read': Check read access (default) | ||
| - 'write': Check write access | ||
| - 'advanced_settings': Check advanced settings access (DISABLE_ADVANCED_SETTINGS feature) |
There was a problem hiding this comment.
I don't think this comment is correct at this point?
There was a problem hiding this comment.
Indirectly via has_studio_advanced_settings_access, but I agree this description could use some work.
There was a problem hiding this comment.
Can we make the access_type option more descriptive? perhaps 'legacy_disable_advanced_settings_flag_check' or something like that?
bmtcril
left a comment
There was a problem hiding this comment.
Just a few comments to make sure I understand how this works with the DISABLE_ADVANCED_SETTINGS flag
rodmgwgu
left a comment
There was a problem hiding this comment.
Looking good, just some comments on active discussions.
| bool: True if user has permission, False otherwise | ||
| """ | ||
| if core_toggles.AUTHZ_COURSE_AUTHORING_FLAG.is_enabled(course_key): | ||
| return authz_api.is_user_allowed(user.username, MANAGE_ADVANCED_SETTINGS.identifier, str(course_key)) |
There was a problem hiding this comment.
Mmm so the idea is that with MANAGE_ADVANCED_SETTINGS, we should be able to have the granularity to enable or disable advanced settings for specific users, so DISABLE_ADVANCED_SETTINGS won't be necessary anymore. I would vote then to only check for MANAGE_ADVANCED_SETTINGS if the flag is enabled.
| access_type: Type of access to check. Options: | ||
| - 'read': Check read access (default) | ||
| - 'write': Check write access | ||
| - 'advanced_settings': Check advanced settings access (DISABLE_ADVANCED_SETTINGS feature) |
There was a problem hiding this comment.
Can we make the access_type option more descriptive? perhaps 'legacy_disable_advanced_settings_flag_check' or something like that?
Description
Add the option to authorize with openedx-authz for the advanced settings related endpoints. If the
AUTHZ_COURSE_AUTHORING_FLAGis enabled for the course, then the system will do the permission check against openedx-authz.This functionality depends on features introduced to openedx-authz in version 0.21.0.
Supporting information
Resolves #37926.
Testing instructions
To run the relevant automated tests:
To manually test:
./manage.py cms load_policiesAUTHZ_COURSE_AUTHORING_FLAGflag is enabled for the given course (see feat: Add Waffle flag for AuthZ for Course Authoring #37985).COURSE_STAFFrole to the user with the scope being the course you are testing access for. Afterwards the user should have access to the advanced settings page.Deadline
Verawood release