def test_microsite_expired_manager_access(self):
     microsite = self.microsite
     with api.env.adopt_roles(['Manager', ]):
         behavior = ISmartExpiration(microsite)
         behavior.expires = EXPIRED
         microsite.reindexObject()
         transaction.commit()
     browser = self.browser
     browser.addHeader('Authorization', 'Basic %s:%s' % (SITE_OWNER_NAME, SITE_OWNER_PASSWORD,))
     browser.open('{0}'.format(microsite.absolute_url()))
     self.assertEqual(browser.headers['status'], '200 Ok')
     self.assertEqual(browser.url, microsite.absolute_url())
 def test_microsite_expired_sub_contents(self):
     microsite = self.microsite
     with api.env.adopt_roles(['Manager', ]):
         behavior = ISmartExpiration(microsite)
         behavior.expires = EXPIRED
         microsite.reindexObject()
         transaction.commit()
     browser = self.browser
     browser.open('{0}'.format(self.page.absolute_url()))
     self.assertEqual(browser.headers['status'], '200 Ok')
     # Nao vemos a pagina
     self.assertNotEqual(browser.url, self.page.absolute_url())
     # Voltamos para a raiz do portal
     self.assertEqual(browser.url, self.portal.absolute_url())
 def test_microsite_expired_anonymous_access_empty_url(self):
     microsite = self.microsite
     with api.env.adopt_roles(['Manager', ]):
         behavior = ISmartExpiration(microsite)
         behavior.expires = EXPIRED
         behavior.expires_redirect = u' '
         microsite.reindexObject()
         transaction.commit()
     browser = self.browser
     browser.open('{0}'.format(microsite.absolute_url()))
     self.assertEqual(browser.headers['status'], '200 Ok')
     # Nao estamos dentro do microsite
     self.assertNotEqual(browser.url, microsite.absolute_url())
     # Voltamos para a raiz do portal
     self.assertEqual(browser.url, self.portal.absolute_url())
Beispiel #4
0
 def setup_microsite(self):
     with api.env.adopt_roles(['Manager', 'Reviewer']):
         microsite = api.content.create(type='sc.microsite',
                                        id='microsite',
                                        container=self.portal)
         behavior = IPaginaDestaque(microsite)
         behavior.title_1 = u'Portal Brasil'
         behavior.title_2 = u'7 de Setembro'
         behavior.description = u'Pagina Destaque para 7 de Setembro'
         behavior.links = [
             {
                 'title_1': u'Min.',
                 'title_2': u'dos Esportes',
                 'url': u'http://esportes.gov.br'
             },
             {
                 'title_1': u'Min.',
                 'title_2': u'da Justiça',
                 'url': u'http://justiça.gov.br'
             },
         ]
         behavior = ISmartExpiration(microsite)
         behavior.expires = EXPIRES
         behavior.expires_url = api.portal.get().absolute_url()
     return microsite
Beispiel #5
0
 def test_microsite_expired_sub_contents(self):
     microsite = self.microsite
     with api.env.adopt_roles([
             'Manager',
     ]):
         behavior = ISmartExpiration(microsite)
         behavior.expires = EXPIRED
         microsite.reindexObject()
         transaction.commit()
     browser = self.browser
     browser.open('{0}'.format(self.page.absolute_url()))
     self.assertEqual(browser.headers['status'], '200 Ok')
     # Nao vemos a pagina
     self.assertNotEqual(browser.url, self.page.absolute_url())
     # Voltamos para a raiz do portal
     self.assertEqual(browser.url, self.portal.absolute_url())
Beispiel #6
0
 def test_microsite_expired_anonymous_access_empty_url(self):
     microsite = self.microsite
     with api.env.adopt_roles([
             'Manager',
     ]):
         behavior = ISmartExpiration(microsite)
         behavior.expires = EXPIRED
         behavior.expires_redirect = u' '
         microsite.reindexObject()
         transaction.commit()
     browser = self.browser
     browser.open('{0}'.format(microsite.absolute_url()))
     self.assertEqual(browser.headers['status'], '200 Ok')
     # Nao estamos dentro do microsite
     self.assertNotEqual(browser.url, microsite.absolute_url())
     # Voltamos para a raiz do portal
     self.assertEqual(browser.url, self.portal.absolute_url())
Beispiel #7
0
 def test_microsite_expired_manager_access(self):
     microsite = self.microsite
     with api.env.adopt_roles([
             'Manager',
     ]):
         behavior = ISmartExpiration(microsite)
         behavior.expires = EXPIRED
         microsite.reindexObject()
         transaction.commit()
     browser = self.browser
     browser.addHeader(
         'Authorization', 'Basic %s:%s' % (
             SITE_OWNER_NAME,
             SITE_OWNER_PASSWORD,
         ))
     browser.open('{0}'.format(microsite.absolute_url()))
     self.assertEqual(browser.headers['status'], '200 Ok')
     self.assertEqual(browser.url, microsite.absolute_url())
Beispiel #8
0
 def test_behavior_enabled_by_default(self):
     fti = queryUtility(IDexterityFTI, name='sc.microsite')
     behaviors = fti.behaviors
     self.assertIn(
         'brasil.gov.paginadestaque.behaviors.expiration.ISmartExpiration',
         behaviors)
     with api.env.adopt_roles([
             'Manager',
     ]):
         microsite = api.content.create(type='sc.microsite',
                                        id='microsite',
                                        container=self.portal)
     behavior = ISmartExpiration(microsite, None)
     self.assertIsNotNone(behavior)
def microsite_expiration_enforcer(event):
    """Validamos se estamos dentro de um microsite e se ele esta
       expirado. Se estiver, validamos se o usuario pode editar o
       microsite, se nao puder redirecionamos para a url definida
       em expires_redirect
    """
    request = event.request
    object = request.get('microsite', None)

    if not IPaginaDestaque.providedBy(request):
        return

    behavior = ISmartExpiration(object, None)
    if behavior:
        expired = behavior.expires and _is_expired(behavior.expires)
        sm = getSecurityManager()
        if expired and not sm.checkPermission(ModifyPortalContent, object):
            portal = api.portal.get()
            expires_redirect = getattr(object, 'expires_redirect', '').strip()
            expires_redirect = (expires_redirect
                                if expires_redirect else portal.absolute_url())
            raise Redirect(expires_redirect)