def get_allowed_types(context):
    context = getContext(context)

    if IConstrainTypes.providedBy(context):
        types = IConstrainTypes(context).getImmediatelyAddableTypes()
    else:
        types = context.allowedContentTypes()
    return types
Exemplo n.º 2
0
def _verifyObjectPaste(self, obj, validate_src=True):
    self._old__verifyObjectPaste(obj, validate_src=True)
    portal_type = getattr(aq_base(obj), "portal_type", None)
    constrains = IConstrainTypes(self, None)
    if constrains:
        allowed_ids = [i.getId() for i in constrains.allowedContentTypes()]
        if portal_type not in allowed_ids:
            raise ValueError("Disallowed subobject type: %s" % portal_type)
Exemplo n.º 3
0
    def allowedContentTypes(self, context=None):
        if not context:
            context = self

        constrains = IConstrainTypes(context, None)
        if not constrains:
            return super(Container, self).allowedContentTypes()

        return constrains.allowedContentTypes()
Exemplo n.º 4
0
    def allowedContentTypes(self, context=None):
        if not context:
            context = self

        constrains = IConstrainTypes(context, None)
        if not constrains:
            return super(Container, self).allowedContentTypes()

        return constrains.allowedContentTypes()
Exemplo n.º 5
0
    def invokeFactory(self, type_name, id, RESPONSE=None, *args, **kw):
        """Invokes the portal_types tool
        """
        constrains = IConstrainTypes(self, None)

        if constrains and not type_name in [fti.getId() for fti in constrains.allowedContentTypes()]:
            raise ValueError('Subobject type disallowed by IConstrainTypes adapter: %s' % type_name)

        return super(Container, self).invokeFactory(type_name, id, RESPONSE, *args, **kw)
Exemplo n.º 6
0
    def invokeFactory(self, type_name, id, RESPONSE=None, *args, **kw):
        """Invokes the portal_types tool
        """
        constrains = IConstrainTypes(self, None)

        if constrains and not type_name in [fti.getId() for fti in constrains.allowedContentTypes()]:
            raise ValueError('Subobject type disallowed by IConstrainTypes adapter: %s' % type_name)

        return super(Container, self).invokeFactory(type_name, id, RESPONSE, *args, **kw)
Exemplo n.º 7
0
    def __call__(self, expand=False):
        result = {"types": {"@id": f"{self.context.absolute_url()}/@types"}}
        if not expand:
            return result

        check_security(self.context)

        vocab_factory = getUtility(
            IVocabularyFactory,
            name="plone.app.vocabularies.ReallyUserFriendlyTypes")

        portal_types = getToolByName(self.context, "portal_types")
        # allowedContentTypes already checks for permissions
        constrains = IConstrainTypes(self.context, None)
        if constrains:
            allowed_types = constrains.getLocallyAllowedTypes()
            immediately_types = constrains.getImmediatelyAddableTypes()
        else:
            allowed_types = [
                x.getId() for x in self.context.allowedContentTypes()
            ]
            immediately_types = allowed_types

        portal = getMultiAdapter((self.context, self.request),
                                 name="plone_portal_state").portal()
        portal_url = portal.absolute_url()

        # only addables if the content type is folderish
        can_add = IFolderish.providedBy(self.context)

        # Filter out any type that doesn't have lookupSchema. We are depended
        # on that in lower level code.
        ftis = [portal_types[x.value] for x in vocab_factory(self.context)]
        ftis = [fti for fti in ftis if getattr(fti, "lookupSchema", None)]

        result["types"] = [{
            "@id":
            f"{portal_url}/@types/{fti.getId()}",
            "title":
            translate(fti.Title(), context=self.request),
            "addable":
            fti.getId() in allowed_types if can_add else False,
            "immediately_addable":
            fti.getId() in immediately_types if can_add else False,
        } for fti in ftis]

        return result
def get_allowed_types(context):
    context = getContext(context)

    if IConstrainTypes.providedBy(context):
        types = IConstrainTypes(context).getImmediatelyAddableTypes()
    else:
        types = context.allowedContentTypes()
    return types
Exemplo n.º 9
0
    def invokeFactory(self, type_name, id, RESPONSE=None, *args, **kw):
        # Invokes the portal_types tool.
        constrains = IConstrainTypes(self, None)

        if constrains:
            # Do permission check before constrain checking so we'll get
            # an Unauthorized over a ValueError.
            fti = queryUtility(ITypeInformation, name=type_name)
            if fti is not None and not fti.isConstructionAllowed(self):
                raise Unauthorized('Cannot create %s' % fti.getId())

            allowed_ids = [i.getId() for i in constrains.allowedContentTypes()]
            if type_name not in allowed_ids:
                raise ValueError(
                    'Subobject type disallowed by IConstrainTypes adapter: %s'
                    % type_name)

        return super(Container, self).invokeFactory(type_name, id, RESPONSE,
                                                    *args, **kw)
Exemplo n.º 10
0
    def invokeFactory(self, type_name, id, RESPONSE=None, *args, **kw):
        # Invokes the portal_types tool.
        constrains = IConstrainTypes(self, None)

        if constrains:
            # Do permission check before constrain checking so we'll get
            # an Unauthorized over a ValueError.
            fti = queryUtility(ITypeInformation, name=type_name)
            if fti is not None and not fti.isConstructionAllowed(self):
                raise Unauthorized('Cannot create %s' % fti.getId())

            allowed_ids = [i.getId() for i in constrains.allowedContentTypes()]
            if type_name not in allowed_ids:
                raise ValueError(
                    'Subobject type disallowed by IConstrainTypes adapter: %s'
                    % type_name
                )

        return super(Container, self).invokeFactory(
            type_name, id, RESPONSE, *args, **kw
        )
Exemplo n.º 11
0
def get_locally_allowed_types(brain_or_object):
    """Checks if the passed in object is folderish

    :param brain_or_object: A single catalog brain or content object
    :type brain_or_object: ATContentType/DexterityContentType/CatalogBrain
    :returns: A list of locally allowed content types
    :rtype: list
    """
    if not is_folderish(brain_or_object):
        return []
    # ensure we have an object
    obj = get_object(brain_or_object)
    method = getattr(obj, "getLocallyAllowedTypes", None)
    if method is None:
        constrains = IConstrainTypes(obj, None)
        if constrains:
            method = constrains.getLocallyAllowedTypes
    if not callable(method):
        return []
    return method()