Example #1
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())
Example #2
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())
Example #3
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())
Example #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())
Example #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())
Example #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())
Example #7
0
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 []
Example #8
0
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 []
Example #9
0
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))
Example #10
0
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))
Example #11
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())
Example #12
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())
Example #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())
Example #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())