-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat: add authz permission for certificates #38190
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,75 @@ | |
| from common.djangoapps.student.tests.factories import UserFactory | ||
|
|
||
|
|
||
| class AuthzTestMixin: | ||
|
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. Didn't we already have a Mixin for this? (from your previous PR)
Contributor
Author
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. Yes, I updated the mixin to use AuthzTestMixin as the base test. I also added a comment explaining this change and updated CourseAuthzTestMixin without altering its behavior, since it’s used in other parts of the codebase. |
||
| """ | ||
| Minimal reusable mixin for AuthZ-enabled tests. | ||
| """ | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls): | ||
| cls.toggle_patcher = patch.object( | ||
| core_toggles.AUTHZ_COURSE_AUTHORING_FLAG, | ||
| "is_enabled", | ||
| return_value=True, | ||
| ) | ||
| cls.toggle_patcher.start() | ||
| super().setUpClass() | ||
|
|
||
| @classmethod | ||
| def tearDownClass(cls): | ||
| cls.toggle_patcher.stop() | ||
| super().tearDownClass() | ||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
|
|
||
| self._seed_policies() | ||
|
|
||
| self.authorized_user = UserFactory() | ||
| self.unauthorized_user = UserFactory() | ||
|
|
||
| self.authorized_client = APIClient() | ||
| self.authorized_client.force_authenticate(user=self.authorized_user) | ||
|
|
||
| self.unauthorized_client = APIClient() | ||
| self.unauthorized_client.force_authenticate(user=self.unauthorized_user) | ||
|
|
||
| def tearDown(self): | ||
| super().tearDown() | ||
| AuthzEnforcer.get_enforcer().clear_policy() | ||
|
|
||
| def add_user_to_role(self, user, role, course_key): | ||
| """Helper method to add a user to a role for the course.""" | ||
| assign_role_to_user_in_scope( | ||
| user.username, | ||
| role, | ||
| str(course_key) | ||
| ) | ||
| AuthzEnforcer.get_enforcer().load_policy() | ||
|
|
||
| @classmethod | ||
| def _seed_policies(cls): | ||
| """Seed the database with AuthZ policies.""" | ||
| global_enforcer = AuthzEnforcer.get_enforcer() | ||
| global_enforcer.load_policy() | ||
|
|
||
| model_path = pkg_resources.resource_filename( | ||
| "openedx_authz.engine", | ||
| "config/model.conf", | ||
| ) | ||
|
|
||
| policy_path = pkg_resources.resource_filename( | ||
| "openedx_authz.engine", | ||
| "config/authz.policy", | ||
| ) | ||
|
|
||
| migrate_policy_between_enforcers( | ||
| source_enforcer=casbin.Enforcer(model_path, policy_path), | ||
| target_enforcer=global_enforcer, | ||
| ) | ||
|
|
||
|
|
||
| class CourseAuthzTestMixin: | ||
| """ | ||
| Reusable mixin for testing course-scoped AuthZ endpoints. | ||
|
|
||
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 to keep the previous behavior this should be LegacyAuthoringPermission.WRITE (was has_studio_write_access)
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.
Right, changed it. Thanks