当前位置: 首页>>代码示例>>Python>>正文


Python auth.add_users函数代码示例

本文整理汇总了Python中student.auth.add_users函数的典型用法代码示例。如果您正苦于以下问题:Python add_users函数的具体用法?Python add_users怎么用?Python add_users使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了add_users函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cm_enroll_user

def cm_enroll_user(request):
    response_format = request.REQUEST.get('format','html')
    if response_format == 'json' or 'application/json' in request.META.get('HTTP/ACCEPT', 'application/json'):
        if request.method == 'POST':
            if validate_token(request.body, request) is False:
                return HttpResponse('Unauthorized', status=401)
            if 'email' not in request.json or 'course_id' not in request.json:
                return HttpResponse(content=json.dumps({'errors':'Missing params'}), \
                        content_type = 'application/json', status=400)
            try:
                log.info("Enrolling user: " + request.json.get('email') + " course: " + request.json.get('course_id'))
                CourseEnrollment.enroll_by_email(request.json.get('email'), \
                                                 get_key_from_course_id(request.json.get('course_id')), ignore_errors=False)

                # See if enrolling with staff credentials
                if request.json.get('role') == 'staff':
                    global_admin = AdminFactory()
                    course = get_key_from_course_id(request.json.get('course_id'))
                    auth.add_users(global_admin, CourseInstructorRole(course), User.objects.get(email=request.json.get('email')))
                    
                content = {'success':'ok'}
                status_code = 200
            except User.DoesNotExist:
                content = {'errors':'User does not exist'}
                status_code = 422
            return HttpResponse(content=json.dumps(content), status=status_code, \
                    content_type = 'application/json')
        else:
            return HttpResponse(content=json.dumps({}), status=404, content_type = 'application/json')
    else:
        return HttpResponse(content=json.dumps({}), status=404, content_type = 'application/json')
开发者ID:edcast-inc,项目名称:edx-platform-edcast,代码行数:31,代码来源:views.py

示例2: test_add_user_to_group_requires_staff_access

    def test_add_user_to_group_requires_staff_access(self):
        with self.assertRaises(PermissionDenied):
            self.admin.is_staff = False
            add_users(self.admin, CourseCreatorRole(), self.user)

        with self.assertRaises(PermissionDenied):
            add_users(self.user, CourseCreatorRole(), self.user)
开发者ID:1amongus,项目名称:edx-platform,代码行数:7,代码来源:test_authz.py

示例3: test_get_all_users

    def test_get_all_users(self):
        """
        Test getting all authors for a course where their permissions run the gamut of allowed group
        types.
        """
        # first check the course creator.has explicit access (don't use has_access as is_staff
        # will trump the actual test)
        self.assertTrue(CourseInstructorRole(self.course_key).has_user(self.user), "Didn't add creator as instructor.")
        users = copy.copy(self.users)
        # doesn't use role.users_with_role b/c it's verifying the roles.py behavior
        user_by_role = {}
        # add the misc users to the course in different groups
        for role in [CourseInstructorRole, CourseStaffRole, OrgStaffRole, OrgInstructorRole]:
            user_by_role[role] = []
            # Org-based roles are created via org name, rather than course_key
            if (role is OrgStaffRole) or (role is OrgInstructorRole):
                group = role(self.course_key.org)
            else:
                group = role(self.course_key)
            # NOTE: this loop breaks the roles.py abstraction by purposely assigning
            # users to one of each possible groupname in order to test that has_course_author_access
            # and remove_user work
            user = users.pop()
            group.add_users(user)
            user_by_role[role].append(user)
            self.assertTrue(
                auth.has_course_author_access(user, self.course_key), "{} does not have access".format(user)
            )

        course_team_url = reverse_course_url("course_team_handler", self.course_key)
        response = self.client.get_html(course_team_url)
        for role in [CourseInstructorRole, CourseStaffRole]:  # Global and org-based roles don't appear on this page
            for user in user_by_role[role]:
                self.assertContains(response, user.email)

        # test copying course permissions
        copy_course_key = self.store.make_course_key("copyu", "copydept.mycourse", "myrun")
        for role in [CourseInstructorRole, CourseStaffRole, OrgStaffRole, OrgInstructorRole]:
            if (role is OrgStaffRole) or (role is OrgInstructorRole):
                auth.add_users(self.user, role(copy_course_key.org), *role(self.course_key.org).users_with_role())
            else:
                auth.add_users(self.user, role(copy_course_key), *role(self.course_key).users_with_role())
        # verify access in copy course and verify that removal from source course w/ the various
        # groupnames works
        for role in [CourseInstructorRole, CourseStaffRole, OrgStaffRole, OrgInstructorRole]:
            for user in user_by_role[role]:
                # forcefully decache the groups: premise is that any real request will not have
                # multiple objects repr the same user but this test somehow uses different instance
                # in above add_users call
                if hasattr(user, "_roles"):
                    del user._roles

                self.assertTrue(auth.has_course_author_access(user, copy_course_key), "{} no copy access".format(user))
                if (role is OrgStaffRole) or (role is OrgInstructorRole):
                    auth.remove_users(self.user, role(self.course_key.org), user)
                else:
                    auth.remove_users(self.user, role(self.course_key), user)
                self.assertFalse(
                    auth.has_course_author_access(user, self.course_key), "{} remove didn't work".format(user)
                )
开发者ID:Edraak,项目名称:edx-platform,代码行数:60,代码来源:test_permissions.py

示例4: test_add_user_to_group_requires_authenticated

 def test_add_user_to_group_requires_authenticated(self):
     with self.assertRaises(PermissionDenied):
         with mock.patch(
             'django.contrib.auth.models.User.is_authenticated',
             new_callable=mock.PropertyMock
         ) as mock_is_auth:
             mock_is_auth.return_value = False
             add_users(self.admin, CourseCreatorRole(), self.user)
开发者ID:cpennington,项目名称:edx-platform,代码行数:8,代码来源:test_authz.py

示例5: test_detail_delete_staff

    def test_detail_delete_staff(self):
        auth.add_users(self.user, CourseStaffRole(self.course.id), self.ext_user)

        resp = self.client.delete(self.detail_url, HTTP_ACCEPT="application/json")
        self.assertEqual(resp.status_code, 204)
        # reload user from DB
        ext_user = User.objects.get(email=self.ext_user.email)
        self.assertFalse(auth.user_has_role(ext_user, CourseStaffRole(self.course.id)))
开发者ID:ahmadiga,项目名称:min_edx,代码行数:8,代码来源:test_user.py

示例6: add_instructor

def add_instructor(course_key, requesting_user, new_instructor):
    """
    Adds given user as instructor and staff to the given course,
    after verifying that the requesting_user has permission to do so.
    """
    # can't use auth.add_users here b/c it requires user to already have Instructor perms in this course
    CourseInstructorRole(course_key).add_users(new_instructor)
    auth.add_users(requesting_user, CourseStaffRole(course_key), new_instructor)
开发者ID:Colin-Fredericks,项目名称:edx-platform,代码行数:8,代码来源:utils.py

示例7: test_detail_delete_instructor

    def test_detail_delete_instructor(self):
        auth.add_users(self.user, CourseInstructorRole(self.course_locator), self.ext_user, self.user)

        resp = self.client.delete(self.detail_url, HTTP_ACCEPT="application/json")
        self.assertEqual(resp.status_code, 204)
        # reload user from DB
        ext_user = User.objects.get(email=self.ext_user.email)
        self.assertFalse(auth.has_access(ext_user, CourseInstructorRole(self.course_locator)))
开发者ID:ndiayesamba,项目名称:edx-platform,代码行数:8,代码来源:test_users.py

示例8: add_course_author

def add_course_author(user, course):
    """
    Add the user to the instructor group of the course
    so they will have the permissions to see it in studio
    """
    global_admin = AdminFactory()
    for role in (CourseStaffRole, CourseInstructorRole):
        auth.add_users(global_admin, role(course.id), user)
开发者ID:albluqmun,项目名称:edx-platform,代码行数:8,代码来源:common.py

示例9: test_get_user_role_staff

 def test_get_user_role_staff(self):
     """
     Verifies if user is staff.
     """
     add_users(self.global_admin, CourseStaffRole(self.course_key), self.staff)
     self.assertEqual(
         'staff',
         get_user_role(self.staff, self.course_key)
     )
开发者ID:1amongus,项目名称:edx-platform,代码行数:9,代码来源:test_access.py

示例10: test_get_user_role_staff_locator

 def test_get_user_role_staff_locator(self):
     """
     Verifies if user is staff, using a CourseLocator.
     """
     add_users(self.global_admin, CourseStaffRole(self.locator), self.staff)
     self.assertEqual(
         'staff',
         get_user_role(self.staff, self.locator)
     )
开发者ID:Chitrank-Dixit,项目名称:edx-platform,代码行数:9,代码来源:test_access.py

示例11: setUp

 def setUp(self):
     """
     Set up test variables
     """
     super(CCXCourseGroupTest, self).setUp()
     self.global_admin = AdminFactory()
     self.staff = User.objects.create_user('teststaff', '[email protected]', 'foo')
     self.ccx_course_key = CCXLocator.from_string('ccx-v1:[email protected]')
     add_users(self.global_admin, CourseStaffRole(self.ccx_course_key), self.staff)
开发者ID:Colin-Fredericks,项目名称:edx-platform,代码行数:9,代码来源:test_authz.py

示例12: test_get_user_role_instructor

 def test_get_user_role_instructor(self):
     """
     Verifies if user is instructor.
     """
     add_users(self.global_admin, CourseInstructorRole(self.location), self.instructor)
     self.assertEqual(
         'instructor',
         get_user_role(self.instructor, self.location, self.location.course_id)
     )
开发者ID:Bachmann1234,项目名称:edx-platform,代码行数:9,代码来源:test_access.py

示例13: test_permission_denied_other

    def test_permission_denied_other(self):
        auth.add_users(self.user, CourseStaffRole(self.course_locator), self.user)
        self.user.is_staff = False
        self.user.save()

        resp = self.client.post(self.detail_url, data={"role": "instructor"}, HTTP_ACCEPT="application/json")
        self.assertEqual(resp.status_code, 400)
        result = json.loads(resp.content)
        self.assertIn("error", result)
开发者ID:ndiayesamba,项目名称:edx-platform,代码行数:9,代码来源:test_users.py

示例14: test_remove_user_from_course_group_permission_denied

 def test_remove_user_from_course_group_permission_denied(self):
     """
     Verifies PermissionDenied if caller of remove_user_from_course_group is not instructor role.
     """
     add_users(self.global_admin, CourseInstructorRole(self.course_key), self.creator)
     another_staff = User.objects.create_user('another', '[email protected]', 'foo')
     add_users(self.global_admin, CourseStaffRole(self.course_key), self.creator, self.staff, another_staff)
     with self.assertRaises(PermissionDenied):
         remove_users(self.staff, CourseStaffRole(self.course_key), another_staff)
开发者ID:1amongus,项目名称:edx-platform,代码行数:9,代码来源:test_authz.py

示例15: test_add_user_not_active

 def test_add_user_not_active(self):
     """
     Tests that adding to creator group fails if user is not active
     """
     with mock.patch.dict('django.conf.settings.FEATURES',
                          {'DISABLE_COURSE_CREATION': False, "ENABLE_CREATOR_GROUP": True}):
         self.user.is_active = False
         add_users(self.admin, CourseCreatorRole(), self.user)
         self.assertFalse(has_access(self.user, CourseCreatorRole()))
开发者ID:Egkachai,项目名称:edx-platform,代码行数:9,代码来源:test_authz.py


注:本文中的student.auth.add_users函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。