コード例 #1
0
ファイル: workspaces.py プロジェクト: lmcthbe/faraday
def workspace(workspace):
    validate_workspace(workspace)
    workspaces = list_workspaces_as_user(
        flask.request.cookies, get_basic_auth())['workspaces']
    ws = get_workspace(workspace, flask.request.cookies, get_basic_auth()) if workspace in workspaces else None
    # TODO: When the workspace DAO is ready, we have to remove this next line
    if not ws.get('fdate'): ws['fdate'] = ws.get('duration').get('end')
    if not ws.get('description'): ws['description'] = ''
    return flask.jsonify(ws)
コード例 #2
0
def workspace(workspace):
    validate_workspace(workspace)
    workspaces = list_workspaces_as_user(flask.request.cookies,
                                         get_basic_auth())['workspaces']
    ws = get_workspace(workspace, flask.request.cookies,
                       get_basic_auth()) if workspace in workspaces else None
    # TODO: When the workspace DAO is ready, we have to remove this next line
    if not ws.get('fdate'): ws['fdate'] = ws.get('duration').get('end')
    if not ws.get('description'): ws['description'] = ''
    return flask.jsonify(ws)
コード例 #3
0
ファイル: doc.py プロジェクト: MrMugiwara/faraday
def add_or_update_document(workspace, doc_id):
    validate_workspace(workspace)

    try:
        document = json.loads(flask.request.data)
    except ValueError:
        return build_bad_request_response('invalid json')

    document['_id'] = doc_id  # document dictionary does not have id, add it
    ws = server.database.get(workspace)
    couchdb_conn = ws.couchdb
    is_update_request = bool(document.get('_rev', False))

    # change user in metadata based on session information
    user = get_user_from_session(flask.request.cookies, get_basic_auth())
    if document.get('metadata', {}).has_key('owner'):
        document['metadata']['owner'] = user
    if document.get('metadata', {}).has_key('update_user'):
        document['metadata']['update_user'] = user

    try:
        response = couchdb_conn.save_doc(document)
    except RequestFailed as e:
        response = flask.jsonify(json.loads(e.msg))
        response.status_code = e.status_int
        return response
    except ResourceError as e:
        response = flask.jsonify({'error': e.message})
        response.status_code = e.status_int
        return response

    if response.get('ok', False):
        doc_importer = server.database.DocumentImporter(ws.connector)
        if is_update_request:
            doc_importer.update_entity_from_doc(document)
        else:
            doc_importer.add_entity_from_doc(document)

    return flask.jsonify(response)
コード例 #4
0
def add_or_update_document(workspace, doc_id):
    validate_workspace(workspace)

    try:
        document = json.loads(flask.request.data)
    except ValueError:
        return build_bad_request_response('invalid json')

    document['_id'] = doc_id  # document dictionary does not have id, add it
    ws = server.database.get(workspace)
    couchdb_conn = ws.couchdb
    is_update_request = bool(document.get('_rev', False))

    # change user in metadata based on session information
    user = get_user_from_session(flask.request.cookies, get_basic_auth())
    if document.get('metadata', {}).has_key('owner'):
        document['metadata']['owner'] = user
    if document.get('metadata', {}).has_key('update_user'):
        document['metadata']['update_user'] = user

    try:
        response = couchdb_conn.save_doc(document)
    except RequestFailed as e:
        response = flask.jsonify(json.loads(e.msg))
        response.status_code = e.status_int
        return response
    except ResourceError as e:
        response = flask.jsonify({'error': e.message})
        response.status_code = e.status_int
        return response

    if response.get('ok', False):
        doc_importer = server.database.DocumentImporter(ws.connector)
        if is_update_request:
            doc_importer.update_entity_from_doc(document)
        else:
            doc_importer.add_entity_from_doc(document)

    return flask.jsonify(response)
コード例 #5
0
ファイル: workspaces.py プロジェクト: lmcthbe/faraday
def workspace_list():
    return flask.jsonify(
        list_workspaces_as_user(
            flask.request.cookies, get_basic_auth()))
コード例 #6
0
ファイル: workspaces.py プロジェクト: mr-wrmsr/BlackServerOS
def workspace_list():
    return flask.jsonify(
        list_workspaces_as_user(flask.request.cookies, get_basic_auth()))