Skip to content

Commit

Permalink
feat: Add permission checks to role checks - program_enrollments and …
Browse files Browse the repository at this point in the history
…agreements (#34001)

* feat: add perm check to role check for program_enrollments and agreements
  • Loading branch information
hsinkoff committed Jan 22, 2024
1 parent 4a4ed72 commit 974d5bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lms/djangoapps/program_enrollments/rest_api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from lms.djangoapps.program_enrollments.api import is_course_staff_enrollment
from lms.djangoapps.program_enrollments.models import ProgramCourseEnrollment, ProgramEnrollment

from openedx.core.djangoapps.course_roles.data import CourseRolesPermission
from .constants import CourseRunProgressStatuses

# pylint: disable=abstract-method
Expand Down Expand Up @@ -104,7 +104,11 @@ def get_curriculum_uuid(self, obj):
return str(obj.program_enrollment.curriculum_uuid)

def get_course_staff(self, obj):
return is_course_staff_enrollment(obj)
# TODO: remove is_course_staff_enrollment check once course_roles is fully impelented and data is migrated
return (
is_course_staff_enrollment(obj) or
obj.program_enrollment.user.has_perm(CourseRolesPermission.MANAGE_STUDENTS.perm_name, obj.course_key)
)


class ProgramCourseEnrollmentRequestSerializer(serializers.Serializer, InvalidStatusMixin):
Expand Down
9 changes: 8 additions & 1 deletion openedx/core/djangoapps/agreements/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
get_integrity_signature,
)
from openedx.core.djangoapps.agreements.serializers import IntegritySignatureSerializer, LTIPIISignatureSerializer
from openedx.core.djangoapps.course_roles.data import CourseRolesPermission


def is_user_course_or_global_staff(user, course_id):
Expand All @@ -27,7 +28,13 @@ def is_user_course_or_global_staff(user, course_id):
or is global staff.
"""

return user.is_staff or auth.user_has_role(user, CourseStaffRole(CourseKey.from_string(course_id)))
# TODO: remove user_has_role check once course_roles is fully impelented and data is migrated
course_key = CourseKey.from_string(course_id)
return (
user.is_staff or
auth.user_has_role(user, CourseStaffRole(course_key)) or
user.has_perm(CourseRolesPermission.MANAGE_STUDENTS.perm_name, course_key)
)


class AuthenticatedAPIView(APIView):
Expand Down

0 comments on commit 974d5bc

Please sign in to comment.