Exemple #1
0
def workspace_by_user(user_uri):
    """Its at times like these I just want to pass SQL in... """

    qm = db_session.query(Module)
    qm = qm.join(Module.userroles)
    qm = qm.filter(UserRoleModule.user_uri == user_uri)
    rs1 = qm.all()

    qf = db_session.query(Folder)
    qf = qf.join(Folder.userroles)
    qf = qf.filter(UserRoleFolder.user_uri == user_uri)
    rs2 = qf.all()

    qc = db_session.query(Collection)
    qc = qc.join(Collection.userroles)
    qc = qc.filter(UserRoleCollection.user_uri == user_uri)
    rs3 = qc.all()

    rs1.extend(rs2)
    rs1.extend(rs3)
    db_session.commit()  # hail mary...
    return rs1
Exemple #2
0
def get_by_id(klass, ID, useruri):
    """Here we show why we need each Klass to have a generic named id_
    I want to avoid overly comploex mapping and routing in class
    calls.  However we could map internally in the class (id_ =
    folderid) THis does very little.

    """
    q = db_session.query(klass)
    q = q.filter(klass.id_ == ID)
    rs = q.all()
    if len(rs) == 0:
#        raise Rhaptos2Error("ID Not found in this repo")
        abort(404)
    ### There is a uniq constraint on the table, but anyway...
    if len(rs) > 1:
        raise Rhaptos2Error("Too many matches")

    newu = rs[0]
    if not change_approval(newu, {}, useruri, "GET"):
        abort(403)
    return newu
Exemple #3
0
def get_by_id(klass, ID, useruri):
    """

    refactoring:
    ID -> uri
    Then use uri -> klass to get klass needed
    Then do not abort but raise capturable error.
    THen pass useruri all way through.

    """
    q = db_session.query(klass)
    q = q.filter(klass.id_ == ID)
    rs = q.all()
    if len(rs) == 0:
#        raise Rhaptos2Error("ID Not found in this repo")
        abort(404)
    ### There is a uniq constraint on the table, but anyway...
    if len(rs) > 1:
        raise Rhaptos2Error("Too many matches")

    newu = rs[0]
    if not change_approval(newu, {}, useruri, "GET"):
        abort(403)
    return newu
Exemple #4
0
def obj_from_urn(URN, requesting_user_uri, klass=None):
    """
    THis is the refactored version of get_by_id

    URN
      cnxmodule:1234-5678

    requesting_user_urn
      cnxuser:1234-5678

    I have reservations about encoding the type in the ID string.
    But not many.

    """
    if not klass:
        try:
            klass = klass_from_uri(URN)
        except:
            dolog("INFO", "Faioled getting klass %s" % URN)
            abort(400)

    q = db_session.query(klass)
    q = q.filter(klass.id_ == URN)
    rs = q.all()
    if len(rs) == 0:
        raise Rhaptos2Error("ID Not found in this repo")
    ### There is  a uniq constraint on the table, but anyway...
    if len(rs) > 1:
        raise Rhaptos2Error("Too many matches")

    newu = rs[0]
    if not change_approval(newu, {}, requesting_user_uri, "GET"):
        raise Rhaptos2AccessNotAllowedError("user %s not allowed access to %s"
                                            % (requesting_user_uri,
                                                URN))
    return newu