Ejemplo n.º 1
0
def conferences_put_text_read_marking(conf_no, local_text_no):
    """Mark text as read in the specified recipient conference (only).
    
    .. rubric:: Request
    
    ::
    
      PUT /conferences/14506/texts/29/read-marking HTTP/1.1
    
    .. rubric:: Response
    
    ::
    
      HTTP/1.1 204 OK
    
    .. rubric:: Example
    
    ::
    
      curl -b cookies.txt -c cookies.txt -v \\
           -X PUT http://localhost:5001/conferences/14506/texts/29/read-marking
    
    """
    # TODO: handle conferences/texts that doesn't exist (i.e. return 404).
    g.ksession.mark_as_read_local(local_text_no, conf_no)
    return empty_response(204)
Ejemplo n.º 2
0
def conferences_put_text_read_marking(conf_no, local_text_no):
    """Mark text as read in the specified recipient conference (only).
    
    .. rubric:: Request
    
    ::
    
      PUT /conferences/14506/texts/29/read-marking HTTP/1.1
    
    .. rubric:: Response
    
    ::
    
      HTTP/1.1 204 OK
    
    .. rubric:: Example
    
    ::
    
      curl -b cookies.txt -c cookies.txt -v \\
           -X PUT http://localhost:5001/conferences/14506/texts/29/read-marking
    
    """
    # TODO: handle conferences/texts that doesn't exist (i.e. return 404).
    g.ksession.mark_as_read_local(local_text_no, conf_no)
    return empty_response(204)
Ejemplo n.º 3
0
def status():
    # Only enable status page in debug mode. It's not public information!
    # IMPORTANT: the kom_session.id is VERY secret! You can take over a session with it.
    if app.config['DEBUG']:
        return render_template('status.html', kom_sessions=sessions.kom_sessions)
    else:
        return empty_response(404)
Ejemplo n.º 4
0
def texts_delete_read_marking(text_no):
    """Mark a text as unread in all recipient conferences.
    
    .. rubric:: Request
    
    ::
    
      DELETE /texts/<int:text_no>/read-marking HTTP/1.0
    
    .. rubric:: Responses
    
    Text was marked as read::
    
      HTTP/1.0 204 NO CONTENT
    
    .. rubric:: Example
    
    ::
    
      curl -b cookies.txt -c cookies.txt -v \\
           -X DELETE http://localhost:5001/texts/19680717/read-marking
    
    """
    g.ksession.mark_as_unread(text_no)
    return empty_response(204)
Ejemplo n.º 5
0
def texts_delete_read_marking(text_no):
    """Mark a text as unread in all recipient conferences.
    
    .. rubric:: Request
    
    ::
    
      DELETE /texts/<int:text_no>/read-marking HTTP/1.0
    
    .. rubric:: Responses
    
    Text was marked as read::
    
      HTTP/1.0 204 NO CONTENT
    
    .. rubric:: Example
    
    ::
    
      curl -b cookies.txt -c cookies.txt -v \\
           -X DELETE http://localhost:5001/texts/19680717/read-marking
    
    """
    g.ksession.mark_as_unread(text_no)
    return empty_response(204)
Ejemplo n.º 6
0
def conferences_set_unread():
    """ Expecting:
            Content-Type: application/json 
            Body: { "no-of-unread": 123 }}
        Example:
            curl -b cookies.txt -c cookies.txt -v -X PUT -H "Content-Type: application/json" \
                http://localhost:5001/conferences/set_unread -d '{ "no_of_unread": 10, \
                                                                     "conf_name": "Aka intres" }'
    """
    conf_name = request.json['conf_name']
    conf_no = g.ksession.lookup_name_exact(conf_name, True, True)
    no_of_unread = int(request.json['no_of_unread'])
    g.ksession.set_unread(conf_no, no_of_unread)
    return empty_response(204)
Ejemplo n.º 7
0
def conferences_set_unread():
    """ Expecting:
            Content-Type: application/json 
            Body: { "no-of-unread": 123 }}
        Example:
            curl -b cookies.txt -c cookies.txt -v -X PUT -H "Content-Type: application/json" \
                http://localhost:5001/conferences/set_unread -d '{ "no_of_unread": 10, \
                                                                     "conf_name": "Aka intres" }'
    """
    conf_name = request.json['conf_name']
    conf_no = g.ksession.lookup_name_exact(conf_name, True, True)
    no_of_unread = int(request.json['no_of_unread'])
    g.ksession.set_unread(conf_no, no_of_unread)
    return empty_response(204)
Ejemplo n.º 8
0
def sessions_delete(session_id):
    """Delete a session (i.e. logout).
    
    .. rubric:: Request
    
    ::
    
      DELETE /sessions/033556ee-3e52-423f-9c9a-d85aed7688a1 HTTP/1.1
    
    .. rubric:: Responses
    
    Session exist::
    
      HTTP/1.1 204 No Content
    
    Session does not exist::
    
      HTTP/1.1 404 Not Found
      Set-Cookie: session_id=; expires=Thu, 01-Jan-1970 00:00:00 GMT; Path=/
    
    .. rubric:: Example
    
    ::
    
      curl -b cookies.txt -c cookies.txt -v \\
           -X DELETE http://localhost:5001/sessions/abc123
    
    """
    ksession = _get_komsession(session_id)
    if ksession:
        _logout(ksession)
        response = empty_response(204)
        response.set_cookie('session_id', value='', expires=0)
        return response
    else:
        return empty_response(404)
Ejemplo n.º 9
0
def sessions_delete(session_id):
    """Delete a session (i.e. logout).
    
    .. rubric:: Request
    
    ::
    
      DELETE /sessions/033556ee-3e52-423f-9c9a-d85aed7688a1 HTTP/1.1
    
    .. rubric:: Responses
    
    Session exist::
    
      HTTP/1.1 204 No Content
    
    Session does not exist::
    
      HTTP/1.1 404 Not Found
      Set-Cookie: session_id=; expires=Thu, 01-Jan-1970 00:00:00 GMT; Path=/
    
    .. rubric:: Example
    
    ::
    
      curl -b cookies.txt -c cookies.txt -v \\
           -X DELETE http://localhost:5001/sessions/abc123
    
    """
    ksession = _get_komsession(session_id)
    if ksession:
        _logout(ksession)
        response = empty_response(204)
        response.set_cookie('session_id', value='', expires=0)
        return response
    else:
        return empty_response(404)
Ejemplo n.º 10
0
def sessions_get(session_id):
    """Get information about a session. Usable for checking if your
    session is still valid.
    
    .. rubric:: Request
    
    ::
    
      GET /sessions/033556ee-3e52-423f-9c9a-d85aed7688a1 HTTP/1.1
    
    .. rubric:: Responses
    
    Session exists (i.e. logged in)::
    
      HTTP/1.1 200 OK
      
      { "id": "033556ee-3e52-423f-9c9a-d85aed7688a1",
        "person": { "pers_no": 14506, "pers_name": "Oskars testperson" },
        "client": { "name": "jskom", "version": "0.2" } }
    
    Session does not exist (i.e. not logged in)::
    
      HTTP/1.1 404 Not Found
    
    .. rubric:: Example
    
    ::
    
      curl -b cookies.txt -c cookies.txt -v \\
           -X GET http://localhost:5001/sessions/abc123
    
    """
    session_id = _get_session_id()
    ksession = _get_komsession(session_id)
    if ksession:
        return jsonify(to_dict(ksession, True, ksession))
    else:
        return empty_response(404)
Ejemplo n.º 11
0
def sessions_get(session_id):
    """Get information about a session. Usable for checking if your
    session is still valid.
    
    .. rubric:: Request
    
    ::
    
      GET /sessions/033556ee-3e52-423f-9c9a-d85aed7688a1 HTTP/1.1
    
    .. rubric:: Responses
    
    Session exists (i.e. logged in)::
    
      HTTP/1.1 200 OK
      
      { "id": "033556ee-3e52-423f-9c9a-d85aed7688a1",
        "person": { "pers_no": 14506, "pers_name": "Oskars testperson" },
        "client": { "name": "jskom", "version": "0.2" } }
    
    Session does not exist (i.e. not logged in)::
    
      HTTP/1.1 404 Not Found
    
    .. rubric:: Example
    
    ::
    
      curl -b cookies.txt -c cookies.txt -v \\
           -X GET http://localhost:5001/sessions/abc123
    
    """
    session_id = _get_session_id()
    ksession = _get_komsession(session_id)
    if ksession:
        return jsonify(to_dict(ksession, True, ksession))
    else:
        return empty_response(404)
Ejemplo n.º 12
0
def badrequest(error):
    return empty_response(400)
Ejemplo n.º 13
0
    def decorated(*args, **kwargs):
        g.ksession = _get_komsession(_get_session_id())
        if g.ksession:
            return f(*args, **kwargs)

        return empty_response(401)
Ejemplo n.º 14
0
def notfound(error):
    return empty_response(404)
Ejemplo n.º 15
0
def badrequest(error):
    return empty_response(400)
Ejemplo n.º 16
0
def notfound(error):
    return empty_response(404)
Ejemplo n.º 17
0
 def decorated(*args, **kwargs):
     g.ksession = _get_komsession(_get_session_id())
     if g.ksession:
         return f(*args, **kwargs)
     
     return empty_response(401)