Files
edx-platform/lms/djangoapps/learner_dashboard/permissions.py
Ahtisham Shahid 987c641d82 feat: created API to get program discussion iframe (#29205)
fix: py lint issues fixed

feat: added test cases for API

fix: py lint issues fixed and added tests

fix: updated tests and refactored

fix: fixed return type in the function

fix: conflicts resolved and linter issue

refactor: updated code to accommodate backward compatibility

refactor: updated classes for code clean up

feat: added test for ProgramDetailFragment

feat: added a new flag for masters discussion

refactor: updated flag names and other refactors
2021-11-22 11:27:45 +05:00

33 lines
1.0 KiB
Python

"""
Permissions for program discussion api
"""
from django.core.exceptions import ObjectDoesNotExist
from rest_framework import permissions, status
from rest_framework.exceptions import APIException
from lms.djangoapps.program_enrollments.api import get_program_enrollment
class IsEnrolledInProgram(permissions.BasePermission):
"""Permission that checks to see if the user is enrolled in the course or is staff."""
def has_permission(self, request, view):
"""Returns true if the user is enrolled in program"""
if not view.program:
raise ProgramNotFound
try:
get_program_enrollment(program_uuid=view.kwargs.get('program_uuid'), user=request.user)
except ObjectDoesNotExist:
return False
return True
class ProgramNotFound(APIException):
"""
custom exception class for Program not found error
"""
status_code = status.HTTP_404_NOT_FOUND
default_detail = 'Program not found for provided uuid'
default_code = 'program_not_found'