Skip to content

Commit

Permalink
@auth_sysadmins_check auth function decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Apr 18, 2013
1 parent bb1bba2 commit e0e60c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 12 additions & 0 deletions ckan/logic/__init__.py
Expand Up @@ -383,6 +383,18 @@ def wrapper(context, data_dict):
return wrapper


def auth_sysadmins_check(action):
''' Prevent sysadmins from automatically being authenticated. Instead
they are treated like any other user and the auth function is called.
'''
@functools.wraps(action)
def wrapper(context, data_dict):
return action(context, data_dict)
wrapper.auth_sysadmins_check = True
return wrapper



class UnknownValidator(Exception):
pass

Expand Down
11 changes: 7 additions & 4 deletions ckan/new_authz.py
Expand Up @@ -58,12 +58,15 @@ def is_authorized(action, context, data_dict=None):
if context.get('ignore_auth'):
return {'success': True}

# sysadmins can do anything
if is_sysadmin(context.get('user')):
return {'success': True}

auth_function = _get_auth_function(action)
if auth_function:
# sysadmins can do anything unless the auth_sysadmins_check
# decorator was used in which case they are treated like all other
# users.
if is_sysadmin(context.get('user')):
if not getattr(auth_function, 'auth_sysadmins_check', False):
return {'success': True}

return auth_function(context, data_dict)
else:
raise ValueError(_('Authorization function not found: %s' % action))
Expand Down

0 comments on commit e0e60c1

Please sign in to comment.