Bug 2392 Fixed: Error in getting data when logged in user updates username 94/14694/5
authorAdurti <adurti.v@tataelxsi.co.in>
Fri, 1 Nov 2024 06:32:13 +0000 (06:32 +0000)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 11 Apr 2025 15:54:55 +0000 (17:54 +0200)
Change-Id: I14293aa36061a02d304458a89fd74550143aeea5
Signed-off-by: Adurti <adurti.v@tataelxsi.co.in>
osm_nbi/admin_topics.py
osm_nbi/tests/test_admin_topics.py

index e496806..540a5d9 100644 (file)
@@ -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
index 101604c..40a7884 100755 (executable)
@@ -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,