示例#1
0
def add_webhook():
    key = request.form['login_key']
    bid = request.form['blibb_id']
    callback = request.form['callback']
    fields = request.form['fields']
    action = request.form['action']
    user = get_key(key)
    res = dict()
    wb = {'a': action, 'u': callback, 'f': fields}
    if is_valid_id(bid):
        if Blibb.can_write(user, '', bid):
            Blibb.add_webhook(bid, wb)
            res['result'] = 'ok'
        else:
            abort(401)
    else:
        res['error'] = 'Object Id is not valid'
    return jsonify(res)
示例#2
0
def add_user_to_group():
    key = request.form['login_key']
    bid = request.form['blibb_id']
    username = request.form['username']
    user = get_key(key)
    res = dict()
    if is_valid_id(bid):
        user_to_add = User.get_by_name(username)
        if user_to_add:
            if Blibb.can_write(user, '', bid):
                Blibb.add_user_to_group(username, bid)
                res['result'] = 'ok'
            else:
                res['error'] = 'Not permissions'
        else:
            res['error'] = 'User not found'
    else:
        res['error'] = 'Object Id is not valid'
    return jsonify(res)
示例#3
0
def addItemtoBlibb(username=None, slug=None):
    if username is None or slug is None:
        abort(404)

    user = ''
    app_token = ''
    if 'login_key' in request.form:
        key = request.form['login_key']
        user = get_key(key)
    else:
        app_token = request.form['app_token'] if \
            'app_token' in request.form else ''

    tags = request.form['tags'] if 'tags' in request.form else ''
    blibb = Blibb.get_object({'u': username, 's': slug}, {'_id': 1, 't.i': 1})
    if blibb:
        blibb_id = blibb['_id']
        controls = Blibb.get_controls_as_dict(blibb.get('t'))
        current_app.logger.info(str(user) + ' - ' + str(app_token) + ' - '
           + str(blibb_id) + ' - ' + username + ' - ' + slug)
        if Blibb.can_write(user, app_token, blibb_id):
            bitems = Blitem.get_items_from_request(controls, request)
            if len(bitems) > 0:
                blitem_id = Blitem.insert(blibb_id, user, bitems, tags)
                if is_valid_id(blitem_id):
                    cond = {'s': slug, 'u': username}
                    Blibb.inc_num_item(cond)
                    Blitem.post_process(blitem_id, bitems)
                    res = {'id': blitem_id}
                    return jsonify(res)
            else:
                return jsonify({'error': 'your POST data was not complete'})
        else:
            abort(401)
    else:
        abort(404)