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

feat: add library roles support for roles API #124

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

tehreem-sadat
Copy link
Collaborator

@tehreem-sadat tehreem-sadat commented Nov 1, 2024

Add library roles and library_ids support for course access role APIs

Following are roles details

  • staff role -> can be tenant wide or library specific.
  • instructor role -> can be tenant wide or library specific.
  • library_user -> only valid for library_ids, can not be set tenant wide.

Related Issue: #107

@tehreem-sadat tehreem-sadat changed the title feat: add library roles support for post and update roles feat: add library roles support for roles Nov 1, 2024
@tehreem-sadat tehreem-sadat force-pushed the tehreem/feat_add_library_user_role_support branch from d37d261 to 1eb00da Compare November 4, 2024 09:03
@tehreem-sadat tehreem-sadat force-pushed the tehreem/feat_add_library_user_role_support branch 3 times, most recently from f154c32 to 1c62ff5 Compare November 5, 2024 12:24
@tehreem-sadat tehreem-sadat force-pushed the tehreem/feat_add_library_user_role_support branch from 1c62ff5 to 44aed5d Compare November 5, 2024 12:26
@tehreem-sadat tehreem-sadat changed the title feat: add library roles support for roles feat: add library roles support for roles API Nov 6, 2024
Copy link
Collaborator

@shadinaif shadinaif left a comment

Choose a reason for hiding this comment

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

small changes and it's good to go, thank you @tehreem-sadat !

Comment on lines +148 to +152
result['courses'].update({
str(lib_key): lib_key.org
for lib_key in modulestore().get_library_keys()
if str(lib_key) in course_ids
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought this was bad, then realized it's great! thank you!

Comment on lines +55 to +58
for course_id in course_ids:
if not re.match(cs.LIBRARY_ID_REGX, course_id):
return False
return True
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
for course_id in course_ids:
if not re.match(cs.LIBRARY_ID_REGX, course_id):
return False
return True
return all(re.match(cs.LIBRARY_ID_REGX, course_id) for course_id in course_ids)

Comment on lines +77 to +81
check_broken_rule(
role == cs.COURSE_ACCESS_ROLES_LIBRARY_USER and course_id and not are_all_library_ids([course_id]),
FXExceptionCodes.ROLE_INVALID_ENTRY,
f'role {role} is only valid with library_id',
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

validation order is a bit important in this function. Please move this after ....f'role {role} must have at least an org, it can also have a course_id!',


def get_library_keys(self):
"""mock modulestore library keys method"""
return [CourseKey.from_string(id) for id in self.ids]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mocking is our enemy in tests. Please keep close to the real result as much as possible

Suggested change
return [CourseKey.from_string(id) for id in self.ids]
return [LibraryLocator.from_string(id) for id in self.ids]

from opaque_keys.edx.locator import LibraryLocator

@shadinaif shadinaif self-requested a review November 13, 2024 05:24
@shadinaif shadinaif merged commit 832468c into main Nov 13, 2024
3 checks passed
@shadinaif shadinaif deleted the tehreem/feat_add_library_user_role_support branch November 13, 2024 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants