LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
Added some validation for authorization fields (#573)
ali899110d64512
diff --git a/backend/notification/serializers.py b/backend/notification/serializers.pyindex c274ba32f..a5e405a52 100644--- a/backend/notification/serializers.py+++ b/backend/notification/serializers.py@@ -20,6 +20,7 @@ class NotificationSerializer(serializers.ModelSerializer):"""Validate the data for the NotificationSerializer."""# General validation for the relationship between api and pipelineself._validate_api_or_pipeline(data)+ self._validate_authorization(data)return datadef _validate_api_or_pipeline(self, data):@@ -36,6 +37,57 @@ class NotificationSerializer(serializers.ModelSerializer):"Either 'api' or 'pipeline' must be provided.")+ def _validate_authorization(self, data):+ """Ensure required authorization fields are provided based on the+ authorization type.++ Getting existing data in the case of PATCH request+ """+ authorization_type = data.get(+ "authorization_type", getattr(self.instance, "authorization_type", None)+ )+ authorization_key = data.get(+ "authorization_key", getattr(self.instance, "authorization_key", None)+ )+ authorization_header = data.get(+ "authorization_header", getattr(self.instance, "authorization_header", None)+ )++ try:+ authorization_type_enum = AuthorizationType(authorization_type)+ except ValueError:+ raise serializers.ValidationError(+ f"Invalid authorization type '{authorization_type}'."+ )++ if authorization_type_enum in [+ AuthorizationType.BEARER,+ AuthorizationType.API_KEY,+ AuthorizationType.CUSTOM_HEADER,+ ]:+ if not authorization_key:+ raise serializers.ValidationError(+ {+ "authorization_key": (+ "Authorization key is required for authorization "+ f"type '{authorization_type_enum.value}'."+ )+ }+ )++ if (+ authorization_type_enum == AuthorizationType.CUSTOM_HEADER+ and not authorization_header+ ):+ raise serializers.ValidationError(+ {+ "authorization_header": (+ "Authorization header is required when using "+ "CUSTOM_HEADER authorization type."+ )+ }+ )+def validate_platform(self, value):"""Validate the platform field based on the notification_type."""notification_type = self.initial_data.get(diff --git a/frontend/src/components/pipelines-or-deployments/notification-modal/CreateNotification.jsx b/frontend/src/components/pipelines-or-deployments/notification-modal/CreateNotification.jsxindex ac60bc90f..877eb3c6d 100644--- a/frontend/src/components/pipelines-or-deployments/notification-modal/CreateNotification.jsx+++ b/frontend/src/components/pipelines-or-deployments/notification-modal/CreateNotification.jsx@@ -113,6 +113,16 @@ function CreateNotification({}};+ const handleAuthorizationTypeChange = (value) => {+ setFormDetails((prevDetails) => ({+ ...prevDetails,+ authorization_type: value,+ authorization_key: value === "NONE" ? "" : prevDetails.authorization_key,+ authorization_header:+ value === "CUSTOM_HEADER" ? prevDetails.authorization_header : "",+ }));+ };+const formItems = [{label: "Name",@@ -121,40 +131,66 @@ function CreateNotification({component: <Input />,},{- label: "Url",+ label: "URL",name: "url",rules: [{ required: true, message: "Please enter URL" }],component: <Input />,+ tooltip:+ "Provide the URL associated with this item. This field is required.",},{label: "Notification Type",name: "notification_type",component: <Select options={NOTIFICATION_TYPE_ITEMS} />,+ tooltip: "Select the type of notification you want to send.",},{label: "Platform",name: "platform",component: <Select options={PLATFORM_TYPES} />,+ tooltip: "Choose the platform where the notification will be used.",},{label: "Authorization Type",name: "authorization_type",- component: <Select options={AUTHORIZATION_TYPES} />,+ component: (+ <Select+ options={AUTHORIZATION_TYPES}+ onChange={handleAuthorizationTypeChange}+ />+ ),+ tooltip:+ "Select the type of authorization required for this notification.",},{label: "Authorization Header",name: "authorization_header",component: <Input />,+ tooltip: "Enter the custom authorization header needed for requests.",+ rules:+ formDetails.authorization_type === "CUSTOM_HEADER"+ ? [{ required: true, message: "Authorization Header is required" }]+ : [],+ hidden: formDetails.authorization_type !== "CUSTOM_HEADER",},{label: "Authorization Key",name: "authorization_key",component: <Input />,+ tooltip:+ "Provide the authorization key used to validate the notification.",+ rules:+ formDetails.authorization_type !== "NONE"+ ? [{ required: true, message: "Authorization key is required" }]+ : [],+ hidden: formDetails.authorization_type === "NONE",},{label: "Max Retries",name: "max_retries",component: <Input type="number" />,+ tooltip:+ "Specify the maximum number of times the notification should be retried if it fails.",},];@@ -166,20 +202,24 @@ function CreateNotification({onValuesChange={handleInputChange}onFinish={triggerSubmit}>- {formItems.map(({ label, name, rules, component }) => (- <Form.Item- key={name}- label={label}- name={name}- rules={rules}- validateStatus={- getBackendErrorDetail(name, backendErrors) ? "error" : ""- }- help={getBackendErrorDetail(name, backendErrors)}- >- {component}- </Form.Item>- ))}+ {formItems.map(+ ({ label, name, rules, component, tooltip, hidden }) =>+ !hidden && (+ <Form.Item+ key={name}+ label={label}+ name={name}+ rules={rules}+ tooltip={tooltip || ""}+ validateStatus={+ getBackendErrorDetail(name, backendErrors) ? "error" : ""+ }+ help={getBackendErrorDetail(name, backendErrors)}+ >+ {component}+ </Form.Item>+ )+ )}<Form.Item className="display-flex-right"><Space><Button onClick={() => setIsForm(false)}>Cancel</Button>