From efbef7ddc62d4049b1b041f4ed0a06916c7aa01c Mon Sep 17 00:00:00 2001 From: tobes Date: Tue, 2 Oct 2012 11:51:47 +0100 Subject: [PATCH] [#2939] Auth get_user_id_for_username helper function --- ckan/new_authz.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ckan/new_authz.py b/ckan/new_authz.py index c49b471ab4b..084f8cc1133 100644 --- a/ckan/new_authz.py +++ b/ckan/new_authz.py @@ -27,6 +27,17 @@ def is_authorized(action, context,data_dict=None): else: raise ValueError(_('Authorization function not found: %s' % action)) + +def get_user_id_for_username(user_name, allow_none=False): + ''' Helper function to get user id ''' + # first check if we have the user object already and get from there + if c.userobj and c.userobj.name == user_name: + return c.userobj.id + # FIXME needs completing for if we have no user in session + if allow_none: + return None + raise Exception('Not logged in user') + def _get_auth_function(action, profile=None): from pylons import config