def get_indexes(invalidate=False): """ { "access_users": ["root"], "uuid":"a037df9fa3624b5fb09dbda1480f8210", "contributors":null, "created":"2017-03-16T08:46:00.633690-05:00", "portal_type":"Folder", "title":"Posts", "modified":"2017-03-16T08:46:00.633690-05:00", "depth":2, "subjects":null, "path":"/site/posts", "creators":null, "access_roles":["guillotina.SiteAdmin"], "parent_uuid":"8406d8b94d0e47bfa6cb0a82e531216b" } """ if invalidate: _cached_indexes.clear() if len(_cached_indexes) > 0: return _cached_indexes for type_name, schema in getUtilitiesFor(IResourceFactory): for field_name, catalog_info in get_index_fields(type_name).items(): catalog_type = catalog_info.get('type', 'text') if catalog_type not in index_mappings: index = index_mappings['*'](field_name) else: index = index_mappings[catalog_type](field_name) _cached_indexes[field_name] = index return _cached_indexes
def get_all_possible_schemas_for_type(type_name): result = set() factory = get_cached_factory(type_name) if factory.schema is not None: result.add(factory.schema) for schema in factory.behaviors or (): result.add(schema) for iface, utility in getUtilitiesFor(IBehavior): if utility.for_.isEqualOrExtendedBy(factory.schema): result.add(utility.interface) return [b for b in result]
def load_cached_schema(): for x in getUtilitiesFor(IResourceFactory): factory = x[1] if factory.type_name not in SCHEMA_CACHE: behaviors_registrations = [] for iface in factory.behaviors or (): if Interface.providedBy(iface): name = iface.__identifier__ else: name = iface behaviors_registrations.append(getUtility(IBehavior, name=name)) SCHEMA_CACHE[factory.type_name] = { 'behaviors': behaviors_registrations, 'schema': factory.schema } for iface, utility in getUtilitiesFor(IBehavior): if isinstance(iface, str): name = iface elif Interface.providedBy(iface): name = iface.__identifier__ if name not in BEHAVIOR_CACHE: BEHAVIOR_CACHE[name] = utility.interface
async def __call__(self): if not hasattr(self, 'value'): self.value = [x[1] for x in getUtilitiesFor(IResourceFactory)] if isinstance(self.value, list): result = [] for x in self.value: serializer = getMultiAdapter((x, self.request), IFactorySerializeToJson) result.append(await serializer()) else: serializer = getMultiAdapter((self.value, self.request), IFactorySerializeToJson) result = await serializer() return result
async def default_get(context, request): """We show the available schemas.""" result = {} factory = get_cached_factory(context.type_name) result['static'] = [] for schema in factory.behaviors or (): result['static'].append(schema.__identifier__) # convert to list, could be frozenset result['dynamic'] = [b for b in context.__behaviors__] result['available'] = [] for iface, utility in getUtilitiesFor(IBehavior): serialize = False if isinstance(iface, str): name = iface else: name = iface.__identifier__ if name not in result['dynamic'] and name not in result['static']: adaptable = queryAdapter(context, utility.interface, name='', default=None) if adaptable: result['available'].append(name) serialize = True schema_serializer = getMultiAdapter( (utility.interface, request), ISchemaSerializeToJson) result[name] = await schema_serializer() else: serialize = True if serialize: schema_serializer = getMultiAdapter((utility.interface, request), ISchemaSerializeToJson) result[name] = await schema_serializer() return result
def global_roles(): if 'global_roles' in app_settings: return app_settings['global_roles'] names = [name for name, util in getUtilitiesFor(IRole) if not util.local] app_settings['global_roles'] = names return names
def check_role(context, role_id): names = [name for name, util in getUtilitiesFor(IRole, context)] if role_id not in names: raise ValueError("Undefined role id", role_id)
def get_all_permissions(context=None): """Get the ids of all defined permissions """ for id, permission in getUtilitiesFor(IPermission, context): if id != 'zope.Public': yield id