Esempio n. 1
0
    def __init__(self, id=None, **kwargs):
        OFSContainer.__init__(self, id, **kwargs)
        PortalFolderBase.__init__(self, id, **kwargs)
        DefaultDublinCoreImpl.__init__(self, **kwargs)

        if id is not None:
            self.id = id
Esempio n. 2
0
    def getImmediatelyAddableTypes(self, context=None):
        """Get the list of type ids which should be immediately addable.
        If enableTypeRestrictions is ENABLE, return the list set; if it is
        ACQUIRE, use the value from the parent; if it is DISABLE, return
        all type ids allowable on the item.
        """
        if context is None:
            context = self
        mode = self.getConstrainTypesMode()

        if mode == DISABLED:
            return [fti.getId() for fti in \
                        self.getDefaultAddableTypes(context)]
        elif mode == ENABLED:
            return self.getField('immediatelyAddableTypes').get(self)
        elif mode == ACQUIRE:
            parent = getParent(self)
            if not parent or parent.portal_type == 'Plone Site':
                return [fti.getId() for fti in \
                        PortalFolder.allowedContentTypes(self)]
            elif not parentPortalTypeEqual(self):
                default_allowed = [fti.getId() for fti in \
                        PortalFolder.allowedContentTypes(self)]
                return [t for t in parent.getImmediatelyAddableTypes(context) \
                           if t in default_allowed]
            else:
                parent = aq_parent(aq_inner(self))
                return parent.getImmediatelyAddableTypes(context)
        else:
            raise ValueError, "Invalid value for enableAddRestriction"
Esempio n. 3
0
    def __call__(self, context):
        # catch some bad contexts (such as KSS validator)
        try:
            context.portal_type
        except AttributeError:
            return []

        # get default allowed types, but not the allowed types directly from
        # the context because they may already be filtered.
        if not isinstance(context, PortalFolderBase):
            return []
        types = PortalFolderBase.allowedContentTypes(context)

        # find the dexterity FTIs using the IRestrictedDossier behavior
        restricted_types = filter(
            lambda fti: getattr(fti, 'behaviors', []) and
                self.marker_behavior in fti.behaviors, types)

        # create the terms
        terms = []
        for fti in restricted_types:
            title = translate(fti.title,
                              domain=fti.i18n_domain,
                              context=context.REQUEST)
            terms.append(SimpleVocabulary.createTerm(
                    fti.id, fti.id, title))

        # create the vocabulary
        return SimpleVocabulary(terms)
Esempio n. 4
0
    def allowedContentTypes(self, context=None):
        """returns constrained allowed types as list of fti's
        """
        if context is None:
            context = self
        mode = self.getConstrainTypesMode()

        # Short circuit if we are disabled or acquiring from non-compatible
        # parent

        parent = getParent(self)
        if mode == DISABLED or (mode == ACQUIRE and not parent):
            return PortalFolder.allowedContentTypes(self)
        elif mode == ACQUIRE and not parentPortalTypeEqual(self):
            globalTypes = self.getDefaultAddableTypes(context)
            if parent.portal_type == 'Plone Site':
                return globalTypes
            else:
                allowed = list(parent.getLocallyAllowedTypes(context))
                return [fti for fti in globalTypes if fti.getId() in allowed]
        else:
            globalTypes = self.getDefaultAddableTypes(context)
            allowed = list(self.getLocallyAllowedTypes())
            ftis = [fti for fti in globalTypes if fti.getId() in allowed]
            return ftis
def allowedContentTypes(self, context=None):
    """
    returns constrained allowed types as list of fti's.
    There is a try/except for handle AT folders inside DX containers
    """
    if context is None:
        context = self
    mode = self.getConstrainTypesMode()

    # Short circuit if we are disabled or acquiring from non-compatible
    # parent

    parent = getParent(self)
    if mode == DISABLED or (mode == ACQUIRE and not parent):
        return PortalFolder.allowedContentTypes(self)
    elif mode == ACQUIRE and not parentPortalTypeEqual(self):
        globalTypes = self.getDefaultAddableTypes(context)
        if parent.portal_type == 'Plone Site':
            return globalTypes
        else:
            try:
                allowed = list(parent.getLocallyAllowedTypes(context))
            except AttributeError:
                # parent is a DX content?
                behavior = ISelectableConstrainTypes(parent)
                if not behavior:
                    # return context addable types
                    return get_context_ftis(self)
                allowed = behavior.getLocallyAllowedTypes(context)
            return [fti for fti in globalTypes if fti.getId() in allowed]
    else:
        return get_context_ftis(self)
def getImmediatelyAddableTypes(self, context=None):
    """Get the list of type ids which should be immediately addable.
    If enableTypeRestrictions is ENABLE, return the list set; if it is
    ACQUIRE, use the value from the parent; if it is DISABLE, return
    all type ids allowable on the item.
    There is a try/except for handle AT folders inside DX containers
    """
    if context is None:
        context = self
    mode = self.getConstrainTypesMode()

    if mode == DISABLED:
        return [fti.getId() for fti in self.getDefaultAddableTypes(context)]
    elif mode == ENABLED:
        return self.getField('immediatelyAddableTypes').get(self)
    elif mode == ACQUIRE:
        parent = getParent(self)
        if not parent or parent.portal_type == 'Plone Site':
            return [fti.getId() for fti in
                    PortalFolder.allowedContentTypes(self)]
        elif not parentPortalTypeEqual(self):
            default_allowed = [fti.getId() for fti in
                               PortalFolder.allowedContentTypes(self)]
            try:
                immediately_addable = parent.getImmediatelyAddableTypes(context)
            except AttributeError:
                # parent is a DX content?
                behavior = ISelectableConstrainTypes(parent)
                if not behavior:
                    # return context default addable types
                    immediately_addable = self.getField('immediatelyAddableTypes').get(self)
                immediately_addable = behavior.getImmediatelyAddableTypes(context)
            return [t for t in immediately_addable if t in default_allowed]
        else:
            parent = aq_parent(aq_inner(self))
            try:
                return parent.getImmediatelyAddableTypes(context)
            except AttributeError:
                # parent is a DX content?
                behavior = ISelectableConstrainTypes(parent)
                if not behavior:
                    # return context default addable types
                    return self.getField('immediatelyAddableTypes').get(self)
                return behavior.getImmediatelyAddableTypes(context)
    else:
        raise ValueError, "Invalid value for enableAddRestriction"
Esempio n. 7
0
    def listFolderContents(self, contentFilter=None, suppressHiddenFiles=0):
        # Optionally you can suppress "hidden" files, or files that begin
        # with a dot.
        contents = PortalFolder.listFolderContents(self, contentFilter=contentFilter)
        if suppressHiddenFiles:
            contents = [obj for obj in contents if obj.getId()[:1] != '.']

        return contents
Esempio n. 8
0
 def getSyndicatableContent(self, obj):
     """
     An interface for allowing folderish items to implement an
     equivalent of PortalFolderBase.contentValues()
     """
     if hasattr(obj, 'synContentValues'):
         values = obj.synContentValues()
     else:
         values = PortalFolderBase.contentValues(obj)
     return values
Esempio n. 9
0
def _checkId(self, id, allow_dup=0):
        PortalFolderBase.inheritedAttribute('_checkId')(self, id, allow_dup)

        if allow_dup:
            return

        # FIXME: needed to allow index_html for join code
        if id == 'index_html':
            return

        # Another exception: Must allow "syndication_information" to enable
        # Syndication...
        if id == 'syndication_information':
            return

        # IDs starting with '@@' are reserved for views.
        if id[:2] == '@@':
            raise BadRequest('The id "%s" is invalid because it begins with '
                             '"@@".' % id)
Esempio n. 10
0
 def manage_delObjects(self, ids=[], REQUEST=None):
     """We need to enforce security."""
     if isinstance(ids, basestring):
         ids = [ids]
     for id in ids:
         item = self._getOb(id)
         if not _checkPermission(permissions.DeleteObjects, item):
             raise Unauthorized, (
                 "Do not have permissions to remove this object")
     return PortalFolder.manage_delObjects(self, ids, REQUEST=REQUEST)
Esempio n. 11
0
    def __getitem__(self, key):
        """Overwrite __getitem__.

        At first it's using the BaseObject version. If the element can't be
        retrieved from the schema it's using PortalFolder as fallback which
        should be the ObjectManager's version.
        """
        try:
            return BaseObject.__getitem__(self, key)
        except KeyError:
            return PortalFolder.__getitem__(self, key)
Esempio n. 12
0
    def contentValues(self, filter=None, sort_on=None, reverse=0):
        # Able to sort on field.
        values = PortalFolderBase.contentValues(self, filter=filter)
        if sort_on is not None:
            values.sort(lambda x, y,
                        sort_on=sort_on: safe_cmp(getattr(x, sort_on),
                                                  getattr(y, sort_on)))
        if reverse:
            values.reverse()

        return values
Esempio n. 13
0
 def manage_delObjects(self, ids=[], REQUEST=None):
     """We need to enforce security."""
     mt = getToolByName(self, 'portal_membership')
     if type(ids) is StringType:
         ids = [ids]
     for id in ids:
         item = self._getOb(id)
         if not mt.checkPermission(Permissions.delete_objects, item):
             raise Unauthorized, (
                 "Do not have permissions to remove this object")
     return PortalFolderBase.manage_delObjects(self, ids, REQUEST=REQUEST)
Esempio n. 14
0
 def _verifyObjectPaste(self, object, validate_src=1):
     """Overrides PortalFolder._verifyObjectPaste."""
     # What we do here is trick PortalFolder._verifyObjectPaste in its check
     # for allowed content types. We make our typeinfo temporarily
     # unavailable.
     pt = getToolByName(self, 'portal_types')
     tmp_name = '%s_TMP' % self.portal_type
     ti = pt.getTypeInfo(self.portal_type)
     pt.manage_delObjects([self.portal_type])
     value = PortalFolderBase._verifyObjectPaste(self, object, validate_src)
     pt._setObject(self.portal_type, ti)
     return value
def manage_delObjects(self, ids=None, REQUEST=None):
    """We need to enforce security."""
    sm = getSecurityManager()
    if not sm.checkPermission('Delete objects', self):
        raise Unauthorized(
            "Do not have permissions to remove this object")

    if ids is None:
        ids = []
    if isinstance(ids, basestring):
        ids = [ids]
    for id_ in ids:
        item = self._getOb(id_)
        if not sm.checkPermission("Delete portal content", item):
            raise Unauthorized(
                "Do not have permissions to remove this object")
    return PortalFolder.manage_delObjects(self, ids, REQUEST=REQUEST)
Esempio n. 16
0
    def invokeFactory(self, type_name, id, RESPONSE=None, *args, **kw):
        """Invokes the portal_types tool
        """
        mode = self.getConstrainTypesMode()

        # Short circuit if we are disabled or acquiring from non-compatible
        # parent

        # if mode == DISABLED or \
        #        (parent and parent.portal_types != self.portal_types):
        if mode == DISABLED or (mode == ACQUIRE and not parentPortalTypeEqual(self)):
            return PortalFolder.invokeFactory(self, type_name, id, RESPONSE=None, *args, **kw)

        if not type_name in [fti.getId() for fti in self.allowedContentTypes()]:
            raise Unauthorized("Disallowed subobject type: %s" % type_name)

        pt = getToolByName(self, "portal_types")
        args = (type_name, self, id, RESPONSE) + args
        return pt.constructContent(*args, **kw)
Esempio n. 17
0
    def _catalogRefs(self, aq, uc=None, rc=None):
        ruleset.RLMWithBrains._catalogRefs(self,aq,uc,rc)
        
        # Use the PortalFolderBase implementation to avoid the false
        # result from a bogus inheritence of SimpleItem
        names = PortalFolderBase.objectIds(self)
        
        for name in names:
            if not shasattr(self, name):
                break

            obj=getattr(self,name)
            if obj:
                #import pdb;pdb.set_trace()
                if not uc:
                    uc = getToolByName(aq, config.UID_CATALOG)
                if not rc:
                    rc = getToolByName(aq, config.REFERENCE_CATALOG)
    
                url = getRelURL(uc, obj.getPhysicalPath())
                uc.catalog_object(obj, url)
                #rc.catalog_object(obj, url)
                
                obj._catalogRefs(uc, uc, rc)
Esempio n. 18
0
 def __init__(self, oid, **kwargs):
     # Call skinned first cause baseobject will set new defaults on
     # those attributes anyway
     PortalFolder.__init__(self, oid, self.Title())
     BaseObject.__init__(self, oid, **kwargs)
def manage_delObjects(self, ids=None, REQUEST=None):
    """We need to enforce security."""
    protect_del_objects(self, ids)
    return PortalFolder.manage_delObjects(self, ids, REQUEST=REQUEST)
Esempio n. 20
0
 def __init__(self, id, title=''):
     PortalFolderBase.__init__(self, id, title)
     BTreeFolder2Base.__init__(self, id)
Esempio n. 21
0
 def __init__(self, oid, **kwargs):
     # Call skinned first cause baseobject will set new defaults on
     # those attributes anyway
     PortalFolder.__init__(self, oid, self.Title())
     BaseObject.__init__(self, oid, **kwargs)
Esempio n. 22
0
 def _checkId(self, id, allow_dup=0):
     PortalFolderBase._checkId(self, id, allow_dup)
     BTreeFolder2Base._checkId(self, id, allow_dup)
def manage_delObjects(self, ids=None, REQUEST=None):
    """We need to enforce security."""
    protect_del_objects(self, ids)
    return PortalFolder.manage_delObjects(self, ids, REQUEST=REQUEST)
Esempio n. 24
0
 def __init__(self, id, title=''):
     PortalFolderBase.__init__(self, id, title)
     BTreeFolder2Base.__init__(self, id)
Esempio n. 25
0
 def _checkId(self, id, allow_dup=0):
     PortalFolderBase._checkId(self, id, allow_dup)
     BTreeFolder2Base._checkId(self, id, allow_dup)
Esempio n. 26
0
 def __init__(self, id=None, **kwargs):
     PortalFolderBase.__init__(self, id)
     BTreeFolder2Base.__init__(self, id)
     DexterityContent.__init__(self, id, **kwargs)
Esempio n. 27
0
 def allowedContentTypes(self):
     # Make sure PlominoDocument is hidden in Plone "Add..." menu
     # as getNotAddableTypes is not used anymore in Plone 4
     filterOut = ['PlominoDocument']
     types = PortalFolder.allowedContentTypes(self)
     return [ctype for ctype in types if ctype.getId() not in filterOut]
Esempio n. 28
0
 def allowedContentTypes(self):
     # Make sure PlominoDocument is hidden in Plone "Add..." menu
     filterOut = ['PlominoDocument']
     types = PortalFolder.allowedContentTypes(self)
     return [ctype for ctype in types if ctype.getId() not in filterOut]