예제 #1
0
def rzdoc__create(rzdoc_name):
    """
    create RZ doc
    """
    s_rzdoc_name = sanitize_input__rzdoc_name(rzdoc_name)
    kernel = flask.current_app.kernel
    ctx = __context__common(rzdoc_name=None)  # avoid rzdoc cache lookup exception
    try:
        kernel.rzdoc__create(s_rzdoc_name, ctx)
    except RZDoc_Exception__already_exists as e:
        return common_resp_handle__server_error(error='rzdoc already exists')
    return make_response__json(status=HTTP_STATUS__201_CREATED)
예제 #2
0
파일: rz_api_rest.py 프로젝트: yuvadm/rhizi
def rzdoc__create(rzdoc_name):
    """
    create RZ doc
    """
    s_rzdoc_name = sanitize_input__rzdoc_name(rzdoc_name)
    kernel = flask.current_app.kernel
    ctx = __context__common(
        rzdoc_name=None)  # avoid rzdoc cache lookup exception
    try:
        kernel.rzdoc__create(s_rzdoc_name, ctx)
    except RZDoc_Exception__already_exists as e:
        return common_resp_handle__server_error(error='rzdoc already exists')
    return make_response__json(status=HTTP_STATUS__201_CREATED)
예제 #3
0
파일: rz_api.py 프로젝트: yuvadm/rhizi
def rz_mainpage(rzdoc_name=None):
    """
    Main application load function.

    [!] Do not use as a flask endpoint as multiple functions redirect here
    """

    # fetch rz_username for welcome message
    email_address = session.get('username')
    rz_username = "******"
    role_set = []
    if None != email_address:  # session cookie passed & contains uid (email_address)
        try:
            _uid, u_account = current_app.user_db.lookup_user__by_email_address(
                email_address)
        except Exception as e:
            # may occur on user_db reset or malicious cookie != stale cookie,
            # for which the user would at least be known to the user_db
            # FIXME: remove the cookie
            pass
        else:
            role_set = u_account.role_set
            rz_username = escape(u_account.rz_username)

    rz_config = current_app.rz_config
    if None == rzdoc_name:
        s_rzdoc_name = rz_config.rzdoc__mainpage_name
    else:
        try:
            s_rzdoc_name = sanitize_input__rzdoc_name(rzdoc_name)
        except Exception as e:
            log.exception(e)
            return common_resp_handle__client_error(status=404)

    # establish rz_config template values
    host_addr, host_port = request.host_sock_addr[0], request.host_sock_addr[1]
    rz_config = {
        'rz_config__rzdoc_cur__name': s_rzdoc_name,
        'rz_config__rzdoc__mainpage_name': rz_config.rzdoc__mainpage_name,
        'rz_config__hostname': host_addr,
        'rz_config__port': host_port,
        'rz_config__optimized_main':
        'true' if rz_config.optimized_main else 'false',
        'rz_config__role_set': role_set,
        'fragment_d_path': rz_config.fragment_d_path,
    }
    return render_template('index.html', rz_username=rz_username, **rz_config)
예제 #4
0
def __context__common(rzdoc_name=None):
    """
    Common request context builder passed along with kernel calls:
       - set user_name
       - set rzdoc if rzdoc_name argument was supplied

    @raise RZDoc_Exception__not_found: if rzdoc_name arg was passed and document was not found
    """

    ret = Req_Context()
    if session.has_key('username'):
        ret.user_name = session['username']

    if None != rzdoc_name:
        s_rzdoc_name = sanitize_input__rzdoc_name(rzdoc_name)
        ret.rzdoc = current_app.kernel.cache_lookup__rzdoc(s_rzdoc_name)
    return ret
예제 #5
0
파일: rz_api_rest.py 프로젝트: yuvadm/rhizi
def __context__common(rzdoc_name=None):
    """
    Common request context builder passed along with kernel calls:
       - set user_name
       - set rzdoc if rzdoc_name argument was supplied

    @raise RZDoc_Exception__not_found: if rzdoc_name arg was passed and document was not found
    """

    ret = Req_Context()
    if session.has_key('username'):
        ret.user_name = session['username']

    if None != rzdoc_name:
        s_rzdoc_name = sanitize_input__rzdoc_name(rzdoc_name)
        ret.rzdoc = current_app.kernel.cache_lookup__rzdoc(s_rzdoc_name)
    return ret
예제 #6
0
파일: rz_api.py 프로젝트: shlomif/rhizi
def rz_mainpage(rzdoc_name=None):
    """
    Main application load function.

    [!] Do not use as a flask endpoint as multiple functions redirect here
    """

    # fetch rz_username for welcome message
    email_address = session.get('username')
    rz_username = "******"
    role_set = []
    if None != email_address:  # session cookie passed & contains uid (email_address)
        try:
            _uid, u_account = current_app.user_db.lookup_user__by_email_address(email_address)
        except Exception as e:
            # may occur on user_db reset or malicious cookie != stale cookie,
            # for which the user would at least be known to the user_db
            # FIXME: remove the cookie
            pass
        else:
            role_set = u_account.role_set
            rz_username = escape(u_account.rz_username)

    rz_config = current_app.rz_config
    if None == rzdoc_name:
        s_rzdoc_name = rz_config.rzdoc__mainpage_name
    else:
        try:
            s_rzdoc_name = sanitize_input__rzdoc_name(rzdoc_name)
        except Exception as e:
            log.exception(e)
            return common_resp_handle__client_error(status=404)

    # establish rz_config template values
    host_addr, host_port = request.host_sock_addr[0], request.host_sock_addr[1]
    rz_config = {'rz_config__rzdoc_cur__name': s_rzdoc_name,
                 'rz_config__rzdoc__mainpage_name': rz_config.rzdoc__mainpage_name,
                 'rz_config__hostname': host_addr,
                 'rz_config__port': host_port,
                 'rz_config__optimized_main': 'true' if rz_config.optimized_main else 'false',
                 'rz_config__role_set': role_set,
                 'fragment_d_path': rz_config.fragment_d_path,
                 }
    return render_template('index.html', rz_username=rz_username, **rz_config)