Add wrong attributes check on selector 65/9465/1
authorZhang Rong(Jon) <rong.zhang@windriver.com>
Wed, 2 Nov 2022 05:27:24 +0000 (13:27 +0800)
committerZhang Rong(Jon) <rong.zhang@windriver.com>
Wed, 2 Nov 2022 05:27:24 +0000 (13:27 +0800)
Issue-ID: INF-302
Signed-off-by: Zhang Rong(Jon) <rong.zhang@windriver.com>
Change-Id: I98c96532100373465ab9e0f66a0a6577a1943a2a

o2common/views/pagination_route.py
o2common/views/route.py

index c595d9f..a6c5495 100644 (file)
@@ -13,7 +13,8 @@
 #  limitations under the License.
 
 from urllib.parse import urlparse
-from flask import abort
+
+from o2common.views.route_exception import BadRequestException
 
 from o2common.helper import o2logging
 logger = o2logging.get_logger(__name__)
@@ -28,7 +29,8 @@ def link_header(full_path: str, ret):
     page_current = ret.pop('page_current')
 
     if page_current > page_total:
-        abort(400, "Page size {} bad request.".format(page_current))
+        raise BadRequestException(
+            "Page size {} bad request.".format(page_current))
 
     if 0 == count:
         return [], {'X-Total-Count': count}
index 0941f58..08621ff 100644 (file)
@@ -30,6 +30,8 @@ from flask_restx.model import Model
 from flask_restx.fields import List, Nested, String
 from flask_restx.utils import unpack
 
+from o2common.views.route_exception import BadRequestException
+
 from o2common.helper import o2logging
 logger = o2logging.get_logger(__name__)
 
@@ -128,11 +130,13 @@ class o2_marshal_with(marshal_with):
         mask_val = ''
         if 'all_fields' in kwargs:
             all_fields_without_space = kwargs['all_fields'].replace(" ", "")
-            all_fields = all_fields_without_space.lower()
-            if 'true' == all_fields:
-                selector = self.__gen_selector_from_model_with_value(
-                    self.fields)
-                mask_val = self.__gen_mask_from_selector(selector)
+            logger.info('all_fields selector value is {}'.format(
+                all_fields_without_space))
+            # all_fields = all_fields_without_space.lower()
+            # if 'true' == all_fields:
+            selector = self.__gen_selector_from_model_with_value(
+                self.fields)
+            mask_val = self.__gen_mask_from_selector(selector)
 
         elif 'fields' in kwargs and kwargs['fields'] != '':
             fields_without_space = kwargs['fields'].replace(" ", "")
@@ -211,6 +215,9 @@ class o2_marshal_with(marshal_with):
             if '/' in f:
                 self.__update_selector_tree_value(selector, f, val)
                 continue
+            if f not in self.fields:
+                raise BadRequestException(
+                    'Selector attribute {} not found'.format(f))
             selector[f] = val
 
     def __update_selector_tree_value(self, m: dict, filter: str, val: bool):