예제 #1
0
    def post(self, request, course_id, rolename):
        """
        Implement a handler for the POST method.
        """
        kwargs = self._get_request_kwargs(course_id, rolename)
        form = CourseDiscussionRolesForm(kwargs, request_user=request.user)
        if not form.is_valid():
            raise ValidationError(form.errors)

        course_id = form.cleaned_data['course_key']
        rolename = form.cleaned_data['rolename']

        serializer = DiscussionRolesSerializer(data=request.data)
        if not serializer.is_valid():
            raise ValidationError(serializer.errors)

        action = serializer.validated_data['action']
        user = serializer.validated_data['user']
        try:
            update_forum_role(course_id, user, rolename, action)
        except Role.DoesNotExist:
            raise ValidationError(u"Role '{}' does not exist".format(rolename))

        role = form.cleaned_data['role']
        data = {'course_id': course_id, 'users': role.users.all()}
        context = {
            'course_discussion_settings':
            get_course_discussion_settings(course_id)
        }
        serializer = DiscussionRolesListSerializer(data, context=context)
        return Response(serializer.data)
예제 #2
0
파일: views.py 프로젝트: regisb/fun-apps
def modify_special_forum_contributors(request, course_id):

    unique_student_identifier = request.GET.get('unique_student_identifier')
    rolename = request.GET.get('rolename')
    action = request.GET.get('action')

    try:
        course_id = _check_rights(course_id, request.user, rolename)
    except UnauthorizedAccessError as e:
        return HttpResponseBadRequest(e.message)
    course = get_course_by_id(course_id)
    _check_custom_roles(course_id)

    user = get_student_from_identifier(unique_student_identifier)
    target_is_instructor = has_access(user, 'instructor', course)
    # cannot revoke instructor
    if target_is_instructor and action == 'revoke' and rolename == FORUM_ROLE_ADMINISTRATOR:
        return HttpResponseBadRequest("Cannot revoke instructor forum admin privileges.")
    try:
        update_forum_role(course_id, user, rolename, action)
    except Role.DoesNotExist:
        return HttpResponseBadRequest("Role does not exist.")

    response_payload = {
        'course_id': course_id.to_deprecated_string(),
        'action': action,
    }
    return JsonResponse(response_payload)
예제 #3
0
    def post(self, request, course_id, rolename):
        """
        Implement a handler for the POST method.
        """
        kwargs = self._get_request_kwargs(course_id, rolename)
        form = CourseDiscussionRolesForm(kwargs, request_user=request.user)
        if not form.is_valid():
            raise ValidationError(form.errors)

        course_id = form.cleaned_data['course_key']
        rolename = form.cleaned_data['rolename']

        serializer = DiscussionRolesSerializer(data=request.data)
        if not serializer.is_valid():
            raise ValidationError(serializer.errors)

        action = serializer.validated_data['action']
        user = serializer.validated_data['user']
        try:
            update_forum_role(course_id, user, rolename, action)
        except Role.DoesNotExist:
            raise ValidationError("Role '{}' does not exist".format(rolename))

        role = form.cleaned_data['role']
        data = {'course_id': course_id, 'users': role.users.all()}
        context = {'course_discussion_settings': get_course_discussion_settings(course_id)}
        serializer = DiscussionRolesListSerializer(data, context=context)
        return Response(serializer.data)
예제 #4
0
파일: views.py 프로젝트: julAtWork/fun-apps
def modify_special_forum_contributors(request, course_id):

    unique_student_identifier = request.GET.get('unique_student_identifier')
    rolename = request.GET.get('rolename')
    action = request.GET.get('action')

    try:
        course_id = _check_rights(course_id, request.user, rolename)
    except UnauthorizedAccessError as e:
        return HttpResponseBadRequest(e.message)
    course = get_course_by_id(course_id)
    _check_custom_roles(course_id)

    user = get_student_from_identifier(unique_student_identifier)
    target_is_instructor = has_access(user, 'instructor', course)
    # cannot revoke instructor
    if target_is_instructor and action == 'revoke' and rolename == FORUM_ROLE_ADMINISTRATOR:
        return HttpResponseBadRequest("Cannot revoke instructor forum admin privileges.")
    try:
        update_forum_role(course_id, user, rolename, action)
    except Role.DoesNotExist:
        return HttpResponseBadRequest("Role does not exist.")

    response_payload = {
        'course_id': course_id.to_deprecated_string(),
        'action': action,
    }
    return JsonResponse(response_payload)
예제 #5
0
def update_forum_role_membership(request, course_id):
    """
    Modify user's forum role.

    The requesting user must be at least staff.
    Staff forum admins can access all roles EXCEPT for FORUM_ROLE_ADMINISTRATOR
        which is limited to instructors.
    No one can revoke an instructors FORUM_ROLE_ADMINISTRATOR status.

    Query parameters:
    - `email` is the target users email
    - `rolename` is one of [FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA]
    - `action` is one of ['allow', 'revoke']
    """
    course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id)
    course = get_course_by_id(course_id)
    has_instructor_access = has_access(request.user, 'instructor', course)
    has_forum_admin = has_forum_access(request.user, course_id,
                                       FORUM_ROLE_ADMINISTRATOR)

    unique_student_identifier = request.GET.get('unique_student_identifier')
    rolename = request.GET.get('rolename')
    action = request.GET.get('action')

    # default roles require either (staff & forum admin) or (instructor)
    if not (has_forum_admin or has_instructor_access):
        return HttpResponseBadRequest(
            "Operation requires staff & forum admin or instructor access")

    # EXCEPT FORUM_ROLE_ADMINISTRATOR requires (instructor)
    if rolename == FORUM_ROLE_ADMINISTRATOR and not has_instructor_access:
        return HttpResponseBadRequest("Operation requires instructor access.")

    if not rolename in [
            FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR,
            FORUM_ROLE_COMMUNITY_TA
    ]:
        return HttpResponseBadRequest(
            strip_tags("Unrecognized rolename '{}'.".format(rolename)))

    user = get_student_from_identifier(unique_student_identifier)
    target_is_instructor = has_access(user, 'instructor', course)
    # cannot revoke instructor
    if target_is_instructor and action == 'revoke' and rolename == FORUM_ROLE_ADMINISTRATOR:
        return HttpResponseBadRequest(
            "Cannot revoke instructor forum admin privileges.")

    try:
        update_forum_role(course_id, user, rolename, action)
    except Role.DoesNotExist:
        return HttpResponseBadRequest("Role does not exist.")

    response_payload = {
        'course_id': course_id.to_deprecated_string(),
        'action': action,
    }
    return JsonResponse(response_payload)
예제 #6
0
def update_forum_role_membership(request, course_id):
    """
    Modify user's forum role.

    The requesting user must be at least staff.
    Staff forum admins can access all roles EXCEPT for FORUM_ROLE_ADMINISTRATOR
        which is limited to instructors.
    No one can revoke an instructors FORUM_ROLE_ADMINISTRATOR status.

    Query parameters:
    - `email` is the target users email
    - `rolename` is one of [FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA]
    - `action` is one of ['allow', 'revoke']
    """
    course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id)
    course = get_course_by_id(course_id)
    has_instructor_access = has_access(request.user, 'instructor', course)
    has_forum_admin = has_forum_access(
        request.user, course_id, FORUM_ROLE_ADMINISTRATOR
    )

    unique_student_identifier = request.GET.get('unique_student_identifier')
    rolename = request.GET.get('rolename')
    action = request.GET.get('action')

    # default roles require either (staff & forum admin) or (instructor)
    if not (has_forum_admin or has_instructor_access):
        return HttpResponseBadRequest(
            "Operation requires staff & forum admin or instructor access"
        )

    # EXCEPT FORUM_ROLE_ADMINISTRATOR requires (instructor)
    if rolename == FORUM_ROLE_ADMINISTRATOR and not has_instructor_access:
        return HttpResponseBadRequest("Operation requires instructor access.")

    if not rolename in [FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA]:
        return HttpResponseBadRequest(strip_tags(
            "Unrecognized rolename '{}'.".format(rolename)
        ))

    user = get_student_from_identifier(unique_student_identifier)
    target_is_instructor = has_access(user, 'instructor', course)
    # cannot revoke instructor
    if target_is_instructor and action == 'revoke' and rolename == FORUM_ROLE_ADMINISTRATOR:
        return HttpResponseBadRequest("Cannot revoke instructor forum admin privileges.")

    try:
        update_forum_role(course_id, user, rolename, action)
    except Role.DoesNotExist:
        return HttpResponseBadRequest("Role does not exist.")

    response_payload = {
        'course_id': course_id.to_deprecated_string(),
        'action': action,
    }
    return JsonResponse(response_payload)
예제 #7
0
파일: views.py 프로젝트: ovnicraft/fun-apps
def modify_special_forum_contributors(request, course_id):

    unique_student_identifier = request.GET.get("unique_student_identifier")
    rolename = request.GET.get("rolename")
    action = request.GET.get("action")

    course_id = _check_rights(course_id, request.user, rolename)
    course = get_course_by_id(course_id)
    _check_custom_roles(course_id)

    user = get_student_from_identifier(unique_student_identifier)
    target_is_instructor = has_access(user, "instructor", course)
    # cannot revoke instructor
    if target_is_instructor and action == "revoke" and rolename == FORUM_ROLE_ADMINISTRATOR:
        return HttpResponseBadRequest("Cannot revoke instructor forum admin privileges.")
    try:
        update_forum_role(course_id, user, rolename, action)
    except Role.DoesNotExist:
        return HttpResponseBadRequest("Role does not exist.")

    response_payload = {"course_id": course_id.to_deprecated_string(), "action": action}
    return JsonResponse(response_payload)
예제 #8
0
 def test_bad_mode(self):
     user = UserFactory()
     update_forum_role(self.course.id, user, FORUM_ROLE_MODERATOR,
                       'robot-not-a-mode')
예제 #9
0
 def test_bad_mode(self):
     user = UserFactory()
     update_forum_role(self.course.id, user, FORUM_ROLE_MODERATOR, 'robot-not-a-mode')
예제 #10
0
 def test_revoke_badrole(self):
     user = self.moderators[0]
     update_forum_role(self.course.id, user, 'robot-not-a-real-role', 'allow')
예제 #11
0
 def test_revoke_notallowed(self):
     user = UserFactory()
     update_forum_role(self.course.id, user, FORUM_ROLE_MODERATOR, 'revoke')
     self.assertNotIn(user, self.mod_role.users.all())
예제 #12
0
 def test_revoke_twice(self):
     user = self.moderators[0]
     update_forum_role(self.course.id, user, FORUM_ROLE_MODERATOR, 'revoke')
     self.assertNotIn(user, self.mod_role.users.all())
     update_forum_role(self.course.id, user, FORUM_ROLE_MODERATOR, 'revoke')
     self.assertNotIn(user, self.mod_role.users.all())
예제 #13
0
 def test_allow_badrole(self):
     user = UserFactory.create()
     update_forum_role(self.course.id, user, 'robot-not-a-real-role', 'allow')
예제 #14
0
 def test_allow_twice(self):
     user = UserFactory.create()
     update_forum_role(self.course.id, user, FORUM_ROLE_MODERATOR, 'allow')
     self.assertIn(user, self.mod_role.users.all())
     update_forum_role(self.course.id, user, FORUM_ROLE_MODERATOR, 'allow')
     self.assertIn(user, self.mod_role.users.all())
예제 #15
0
 def test_allow_twice(self):
     user = UserFactory.create()
     update_forum_role(self.course.id, user, FORUM_ROLE_MODERATOR, 'allow')
     self.assertIn(user, self.mod_role.users.all())
     update_forum_role(self.course.id, user, FORUM_ROLE_MODERATOR, 'allow')
     self.assertIn(user, self.mod_role.users.all())
예제 #16
0
 def test_allow_badrole(self):
     user = UserFactory.create()
     update_forum_role(self.course.id, user, 'robot-not-a-real-role',
                       'allow')
예제 #17
0
 def test_revoke_badrole(self):
     user = self.moderators[0]
     update_forum_role(self.course.id, user, 'robot-not-a-real-role',
                       'allow')
예제 #18
0
 def test_revoke_notallowed(self):
     user = UserFactory()
     update_forum_role(self.course.id, user, FORUM_ROLE_MODERATOR, 'revoke')
     self.assertNotIn(user, self.mod_role.users.all())
예제 #19
0
 def test_revoke_twice(self):
     user = self.moderators[0]
     update_forum_role(self.course.id, user, FORUM_ROLE_MODERATOR, 'revoke')
     self.assertNotIn(user, self.mod_role.users.all())
     update_forum_role(self.course.id, user, FORUM_ROLE_MODERATOR, 'revoke')
     self.assertNotIn(user, self.mod_role.users.all())