예제 #1
0
async def addable_types(context, request):
    result = []
    constrains = ICMSConstrainTypes(context, None)

    policy = get_security_policy()

    for id, factory in FACTORY_CACHE.items():
        add = True
        if constrains is not None:
            if not constrains.is_type_allowed(id):
                add = False

        if factory.add_permission:
            if factory.add_permission in PERMISSIONS_CACHE:
                permission = PERMISSIONS_CACHE[factory.add_permission]
            else:
                permission = query_utility(IPermission, name=factory.add_permission)
                PERMISSIONS_CACHE[factory.add_permission] = permission

            if permission is not None and not policy.check_permission(permission.id, context):
                add = False

        if add:
            result.append(id)
    return result
예제 #2
0
async def get_all_types(context, request):
    result = []
    base_url = IAbsoluteURL(context, request)()
    constrains = ICMSConstrainTypes(context, None)

    policy = get_security_policy()

    for id, factory in FACTORY_CACHE.items():
        add = True
        if constrains is not None:
            if not constrains.is_type_allowed(id):
                add = False

        if factory.add_permission:
            if factory.add_permission in PERMISSIONS_CACHE:
                permission = PERMISSIONS_CACHE[factory.add_permission]
            else:
                permission = query_utility(IPermission, name=factory.add_permission)
                PERMISSIONS_CACHE[factory.add_permission] = permission

            if permission is not None and not policy.check_permission(
                permission.id, context
            ):
                add = False
        if add:
            result.append(
                {"@id": base_url + "/@types/" + id, "addable": True, "title": id}
            )
    return result
예제 #3
0
async def get_all_types(context, request):
    result = []
    base_url = IAbsoluteURL(context, request)()
    constrains = IConstrainTypes(context, None)

    for id, factory in FACTORY_CACHE.items():
        add = True
        if constrains is not None:
            if not constrains.is_type_allowed(id):
                add = False

        if factory.add_permission:
            if factory.add_permission in PERMISSIONS_CACHE:
                permission = PERMISSIONS_CACHE[factory.add_permission]
            else:
                permission = query_utility(IPermission,
                                           name=factory.add_permission)
                PERMISSIONS_CACHE[factory.add_permission] = permission

            if permission is not None and \
                    not IInteraction(request).check_permission(
                        permission.id, context):
                add = False
        if add:
            result.append({
                '@id': base_url + '/@types/' + id,
                'addable': True,
                'title': id
            })
    return result
예제 #4
0
async def addable_types(context, request):
    constrains = IConstrainTypes(context, None)
    types = constrains and constrains.get_allowed_types()
    if types is None:
        types = []
        for type_name, factory in FACTORY_CACHE.items():
            types.append(type_name)
    return types
예제 #5
0
def get_metadata():
    global METADATA_CACHE
    if METADATA_CACHE is None:
        mapping = []
        for type_name, type_schema in FACTORY_CACHE.items():
            mapping.extend(
                merged_tagged_value_list(type_schema.schema, metadata.key))
        for _, utility in get_utilities_for(IBehavior):
            mapping.extend(
                merged_tagged_value_list(utility.interface, metadata.key))
        METADATA_CACHE = mapping
    else:
        METADATA_CACHE
    return METADATA_CACHE
예제 #6
0
async def get_all_indices(context, request):
    base_url = IAbsoluteURL(context, request)()
    result = {"@id": base_url, "types": {}, "behaviors": {}}
    for type_name, type_schema in FACTORY_CACHE.items():
        indices = merged_tagged_value_dict(type_schema.schema, index.key)
        result["types"][type_name] = {
            key: value["type"]
            for key, value in indices.items()
        }  # noqa

    for behavior, utility in get_utilities_for(IBehavior):
        indices = merged_tagged_value_dict(utility.interface, index.key)
        result["behaviors"][behavior] = {
            key: value["type"]
            for key, value in indices.items()
        }  # noqa
    return result
예제 #7
0
def get_indexes():
    """ Get all the indexes
    """

    global INDEXES_CACHE
    if INDEXES_CACHE is None:
        mapping = {}
        for type_name, type_schema in FACTORY_CACHE.items():
            mapping.update(
                merged_tagged_value_dict(type_schema.schema, index.key))
        for _, utility in get_utilities_for(IBehavior):
            mapping.update(
                merged_tagged_value_dict(utility.interface, index.key))
        INDEXES_CACHE = mapping
    else:
        INDEXES_CACHE
    return INDEXES_CACHE
 async def total(self):
     count = 0
     for type_name in FACTORY_CACHE.keys():
         count += await get_total_amount_resources(type_name)
     return count