From 50f1160a7f9c7e4e3a58c47880fad2ad7191a190 Mon Sep 17 00:00:00 2001 From: checktheroads Date: Mon, 23 Mar 2020 09:44:50 -0700 Subject: [PATCH] fix feature enable/disable issue --- hyperglass/api/models/query.py | 22 +++++++++++++++++++++ hyperglass/configuration/models/messages.py | 4 ++-- hyperglass/ui/components/QueryType.js | 14 +++++-------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/hyperglass/api/models/query.py b/hyperglass/api/models/query.py index 271c2b4..e2e3698 100644 --- a/hyperglass/api/models/query.py +++ b/hyperglass/api/models/query.py @@ -86,6 +86,28 @@ class Query(BaseModel): """Create SHA256 hash digest of model representation.""" return hashlib.sha256(repr(self).encode()).hexdigest() + @validator("query_type") + def validate_query_type(cls, value): + """Ensure query_type is enabled. + + Arguments: + value {str} -- Query Type + + Raises: + InputInvalid: Raised if query_type is disabled. + + Returns: + {str} -- Valid query_type + """ + query_type_obj = getattr(params.queries, value) + if not query_type_obj.enable: + raise InputInvalid( + params.messages.feature_not_enabled, + level="warning", + feature=query_type_obj.display_name, + ) + return value + @validator("query_location") def validate_query_location(cls, value): """Ensure query_location is defined. diff --git a/hyperglass/configuration/models/messages.py b/hyperglass/configuration/models/messages.py index b2acc84..e021fd0 100644 --- a/hyperglass/configuration/models/messages.py +++ b/hyperglass/configuration/models/messages.py @@ -28,9 +28,9 @@ class Messages(HyperglassModel): description="Displayed when a query target is implicitly denied by a matched VRF's ACL. `{target}` may be used to display the denied query target.", ) feature_not_enabled: StrictStr = Field( - "{feature} is not enabled for {device_name}.", + "{feature} is not enabled.", title="Feature Not Enabled", - description="Displayed when a query type is submitted that is not supported or disabled. The hyperglass UI performs validation of supported query types prior to submitting any requests, so this is primarily relevant to the hyperglass API. `{feature}` and `{device_name}` may be used to display the disabled feature and the selected device/location.", + description="Displayed when a query type is submitted that is not supported or disabled. The hyperglass UI performs validation of supported query types prior to submitting any requests, so this is primarily relevant to the hyperglass API. `{feature}` may be used to display the disabled feature.", ) invalid_input: StrictStr = Field( "{target} is not a valid {query_type} target.", diff --git a/hyperglass/ui/components/QueryType.js b/hyperglass/ui/components/QueryType.js index 7c70f86..8c9ee09 100644 --- a/hyperglass/ui/components/QueryType.js +++ b/hyperglass/ui/components/QueryType.js @@ -1,16 +1,12 @@ import React from "react"; import ChakraSelect from "~/components/ChakraSelect"; -const buildQueries = queryTypes => { - const queries = []; - queryTypes.map(q => { - queries.push({ value: q.name, label: q.display_name }); - }); - return queries; -}; - export default ({ queryTypes, onChange }) => { - const queries = buildQueries(queryTypes); + const queries = queryTypes + .filter(q => q.enable === true) + .map(q => { + return { value: q.name, label: q.display_name }; + }); return (