Exemple #1
0
    def test_data_setter(self):
        folder = create(Builder('folder').titled(u'The Folder'))

        adapter = getAdapter(folder,
                             IDataCollector,
                             name='constrain_types_adapter')
        allowed_types = ['Collection', 'Document', 'Folder']
        immediately_addable_types = ['Collection', 'Folder']

        # Test when mode = 'ENABLED'
        adapter.setData(
            {
                'mode': ENABLED,
                'locally_allowed': allowed_types,
                'immediately_addable': immediately_addable_types
            },
            metadata=None)

        constrain_types = IConstrainTypes(folder)
        self.assertEquals(ENABLED, constrain_types.getConstrainTypesMode())
        self.assertEquals(allowed_types,
                          constrain_types.getLocallyAllowedTypes())
        self.assertEquals(immediately_addable_types,
                          constrain_types.getImmediatelyAddableTypes())

        # Test when mode = 'DISABLED'
        # Results of getLocallyAllowedTypes() and getImmediatelyAddableTypes()
        # are determined by the portal type
        adapter.setData(
            {
                'mode': DISABLED,
                'locally_allowed': allowed_types,
                'immediately_addable': immediately_addable_types
            },
            metadata=None)
        constrain_types = IConstrainTypes(folder)
        self.assertEquals(DISABLED, constrain_types.getConstrainTypesMode())
        self.assertEquals(self.standard_types,
                          constrain_types.getLocallyAllowedTypes())
        self.assertEquals(self.standard_types,
                          constrain_types.getImmediatelyAddableTypes())

        # Test when mode = 'ACQUIRE'
        # Results of getLocallyAllowedTypes() and getImmediatelyAddableTypes()
        # are determined by the parent object
        adapter.setData(
            {
                'mode': ACQUIRE,
                'locally_allowed': allowed_types,
                'immediately_addable': immediately_addable_types
            },
            metadata=None)
        constrain_types = IConstrainTypes(folder)
        self.assertEquals(ACQUIRE, constrain_types.getConstrainTypesMode())
        self.assertEquals(self.standard_types,
                          constrain_types.getLocallyAllowedTypes())
        self.assertEquals(self.standard_types,
                          constrain_types.getImmediatelyAddableTypes())
Exemple #2
0
 def get_constraintypes_config(self, obj):
     ctypes = IConstrainTypes(obj)
     return {
         'mode': ctypes.getConstrainTypesMode(),
         'locally allowed': set(ctypes.getLocallyAllowedTypes()),
         'immediately addable': set(ctypes.getImmediatelyAddableTypes())
     }
Exemple #3
0
 def _addableTypesInContext(self, addContext):
     allowed_types = _allowedTypes(self.request, addContext)
     constrain = IConstrainTypes(addContext, None)
     if constrain is None:
         return allowed_types
     locallyAllowed = constrain.getLocallyAllowedTypes()
     return [fti for fti in allowed_types if fti.getId() in locallyAllowed]
 def _addableTypesInContext(self, addContext):
     allowed_types = _allowedTypes(self.request, addContext)
     constrain = IConstrainTypes(addContext, None)
     if constrain is None:
         return allowed_types
     locallyAllowed = constrain.getLocallyAllowedTypes()
     return [fti for fti in allowed_types if fti.getId() in locallyAllowed]
Exemple #5
0
 def _contentCanBeAdded(self, addContext, request):
     """Find out if content can be added either by local constraints on the
     context or by allowed_content_types on the FTI.
     """
     constrain = IConstrainTypes(addContext, None)
     if constrain is None:
         return _allowedTypes(request, addContext)
     return constrain.getLocallyAllowedTypes()
Exemple #6
0
 def _contentCanBeAdded(self, addContext, request):
     """Find out if content can be added either by local constraints on the
     context or by allowed_content_types on the FTI.
     """
     constrain = IConstrainTypes(addContext, None)
     if constrain is None:
         return _allowedTypes(request, addContext)
     return constrain.getLocallyAllowedTypes()
Exemple #7
0
    def _locallyAllowedTypes(self, addContext):
        addContext = addContext or self.context

        allowed_types = _allowedTypes(self.request, addContext)
        constrain = IConstrainTypes(addContext, None)
        if constrain is None:
            return allowed_types
        locallyAllowed = constrain.getLocallyAllowedTypes()
        # logger.info("locallyAllowed: {}".format(locallyAllowed))
        return locallyAllowed
Exemple #8
0
    def test_list_constrain(self):
        with self.user('admin'):
            lst = api.content.create(
                id='test',
                type='seantis.people.list',
                container=self.new_temporary_folder()
            )
            constrain = IConstrainTypes(lst)

            new_type = self.new_temporary_type(
                behaviors=[IPerson.__identifier__],
                klass='seantis.people.types.base.PersonBase'
            )

            self.assertIs(type(constrain), ListConstrainTypes)
            self.assertEqual(constrain.getConstrainTypesMode(), ENABLED)
            self.assertEqual(constrain.allowedContentTypes(), [new_type])
            self.assertEqual(constrain.getLocallyAllowedTypes(), [new_type.id])
            self.assertEqual(
                constrain.getImmediatelyAddableTypes(), [new_type.id]
            )
Exemple #9
0
 def get_constraintypes_config(self, obj):
     ctypes = IConstrainTypes(obj)
     return {'mode': ctypes.getConstrainTypesMode(),
             'locally allowed': set(ctypes.getLocallyAllowedTypes()),
             'immediately addable': set(
                 ctypes.getImmediatelyAddableTypes())}