Пример #1
0
def createBook():
  status = 200
  res = ResponseCreation.ControllerResponse()
  if g.authenticatedUser['userRole'] != "admin":
    res.addError('Role Error', 'Only admins can create books')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    res = book_ctrl.createBook(request.json, dynamoDBInstance)
    if res.hasErrors():
      status = 400
  return ResponseCreation.createResponse(res,status)
Пример #2
0
def taughtClassList():
  status = 200
  res = ResponseCreation.ControllerResponse()
  role = g.authenticatedUser['userRole']
  if role != 'teacher' and role != 'admin' :
    res.addError('Role error', 'Only teachers can view a list of classes they are teaching')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    res = class_ctrl.getTaughtClassList(dynamoDBInstance)
    if res.hasErrors():
      status = 400
  return ResponseCreation.createResponse(res, status)
Пример #3
0
def updateClassDetails():
  status = 200
  res = ResponseCreation.ControllerResponse()
  role = g.authenticatedUser['userRole']
  if role != 'admin' and role != 'teacher':
    res.addError('Role Error', 'Only teachers or admins can update class details')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    res = class_ctrl.updateClassDetails(request.json, dynamoDBInstance)
    if res.hasErrors():
      status = 400
  return ResponseCreation.createResponse(res,status)
Пример #4
0
def getBookList():
  status = 200
  res = ResponseCreation.ControllerResponse()
  role = g.authenticatedUser['userRole']
  if role != "teacher" and role != "admin" :
    res.addError('Role error', 'Only those with teacher privileges can get all books.')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    res = book_ctrl.getBookList(dynamoDBInstance)
    if res.hasErrors():
      status = 400
  return ResponseCreation.createResponse(res,status)
Пример #5
0
def create_class():
  status = 200

  role = g.authenticatedUser['userRole']
  if role != "teacher" and role != "admin" :
    res = ResponseCreation.ControllerResponse()
    res.addError('Role error', 'Only teachers can create classes')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    res = class_ctrl.createClass(dynamoDBInstance, request.json)
    if res.hasErrors():
      status = 400
  return ResponseCreation.createResponse(res, status)
Пример #6
0
def removeStudentFromClass():
  status = 200
  role = g.authenticatedUser['userRole']
  if role != "teacher" and role != "admin" :
    res = ResponseCreation.ControllerResponse()
    res.addError('Role error', 'Only those with teacher privileges can remove students from classes')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    res = class_ctrl.removeStudent(dynamoDBInstance, request.json)
    if res.hasErrors():
      status = 400
    else:
      #send email
      class_ctrl.sendClassRemovalEmail(dynamoDBInstance, mail, request.json)
  return ResponseCreation.createResponse(res, status)
Пример #7
0
def problemSteps(classId, activity):
  res = ResponseCreation.ControllerResponse()
  res.addError('Invalid request', 'An error occurred')
  status = 400
  userId = g.authenticatedUser['email']
  if request.method == 'GET':
    #Get the problem tree
    status = 200
    dynamoDBInstance = getDatabaseClient()
    index, problem = problem_ctrl.getProblemTemplate(classId, activity, userId, dynamoDBInstance)
    res = algebra.getProblemTree(problem)
    if res.hasErrors():
      status = 461
    else:
      res.addToPayload('problemIndex', index)
  elif request.method == 'POST':
    #Post the students results
    dynamoDBInstance = getDatabaseClient()
    try:
      status = 200
      problemIndex = int(request.json.get('problemIndex', ''))
      didSucceed = request.json.get('didSucceed', 'True') == 'True'
      res = problem_ctrl.updateUserTemplateHistory(classId, activity, userId, problemIndex, didSucceed, dynamoDBInstance)
      if res.hasErrors():
        status = 462
    except ValueError, TypeError:
      pass
Пример #8
0
def getClass(classCode):
  status = 200
  dynamoDBInstance = getDatabaseClient()
  res = class_ctrl.getClass(classCode, dynamoDBInstance)
  if res.hasErrors():
    status = 400
  return ResponseCreation.createResponse(res, status)
Пример #9
0
def public_class_list():
  status = 200
  dynamoDBInstance = getDatabaseClient()
  res = class_ctrl.getPublicClassList(dynamoDBInstance)
  if res.hasErrors():
    status = 400
  return ResponseCreation.createResponse(res, status)
Пример #10
0
def getBook(bookId):
  status = 200
  res = ResponseCreation.ControllerResponse()
  role = g.authenticatedUser['userRole']
  if role != "teacher" and role != "admin" :
    res.addError('Role error', 'Only those with teacher privileges can get a book.')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    book = book_ctrl.getBook(bookId, dynamoDBInstance)
    if not book:
      res.addError('Data error', 'Unable to retrive book.')
      status = 400
    else:
      res.addToPayload('book', book)
  return ResponseCreation.createResponse(res,status)
Пример #11
0
    def test_removeStudentFromClasss(self):
        print('Running removeStudentFromClass test case')

        userRole = 'admin'
        email1 = '[email protected]'
        email2 = '[email protected]'
        classCode = 'f77668db-fb9d-4fd6-81f1-026784d6cc9b'
        res = ResponseCreation.ControllerResponse()

        #Put user and class data into DB
        classesTable = db.getTable('classes', dynamodb)

        classJsonData = {'code': classCode, 'students': [email1, email2]}

        db.putItem(classJsonData, classesTable)

        #Check test data was successfully placed into DB
        jsonData = {'Key': {'code': classCode}}
        response = db.getItem(jsonData, classesTable)
        self.assertIsNotNone(response.get('Item'))
        self.assertEqual(response.get('Item').get('code'), classCode)

        class_ctrl.removeStudentFromClass(dynamodb, res, email1, classCode)

        #check that the student was removed from the class
        jsonData = {'Key': {'code': classCode}}
        response = db.getItem(jsonData, classesTable)
        self.assertIsNotNone(response.get('Item'))
        stu = response.get('Item').get('students')
        self.assertFalse(email1 in stu)
        self.assertTrue(email2 in stu)
Пример #12
0
    def test_removeStudentFromClass_len_zero(self):
        print(
            'Running removeStudentFromClass students length is zero test case')

        userRole = 'admin'
        email = '*****@*****.**'
        classCode = 'f77998db-fb9d-4fd6-81f1-026784d6cc9b'
        res = ResponseCreation.ControllerResponse()

        #Put user and class data into DB
        classesTable = db.getTable('classes', dynamodb)

        classJsonData = {'code': classCode, 'students': [email]}

        db.putItem(classJsonData, classesTable)

        #Check test data was successfully placed into DB
        jsonData = {'Key': {'code': classCode}}
        response = db.getItem(jsonData, classesTable)
        self.assertIsNotNone(response.get('Item'))
        self.assertEqual(response.get('Item').get('code'), classCode)

        class_ctrl.removeStudentFromClass(dynamodb, res, email, classCode)

        #check that the attribute was removed from the class
        jsonData = {'Key': {'code': classCode}}
        response = db.getItem(jsonData, classesTable)
        self.assertIsNotNone(response.get('Item'))
        self.assertIsNone(response.get('Item').get('students'))
Пример #13
0
    def test_removeClassFromStudent_len_zero(self):
        print(
            'Running removeClassFromStudent students length is zero test case')

        userRole = 'admin'
        email = '*****@*****.**'
        classCode = 'f84138db-fb9d-4fd6-81f1-026784d6cc9b'
        res = ResponseCreation.ControllerResponse()

        #Put user and class data into DB
        usersTable = db.getTable('users', dynamodb)

        userJsonData = {'email': email, 'classCodes': [classCode]}

        db.putItem(userJsonData, usersTable)

        # Check test data was successfully placed into DB
        jsonData = {'Key': {'email': email}}
        response = db.getItem(jsonData, usersTable)
        self.assertIsNotNone(response.get('Item'))
        self.assertEqual(response.get('Item').get('email'), email)

        class_ctrl.removeClassFromStudent(dynamodb, res, email, classCode)

        # Check that the attribute was removed from the student
        jsonData = {'Key': {'email': email}}
        response = db.getItem(jsonData, usersTable)
        self.assertIsNotNone(response.get('Item'))
        self.assertIsNone(response.get('Item').get('classCodes'))
Пример #14
0
    def test_removeClassFromStudent(self):
        print('Running removeClassFromStudent test case')

        userRole = 'admin'
        email = '*****@*****.**'
        classCode = 'f77668db-fb9d-4fd6-81f1-026784d6cc9b'
        classCode2 = 'e00045db-fb9d-4fd6-81f1-026784d6cc9b'
        res = ResponseCreation.ControllerResponse()

        # Put user and class data into DB
        usersTable = db.getTable('users', dynamodb)

        userJsonData = {'email': email, 'classCodes': [classCode, classCode2]}

        db.putItem(userJsonData, usersTable)

        # Check test data was successfully placed into DB
        jsonData = {'Key': {'email': email}}
        response = db.getItem(jsonData, usersTable)
        self.assertIsNotNone(response.get('Item'))
        self.assertEqual(response.get('Item').get('email'), email)

        class_ctrl.removeClassFromStudent(dynamodb, res, email, classCode2)

        # Check that the classCode was removed from the student
        jsonData = {'Key': {'email': email}}
        response = db.getItem(jsonData, usersTable)
        self.assertIsNotNone(response.get('Item'))
        cc = response.get('Item').get('classCodes')
        self.assertFalse(classCode2 in cc)
        self.assertTrue(classCode in cc)
Пример #15
0
def resetPassword():
  status = 200
  dynamoDBInstance = getDatabaseClient()
  res = user_ctrl.resetUserPassword(request.json, dynamoDBInstance)
  if res.hasErrors():
    status = 400
  return ResponseCreation.createResponse(res,status)
Пример #16
0
def activate(activationid):
  logger.info(str(request))
  dynamoDBInstance = getDatabaseClient()
  res = user_ctrl.activate(activationid, dynamoDBInstance)
  status = 200
  if res.hasErrors():
    status = 400
  flaskResponse = ResponseCreation.createResponse(res, status)
  logger.info(str(flaskResponse))
  return flaskResponse
Пример #17
0
def getSampleProblems(bookId, chapterTitle, sectionTitle):
  status = 200
  res = ResponseCreation.ControllerResponse()
  role = g.authenticatedUser['userRole']
  if role != "teacher" and role != "admin" :
    res.addError('Role error', 'Only those with teacher privileges can get sample problems from a book.')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    problemCount = 4
    sampleProblems = set() #prevent duplicates
    for _ in range(problemCount):
      template = problem_ctrl.getProblemFromBook( bookId, chapterTitle, sectionTitle, g.authenticatedUser['email'], dynamoDBInstance)[1]
      sampleProblems.add(algebra.getProblem(template))
    sampleProblems = list(sampleProblems)
    if 'Bad Problem' in sampleProblems:
      status = 400
    else:
      res.addToPayload('problems', sampleProblems)
  return ResponseCreation.createResponse(res, status)
Пример #18
0
def register():
  logger.info(str(request))
  status = 200
  dynamoDBInstance = getDatabaseClient()
  httpOrigin = request.environ.get('HTTP_ORIGIN')
  jsonData = request.json
  res = user_ctrl.register(httpOrigin, jsonData, mail, dynamoDBInstance)
  status = 201
  if res.hasErrors():
    status = 400
  flaskResponse =  ResponseCreation.createResponse(res, status)
  logger.info(str(flaskResponse))
  return flaskResponse
Пример #19
0
def signin():
  logger.info(str(request))
  status = 200

  email = request.authorization.username
  password = request.authorization.password
  dynamoDBInstance = getDatabaseClient()
  userRole = user_ctrl.getRole(email, dynamoDBInstance)
  if not userRole:
    userRole = 'student'
  userCredentials = {
    'email': email,
    'userRole': userRole,
    'password': password
  }

  response = ResponseCreation.ControllerResponse()
  token = MentiiAuth.generateAuthToken(userCredentials, appSecret)
  response.addToPayload('token', token)
  flaskResponse = ResponseCreation.createResponse(response, status)

  logger.info(str(flaskResponse))
  return flaskResponse
Пример #20
0
    else:
      res.addToPayload('problemIndex', index)
  elif request.method == 'POST':
    #Post the students results
    dynamoDBInstance = getDatabaseClient()
    try:
      status = 200
      problemIndex = int(request.json.get('problemIndex', ''))
      didSucceed = request.json.get('didSucceed', 'True') == 'True'
      res = problem_ctrl.updateUserTemplateHistory(classId, activity, userId, problemIndex, didSucceed, dynamoDBInstance)
      if res.hasErrors():
        status = 462
    except ValueError, TypeError:
      pass

  return ResponseCreation.createResponse(res,status)


@app.route('/classes/remove', methods=['POST', 'OPTIONS'])
@auth.login_required
@handleOptionsRequest
def removeStudentFromClass():
  status = 200
  role = g.authenticatedUser['userRole']
  if role != "teacher" and role != "admin" :
    res = ResponseCreation.ControllerResponse()
    res.addError('Role error', 'Only those with teacher privileges can remove students from classes')
    status = 403
  else:
    dynamoDBInstance = getDatabaseClient()
    res = class_ctrl.removeStudent(dynamoDBInstance, request.json)
Пример #21
0
def index():
  logger.info(str(request))
  response = ResponseCreation.createEmptyResponse(200)
  logger.info(str(response))
  return response
Пример #22
0
def forgotPassword():
  dynamoDBInstance = getDatabaseClient()
  httpOrigin = request.environ.get('HTTP_ORIGIN')
  user_ctrl.sendForgotPasswordEmail(httpOrigin, request.json, mail, dynamoDBInstance)
  return ResponseCreation.createEmptyResponse(200)