Commit 68b0daad by Steve Magoun

Merge pull request #657 from edx-solutions/rc/2016-03-23

Rc/2016 03 23
parents b84a71b7 7e98f454
......@@ -52,7 +52,7 @@ from progress.serializers import CourseModuleCompletionSerializer
from api_manager.courseware_access import get_course, get_course_child, get_course_key, course_exists
from api_manager.permissions import SecureAPIView, SecureListAPIView, IdsInFilterBackend, HasOrgsFilterBackend
from api_manager.models import GroupProfile, APIUser as User
from organizations.serializers import OrganizationSerializer
from organizations.serializers import BasicOrganizationSerializer
from api_manager.utils import generate_base_uri, dict_has_items, extract_data_params
from projects.serializers import BasicWorkgroupSerializer
from .serializers import UserSerializer, UserCountByCitySerializer, UserRolesSerializer
......@@ -1216,7 +1216,7 @@ class UsersOrganizationsList(SecureListAPIView):
- GET: Provides paginated list of organizations for a user
"""
serializer_class = OrganizationSerializer
serializer_class = BasicOrganizationSerializer
def get_queryset(self):
user_id = self.kwargs['user_id']
......
......@@ -23,5 +23,6 @@ class BasicOrganizationSerializer(serializers.ModelSerializer):
class Meta:
""" Serializer/field specification """
model = Organization
fields = ('url', 'id', 'name', 'created', 'display_name', 'logo_url')
fields = ('url', 'id', 'name', 'display_name', 'contact_name', 'contact_email', 'contact_phone',
'logo_url', 'created', 'modified')
read_only = ('url', 'id', 'created',)
......@@ -152,11 +152,13 @@ class OrganizationsApiTests(ModuleStoreTestCase):
self.assertEqual(response.data['contact_email'], self.test_organization_contact_email)
self.assertEqual(response.data['contact_phone'], self.test_organization_contact_phone)
self.assertEqual(response.data['logo_url'], self.test_organization_logo_url)
self.assertIsNotNone(response.data['workgroups'])
self.assertEqual(len(response.data['users']), len(users))
self.assertIsNotNone(response.data['created'])
self.assertIsNotNone(response.data['modified'])
users_get_uri = "{}users/?view=ids".format(confirm_uri)
response = self.do_get(users_get_uri)
self.assertEqual(len(response.data), len(users))
def test_organizations_detail_get(self):
data = {
'name': self.test_organization_name,
......@@ -178,8 +180,9 @@ class OrganizationsApiTests(ModuleStoreTestCase):
self.assertEqual(response.data['contact_name'], self.test_organization_contact_name)
self.assertEqual(response.data['contact_email'], self.test_organization_contact_email)
self.assertEqual(response.data['contact_phone'], self.test_organization_contact_phone)
self.assertIsNotNone(response.data['workgroups'])
self.assertIsNotNone(response.data['users'])
# we have separate api for groups and users organization so that data should not be returned
self.assertFalse("users" in response.data)
self.assertFalse("groups" in response.data)
self.assertIsNotNone(response.data['created'])
self.assertIsNotNone(response.data['modified'])
......@@ -230,7 +233,13 @@ class OrganizationsApiTests(ModuleStoreTestCase):
}
response = self.do_post(self.base_organizations_uri, data)
self.assertEqual(response.status_code, 201)
self.assertEqual(len(response.data['groups']), len(groups))
organization_id = response.data['id']
groups_get_uri = "{base_url}{organization_id}/groups/?view=ids".format(
base_url=self.base_organizations_uri,
organization_id=organization_id,
)
response = self.do_get(groups_get_uri)
self.assertEqual(len(response.data), len(groups))
def test_organizations_users_post(self):
data = {
......@@ -247,9 +256,11 @@ class OrganizationsApiTests(ModuleStoreTestCase):
data = {"id": self.test_user.id}
response = self.do_post(users_uri, data)
self.assertEqual(response.status_code, 201)
response = self.do_get(test_uri)
users_get_uri = '{}users/?view=ids'.format(test_uri)
response = self.do_get(users_get_uri)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['users'][0], self.test_user.id)
self.assertEqual(response.data[0], self.test_user.id)
def test_organizations_users_post_invalid_user(self):
data = {
......
......@@ -19,7 +19,7 @@ from gradebook.models import StudentGradebook
from student.models import CourseEnrollment
from student.roles import get_aggregate_exclusion_user_ids
from .serializers import OrganizationSerializer
from .serializers import OrganizationSerializer, BasicOrganizationSerializer
class OrganizationsViewSet(viewsets.ModelViewSet):
......@@ -29,6 +29,14 @@ class OrganizationsViewSet(viewsets.ModelViewSet):
serializer_class = OrganizationSerializer
model = Organization
def list(self, request, *args, **kwargs):
self.serializer_class = BasicOrganizationSerializer
return super(OrganizationsViewSet, self).list(request, *args, **kwargs)
def retrieve(self, request, *args, **kwargs):
self.serializer_class = BasicOrganizationSerializer
return super(OrganizationsViewSet, self).retrieve(request, *args, **kwargs)
@action(methods=['get', ])
def metrics(self, request, pk):
"""
......@@ -89,6 +97,8 @@ class OrganizationsViewSet(viewsets.ModelViewSet):
* include_course_counts parameter should be `true` to get user's enrollment count
* include_grades parameter should be `true` to get user's grades
* for the course given in the course_id parameter
* view parameter can be used to get a particular data .i.e. view=ids to
* get list of user ids
- POST: Adds a User to an Organization
"""
......@@ -96,6 +106,7 @@ class OrganizationsViewSet(viewsets.ModelViewSet):
include_course_counts = request.QUERY_PARAMS.get('include_course_counts', None)
include_grades = request.QUERY_PARAMS.get('include_grades', None)
course_id = request.QUERY_PARAMS.get('course_id', None)
view = request.QUERY_PARAMS.get('view', None)
grade_complete_match_range = getattr(settings, 'GRADEBOOK_GRADE_COMPLETE_PROFORMA_MATCH_RANGE', 0.01)
course_key = None
if course_id:
......@@ -115,6 +126,11 @@ class OrganizationsViewSet(viewsets.ModelViewSet):
for enrollment in enrollments:
enrollments_by_user[enrollment['user']] = enrollment['total']
# if we only need ids of users in organization return now
if view == 'ids':
user_ids = users.values_list('id', flat=True)
return Response(user_ids)
response_data = []
if users:
for user in users:
......@@ -152,12 +168,24 @@ class OrganizationsViewSet(viewsets.ModelViewSet):
def groups(self, request, pk):
"""
Add a Group to a organization or retrieve list of groups in organization
- GET: Returns groups in an organization
* view parameter can be used to get a particular data .i.e. view=ids to
* get list of group ids
"""
if request.method == 'GET':
group_type = request.QUERY_PARAMS.get('type', None)
view = request.QUERY_PARAMS.get('view', None)
groups = Group.objects.filter(organizations=pk)
if group_type:
groups = groups.filter(groupprofile__group_type=group_type)
# if we only need ids of groups in organization return now
if view == 'ids':
group_ids = groups.values_list('id', flat=True)
return Response(group_ids)
response_data = []
if groups:
for group in groups:
......
......@@ -12,7 +12,7 @@
-e git+https://github.com/open-craft/xblock-poll.git@bd93e4851c15d9cb1522e692f8b692cf584d23b1#egg=xblock-poll
-e git+https://github.com/edx/edx-notifications.git@484014cc87278a5c474e6cc1bca14c417fb35599#egg=edx-notifications
-e git+https://github.com/open-craft/problem-builder.git@594f1f2853d05bf65fe4d48aeecd343088cfab4f#egg=problem-builder
-e git+https://github.com/open-craft/xblock-group-project-v2.git@d693b833d7226f4cb287566abca10d330220ea60#egg=xblock-group-project-v2
-e git+https://github.com/open-craft/xblock-group-project-v2.git@1913bcc962bbbf0638dc7abd99fb955fe1ace77d#egg=xblock-group-project-v2
-e git+https://github.com/OfficeDev/xblock-officemix.git@86238f5968a08db005717dbddc346808f1ed3716#egg=xblock-officemix
-e git+https://github.com/edx-solutions/xblock.git@d25a661454da9e6b149d6c559de50ddcd0770857#egg=xblock
-e git+https://github.com/mckinseyacademy/xblock-diagnosticfeedback.git@4c593dd5599fc21f6d8612d6be2ef2d17de96f0f#egg=xblock-diagnostic-feedback
-e git+https://github.com/mckinseyacademy/xblock-diagnosticfeedback.git@4e3d78bf69adf00347e3fd3b62055e89c9c44ec4#egg=xblock-diagnostic-feedback
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