-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat: AuthZ for course authoring compatibility layer #38013
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
Open
rodmgwgu
wants to merge
6
commits into
openedx:master
Choose a base branch
from
WGU-Open-edX:rod/authz-compat-layer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+578
−174
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
587c3b5
feat: AuthZ for Course Authoring compatibility layer
rodmgwgu 789b6a8
squash!: Add active user validation on _authz_add_users
rodmgwgu 2f673c4
squash!: Attend PR comments
rodmgwgu 6a80465
squash!: Emit events on role changes
rodmgwgu 68aad70
squash!: Correct authz_add_role behavior to match legacy behavior
rodmgwgu 7638824
squash!: Update openedx-authz
rodmgwgu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,24 +73,34 @@ def _user_can_create_library_for_org(user, org=None): | |
| elif user.is_staff: | ||
| return True | ||
| elif settings.FEATURES.get('ENABLE_CREATOR_GROUP', False): | ||
| org_filter_params = {} | ||
| if org: | ||
| org_filter_params['org'] = org | ||
| is_course_creator = get_course_creator_status(user) == 'granted' | ||
| has_org_staff_role = OrgStaffRole().get_orgs_for_user(user).filter(**org_filter_params).exists() | ||
| has_course_staff_role = ( | ||
| UserBasedRole(user=user, role=CourseStaffRole.ROLE) | ||
| .courses_with_role() | ||
| .filter(**org_filter_params) | ||
| .exists() | ||
| ) | ||
| has_course_admin_role = ( | ||
| UserBasedRole(user=user, role=CourseInstructorRole.ROLE) | ||
| .courses_with_role() | ||
| .filter(**org_filter_params) | ||
| .exists() | ||
| ) | ||
| return is_course_creator or has_org_staff_role or has_course_staff_role or has_course_admin_role | ||
| if is_course_creator: | ||
| return True | ||
|
|
||
| orgs_with_staff_role = OrgStaffRole().get_orgs_for_user(user) | ||
| if org is not None: | ||
| orgs_with_staff_role = [user_org for user_org in orgs_with_staff_role if user_org == org] | ||
| has_org_staff_role = len(orgs_with_staff_role) > 0 | ||
| if has_org_staff_role: | ||
| return True | ||
|
|
||
| all_courses_with_staff_role = UserBasedRole(user=user, role=CourseStaffRole.ROLE).courses_with_role() | ||
bmtcril marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| courses_with_staff_role_on_org = all_courses_with_staff_role | ||
| if org is not None: | ||
| courses_with_staff_role_on_org = [course for course in all_courses_with_staff_role if course.org == org] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest following the same approach in |
||
| has_course_staff_role = len(courses_with_staff_role_on_org) > 0 | ||
| if has_course_staff_role: | ||
| return True | ||
|
|
||
| all_courses_with_admin_role = UserBasedRole(user=user, role=CourseInstructorRole.ROLE).courses_with_role() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| courses_with_admin_role_on_org = all_courses_with_admin_role | ||
| if org is not None: | ||
| courses_with_admin_role_on_org = [course for course in all_courses_with_admin_role if course.org == org] | ||
| has_course_admin_role = len(courses_with_admin_role_on_org) > 0 | ||
| if has_course_admin_role: | ||
| return True | ||
|
|
||
| return False | ||
| else: | ||
| # EDUCATOR-1924: DISABLE_LIBRARY_CREATION overrides DISABLE_COURSE_CREATION, if present. | ||
| disable_library_creation = settings.FEATURES.get('DISABLE_LIBRARY_CREATION', None) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend adding a new method in RoleBase called
has_org_for_user(user, org) (return bool).This avoids leaking implementation details:
By encapsulating the filtering logic inside
has_org_for_user, we keep the interface consistent and allow each implementation to optimize independently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, it is a good strategy for optimizing this, however I don't think in this specific case this would be important, as this code is related to libraries v1 functionality which to my understanding is deprecated. What do you think @bmtcril should we spend more time optimizing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we will have other uses for it and this code for v1 libraries will be hanging around in the code until at least Xylon so it's probably worth it.