コード例 #1
0
ファイル: test_access.py プロジェクト: Codeyelp/edx-platform
 def test_allow(self):
     user = UserFactory()
     allow_access(self.course, user, 'staff')
     group = Group.objects.get(
         name=get_access_group_name(self.course, 'staff')
     )
     self.assertIn(user, group.user_set.all())
コード例 #2
0
ファイル: test_access.py プロジェクト: Codeyelp/edx-platform
 def test_revoke_twice(self):
     user = self.staff[0]
     revoke_access(self.course, user, 'staff')
     group = Group.objects.get(
         name=get_access_group_name(self.course, 'staff')
     )
     self.assertNotIn(user, group.user_set.all())
コード例 #3
0
ファイル: test_access.py プロジェクト: Codeyelp/edx-platform
 def test_revoke_badrolename(self):
     user = UserFactory()
     revoke_access(self.course, user, 'robot-not-a-level')
     group = Group.objects.get(
         name=get_access_group_name(self.course, 'robot-not-a-level')
     )
     self.assertNotIn(user, group.user_set.all())
コード例 #4
0
 def test_allow(self):
     user = UserFactory()
     allow_access(self.course, user, 'staff')
     group = Group.objects.get(
         name=get_access_group_name(self.course, 'staff')
     )
     self.assertIn(user, group.user_set.all())
コード例 #5
0
 def test_revoke_badrolename(self):
     user = UserFactory()
     revoke_access(self.course, user, 'robot-not-a-level')
     group = Group.objects.get(
         name=get_access_group_name(self.course, 'robot-not-a-level')
     )
     self.assertNotIn(user, group.user_set.all())
コード例 #6
0
 def test_revoke_twice(self):
     user = self.staff[0]
     revoke_access(self.course, user, 'staff')
     group = Group.objects.get(
         name=get_access_group_name(self.course, 'staff')
     )
     self.assertNotIn(user, group.user_set.all())
コード例 #7
0
ファイル: access.py プロジェクト: Codeyelp/edx-platform
def list_with_level(course, level):
    """
    List users who have 'level' access.

    `level` is in ['instructor', 'staff', 'beta'] for standard courses.
    There could be other levels specific to the course.
    If there is no Group for that course-level, returns an empty list
    """
    if level == 'beta':
        grpname = course_beta_test_group_name(course.location)
    else:
        grpname = get_access_group_name(course, level)

    try:
        return Group.objects.get(name=grpname).user_set.all()
    except Group.DoesNotExist:
        log.info("list_with_level called with non-existant group named {}".format(grpname))
        return []
コード例 #8
0
ファイル: access.py プロジェクト: neurolit/edx-platform
def list_with_level(course, level):
    """
    List users who have 'level' access.

    `level` is in ['instructor', 'staff', 'beta'] for standard courses.
    There could be other levels specific to the course.
    If there is no Group for that course-level, returns an empty list
    """
    if level == 'beta':
        grpname = course_beta_test_group_name(course.location)
    else:
        grpname = get_access_group_name(course, level)

    try:
        return Group.objects.get(name=grpname).user_set.all()
    except Group.DoesNotExist:
        log.info(
            "list_with_level called with non-existant group named {}".format(
                grpname))
        return []
コード例 #9
0
ファイル: access.py プロジェクト: neurolit/edx-platform
def _change_access(course, user, level, action):
    """
    Change access of user.

    `level` is one of ['instructor', 'staff', 'beta']
    action is one of ['allow', 'revoke']

    NOTE: will create a group if it does not yet exist.
    """

    if level == 'beta':
        grpname = course_beta_test_group_name(course.location)
    elif level in ['instructor', 'staff']:
        grpname = get_access_group_name(course, level)
    else:
        raise ValueError("unrecognized level '{}'".format(level))
    group, _ = Group.objects.get_or_create(name=grpname)

    if action == 'allow':
        user.groups.add(group)
    elif action == 'revoke':
        user.groups.remove(group)
    else:
        raise ValueError("unrecognized action '{}'".format(action))
コード例 #10
0
ファイル: access.py プロジェクト: Codeyelp/edx-platform
def _change_access(course, user, level, action):
    """
    Change access of user.

    `level` is one of ['instructor', 'staff', 'beta']
    action is one of ['allow', 'revoke']

    NOTE: will create a group if it does not yet exist.
    """

    if level == 'beta':
        grpname = course_beta_test_group_name(course.location)
    elif level in ['instructor', 'staff']:
        grpname = get_access_group_name(course, level)
    else:
        raise ValueError("unrecognized level '{}'".format(level))
    group, _ = Group.objects.get_or_create(name=grpname)

    if action == 'allow':
        user.groups.add(group)
    elif action == 'revoke':
        user.groups.remove(group)
    else:
        raise ValueError("unrecognized action '{}'".format(action))
コード例 #11
0
ファイル: test_access.py プロジェクト: Codeyelp/edx-platform
 def test_allow_noneuser(self):
     user = None
     allow_access(self.course, user, 'staff')
     group = Group.objects.get(name=get_access_group_name(self.course, 'staff'))
     self.assertIn(user, group.user_set.all())
コード例 #12
0
ファイル: test_access.py プロジェクト: Codeyelp/edx-platform
 def test_allow_badlevel(self):
     user = UserFactory()
     allow_access(self.course, user, 'robot-not-a-level')
     group = Group.objects.get(name=get_access_group_name(self.course, 'robot-not-a-level'))
     self.assertIn(user, group.user_set.all())
コード例 #13
0
 def test_allow_noneuser(self):
     user = None
     allow_access(self.course, user, 'staff')
     group = Group.objects.get(name=get_access_group_name(self.course, 'staff'))
     self.assertIn(user, group.user_set.all())
コード例 #14
0
 def test_allow_badlevel(self):
     user = UserFactory()
     allow_access(self.course, user, 'robot-not-a-level')
     group = Group.objects.get(name=get_access_group_name(self.course, 'robot-not-a-level'))
     self.assertIn(user, group.user_set.all())