@@ -815,97 +815,97 @@ class LoginRequired(object):
log.info('default user is not accepted here @ %s', loc)
else:
log.warning('user %s NOT authenticated with regular auth @ %s', user, loc)
raise _redirect_to_login()
# Use as decorator
class NotAnonymous(object):
"""Ensures that client is not logged in as the "default" user, and
redirects to the login page otherwise. Must be used together with
LoginRequired."""
def __call__(self, func):
return decorator(self.__wrapper, func)
def __wrapper(self, func, *fargs, **fkwargs):
cls = fargs[0]
user = request.authuser
log.debug('Checking that user %s is not anonymous @%s', user.username, cls)
if user.is_default_user:
raise _redirect_to_login(_('You need to be a registered user to '
'perform this action'))
return func(*fargs, **fkwargs)
class _PermsDecorator(object):
"""Base class for controller decorators with multiple permissions"""
def __init__(self, *required_perms):
self.required_perms = required_perms # usually very short - a list is thus fine
log.debug('checking %s permissions %s for %s %s',
self.__class__.__name__, self.required_perms, cls, user)
if self.check_permissions(user):
log.debug('Permission granted for %s %s', cls, user)
log.debug('Permission denied for %s %s', cls, user)
log.info('Permission denied for %s %s', cls, user)
raise _redirect_to_login(_('You need to be signed in to view this page'))
raise HTTPForbidden()
def check_permissions(self, user):
raise NotImplementedError()
class HasPermissionAnyDecorator(_PermsDecorator):
"""
Checks the user has any of the given global permissions.
global_permissions = user.permissions['global'] # usually very short
return any(p in global_permissions for p in self.required_perms)
class _PermDecorator(_PermsDecorator):
"""Base class for controller decorators with a single permission"""
def __init__(self, required_perm):
_PermsDecorator.__init__(self, [required_perm])
self.required_perm = required_perm
class HasRepoPermissionLevelDecorator(_PermDecorator):
Checks the user has at least the specified permission level for the requested repository.
repo_name = get_repo_slug(request)
return user.has_repository_permission_level(repo_name, self.required_perm)
class HasRepoGroupPermissionLevelDecorator(_PermDecorator):
Checks the user has any of given permissions for the requested repository group.
repo_group_name = get_repo_group_slug(request)
return user.has_repository_group_permission_level(repo_group_name, self.required_perm)
class HasUserGroupPermissionLevelDecorator(_PermDecorator):
Status change: