CAT-SOOP is a flexible, programmable learning management system based on the Python programming language. https://catsoop.mit.edu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

57 lines
1.9 KiB

  1. # This file is part of CAT-SOOP
  2. # Copyright (c) 2011-2017 Adam Hartz <hartz@mit.edu>
  3. #
  4. # This program is free software: you can redistribute it and/or modify it under
  5. # the terms of the GNU Affero General Public License as published by the Free
  6. # Software Foundation, either version 3 of the License, or (at your option) any
  7. # later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  12. # details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. import json
  17. api_token = cs_form.get('api_token', None)
  18. path = cs_form.get('path', None)
  19. _as = cs_form.get('as', None)
  20. error = None
  21. if api_token is None:
  22. error = "api_token is required"
  23. try:
  24. path = opath = json.loads(path)
  25. course, path = path[0], path[1:]
  26. except:
  27. error = "invalid path: %s" % path
  28. if error is None:
  29. output = csm_api.get_user_information(globals(), api_token=api_token, course=course, _as=_as)
  30. if output['ok']:
  31. uinfo = output['user_info']
  32. else:
  33. error = 'Could not get user information'
  34. if error is None:
  35. ctx = csm_loader.spoof_early_load(opath)
  36. section, group, members = csm_groups.get_group(ctx, course, path, uinfo['username'])
  37. if section is None and group is None:
  38. error = "%s has not been assigned to a group" % uinfo['username']
  39. members = [uinfo['username']]
  40. members = list(sorted(members, key=lambda x: (0 if x == uinfo['username'] else 1, x)))
  41. if error is not None:
  42. output = {'ok': False, 'error': error}
  43. else:
  44. output = {'ok': True, 'section': section, 'group': group, 'members': members}
  45. cs_handler = 'raw_response'
  46. content_type = 'application/json'
  47. response = json.dumps(output)