-
Notifications
You must be signed in to change notification settings - Fork 15
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
Refactor the role filtering parameter to be a tuple #7020
Open
marcospri
wants to merge
1
commit into
main
Choose a base branch
from
refactor-role-parameter
base: main
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.
Open
Changes from all commits
Commits
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 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 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 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 |
---|---|---|
|
@@ -160,8 +160,7 @@ def _user_search_query(self, application_instance_id, user_id) -> Select: | |
|
||
def get_users_for_assignment( | ||
self, | ||
role_scope: RoleScope, | ||
role_type: RoleType, | ||
include_role: tuple[RoleScope, RoleType], | ||
assignment_id: int, | ||
h_userids: list[str] | None = None, | ||
) -> Select[tuple[LMSUser]]: | ||
|
@@ -175,10 +174,8 @@ def get_users_for_assignment( | |
) | ||
.where( | ||
LMSUserAssignmentMembership.assignment_id == assignment_id, | ||
LMSUserAssignmentMembership.lti_role_id.in_( | ||
select(LTIRole.id).where( | ||
LTIRole.scope == role_scope, LTIRole.type == role_type | ||
) | ||
self._filter_membership_by_role_clause( | ||
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. Adding a small helper function here to avoid a bit duplication. Again, this will make more sense once we add |
||
LMSUserAssignmentMembership, include_role | ||
), | ||
) | ||
) | ||
|
@@ -189,8 +186,7 @@ def get_users_for_assignment( | |
|
||
def get_users_for_course( | ||
self, | ||
role_scope: RoleScope, | ||
role_type: RoleType, | ||
include_role: tuple[RoleScope, RoleType], | ||
lms_course: LMSCourse, | ||
h_userids: list[str] | None = None, | ||
) -> Select[tuple[LMSUser]]: | ||
|
@@ -205,10 +201,8 @@ def get_users_for_course( | |
.join(LMSCourse, LMSCourse.id == LMSCourseMembership.lms_course_id) | ||
.where( | ||
LMSCourseMembership.lms_course_id == lms_course.id, | ||
LMSCourseMembership.lti_role_id.in_( | ||
select(LTIRole.id).where( | ||
LTIRole.scope == role_scope, LTIRole.type == role_type | ||
) | ||
self._filter_membership_by_role_clause( | ||
LMSCourseMembership, include_role | ||
), | ||
) | ||
) | ||
|
@@ -219,14 +213,13 @@ def get_users_for_course( | |
|
||
def get_users_for_segments( | ||
self, | ||
role_scope: RoleScope, | ||
role_type: RoleType, | ||
include_role: tuple[RoleScope, RoleType], | ||
segment_ids: list[int], | ||
h_userids: list[str] | None = None, | ||
) -> Select[tuple[LMSUser]]: | ||
"""Get the users that belong to a list of segment. | ||
|
||
This method doesn't use roste data, just launches. | ||
This method doesn't use roster data, just launches. | ||
""" | ||
query = ( | ||
select(LMSUser) | ||
|
@@ -237,10 +230,8 @@ def get_users_for_segments( | |
) | ||
.where( | ||
LMSSegmentMembership.lms_segment_id.in_(segment_ids), | ||
LMSSegmentMembership.lti_role_id.in_( | ||
select(LTIRole.id).where( | ||
LTIRole.scope == role_scope, LTIRole.type == role_type | ||
) | ||
self._filter_membership_by_role_clause( | ||
LMSSegmentMembership, include_role | ||
), | ||
) | ||
) | ||
|
@@ -249,10 +240,9 @@ def get_users_for_segments( | |
|
||
return query.order_by(LMSUser.display_name, LMSUser.id) | ||
|
||
def get_users_for_organization( # noqa: PLR0913 | ||
def get_users_for_organization( | ||
self, | ||
role_scope: RoleScope, | ||
role_type: RoleType, | ||
include_role: tuple[RoleScope, RoleType], | ||
course_ids: list[int] | None = None, | ||
instructor_h_userid: str | None = None, | ||
admin_organization_ids: list[int] | None = None, | ||
|
@@ -273,11 +263,9 @@ def get_users_for_organization( # noqa: PLR0913 | |
) | ||
.join(candidate_courses, candidate_courses.c[0] == Grouping.id) | ||
.where( | ||
LMSCourseMembership.lti_role_id.in_( | ||
select(LTIRole.id).where( | ||
LTIRole.scope == role_scope, LTIRole.type == role_type | ||
) | ||
) | ||
self._filter_membership_by_role_clause( | ||
LMSCourseMembership, include_role | ||
), | ||
) | ||
) | ||
|
||
|
@@ -288,8 +276,7 @@ def get_users_for_organization( # noqa: PLR0913 | |
|
||
def get_users( # noqa: PLR0913 | ||
self, | ||
role_scope: RoleScope, | ||
role_type: RoleType, | ||
include_role: tuple[RoleScope, RoleType], | ||
instructor_h_userid: str | None = None, | ||
admin_organization_ids: list[int] | None = None, | ||
course_ids: list[int] | None = None, | ||
|
@@ -310,8 +297,7 @@ def get_users( # noqa: PLR0913 | |
:param segment_authority_provided_ids: return only users that belong these segments. | ||
""" | ||
query = self.get_users_for_organization( | ||
role_scope=role_scope, | ||
role_type=role_type, | ||
include_role=include_role, | ||
instructor_h_userid=instructor_h_userid, | ||
admin_organization_ids=admin_organization_ids, | ||
h_userids=h_userids, | ||
|
@@ -346,6 +332,18 @@ def get_users( # noqa: PLR0913 | |
|
||
return query.order_by(LMSUser.display_name, LMSUser.id) | ||
|
||
def _filter_membership_by_role_clause( | ||
self, | ||
MembershipModel, # noqa: N803 | ||
include_role: tuple[RoleScope, RoleType], | ||
): | ||
role_scope, role_type = include_role | ||
return MembershipModel.lti_role_id.in_( | ||
select(LTIRole.id).where( | ||
LTIRole.scope == role_scope, LTIRole.type == role_type | ||
) | ||
) | ||
|
||
|
||
def factory(_context, request): | ||
"""Service factory for the UserService.""" | ||
|
This file contains 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 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 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.
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.
Most of the changes is this, from two parameters to a tuple.
I might create a type alias when we add
exclude_role
.