Пример #1
1
    def __call__(self, *args):
        site = getObject(self.context)
        try:
            sm = site.getSiteManager()
        except:
            site.setSiteManager(LocalSiteManager(site, False))
            sm = site.getSiteManager()

        if u'intids' not in sm:
            ob = IntIds()
            notify(ObjectCreatedEvent(ob))
            sm[u'intids'] = ob
            sm.registerUtility(ob, IIntIds)
Пример #2
0
    def test__call__w_ILocation_w_spacesuit_w_existing_parent(self):
        from zope.security.proxy import getObject
        from zope.security.proxy import ProxyFactory
        from zope.security.proxy import removeSecurityProxy
        factory = self._makeFactory()
        factory.__name__ = None
        factory.__parent__ = parent = object()
        directlyProvides(factory, ILocation)
        ltaf = self._makeOne(factory)

        class _Adapter(object):
            pass

        adapter = _Adapter()
        proxy = ProxyFactory(adapter)
        before = {
            k: v
            for k, v in factory.__dict__.items()
            if k not in ('_called_with', '__parent__')
        }
        returned = ltaf(proxy)
        self.assertFalse(returned is factory)
        ploc = removeSecurityProxy(returned)
        self.assertIs(ploc.__parent__, parent)
        unwrapped = getObject(ploc)
        self.assertIs(unwrapped, factory)
        after = {
            k: v
            for k, v in unwrapped.__dict__.items()
            if k not in ('_called_with', '__parent__')
        }
        self.assertEqual(factory._called_with, (adapter, ))
        self.assertEqual(after, before)  # no added attrs
Пример #3
0
 def test__call__w_ILocation_w_spacesuit_w_existing_parent(self):
     from zope.interface import directlyProvides
     from zope.location import ILocation
     from zope.security.proxy import getObject
     from zope.security.proxy import ProxyFactory
     from zope.security.proxy import removeSecurityProxy
     factory = self._makeFactory()
     factory.__name__ = None
     factory.__parent__ = parent = object()
     directlyProvides(factory, ILocation)
     ltaf = self._makeOne(factory)
     class _Adapter(object):
         pass
     adapter = _Adapter()
     proxy = ProxyFactory(adapter)
     before = dict([(k, v) for k, v in factory.__dict__.items()
                      if k not in ('_called_with', '__parent__')])
     returned = ltaf(proxy)
     self.assertFalse(returned is factory)
     ploc = removeSecurityProxy(returned)
     self.assertTrue(ploc.__parent__ is parent)
     unwrapped = getObject(ploc)
     self.assertTrue(unwrapped is factory)
     after = dict([(k, v) for k, v in unwrapped.__dict__.items()
                      if k not in ('_called_with', '__parent__')])
     self.assertEqual(factory._called_with, (adapter,))
     self.assertEqual(after, before) # no added attrs
Пример #4
0
 def test__call__w_ILocation_w_spacesuit(self):
     from zope.interface import directlyProvides
     from zope.location import ILocation
     from zope.security.proxy import getObject
     from zope.security.proxy import ProxyFactory
     from zope.security.proxy import removeSecurityProxy
     factory = self._makeFactory()
     factory.__parent__ = factory.__name__ = None
     directlyProvides(factory, ILocation)
     ltaf = self._makeOne(factory)
     class _Adapter(object):
         pass
     adapter = _Adapter()
     proxy = ProxyFactory(adapter)
     before = dict([(k, v) for k, v in factory.__dict__.items()
                      if k not in ('_called_with', '__parent__')])
     returned = ltaf(proxy)
     self.assertFalse(returned is factory)
     ploc = removeSecurityProxy(returned)
     self.assertTrue(ploc.__parent__ is adapter)
     unwrapped = getObject(ploc)
     self.assertTrue(unwrapped is factory)
     after = dict([(k, v) for k, v in unwrapped.__dict__.items()
                      if k not in ('_called_with', '__parent__')])
     self.assertEqual(factory._called_with, (adapter,))
     self.assertTrue(factory.__parent__ is adapter)
     self.assertEqual(after, before) # no added attrs
Пример #5
0
 def test__call__w_ILocation_w_spacesuit(self):
     from zope.security.proxy import getObject
     from zope.security.proxy import ProxyFactory
     from zope.security.proxy import removeSecurityProxy
     factory = self._makeFactory()
     factory.__parent__ = factory.__name__ = None
     directlyProvides(factory, ILocation)
     ltaf = self._makeOne(factory)
     class _Adapter(object):
         pass
     adapter = _Adapter()
     proxy = ProxyFactory(adapter)
     before = {k: v for k, v in factory.__dict__.items()
               if k not in ('_called_with', '__parent__')}
     returned = ltaf(proxy)
     self.assertFalse(returned is factory)
     ploc = removeSecurityProxy(returned)
     self.assertIs(ploc.__parent__, adapter)
     unwrapped = getObject(ploc)
     self.assertIs(unwrapped, factory)
     after = {k: v for k, v in unwrapped.__dict__.items()
              if k not in ('_called_with', '__parent__')}
     self.assertEqual(factory._called_with, (adapter,))
     self.assertIs(factory.__parent__, adapter)
     self.assertEqual(after, before) # no added attrs
Пример #6
0
    def __call__(self, *args):
        site = getObject(self.context)
        sm = site.getSiteManager()

        if u'answers' not in site:
            ob = Answers()
            notify(ObjectCreatedEvent(ob))
            site[u'answers'] = ob
            sm.registerUtility(ob, IAnswers)
Пример #7
0
    def __call__(self, data):
        self.verify(data)

        site = getObject(self.context)
        sm = site.getSiteManager()

        self.create_user(
            site, sm, {'login': data.get('login'),
                       'password': data.get('password'),
                       'title': data.get('title')},
            site_roles=data.get('roles'),
            site_permissions=data.get('permissions'))
Пример #8
0
    def __call__(self, *args):
        site = getObject(self.context)
        sm = site.getSiteManager()

        # устанавливаем утилиту аутентификации
        if u'authentication' not in sm:
            pau = zope.pluggableauth.PluggableAuthentication(prefix='bbru.')
            zope.event.notify(ObjectCreatedEvent(pau))
            sm[u'authentication'] = pau
            sm.registerUtility(pau, IAuthentication)

        pau = sm.getUtility(IAuthentication)

        # устанавливаем в утилиту аутентификации
        # стандартный контейнер для пользователей
        if u'principals' not in pau:
            plugin = PrincipalFolder(prefix='principal.')
            zope.event.notify(ObjectCreatedEvent(plugin))
            pau[u'principals'] = plugin
            pau.authenticatorPlugins += (u'principals',)
            zope.event.notify(ObjectModifiedEvent(pau))

        # устанавливаем в утилиту аутентификации
        # стандартный контейнер для групп пользователей
        if u'group' not in pau:
            groupfolder = GroupFolder(prefix='group.')
            zope.event.notify(ObjectCreatedEvent(groupfolder))
            pau[u'group'] = groupfolder
            pau.authenticatorPlugins += (u'group',)
            zope.event.notify(ObjectModifiedEvent(pau))

        groupfolder = pau[u'group']
        roles = IPrincipalRoleManager(site)

        # создаем одну предустановленную группу
        if u'members' not in groupfolder:
            group = GroupInformation(title=u'members')
            zope.event.notify(ObjectCreatedEvent(group))
            groupfolder[u'members'] = group
            roles.assignRoleToPrincipal('bbru.Member', 'bbru.group.members')

        # конфигрируем утилиту подключаемой аутентификации так, чтобы
        # использовать сессии для хранения удостоверений безопасности
        if u'Session Credentials' not in pau.credentialsPlugins:
            pau.credentialsPlugins += (u'Session Credentials',)
Пример #9
0
    def __call__(self, *args):
        site  = getObject(self.context)
        #sm = site.getSiteManager()
        setSite(site)

        # blogger product
        blogger = getUtility(IBloggerProduct)
        if not blogger.__installed__:
            blogger.install()

        # set wysiwyg editor
        configlet = getUtility(IContentEditorConfiglet)
        configlet.default_editor = 'tinymce'
        notify(ObjectModifiedEvent(configlet))

        # set skin
        skintool = getUtility(ISkinTool)
        skintool.skin = 'quick.theme.sample'
        notify(ObjectModifiedEvent(skintool))
Пример #10
0
 def update_topics(self, titles):
     dels = []
     for ob in self._topics:
         if ob.title not in titles:
             dels.append(ob)
     for ob in dels:
         self._topics.remove(ob)
         ob.del_doc(self)
         if ob.is_empty():
             topic_key = ob.__name__
             project = get_project()
             try:
                 del project.topics[topic_key]
             except KeyError:
                 pass
     topic_folder = get_project().topics
     topics_keys = [x.__name__ for x in self._topics]
     for title in titles:
         if valid_title_p(title):
             ob = getObject(topic_folder.search(title))
             if ob.__name__ not in topics_keys:
                 self._topics.append(ob)
                 ob.add_doc(self)
Пример #11
0
    def handleAdd(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return
        factory = getUtility(IFactory, name=data['factory'])
        ob = factory()
        title = data.get('title')
        if title:
            dc = IZopeDublinCore(ob)
            dc.title = title
        notify(ObjectCreatedEvent(ob))
        name = data['name']
        if name not in self.context:
            self.context[name] = ob
        else:
            self.status = u"Identifier already used"
            return

        installed = getObject(IInstalledContent(self.context))
        installed.contents += (name,)
        notify(ObjectModifiedEvent(installed))

        self.request.response.redirect(self.request.URL)
Пример #12
0
 def __init__(self, context):
     self.context = getObject(context.context)
def sudo(obj):
    """ System utility to elevate privileges to certain object accesses """
    obj = getObject(obj) if type(obj) is Proxy else obj
    return checker.proxy_factory(obj, new_interaction('root'))
Пример #14
0
 def __call__(self, *args):
     site = getObject(self.context)
     sm = site.getSiteManager()
Пример #15
0
def sudo(obj):
    """ System utility to elevate privileges to certain object accesses """
    obj = getObject(obj) if type(obj) is Proxy else obj
    return checker.proxy_factory(obj, new_interaction('root'))