From: Eduardo Sousa Date: Mon, 20 May 2019 14:41:54 +0000 (+0100) Subject: Adding filter to UserTopicAuth X-Git-Tag: v6.0.0~44 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=2d5a515d32cf20f526e5922fae130868c9710dc3;p=osm%2FNBI.git Adding filter to UserTopicAuth Change-Id: I3ff383f6f461a22969aa490681d4b4964894d36b Signed-off-by: Eduardo Sousa --- diff --git a/osm_nbi/admin_topics.py b/osm_nbi/admin_topics.py index d894a09..9f2eb68 100644 --- a/osm_nbi/admin_topics.py +++ b/osm_nbi/admin_topics.py @@ -559,7 +559,10 @@ class UserTopicAuth(UserTopic): :param filter_q: filter of data to be applied :return: The list, it can be empty if no one match the filter. """ - return self.auth.get_user_list() + if not filter_q: + filter_q = {} + + return self.auth.get_user_list(filter_q) def delete(self, session, _id, dry_run=False): """ diff --git a/osm_nbi/authconn.py b/osm_nbi/authconn.py index 0ffaad8..8f2f128 100644 --- a/osm_nbi/authconn.py +++ b/osm_nbi/authconn.py @@ -184,10 +184,11 @@ class Authconn: """ raise AuthconnNotImplementedException("Should have implemented this") - def get_user_list(self): + def get_user_list(self, filter_q={}): """ Get user list. + :param filter_q: dictionary to filter user list. :return: returns a list of users. """ diff --git a/osm_nbi/authconn_keystone.py b/osm_nbi/authconn_keystone.py index 54442c8..e917306 100644 --- a/osm_nbi/authconn_keystone.py +++ b/osm_nbi/authconn_keystone.py @@ -247,10 +247,11 @@ class AuthconnKeystone(Authconn): self.logger.exception("Error during user deletion using keystone") raise AuthconnOperationException("Error during user deletion using Keystone") - def get_user_list(self): + def get_user_list(self, filter_q={}): """ Get user list. + :param filter_q: dictionary to filter user list. :return: returns a list of users. """ try: @@ -260,6 +261,14 @@ class AuthconnKeystone(Authconn): "_id": user.id } for user in users if user.name != self.admin_username] + allowed_fields = ["_id", "username"] + for key in filter_q.keys(): + if key not in allowed_fields: + continue + + users = [user for user in users + if filter_q[key] == user[key]] + for user in users: projects = self.keystone.projects.list(user=user["_id"]) projects = [{