Cornices / cornice

Build Web Services with Pyramid.
https://cornice.readthedocs.io
Other
383 stars 149 forks source link

Document how to use __acl__ in version 3 #467

Open circlingthesun opened 6 years ago

circlingthesun commented 6 years ago

Is there an example of how to use an acl with a Service in version 3? The docs only mention Resources.

leplatrem commented 6 years ago

If I'm not wrong you can simply pass a factory argument to your service

circlingthesun commented 6 years ago

Thanks for the tip. I finally got around to upgrading. It would probably helpful to have in the docs. I did the following:

class BusinessACL(object):
    def __init__(self, request):
        self.request = request

    def __acl__(self):
        business_id = self.request.matchdict['id']
        return [
            (Allow, 'group:root', ALL_PERMISSIONS),
            (Allow, 'group:admin-%s' % business_id, 'write'),
            (Allow, Everyone, 'read'),
        ]

calendar_export = Service(
    name='calendar',
    path='/api/business/{id:\d+}/calendar.ics',
    description="ICS export for business",
    factory=BusinessACL
)