Ejemplo n.º 1
0
def share_resource():
    if 'entity_id' not in session:
        return auth_failed_response()
    
    entity_id = session['entity_id']
    
    if "resource_id" not in request.json:
        return bad_parameter_response("resource_id")
    if "other_entity_ids" not in request.json:
        return bad_parameter_response("other_entity_ids")
        
    resource_id = request.json["resource_id"]
    other_entity_ids = request.json["other_entity_ids"]
        
    if isinstance(other_entity_ids,str):
        other_entity_ids = [other_entity_ids]
    elif not isinstance(other_entity_ids,list):
        return bad_parameter_response("other_entity_ids")
    
    resource_auth = ResourceAuth().query.filter_by(entity_id=entity_id,is_owner=True,resource_id=resource_id).first()
    
    if not resource_auth:
        return jsonify({"error":"not owner"})
    else:
        for eid in other_entity_ids:
            existing_resource_auth = ResourceAuth().query.filter_by(entity_id=eid,resource_id=resource_id).first()
            if not existing_resource_auth:
                new_resource_auth = ResourceAuth()
                new_resource_auth.entity_id = eid
                new_resource_auth.resource_id = resource_id
                new_resource_auth.is_owner = False
                db.session.add(new_resource_auth)
                db.session.commit()
    
        return ok_response()
Ejemplo n.º 2
0
def new_resource():
    if 'entity_id' not in session:
        return auth_failed_response()
        
    if "owner_id" not in request.json:
        return bad_parameter_response("owner_id")
        
    owner_id = request.json["owner_id"]    
    
    new_id =  str(uuid.uuid4())
    
    new_resource_auth = ResourceAuth()
    new_resource_auth.entity_id = owner_id
    new_resource_auth.is_owner = True
    new_resource_auth.resource_id = new_id
    
    db.session.add(new_resource_auth)
    db.session.commit()
    
    return jsonify({"resource_id":new_id})
Ejemplo n.º 3
0
def new_resource():
    if 'entity_id' not in session:
        return auth_failed_response()

    if "owner_id" not in request.json:
        return bad_parameter_response("owner_id")

    owner_id = request.json["owner_id"]

    new_id = str(uuid.uuid4())

    new_resource_auth = ResourceAuth()
    new_resource_auth.entity_id = owner_id
    new_resource_auth.is_owner = True
    new_resource_auth.resource_id = new_id

    db.session.add(new_resource_auth)
    db.session.commit()

    return jsonify({"resource_id": new_id})
Ejemplo n.º 4
0
def share_resource():
    if 'entity_id' not in session:
        return auth_failed_response()

    entity_id = session['entity_id']

    if "resource_id" not in request.json:
        return bad_parameter_response("resource_id")
    if "other_entity_ids" not in request.json:
        return bad_parameter_response("other_entity_ids")

    resource_id = request.json["resource_id"]
    other_entity_ids = request.json["other_entity_ids"]

    if isinstance(other_entity_ids, str):
        other_entity_ids = [other_entity_ids]
    elif not isinstance(other_entity_ids, list):
        return bad_parameter_response("other_entity_ids")

    resource_auth = ResourceAuth().query.filter_by(
        entity_id=entity_id, is_owner=True, resource_id=resource_id).first()

    if not resource_auth:
        return jsonify({"error": "not owner"})
    else:
        for eid in other_entity_ids:
            existing_resource_auth = ResourceAuth().query.filter_by(
                entity_id=eid, resource_id=resource_id).first()
            if not existing_resource_auth:
                new_resource_auth = ResourceAuth()
                new_resource_auth.entity_id = eid
                new_resource_auth.resource_id = resource_id
                new_resource_auth.is_owner = False
                db.session.add(new_resource_auth)
                db.session.commit()

        return ok_response()