forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
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: move progress related apis permissions to standard permission file #51
Closed
tehreem-sadat
wants to merge
1
commit into
open-release/palm.nelp
from
tehreem/move_permissions_to_std_permissions_file
Closed
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
""" | ||
Permissions for the course home apis and associated actions | ||
""" | ||
from bridgekeeper import perms | ||
from lms.djangoapps.courseware.rules import HasAccessRule | ||
|
||
|
||
CAN_MASQUARADE_LEARNER_PROGRESS = 'course_home_api.can_masquarade_progress' | ||
|
||
perms[CAN_MASQUARADE_LEARNER_PROGRESS] = HasAccessRule('staff') |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
Tests for permissions defined in courseware.rules | ||
""" | ||
import ddt | ||
|
||
from common.djangoapps.student.roles import OrgStaffRole, CourseStaffRole | ||
from common.djangoapps.student.tests.factories import UserFactory | ||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order | ||
from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order | ||
from lms.djangoapps.course_home_api.permissions import CAN_MASQUARADE_LEARNER_PROGRESS | ||
|
||
|
||
@ddt.ddt | ||
class PermissionTests(ModuleStoreTestCase): | ||
""" | ||
Tests for permissions defined in courseware.rules | ||
""" | ||
def setUp(self): | ||
super().setUp() | ||
self.user = UserFactory() | ||
self.course = CourseFactory(org='org') | ||
self.another_course = CourseFactory(org='org') | ||
|
||
def tearDown(self): | ||
super().tearDown() | ||
self.user.delete() | ||
|
||
@ddt.data( | ||
( | ||
True, None, None, True, | ||
"Global staff users should have masquerade access", | ||
), | ||
( | ||
False, None, None, False, | ||
"Non-staff users shouldn't have masquerade access", | ||
), | ||
( | ||
False, 'another_org', None, False, | ||
"User with staff access on another org shouldn't have masquerade access", | ||
), | ||
( | ||
False, 'org', None, True, | ||
"User with org-wide staff access should have masquerade access", | ||
), | ||
( | ||
False, None, 'another_course', False, | ||
"User with staff access on another course shouldn't have masquerade access", | ||
), | ||
( | ||
False, None, 'course', True, | ||
"User with staff access on the course should have masquerade access", | ||
), | ||
) | ||
@ddt.unpack | ||
def test_can_masquerade_return_value(self, is_staff, org_role, course_role, expected_permission, description): | ||
""" | ||
Test that only authorized users have masquerade access | ||
""" | ||
self.user.is_staff = is_staff | ||
self.user.save() | ||
assert self.user.is_staff == is_staff | ||
|
||
if org_role: | ||
OrgStaffRole(org_role).add_users(self.user) | ||
|
||
if course_role: | ||
CourseStaffRole(getattr(self, course_role).id).add_users(self.user) | ||
|
||
has_perm = self.user.has_perm(CAN_MASQUARADE_LEARNER_PROGRESS, self.course.id) | ||
assert has_perm == expected_permission, description |
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.
meanwhile @tehreem-sadat , please try to add a test that checks the flow when
permissions.CAN_MASQUARADE_LEARNER_PROGRESS
returnsTrue
andFalse
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.
yess, that can be added, thanks.