def is_update_allowed(obj): """Returns whether the update of the object passed in is supported :param obj: The object to be updated :type obj: ATContentType/DexterityContentType :returns: True if it is allowed to update this object :rtype: bool """ # Do not allow to update the site itself if api.is_portal(obj): return False # Do not allow the update of objects that belong to site root folder parent = api.get_parent(obj) if api.is_portal(parent): return False # Do not allow the update of objects that belong to setup folder if parent == api.get_setup(): return False # Look for an update-specific adapter for this object adapter = queryAdapter(obj, IUpdate) if adapter: return adapter.is_update_allowed() return True
def importObjects(obj, parent_path, context): """ Import subobjects recursively. """ if not can_import(obj): logger.info("Skipping import of {}".format(repr(obj))) return if api.is_portal(obj): # explicitly instantiate the importer to avoid adapter clash of # Products.CMFCore.exportimport.properties.PropertiesXMLAdapter importer = SenaiteSiteXMLAdapter(obj, context) else: importer = queryMultiAdapter((obj, context), IBody) path = "%s%s" % (parent_path, get_id(obj)) __traceback_info__ = path if importer: if importer.name: path = "%s%s" % (parent_path, importer.name) filename = "%s%s" % (path, importer.suffix) body = context.readDataFile(filename) if body is not None: importer.filename = filename # for error reporting importer.body = body if getattr(obj, "objectValues", False): for sub in obj.objectValues(): importObjects(sub, path + "/", context)
def exportObjects(obj, parent_path, context): """ Export subobjects recursively. """ if not can_export(obj): logger.info("Skipping export of {}".format(repr(obj))) return if api.is_portal(obj): # explicitly instantiate the exporter to avoid adapter clash of # Products.CMFCore.exportimport.properties.PropertiesXMLAdapter exporter = SenaiteSiteXMLAdapter(obj, context) else: exporter = queryMultiAdapter((obj, context), IBody) path = "%s%s" % (parent_path, get_id(obj)) if exporter: if exporter.name: path = "%s%s" % (parent_path, exporter.name) filename = "%s%s" % (path, exporter.suffix) body = exporter.body if body is not None: context.writeDataFile(filename, body, exporter.mime_type) if getattr(obj, "objectValues", False): for sub in obj.objectValues(): exportObjects(sub, path + "/", context)
def get_breadcrumbs(self): """Generates the breadcrumbs. Items for which current user does not have the View permission granted are omitted """ hierarchy = [] current = self.context while not api.is_portal(current): if api.is_object(current): if check_permission(View, current): hierarchy.append(current) else: # Some objects (e.g. portal_registry) are not supported hierarchy.append(current) current = current.aq_parent hierarchy = reversed(hierarchy) return map(self.to_breadcrumb, hierarchy)
def get_all_granted_roles_for(folder, permission): """Returns a list of roles that have granted access to the folder. If the folder is acquire=1, it looks through all the hierarchy until acquire=0 to grab all the roles that effectively (regardless of acquire) has permission """ roles = filter(lambda perm: perm.get('selected') == 'SELECTED', folder.rolesOfPermission(permission)) roles = map(lambda prole: prole['name'], roles) if api.is_portal(folder): return roles acquired = folder.acquiredRolesAreUsedBy( permission) == 'CHECKED' and 1 or 0 if acquired: # Grab from the parent parent_roles = get_all_granted_roles_for(folder.aq_parent, permission) roles.extend(parent_roles) return list(set(roles))
def get_id(obj): if api.is_portal(obj): return SITE_ID return obj.getId().replace(" ", "_")
def is_root(brain_or_object): """Proxy to bika.lims.api.is_portal """ return api.is_portal(brain_or_object)
def is_root(brain_or_object): """Proxy to senaite.api.is_portal """ return api.is_portal(brain_or_object)