예제 #1
0
파일: test_rolemap.py 프로젝트: dtgit/dtedu
    def test_unacquired_permission_skip_purge( self ):

        ACI = 'Access contents information'
        VIEW = 'View'

        self.app.site = Folder(id='site')
        site = self.app.site
        site.manage_permission( VIEW, () )

        existing_allowed = [ x[ 'name' ]
                                for x in site.rolesOfPermission( ACI )
                                if x[ 'selected' ] ]

        self.assertEqual( existing_allowed, [ 'Manager' ] )

        self.failUnless( site.acquiredRolesAreUsedBy( ACI ) )
        self.failIf( site.acquiredRolesAreUsedBy( VIEW ) )

        context = DummyImportContext( site, False )
        context._files[ 'rolemap.xml' ] = _UNACQUIRED_EXPORT

        from Products.GenericSetup.rolemap import importRolemap
        importRolemap( context )

        new_allowed = [ x[ 'name' ]
                           for x in site.rolesOfPermission( ACI )
                           if x[ 'selected' ] ]

        self.assertEqual( new_allowed, [ 'Manager', 'Owner' ] )

        self.failIf( site.acquiredRolesAreUsedBy( ACI ) )
        self.failIf( site.acquiredRolesAreUsedBy( VIEW ) )
예제 #2
0
    def test_unacquired_permission_skip_purge(self):

        ACI = 'Access contents information'
        VIEW = 'View'

        self.app.site = Folder(id='site')
        site = self.app.site
        site.manage_permission(VIEW, ())

        existing_allowed = [
            x['name'] for x in site.rolesOfPermission(ACI) if x['selected']
        ]

        self.assertEqual(existing_allowed, ['Manager'])

        self.failUnless(site.acquiredRolesAreUsedBy(ACI))
        self.failIf(site.acquiredRolesAreUsedBy(VIEW))

        context = DummyImportContext(site, False)
        context._files['rolemap.xml'] = _UNACQUIRED_EXPORT

        from Products.GenericSetup.rolemap import importRolemap
        importRolemap(context)

        new_allowed = [
            x['name'] for x in site.rolesOfPermission(ACI) if x['selected']
        ]

        self.assertEqual(new_allowed, ['Manager', 'Owner'])

        self.failIf(site.acquiredRolesAreUsedBy(ACI))
        self.failIf(site.acquiredRolesAreUsedBy(VIEW))
    def test_acquired_permission_explicit_purge(self):

        ACI = 'Access contents information'
        VIEW = 'View'

        self.app.site = Folder(id='site')
        site = self.app.site
        site.manage_permission(ACI, ())
        site.manage_permission(VIEW, ())

        existing_allowed = [x['name']
                            for x in site.rolesOfPermission(ACI)
                            if x['selected']]

        self.assertEqual(existing_allowed, [])

        self.assertFalse(site.acquiredRolesAreUsedBy(ACI))
        self.assertFalse(site.acquiredRolesAreUsedBy(VIEW))

        context = DummyImportContext(site, True)
        context._files['rolemap.xml'] = _ACQUIRED_EXPORT

        from Products.GenericSetup.rolemap import importRolemap
        importRolemap(context)

        new_allowed = [x['name']
                       for x in site.rolesOfPermission(ACI)
                       if x['selected']]

        self.assertEqual(new_allowed, ['Manager', 'Owner'])

        # ACI is overwritten by XML, but VIEW was purged
        self.assertTrue(site.acquiredRolesAreUsedBy(ACI))
        self.assertTrue(site.acquiredRolesAreUsedBy(VIEW))
예제 #4
0
    def test_empty_skip_purge(self):

        self.app.site = Folder(id='site')
        site = self.app.site
        original_roles = list(getattr(site, '__ac_roles__', []))[:]
        modified_roles = original_roles[:]
        modified_roles.append('ZZZ')
        site.__ac_roles__ = modified_roles

        context = DummyImportContext(site, False)
        context._files['rolemap.xml'] = _EMPTY_EXPORT

        from Products.GenericSetup.rolemap import importRolemap
        importRolemap(context)

        new_roles = list(getattr(site, '__ac_roles__', []))[:]

        modified_roles.sort()
        new_roles.sort()

        self.assertEqual(modified_roles, new_roles)
예제 #5
0
파일: test_rolemap.py 프로젝트: dtgit/dtedu
    def test_empty_skip_purge( self ):

        self.app.site = Folder(id='site')
        site = self.app.site
        original_roles = list( getattr( site, '__ac_roles__', [] ) )[:]
        modified_roles = original_roles[:]
        modified_roles.append( 'ZZZ' )
        site.__ac_roles__ = modified_roles

        context = DummyImportContext( site, False )
        context._files[ 'rolemap.xml' ] = _EMPTY_EXPORT

        from Products.GenericSetup.rolemap import importRolemap
        importRolemap( context )

        new_roles = list( getattr( site, '__ac_roles__', [] ) )[:]

        modified_roles.sort()
        new_roles.sort()

        self.assertEqual( modified_roles, new_roles )
예제 #6
0
    def test_existing_roles_missing_xml_doesnt_purge(self):
        # LP # 279294
        ACI = 'Access contents information'
        VIEW = 'View'

        self.app.site = Folder(id='site')
        site = self.app.site  # wrap
        original_roles = list(getattr(site, '__ac_roles__', []))[:]
        modified_roles = original_roles[:]
        modified_roles.append('ZZZ')

        site.__ac_roles__ = modified_roles
        site.manage_permission(VIEW, ())
        site.manage_permission(ACI, ('Manager', 'ZZZ'))

        existing_allowed = [
            x['name'] for x in site.rolesOfPermission(ACI) if x['selected']
        ]

        self.assertEqual(existing_allowed, ['Manager', 'ZZZ'])

        context = DummyImportContext(site, True)
        #context._files[ 'rolemap.xml' ] = _EMPTY_EXPORT # no file!

        from Products.GenericSetup.rolemap import importRolemap
        importRolemap(context)

        new_roles = list(getattr(site, '__ac_roles__', []))[:]

        modified_roles.sort()
        new_roles.sort()

        self.assertEqual(modified_roles, new_roles)

        new_allowed = [
            x['name'] for x in site.rolesOfPermission(ACI) if x['selected']
        ]

        self.assertEqual(new_allowed, existing_allowed)
    def test_existing_roles_missing_xml_doesnt_purge(self):
        # LP # 279294
        ACI = 'Access contents information'
        VIEW = 'View'

        self.app.site = Folder(id='site')
        site = self.app.site # wrap
        original_roles = list(getattr(site, '__ac_roles__', []))[:]
        modified_roles = original_roles[:]
        modified_roles.append('ZZZ')

        site.__ac_roles__ = modified_roles
        site.manage_permission(VIEW, ())
        site.manage_permission(ACI, ('Manager', 'ZZZ'))

        existing_allowed = [x['name'] for x in site.rolesOfPermission(ACI)
                                if x['selected']]

        self.assertEqual(existing_allowed, ['Manager', 'ZZZ'])

        context = DummyImportContext(site, True)
        #context._files[ 'rolemap.xml' ] = _EMPTY_EXPORT # no file!

        from Products.GenericSetup.rolemap import importRolemap
        importRolemap(context)

        new_roles = list(getattr(site, '__ac_roles__', []))[:]

        modified_roles.sort()
        new_roles.sort()

        self.assertEqual(modified_roles, new_roles)

        new_allowed = [x['name'] for x in site.rolesOfPermission(ACI)
                                if x['selected']]

        self.assertEqual(new_allowed, existing_allowed)
예제 #8
0
    def test_unacquired_permission_added_role_skip_purge_encode_ascii( self ):

        ACI = 'Access contents information'
        VIEW = 'View'

        self.root.site = Folder( id='site' )
        site = self.root.site
        site.manage_permission( VIEW, () )

        existing_allowed = [ x[ 'name' ]
                                for x in site.rolesOfPermission( ACI )
                                if x[ 'selected' ] ]

        self.assertEqual( existing_allowed, [ 'Manager' ] )

        self.failUnless( site.acquiredRolesAreUsedBy( ACI ) )
        self.failIf( site.acquiredRolesAreUsedBy( VIEW ) )

        self.failIf( site._has_user_defined_role( 'ZZZ' ) )

        context = DummyImportContext( site, False, encoding='ascii' )
        context._files[ 'rolemap.xml' ] = _COMBINED_EXPORT

        from Products.GenericSetup.rolemap import importRolemap
        importRolemap( context )

        self.failUnless( site._has_user_defined_role( 'ZZZ' ) )

        new_allowed = [ x[ 'name' ]
                           for x in site.rolesOfPermission( ACI )
                           if x[ 'selected' ] ]

        self.assertEqual( new_allowed, [ 'Manager', 'Owner', 'ZZZ' ] )

        self.failIf( site.acquiredRolesAreUsedBy( ACI ) )
        self.failIf( site.acquiredRolesAreUsedBy( VIEW ) )
예제 #9
0
    def test_unacquired_permission_added_role_skip_purge_encode_ascii(self):

        ACI = 'Access contents information'
        VIEW = 'View'

        self.root.site = Folder(id='site')
        site = self.root.site
        site.manage_permission(VIEW, ())

        existing_allowed = [
            x['name'] for x in site.rolesOfPermission(ACI) if x['selected']
        ]

        self.assertEqual(existing_allowed, ['Manager'])

        self.failUnless(site.acquiredRolesAreUsedBy(ACI))
        self.failIf(site.acquiredRolesAreUsedBy(VIEW))

        self.failIf(site._has_user_defined_role('ZZZ'))

        context = DummyImportContext(site, False, encoding='ascii')
        context._files['rolemap.xml'] = _COMBINED_EXPORT

        from Products.GenericSetup.rolemap import importRolemap
        importRolemap(context)

        self.failUnless(site._has_user_defined_role('ZZZ'))

        new_allowed = [
            x['name'] for x in site.rolesOfPermission(ACI) if x['selected']
        ]

        self.assertEqual(new_allowed, ['Manager', 'Owner', 'ZZZ'])

        self.failIf(site.acquiredRolesAreUsedBy(ACI))
        self.failIf(site.acquiredRolesAreUsedBy(VIEW))