Skip to content

Commit

Permalink
Reduce sql queries for groupname tests. (STUD-1039)
Browse files Browse the repository at this point in the history
Conflicts:
	cms/djangoapps/auth/authz.py
  • Loading branch information
Don Mitchell authored and adampalay committed Dec 10, 2013
1 parent ddc45ea commit 7e4820a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
15 changes: 6 additions & 9 deletions cms/djangoapps/auth/authz.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_all_course_role_groupnames(location, role, use_filter=True):
# filter to the ones which exist
default = groupnames[0]
if use_filter:
groupnames = [group for group in groupnames if Group.objects.filter(name=group).exists()]
groupnames = [group.name for group in Group.objects.filter(name__in=groupnames)]
return groupnames, default


Expand Down Expand Up @@ -203,12 +203,9 @@ def remove_user_from_course_group(caller, user, location, role):

# see if the user is actually in that role, if not then we don't have to do anything
groupnames, _ = get_all_course_role_groupnames(location, role)
for groupname in groupnames:
groups = user.groups.filter(name=groupname)
if groups:
# will only be one with that name
user.groups.remove(groups[0])
user.save()
for group in user.groups.filter(name__in=groupnames):
user.groups.remove(group)
user.save()


def remove_user_from_creator_group(caller, user):
Expand Down Expand Up @@ -243,7 +240,7 @@ def is_user_in_course_group_role(user, location, role, check_staff=True):
if check_staff and user.is_staff:
return True
groupnames, _ = get_all_course_role_groupnames(location, role)
return any(user.groups.filter(name=groupname).exists() for groupname in groupnames)
return user.groups.filter(name__in=groupnames).exists()

return False

Expand All @@ -266,7 +263,7 @@ def is_user_in_creator_group(user):

# Feature flag for using the creator group setting. Will be removed once the feature is complete.
if settings.MITX_FEATURES.get('ENABLE_CREATOR_GROUP', False):
return user.groups.filter(name=COURSE_CREATOR_GROUP_NAME).count() > 0
return user.groups.filter(name=COURSE_CREATOR_GROUP_NAME).exists()

return True

Expand Down
1 change: 0 additions & 1 deletion lms/djangoapps/courseware/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

from abc import ABCMeta, abstractmethod
from functools import partial

from django.contrib.auth.models import User, Group

Expand Down

0 comments on commit 7e4820a

Please sign in to comment.