'Decorator that prevents access to action if not logged in or
if user logged in is not a member of group_id. If role is
provided instead of group_id then the group_id is calculated.
Extends Web2Py\'s requires_membership() to add new functionality:
- Custom Flash style
- Uses s3_has_role()
- Administrators (id=1) are deemed to have all roles'

def s3_requires_membership(self, role):

    def decorator(action):
        def f(*a, **b):
            if self.override:
                return action(*a, **b)
            ADMIN = self.get_system_roles().ADMIN
            if ((not self.s3_has_role(role)) and (not self.s3_has_role(ADMIN))):
                self.permission.fail()
            return action(*a, **b)
        f.__doc__ = action.__doc__
        return f
    return decorator
