How to use the grok.require function in grok

To help you get started, we’ve selected a few grok examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zopefoundation / grok / src / grok / ftests / security / roles.py View on Github external
def render(self):
        return 'What a beautiful painting.'

class EditCavePainting(grok.View):

    grok.context(zope.interface.Interface)
    grok.require(EditPermission)

    def render(self):
        return 'Let\'s make it even prettier.'

class EraseCavePainting(grok.View):

    grok.context(zope.interface.Interface)
    grok.require(ErasePermission)

    def render(self):
        return 'Oops, mistake, let\'s erase it.'

class ApproveCavePainting(grok.View):

    grok.context(zope.interface.Interface)
    grok.require(ApprovePermission)

    def render(self):
        return 'Painting owners cannot approve their paintings.'
github zopefoundation / grok / src / grok / ftests / rest / localgrants.py View on Github external
    @grok.require(TouchMammoth)
    def GET(self):
        return self.context.name
github zopefoundation / grok / src / grok / ftests / security / groups.py View on Github external
import grok
import zope.interface


class PublicView(grok.View):

    grok.context(zope.interface.Interface)
    grok.require('zope.Public')

    def render(self):
        return ', '.join(self.request.principal.groups)


class ProtectedView(grok.View):
    grok.context(zope.interface.Interface)
    grok.require('grok.test')

    def render(self):
        return ', '.join(self.request.principal.groups)
github zopefoundation / grok / src / grok / ftests / rest / rest.py View on Github external
    @grok.require('zope.ManageContent')
    def POST(self):
        return "POST3"
github zopefoundation / grok / src / grok / ftests / xmlrpc / require.py View on Github external
import grok
import zope.interface

class MammothRPC(grok.XMLRPC):
    grok.context(zope.interface.Interface)

    def stomp(self):
        return 'Manfred stomped.'

    @grok.require('zope.ManageContent')
    def dance(self):
        return 'Manfred doesn\'t like to dance.'

class CavemanRPC(grok.XMLRPC):
    grok.context(zope.interface.Interface)
    grok.require('zope.ManageContent')

    def hunt(self):
        return 'ME GROK LIKE MAMMOTH!'

    @grok.require('zope.View')
    def eat(self):
        return 'MMM, MANFRED TASTE GOOD!'

    @grok.require(grok.Public)
    def rest(self):
        return 'ME GROK TIRED!'
github zopefoundation / grok / src / grok / ftests / security / groups.py View on Github external
And of course you can access the protected view.

  >>> browser.open("http://localhost/@@protectedview")
  >>> 'zope.Authenticated' in browser.contents
  True
"""

import grok
import zope.interface


class PublicView(grok.View):

    grok.context(zope.interface.Interface)
    grok.require('zope.Public')

    def render(self):
        return ', '.join(self.request.principal.groups)


class ProtectedView(grok.View):
    grok.context(zope.interface.Interface)
    grok.require('grok.test')

    def render(self):
        return ', '.join(self.request.principal.groups)
github zopefoundation / grok / src / grok / ftests / xmlrpc / require.py View on Github external
    @grok.require('zope.View')
    def eat(self):
        return 'MMM, MANFRED TASTE GOOD!'
github zopefoundation / grok / src / grok / ftests / security / json.py View on Github external
    @grok.require('zope.ManageContent')
    def dance(self):
        return {'Manfred doesn\'t like to dance.': ''}
github zopefoundation / grok / src / grok / admin / view.py View on Github external
def update(self):
        apps = zope.component.getAllUtilitiesRegisteredFor(
            grok.interfaces.IApplication)
        self.applications = ("%s.%s" % (x.__module__, x.__name__)
                             for x in apps)
        # Go to the first page immediately.
        self.redirect(self.url('applications'))


class Applications(GAIAView):
    """View for application management.

    """

    grok.name('applications')
    grok.require('grok.ManageApplications')

    def getDocOfApp(self, apppath, headonly = True):
        doctor = docgrok.docgrok_handle(apppath)
        result = doctor.getDoc(headonly)
        if result is None:
            result = ""
        return result

    def update(self):
        from ZODB import broken

        from zope.app.broken.broken import IBroken

        # Available apps...
        apps = zope.component.getAllUtilitiesRegisteredFor(
            grok.interfaces.IApplication)
github zopefoundation / grok / doc / design / permission.py View on Github external
    @grok.require('some.permission')
    def doSomethingVerySecret(self):
        pass