Course add/delete participant cleanup (#701)

This commit is contained in:
Ross Scroggs
2018-03-15 11:35:47 -07:00
committed by Jay Lee
parent 3cb8dae374
commit 481b060caf

View File

@@ -1492,21 +1492,23 @@ def deleteDelegate(users):
def doAddCourseParticipant(): def doAddCourseParticipant():
croom = buildGAPIObject(u'classroom') croom = buildGAPIObject(u'classroom')
courseId = addCourseIdScope(sys.argv[2]) courseId = addCourseIdScope(sys.argv[2])
noScopeCourseId = removeCourseIdScope(courseId)
participant_type = sys.argv[4].lower() participant_type = sys.argv[4].lower()
new_id = sys.argv[5] new_id = sys.argv[5]
if participant_type in [u'teacher', u'teachers']: if participant_type in [u'student', u'students']:
service = croom.courses().teachers() new_id = normalizeEmailAddressOrUID(new_id)
body = {u'userId': new_id} callGAPI(croom.courses().students(), u'create', courseId=courseId, body={u'userId': new_id})
elif participant_type in [u'students', u'student']: print u'Added %s as a student of course %s' % (new_id, noScopeCourseId)
service = croom.courses().students() elif participant_type in [u'teacher', u'teachers']:
body = {u'userId': new_id} new_id = normalizeEmailAddressOrUID(new_id)
callGAPI(croom.courses().teachers(), u'create', courseId=courseId, body={u'userId': new_id})
print u'Added %s as a teacher of course %s' % (new_id, noScopeCourseId)
elif participant_type in [u'alias']: elif participant_type in [u'alias']:
service = croom.courses().aliases() new_id = addCourseIdScope(new_id)
body = {u'alias': addCourseIdScope(new_id)} callGAPI(croom.courses().aliases(), u'create', courseId=courseId, body={u'alias': new_id})
print u'Added %s as an alias of course %s' % (removeCourseIdScope(new_id), noScopeCourseId)
else: else:
systemErrorExit(2, u'%s is not a valid argument to "gam course ID add"' % participant_type) systemErrorExit(2, u'%s is not a valid argument to "gam course ID add"' % participant_type)
callGAPI(service, u'create', courseId=courseId, body=body)
print u'Added %s as a %s of course %s' % (removeCourseIdScope(new_id), participant_type, removeCourseIdScope(courseId))
def doSyncCourseParticipants(): def doSyncCourseParticipants():
courseId = addCourseIdScope(sys.argv[2]) courseId = addCourseIdScope(sys.argv[2])
@@ -1533,21 +1535,23 @@ def doSyncCourseParticipants():
def doDelCourseParticipant(): def doDelCourseParticipant():
croom = buildGAPIObject(u'classroom') croom = buildGAPIObject(u'classroom')
courseId = addCourseIdScope(sys.argv[2]) courseId = addCourseIdScope(sys.argv[2])
noScopeCourseId = removeCourseIdScope(courseId)
participant_type = sys.argv[4].lower() participant_type = sys.argv[4].lower()
remove_id = sys.argv[5] remove_id = sys.argv[5]
if participant_type in [u'teacher', u'teachers']: if participant_type in [u'student', u'students']:
service = croom.courses().teachers() remove_id = normalizeEmailAddressOrUID(remove_id)
kwargs = {u'userId': remove_id} callGAPI(croom.courses().students(), u'delete', courseId=courseId, userId=remove_id)
elif participant_type in [u'student', u'students']: print u'Removed %s as a student of course %s' % (remove_id, noScopeCourseId)
service = croom.courses().students() elif participant_type in [u'teacher', u'teachers']:
kwargs = {u'userId': remove_id} remove_id = normalizeEmailAddressOrUID(remove_id)
callGAPI(croom.courses().teachers(), u'delete', courseId=courseId, userId=remove_id)
print u'Removed %s as a teacher of course %s' % (remove_id, noScopeCourseId)
elif participant_type in [u'alias']: elif participant_type in [u'alias']:
service = croom.courses().aliases() remove_id = addCourseIdScope(remove_id)
kwargs = {u'alias': addCourseIdScope(remove_id)} callGAPI(croom.courses().aliases(), u'delete', courseId=courseId, alias=remove_id)
print u'Removed %s as an alias of course %s' % (removeCourseIdScope(remove_id), noScopeCourseId)
else: else:
systemErrorExit(2, u'%s is not a valid argument to "gam course ID delete"' % participant_type) systemErrorExit(2, u'%s is not a valid argument to "gam course ID delete"' % participant_type)
callGAPI(service, u'delete', courseId=courseId, **kwargs)
print u'Removed %s as a %s of course %s' % (removeCourseIdScope(remove_id), participant_type, removeCourseIdScope(courseId))
def doDelCourse(): def doDelCourse():
croom = buildGAPIObject(u'classroom') croom = buildGAPIObject(u'classroom')
@@ -2477,10 +2481,7 @@ def doPrintCourseParticipants():
while i < len(sys.argv): while i < len(sys.argv):
myarg = sys.argv[i].lower() myarg = sys.argv[i].lower()
if myarg in [u'course', u'class']: if myarg in [u'course', u'class']:
course = sys.argv[i+1] courses.append(addCourseIdScope(sys.argv[i+1]))
if not course.isdigit():
course = u'd:%s' % course
courses.append(course)
i += 2 i += 2
elif myarg == u'teacher': elif myarg == u'teacher':
teacherId = normalizeEmailAddressOrUID(sys.argv[i+1]) teacherId = normalizeEmailAddressOrUID(sys.argv[i+1])