def secure(self, func): '''Enforce authentication on a given method/verb and optionnaly check a given permission''' if isinstance(func, basestring): return self._apply_permission(Permission(RoleNeed(func))) elif isinstance(func, Permission): return self._apply_permission(func) else: return self._apply_secure(func)
from udata.auth import Permission, RoleNeed, UserNeed from udata.i18n import lazy_gettext as _ ROLES = { 'admin': _('System administrator'), 'editor': _('Site editorialist'), 'moderator': _('Site moderator'), } sysadmin = Permission(RoleNeed('admin')) class UserEditPermission(Permission): def __init__(self, user): need = UserNeed(user.id) super(UserEditPermission, self).__init__(need)