fix 1046. Allow auth_internal.user_list filtering with the _id
Change-Id: I94e190dc3e104a7f98a085368cb0d4ba13a719cd
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
diff --git a/osm_nbi/__init__.py b/osm_nbi/__init__.py
index 1644d0b..2c895ce 100644
--- a/osm_nbi/__init__.py
+++ b/osm_nbi/__init__.py
@@ -12,8 +12,8 @@
# under the License.
##
-version = '7.0.0.post11'
-version_date = '2019-02-04'
+version = '7.0.1.post17'
+version_date = '2019-03-31'
# Obtain installed package version. Ignore if error, e.g. pkg_resources not installed
try:
diff --git a/osm_nbi/admin_topics.py b/osm_nbi/admin_topics.py
index 9ecb61b..df31e90 100644
--- a/osm_nbi/admin_topics.py
+++ b/osm_nbi/admin_topics.py
@@ -655,7 +655,7 @@
Get complete information on an topic
:param session: contains "username", "admin", "force", "public", "project_id", "set_project"
- :param _id: server internal id
+ :param _id: server internal id or username
:return: dictionary, raise exception if not found.
"""
# Allow _id to be a name or uuid
@@ -665,9 +665,9 @@
if len(users) == 1:
return users[0]
elif len(users) > 1:
- raise EngineException("Too many users found", HTTPStatus.CONFLICT)
+ raise EngineException("Too many users found for '{}'".format(_id), HTTPStatus.CONFLICT)
else:
- raise EngineException("User not found", HTTPStatus.NOT_FOUND)
+ raise EngineException("User '{}' not found".format(_id), HTTPStatus.NOT_FOUND)
def edit(self, session, _id, indata=None, kwargs=None, content=None):
"""
diff --git a/osm_nbi/authconn_internal.py b/osm_nbi/authconn_internal.py
index 88b276d..b8cfe5b 100644
--- a/osm_nbi/authconn_internal.py
+++ b/osm_nbi/authconn_internal.py
@@ -28,12 +28,13 @@
"Alfonso Tierno <alfonso.tiernosepulveda@telefoncia.com"
__date__ = "$06-jun-2019 11:16:08$"
+import logging
+import re
+
from osm_nbi.authconn import Authconn, AuthException # , AuthconnOperationException
from osm_common.dbbase import DbException
from osm_nbi.base_topic import BaseTopic
-
-import logging
-import re
+from osm_nbi.validation import is_valid_uuid
from time import time, sleep
from http import HTTPStatus
from uuid import uuid4
@@ -346,13 +347,17 @@
"""
Get user list.
- :param filter_q: dictionary to filter user list by name (username is also admited) and/or _id
+ :param filter_q: dictionary to filter user list by:
+ name (username is also admitted). If a user id is equal to the filter name, it is also provided
+ other
:return: returns a list of users.
"""
filt = filter_q or {}
- if "name" in filt:
- filt["username"] = filt["name"]
- del filt["name"]
+ if "name" in filt: # backward compatibility
+ filt["username"] = filt.pop("name")
+ if filt.get("username") and is_valid_uuid(filt["username"]):
+ # username cannot be a uuid. If this is the case, change from username to _id
+ filt["_id"] = filt.pop("username")
users = self.db.get_list("users", filt)
project_id_name = {}
role_id_name = {}