-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: modify REST API endpoints for LR MFE (#1760)
Co-authored-by: Maxwell Frank <[email protected]>
- Loading branch information
1 parent
d26436e
commit b0d8339
Showing
3 changed files
with
170 additions
and
19 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
Custom permissions classes for use with DRF. | ||
""" | ||
from edx_rest_framework_extensions.permissions import get_username_param | ||
from rest_framework import permissions | ||
|
||
|
||
class IsPublic(permissions.BasePermission): | ||
""" | ||
Allows access if URL is for a public record. | ||
""" | ||
|
||
def has_permission(self, request, view): | ||
""" | ||
Check to see what type of record (private/public) in the query parameter. | ||
If it is not public, run a normal authentication permission check. | ||
""" | ||
query_param_is_public = request.query_params.get("is_public", "") | ||
is_public = query_param_is_public.lower() == "true" | ||
if not is_public: | ||
return bool(request.user and request.user.is_authenticated) | ||
return True | ||
|
||
|
||
class CanAccessProgramRecord(permissions.BasePermission): | ||
""" | ||
Allows access if the requesting user a staff member or a superuser. | ||
""" | ||
|
||
def has_permission(self, request, view): | ||
""" | ||
If there is a username query param, check for either superuser or staff access. | ||
""" | ||
if get_username_param(request): | ||
return request.user and (request.user.is_superuser or request.user.is_staff) | ||
return True |
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