Ejemplo n.º 1
0
def DoGetAccessRules():
    sql = "SELECT ownerUserName='', * FROM metric.accessRules"
    rows = dbmetrics.executesql(sql)
    rules = {}
    counters = GetCounters()
    sql = "SELECT digestID, userName FROM metric.digests"
    digests = {}
    for r in dbmetrics.executesql(sql):
        digests[r.digestID] = r.userName
    sql = "SELECT collectionID, userName FROM metric.collections"
    collections = {}
    for r in dbmetrics.executesql(sql):
        collections[r.collectionID] = r.userName
    sql = "SELECT dashboardID, userName FROM metric.dashboards"
    dashboards = {}
    for r in dbmetrics.executesql(sql):
        dashboards[r.dashboardID] = r.userName

    for r in rows:
        k = (r.contentType, r.contentID)
        if k not in rules:
            rules[k] = []
        if r.contentType == "COUNTER":
            r.ownerUserName = counters[r.contentID].userName
        elif r.contentType == "DIGEST":
            r.ownerUserName = digests.get(r.contentID, "")
        elif r.contentType == "COLLECTION":
            r.ownerUserName = collections.get(r.contentID, "")
        elif r.contentType == "DASHBOARD":
            r.ownerUserName = dashboards.get(r.contentID, "")
        rules[k].append(r)
    return rules
Ejemplo n.º 2
0
def DoGetAccessRules():
    sql = "SELECT ownerUserName='', * FROM metric.accessRules"
    rows = dbmetrics.executesql(sql)
    rules = {}
    counters = GetCounters()
    sql = "SELECT digestID, userName FROM metric.digests"
    digests = {}
    for r in dbmetrics.executesql(sql):
        digests[r.digestID] = r.userName
    sql = "SELECT collectionID, userName FROM metric.collections"
    collections = {}
    for r in dbmetrics.executesql(sql):
        collections[r.collectionID] = r.userName
    sql = "SELECT dashboardID, userName FROM metric.dashboards"
    dashboards = {}
    for r in dbmetrics.executesql(sql):
        dashboards[r.dashboardID] = r.userName

    for r in rows:
        k = (r.contentType, r.contentID)
        if k not in rules:
            rules[k] = []
        if r.contentType == "COUNTER":
            r.ownerUserName = counters[r.contentID].userName
        elif r.contentType == "DIGEST":
            r.ownerUserName = digests.get(r.contentID, "")
        elif r.contentType == "COLLECTION":
            r.ownerUserName = collections.get(r.contentID, "")
        elif r.contentType == "DASHBOARD":
            r.ownerUserName = dashboards.get(r.contentID, "")
        rules[k].append(r)
    return rules
Ejemplo n.º 3
0
def linkTo(validator, linkTo, instance, schema):
    # avoid circular import
    from snovault import Item, COLLECTIONS

    if not validator.is_type(instance, "string"):
        return

    request = get_current_request()
    collections = request.registry[COLLECTIONS]
    if validator.is_type(linkTo, "string"):
        base = collections.get(linkTo, request.root)
        linkTo = [linkTo] if linkTo else []
    elif validator.is_type(linkTo, "array"):
        base = request.root
    else:
        raise Exception("Bad schema")  # raise some sort of schema error
    try:
        item = find_resource(base, instance.replace(':', '%3A'))
        if item is None:
            raise KeyError()
    except KeyError:
        error = "%r not found" % instance
        yield ValidationError(error)
        return
    if not isinstance(item, Item):
        error = "%r is not a linkable resource" % instance
        yield ValidationError(error)
        return
    if linkTo and not set([item.type_info.name] + item.base_types).intersection(set(linkTo)):
        reprs = (repr(it) for it in linkTo)
        error = "%r is not of type %s" % (instance, ", ".join(reprs))
        yield ValidationError(error)
        return

    linkEnum = schema.get('linkEnum')
    if linkEnum is not None:
        if not validator.is_type(linkEnum, "array"):
            raise Exception("Bad schema")
        if not any(UUID(enum_uuid) == item.uuid for enum_uuid in linkEnum):
            reprs = ', '.join(repr(it) for it in linkTo)
            error = "%r is not one of %s" % (instance, reprs)
            yield ValidationError(error)
            return

    if schema.get('linkSubmitsFor'):
        userid = None
        for principal in request.effective_principals:
            if principal.startswith('userid.'):
                userid = principal[len('userid.'):]
                break
        if userid is not None:
            user = request.root[userid]
            submits_for = user.upgrade_properties().get('submits_for')
            if (submits_for is not None and
                    not any(UUID(uuid) == item.uuid for uuid in submits_for) and
                    not request.has_permission('submit_for_any')):
                error = "%r is not in user submits_for" % instance
                yield ValidationError(error)
                return

    # And normalize the value to a uuid
    if validator._serialize:
        validator._validated[-1] = str(item.uuid)
Ejemplo n.º 4
0
def linkTo(validator, linkTo, instance, schema):
    # avoid circular import
    from snovault import Item, COLLECTIONS

    if not validator.is_type(instance, "string"):
        return

    request = get_current_request()
    collections = request.registry[COLLECTIONS]
    if validator.is_type(linkTo, "string"):
        base = collections.get(linkTo, request.root)
        linkTo = [linkTo] if linkTo else []
    elif validator.is_type(linkTo, "array"):
        base = request.root
    else:
        raise Exception("Bad schema")  # raise some sort of schema error
    try:
        item = find_resource(base, instance.replace(':', '%3A'))
        if item is None:
            raise KeyError()
    except KeyError:
        error = "%r not found" % instance
        yield ValidationError(error)
        return
    if not isinstance(item, Item):
        error = "%r is not a linkable resource" % instance
        yield ValidationError(error)
        return
    if linkTo and not set([item.type_info.name] + item.base_types).intersection(set(linkTo)):
        reprs = (repr(it) for it in linkTo)
        error = "%r is not of type %s" % (instance, ", ".join(reprs))
        yield ValidationError(error)
        return

    linkEnum = schema.get('linkEnum')
    if linkEnum is not None:
        if not validator.is_type(linkEnum, "array"):
            raise Exception("Bad schema")
        if not any(UUID(enum_uuid) == item.uuid for enum_uuid in linkEnum):
            reprs = ', '.join(repr(it) for it in linkTo)
            error = "%r is not one of %s" % (instance, reprs)
            yield ValidationError(error)
            return

    if schema.get('linkSubmitsFor'):
        userid = None
        for principal in request.effective_principals:
            if principal.startswith('userid.'):
                userid = principal[len('userid.'):]
                break
        if userid is not None:
            user = request.root[userid]
            submits_for = user.upgrade_properties().get('submits_for')
            if (submits_for is not None and
                    not any(UUID(uuid) == item.uuid for uuid in submits_for) and
                    not request.has_permission('submit_for_any')):
                error = "%r is not in user submits_for" % instance
                yield ValidationError(error)
                return

    # And normalize the value to a uuid
    if validator._serialize:
        validator._validated[-1] = str(item.uuid)