From: Adurti Date: Fri, 1 Nov 2024 06:32:13 +0000 (+0000) Subject: Bug 2392 Fixed: Error in getting data when logged in user updates username X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=7149f154ff3f81a5bab43d8eee7d4600bf1c9728;p=osm%2FNBI.git Bug 2392 Fixed: Error in getting data when logged in user updates username Change-Id: I14293aa36061a02d304458a89fd74550143aeea5 Signed-off-by: Adurti Signed-off-by: garciadeblas --- diff --git a/osm_nbi/admin_topics.py b/osm_nbi/admin_topics.py index e496806..540a5d9 100644 --- a/osm_nbi/admin_topics.py +++ b/osm_nbi/admin_topics.py @@ -72,7 +72,7 @@ class UserTopic(BaseTopic): if session["admin"]: # allows all return {} else: - return {"username": session["username"]} + return {"_id": session["user_id"]} def check_conflict_on_new(self, session, indata): # check username not exists @@ -904,7 +904,7 @@ class UserTopicAuth(UserTopic): :param db_content: The database content of this item _id :return: None if ok or raises EngineException with the conflict """ - if db_content["username"] == session["username"]: + if db_content["_id"] == session["user_id"]: raise EngineException( "You cannot delete your own login user ", http_code=HTTPStatus.CONFLICT ) @@ -1269,9 +1269,7 @@ class UserTopicAuth(UserTopic): user_list = self.auth.get_user_list(filter_q) if not session["allow_show_user_project_role"]: # Bug 853 - Default filtering - user_list = [ - usr for usr in user_list if usr["username"] == session["username"] - ] + user_list = [usr for usr in user_list if usr["_id"] == session["user_id"]] return user_list def delete(self, session, _id, dry_run=False, not_send_msg=None): @@ -1478,7 +1476,7 @@ class ProjectTopicAuth(ProjectTopic): project_list = self.auth.get_project_list(filter_q) if not session["allow_show_user_project_role"]: # Bug 853 - Default filtering - user = self.auth.get_user(session["username"]) + user = self.auth.get_user(session["user_id"]) projects = [prm["project"] for prm in user["project_role_mappings"]] project_list = [proj for proj in project_list if proj["_id"] in projects] return project_list @@ -1780,7 +1778,7 @@ class RoleTopicAuth(BaseTopic): role_list = self.auth.get_role_list(filter_q) if not session["allow_show_user_project_role"]: # Bug 853 - Default filtering - user = self.auth.get_user(session["username"]) + user = self.auth.get_user(session["user_id"]) roles = [prm["role"] for prm in user["project_role_mappings"]] role_list = [role for role in role_list if role["_id"] in roles] return role_list diff --git a/osm_nbi/tests/test_admin_topics.py b/osm_nbi/tests/test_admin_topics.py index 101604c..40a7884 100755 --- a/osm_nbi/tests/test_admin_topics.py +++ b/osm_nbi/tests/test_admin_topics.py @@ -1044,7 +1044,8 @@ class Test_UserTopicAuth(TestCase): def test_delete_user(self): with self.subTest(i=1): uid = str(uuid4()) - self.fake_session["username"] = self.test_name + other_uid = str(uuid4()) + self.fake_session["user_id"] = other_uid user = user = { "_id": uid, "username": "other-user-name", @@ -1226,7 +1227,7 @@ class Test_UserTopicAuth(TestCase): def test_conflict_on_del(self): with self.subTest(i=1): uid = str(uuid4()) - self.fake_session["username"] = self.test_name + self.fake_session["user_id"] = uid user = user = { "_id": uid, "username": self.test_name,