Fixed bug 1197
[osm/NBI.git] / osm_nbi / admin_topics.py
index 998c12f..3c3249c 100644 (file)
@@ -679,12 +679,13 @@ class UserTopicAuth(UserTopic):
         except ValidationError as e:
             raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
 
         except ValidationError as e:
             raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
 
-    def show(self, session, _id):
+    def show(self, session, _id, api_req=False):
         """
         Get complete information on an topic
 
         :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
         :param _id: server internal id or username
         """
         Get complete information on an topic
 
         :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
         :param _id: server internal id or username
+        :param api_req: True if this call is serving an external API request. False if serving internal request.
         :return: dictionary, raise exception if not found.
         """
         # Allow _id to be a name or uuid
         :return: dictionary, raise exception if not found.
         """
         # Allow _id to be a name or uuid
@@ -812,11 +813,12 @@ class UserTopicAuth(UserTopic):
         except ValidationError as e:
             raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
 
         except ValidationError as e:
             raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
 
-    def list(self, session, filter_q=None):
+    def list(self, session, filter_q=None, api_req=False):
         """
         Get a list of the topic that matches a filter
         :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
         :param filter_q: filter of data to be applied
         """
         Get a list of the topic that matches a filter
         :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
         :param filter_q: filter of data to be applied
+        :param api_req: True if this call is serving an external API request. False if serving internal request.
         :return: The list, it can be empty if no one match the filter.
         """
         user_list = self.auth.get_user_list(filter_q)
         :return: The list, it can be empty if no one match the filter.
         """
         user_list = self.auth.get_user_list(filter_q)
@@ -963,12 +965,13 @@ class ProjectTopicAuth(ProjectTopic):
         except ValidationError as e:
             raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
 
         except ValidationError as e:
             raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY)
 
-    def show(self, session, _id):
+    def show(self, session, _id, api_req=False):
         """
         Get complete information on an topic
 
         :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
         :param _id: server internal id
         """
         Get complete information on an topic
 
         :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
         :param _id: server internal id
+        :param api_req: True if this call is serving an external API request. False if serving internal request.
         :return: dictionary, raise exception if not found.
         """
         # Allow _id to be a name or uuid
         :return: dictionary, raise exception if not found.
         """
         # Allow _id to be a name or uuid
@@ -982,7 +985,7 @@ class ProjectTopicAuth(ProjectTopic):
         else:
             raise EngineException("Project not found", HTTPStatus.NOT_FOUND)
 
         else:
             raise EngineException("Project not found", HTTPStatus.NOT_FOUND)
 
-    def list(self, session, filter_q=None):
+    def list(self, session, filter_q=None, api_req=False):
         """
         Get a list of the topic that matches a filter
 
         """
         Get a list of the topic that matches a filter
 
@@ -1078,9 +1081,9 @@ class RoleTopicAuth(BaseTopic):
             if role_def[-1] == ":":
                 raise ValidationError("Operation cannot end with ':'")
 
             if role_def[-1] == ":":
                 raise ValidationError("Operation cannot end with ':'")
 
-            role_def_matches = [op for op in operations if op.startswith(role_def)]
+            match = next((op for op in operations if op == role_def or op.startswith(role_def + ":")), None)
 
 
-            if len(role_def_matches) == 0:
+            if not match:
                 raise ValidationError("Invalid permission '{}'".format(role_def))
 
     def _validate_input_new(self, input, force=False):
                 raise ValidationError("Invalid permission '{}'".format(role_def))
 
     def _validate_input_new(self, input, force=False):
@@ -1231,12 +1234,13 @@ class RoleTopicAuth(BaseTopic):
             final_content["permissions"]["admin"] = False
         return None
 
             final_content["permissions"]["admin"] = False
         return None
 
-    def show(self, session, _id):
+    def show(self, session, _id, api_req=False):
         """
         Get complete information on an topic
 
         :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
         :param _id: server internal id
         """
         Get complete information on an topic
 
         :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
         :param _id: server internal id
+        :param api_req: True if this call is serving an external API request. False if serving internal request.
         :return: dictionary, raise exception if not found.
         """
         filter_q = {BaseTopic.id_field(self.topic, _id): _id}
         :return: dictionary, raise exception if not found.
         """
         filter_q = {BaseTopic.id_field(self.topic, _id): _id}
@@ -1248,7 +1252,7 @@ class RoleTopicAuth(BaseTopic):
             raise AuthconnConflictException("Found more than one role with filter {}".format(filter_q))
         return roles[0]
 
             raise AuthconnConflictException("Found more than one role with filter {}".format(filter_q))
         return roles[0]
 
-    def list(self, session, filter_q=None):
+    def list(self, session, filter_q=None, api_req=False):
         """
         Get a list of the topic that matches a filter
 
         """
         Get a list of the topic that matches a filter