Commit 2a5b0069 by asadiqbal08 Committed by Jonathan Piacenti

asadiqbal08/add_is_active_flag_to_userlist_in_group:[1291] Added is_active flag…

asadiqbal08/add_is_active_flag_to_userlist_in_group:[1291] Added is_active flag to user list in a group
parent ca8164a8
......@@ -37,6 +37,8 @@ class GroupsApiTests(ModuleStoreTestCase):
self.test_password = str(uuid.uuid4())
self.test_email = str(uuid.uuid4()) + '@test.org'
self.test_group_name = str(uuid.uuid4())
self.test_first_name = str(uuid.uuid4())
self.test_last_name = str(uuid.uuid4())
self.base_users_uri = '/api/users'
self.base_groups_uri = '/api/groups'
......@@ -347,6 +349,54 @@ class GroupsApiTests(ModuleStoreTestCase):
self.assertEqual(users[0]['first_name'], 'Joe')
self.assertEqual(users[0]['last_name'], 'Smith')
def test_group_users_list_get_with_is_active_flag(self):
group_data = {'name': 'Alpha Group', 'type': 'test'}
response = self.do_post(self.base_groups_uri, group_data)
group_id = response.data['id']
is_active = True
for num in range(0, 5):
local_username = self.test_username + str(randint(11, 99))
if num == 3:
is_active = False
data = {
'email': self.test_email,
'username': local_username,
'password': self.test_password,
'first_name': self.test_first_name,
'last_name': self.test_last_name,
'is_active': is_active
}
# associating a user with a group
response = self.do_post(self.base_users_uri, data)
user_id = response.data['id']
test_uri = self.base_groups_uri + '/' + str(group_id) + '/users'
response = self.do_post(test_uri, data={'user_id': user_id})
self.assertEqual(response.status_code, 201)
# getting users without is_active in query params
response = self.do_get(test_uri)
self.assertEqual(response.status_code, 200)
users = response.data['users']
self.assertEqual(len(users), 5)
# getting users with is_active=false
test_uri_inactive_user = test_uri + '/?is_active=false'
response = self.do_get(test_uri_inactive_user)
users = response.data['users']
self.assertEqual(len(users), 2)
# getting users with is_active=true
test_uri_active_user = test_uri + '/?is_active=true'
response = self.do_get(test_uri_active_user)
self.assertEqual(response.status_code, 200)
users = response.data['users']
self.assertEqual(len(users), 3)
def test_group_users_list_get_invalid_group(self):
test_uri = self.base_groups_uri + '/1231241/users'
response = self.do_get(test_uri)
......
......@@ -16,6 +16,7 @@ from api_manager.models import GroupRelationship, CourseGroupRelationship, Group
from xmodule.modulestore.django import modulestore
from api_manager.permissions import SecureAPIView
from xmodule.modulestore import Location, InvalidLocationError
from api_manager.utils import str2bool
RELATIONSHIP_TYPES = {'hierarchical': 'h', 'graph': 'g'}
......@@ -287,6 +288,11 @@ class GroupsUsersList(SecureAPIView):
except ObjectDoesNotExist:
return Response({}, status.HTTP_404_NOT_FOUND)
users = existing_group.user_set.all()
is_active = request.QUERY_PARAMS.get('is_active', None)
if is_active:
users = users.filter(is_active=str2bool(is_active))
response_data = {}
response_data['users'] = []
for user in users:
......
......@@ -27,3 +27,10 @@ def get_client_ip_address(request):
else:
ip_address = request.META.get('REMOTE_ADDR')
return ip_address
def str2bool(value):
"""
convert string to bool
"""
return value.lower() in ("true",)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment