def deletePerson(person_id): try: PeopleManager.deletePerson(person_id) return makeResponse(message="Deleted person", payload={}) except FindError as e: return makeResponse(error=e) except DbError as e: return makeResponse(error=e)
def editPerson(): surname = request.form.get('surname') forename = request.form.get('forename') location = request.form.get('location') email = request.form.get('email') url = request.form.get('url') tagline = request.form.get('tagline') is_disabled = request.form.get('is_disabled') nyunetid = request.form.get('nyunetid') # Get person by auth token current_token = get_raw_jwt() jti = current_token['jti'] # email address if request.form.get('person_id') is None: identity = current_token['identity'] else: identity = request.form.get('person_id') try: return makeResponse(payload=PeopleManager.editPerson(identity, forename, surname, location, email, url, tagline, is_disabled, nyunetid), message="") except FindError as e: return makeResponse(error=e) except ValidationError as e: return makeResponse(error=e) except DbError as e: return makeResponse(error=e) except SaveError as e: return makeResponse(error=e) except Exception as e: return makeResponse(error=e)
def editPerson(): surname = request.form.get('surname') forename = request.form.get('forename') location = request.form.get('location') email = request.form.get('email') url = request.form.get('url') tagline = request.form.get('tagline') is_disabled = request.form.get('is_disabled') nyunetid = request.form.get('nyunetid') # Get person by auth token current_token = get_raw_jwt() jti = current_token['jti'] # email address if request.form.get('person_id') is None: identity = current_token['identity'] else: identity = request.form.get('person_id') try: return makeResponse(payload=PeopleManager.editPerson( identity, forename, surname, location, email, url, tagline, is_disabled, nyunetid), message="") except FindError as e: return makeResponse(error=e) except ValidationError as e: return makeResponse(error=e) except DbError as e: return makeResponse(error=e) except SaveError as e: return makeResponse(error=e) except Exception as e: return makeResponse(error=e)
def deleteType(repo_id, type_id): current_user = get_jwt_identity() if PeopleManager.checkRepoPermissions(current_user, repo_id) == False: return makeResponse(status=401, message="You do not have permissions to access this repository!") try: return makeResponse(payload=SchemaManager.deleteType(repo_id, type_id), message="Deleted type") except Exception as e: return makeResponse(error=e)
def getType(repo_id, schema_id): current_user = get_jwt_identity() if PeopleManager.checkRepoPermissions(current_user, repo_id) == False: return makeResponse( status=401, message="You do not have permissions to access this repository!") try: return makeResponse(payload=SchemaManager.getType(repo_id, schema_id)) except Exception as e: return makeResponse(error=e)
def getPersonRepos(): identity = request.form.get('person_id') if identity is None: current_token = get_raw_jwt() identity = current_token['identity'] try: return makeResponse(payload=PeopleManager.getReposForPerson(identity)) except FindError as e: return makeResponse(error=e)
def addType(repo_id): name = request.form.get('name') code = request.form.get('code') description = request.form.get('description') current_user = get_jwt_identity() if PeopleManager.checkRepoPermissions(current_user, repo_id) == False: return makeResponse(status=401, message="You do not have permissions to access this repository!") try: return makeResponse(message="Added type", payload=SchemaManager.addType(repo_id, name, code, description, extractRepeatingParameterBlocksFromRequest(request, 'fields'))) except Exception as e: return makeResponse(error=e)
def addField(repo_id, typecode): name = request.form.get('name') code = request.form.get('code') fieldtype = request.form.get('type') description = request.form.get('description') current_user = get_jwt_identity() if PeopleManager.checkRepoPermissions(current_user, repo_id) == False: return makeResponse(status=401, message="You do not have permissions to access this repository!") try: return makeResponse(payload=SchemaManager.addField(repo_id, typecode, name, code, fieldtype, description), message="Added field") except Exception as e: return makeResponse(error=e)
def addData(repo_id, typecode): data = request.form.get('data') current_user = get_jwt_identity() if PeopleManager.checkRepoPermissions(current_user, repo_id) == False: return makeResponse(status=401, message="You do not have permissions to access this repository!") try: if SchemaManager.addDataToRepo(repo_id, typecode, json.loads(data)): return makeResponse(payload={"msg": "Added data to repository"}) else: return makeResponse(payload={"msg": "No data to add"}) except Exception as e: return makeResponse(error=e)
def getPerson(): if request.method == 'GET': # Get person by auth token current_token = get_raw_jwt() jti = current_token['jti'] # email address identity = current_token['identity'] if request.method == 'POST': identity = int(request.form.get('person_id')) person = PeopleManager.getInfo(identity) ret = {} if person is not None: ret['person'] = person # If request method is GET, then it's our logged in user, get Repos and repo data too! if request.method == 'GET': ret['repos'] = PeopleManager.getRepos(identity) return makeResponse(payload=ret)
def addData(repo_id, typecode): data = request.form.get('data') current_user = get_jwt_identity() if PeopleManager.checkRepoPermissions(current_user, repo_id) == False: return makeResponse( status=401, message="You do not have permissions to access this repository!") try: if SchemaManager.addDataToRepo(repo_id, typecode, json.loads(data)): return makeResponse(payload={"msg": "Added data to repository"}) else: return makeResponse(payload={"msg": "No data to add"}) except Exception as e: return makeResponse(error=e)
def findPerson(): q = request.form.get('q') msg = 'No people found' ret = {'q': q, 'results': []} if q is not None and len(q) > 0: people = PeopleManager.find({'surname': q, 'email': q}) if people is not None: msg = 'Success' ret['results'] = people return makeResponse(payload=ret, message=msg)
def addField(repo_id, typecode): name = request.form.get('name') code = request.form.get('code') fieldtype = request.form.get('type') description = request.form.get('description') current_user = get_jwt_identity() if PeopleManager.checkRepoPermissions(current_user, repo_id) == False: return makeResponse( status=401, message="You do not have permissions to access this repository!") try: return makeResponse(payload=SchemaManager.addField( repo_id, typecode, name, code, fieldtype, description), message="Added field") except Exception as e: return makeResponse(error=e)
def addType(repo_id): name = request.form.get('name') code = request.form.get('code') description = request.form.get('description') current_user = get_jwt_identity() if PeopleManager.checkRepoPermissions(current_user, repo_id) == False: return makeResponse( status=401, message="You do not have permissions to access this repository!") try: return makeResponse(message="Added type", payload=SchemaManager.addType( repo_id, name, code, description, extractRepeatingParameterBlocksFromRequest( request, 'fields'))) except Exception as e: return makeResponse(error=e)
def addPerson(): surname = request.form.get('surname') forename = request.form.get('forename') location = request.form.get('location') email = request.form.get('email') url = request.form.get('url') tagline = request.form.get('tagline') password = request.form.get('password') nyunetid = request.form.get('nyunetid') try: ret = PeopleManager.addPerson(forename, surname, location, email, nyunetid, url, tagline, password) return makeResponse(payload=ret, message="Added person") except DbError as e: return makeResponse(error=e) except SaveError as e: return makeResponse(error=e) except FindError as e: return makeResponse(error=e) except ValidationError as e: return makeResponse(error=e)
def register(): surname = request.form.get('surname') forename = request.form.get('forename') location = request.form.get('location') email = request.form.get('email') url = request.form.get('url') tagline = request.form.get('tagline') password = request.form.get('password') nyunetid = request.form.get('nyunetid') try: ret = PeopleManager.addPerson(forename, surname, location, email, nyunetid, url, tagline, password) return makeResponse(payload=ret, message="Added person") except DbError as e: return makeResponse(error=e) except SaveError as e: return makeResponse(error=e) except FindError as e: return makeResponse(error=e) except ValidationError as e: return makeResponse(error=e)
def boot(): current_user = get_jwt_identity() repo_id = request.form.get('repo_id') try: repo_id = int(repo_id) except: repo_id = None payload = {'repos': PeopleManager.getReposForPerson(current_user)} try: # Try to get first repo_id if repo_id is None or repo_id == 0: repo_id = payload['repos']['repos'][0]['id'] payload['schema'] = {'types': SchemaManager.getTypes(repo_id)} except: pass try: return makeResponse(payload=payload) except Exception as e: return makeResponse(error=e)
def peopleList(): return makeResponse(payload={"people": PeopleManager.getAll()})