Ejemplo n.º 1
0
def get_campus_by_suffix(suffix):
    query = Campus.all()
    query.filter("email_ending = ", suffix)

    for c in query.run(limit = 1):
        return c
    return None
Ejemplo n.º 2
0
Archivo: API.py Proyecto: jce-il/SE-Hub
 def createUser(gitHubUserName):
     """
     <span class="card-title">Go To This URL To Set The SE-Token Cookie</span>
     <br>
     <p>This User Will Automatically be added to JCE Campus as a Lecturer</p>
     <b>Route Parameters</b><br>
         - gitHubUserName: A Username<br>
     <br>
     <b>Payload</b><br>
      - None
     <b>Response</b>
     <br>
     None.
     """
     try:
         query = Campus.all().filter('title =', 'JCE')
         for c in query.run(limit=1):
             campus = c
         user = User(name=";", username=gitHubUserName, isFirstLogin=False,
                     avatar_url='http://placekitten.com/g/200/'+str(counter), accessToken="RandomGitHubToken",
                     email='*****@*****.**', campuses_id_list=[str(campus.key().id())],
                     seToken=str(uuid.uuid4()), isLecturer=True)
         db.put(user)
         return created(gitHubUserName + 'Was Created. Token: ' + user.seToken)
     except Exception as e:
         return bad_request(str(e))
Ejemplo n.º 3
0
def get_campus_by_campusName(campusName):
    query = Campus.all()
    query.filter("title = ", campusName)

    for u in query.run(limit = 1):
        return u
    return None
Ejemplo n.º 4
0
def create_campus(token):
    """
    <span class="card-title">This call will create a new campus in the DB</span>
    <br>
    <b>Route Parameters</b><br>
        - seToken: 'seToken'
    <br>
    <br>
    <b>Payload</b><br>
     - JSON Object, Example: <br>
     {<br>
     'title': 'Campus name',<br>
     'email_ending': '@campus.ac.com',<br>
     'avatar_url': 'http://location.domain.com/image.jpg'<br>
    }<br>
    <br>
    <br>
    <b>Response</b>
    <br>
    200 - OK
    <br>
    403 - Invalid Token/Forbidden
    """
    if not request.data:
        return bad_request()
    if not is_lecturer(token):  #todo: change to lecturer id
        return forbidden("Invalid token or not a lecturer!")

    #try to parse payload
    try:
        payload = json.loads(request.data)
    except Exception as e:
        return bad_request(e)

    #check if name already exists
    try:
        query = Campus.all()
        query.filter("title =", payload['title'])
        for c in query.run(limit=1):
            return forbidden("Campus with same name already exists")
    except Exception as e:
        print e

    user = get_user_by_token(token)
    arr = []
    arr.append(str(user.key().id()))
    try:
        campus = Campus(title=payload['title'], email_ending=payload['email_ending'], master_user_id=user.key().id(), avatar_url=payload['avatar_url'], membersId=arr)
    except Exception:
        return bad_request()

    send_create_campus_request(user.email, user.name, campus.title)
    db.put(campus)
    notify_se_hub_campus_request(campus, campus.title)
    db.delete(campus)
    return ok()
Ejemplo n.º 5
0
def get_campuses(token):
    """
    <span class="card-title">This Call will return an array of all Campuses available</span>
    <br>
    <b>Route Parameters</b><br>
        - seToken: 'seToken'
    <br>
    <br>
    <b>Payload</b><br>
     - NONE <br>
    <br>
    <br>
    <b>Response</b>
    <br>
    200 - JSON Array, Example:<br>
    [<br>
    {
                'title': 'JCE',<br>
                'email_ending': '@post.jce.ac.il',<br>
                'master_user_id': 123453433341, (User that created the campus)<br>
                'avatar_url': 'http://some.domain.com/imagefile.jpg',<br>
                'id' : 1234567890<br>
    },<br>
    ....<br>
    {<br>
    ...<br>
    }req<br>
    ]<br>
    <br>
    403 - Invalid Token<br>
    """
    if is_user_token_valid(token):
        arr = []
        query = Campus.all()
        for c in query.run():
            arr.append(dict(json.loads(c.to_JSON())))
        print "ARR:"
        print arr
        for c in arr:
            print"c:"
            print c
        if len(arr) != 0:
            return Response(response=json.dumps(arr),
                            status=200,
                            mimetype="application/json")
        else:
            return Response(response=[],
                            status=200,
                            mimetype="application/json")
    else:
        return forbidden("Invalid Token")