bbovenzi commented on code in PR #72896:
URL: https://github.com/apache/airflow/pull/72896#discussion_r4048509735


##########
airflow-core/src/airflow/ui/src/pages/Dashboard/Stats/DagImportErrorsModal.tsx:
##########
@@ -20,23 +20,59 @@ import { useState } from "react";
 
 import { Box, ClipboardRoot, Heading, HStack, Text } from "@chakra-ui/react";
 import { useTranslation } from "react-i18next";
+import { AiOutlineFileSync } from "react-icons/ai";
 import { LuFileWarning } from "react-icons/lu";
 import { PiFilePy } from "react-icons/pi";
 
-import { useImportErrorServiceGetImportErrors } from "openapi/queries";
+import { useDagParsingServiceReparseDagFile, 
useImportErrorServiceGetImportErrors } from "openapi/queries";
 
-import { Accordion, ClipboardIconButton, Modal, Pagination } from 
"src/system-components";
+import {
+  Accordion,
+  ClipboardIconButton,
+  IconButton,
+  Modal,
+  Pagination,
+  toaster,
+} from "src/system-components";
 
 import { SearchBar } from "src/components/SearchBar";
 import Time from "src/components/Time";
 
+import { createErrorToaster } from "src/utils";
+
 type ImportDAGErrorModalProps = {
   readonly onClose: () => void;
   readonly open: boolean;
 };
 
 const PAGE_LIMIT = 15;
 
+const ReparseButton = ({ fileToken }: { readonly fileToken: string }) => {
+  const { t: translate } = useTranslation(["components", "dag"]);
+
+  const { isPending, mutate } = useDagParsingServiceReparseDagFile({
+    onError: (error) => createErrorToaster(error, { titleKey: 
"dag:parse.toaster.error.title" }, translate),
+    onSuccess: () =>
+      toaster.create({
+        description: translate("dag:parse.toaster.success.description"),
+        title: translate("dag:parse.toaster.success.title"),
+        type: "success",
+      }),
+  });

Review Comment:
   Do we have any query invalidation to refresh the dags list? Also, I wonder 
if we should extend `useDagParsing.tsx` to handle accepting a filetoken param 
so we can reuse it here.



##########
airflow-core/src/airflow/api_fastapi/core_api/security.py:
##########
@@ -256,7 +257,31 @@ def inner(
             )
         )
         if not dag_ids:
-            raise HTTPException(status.HTTP_404_NOT_FOUND, "File not found")
+            # A file with an import error has no registered Dag to authorize 
per-Dag against, so
+            # reparsing it is gated on the dedicated ``REPARSE_ALL`` 
permission -- admin-by-default,
+            # scoped to the file's team via its bundle -- rather than on the 
permission to view
+            # import errors. Reparse is an action, so it must not ride on 
being able to see the error.
+            has_import_error = session.scalar(
+                select(ParseImportError.id).where(
+                    ParseImportError.bundle_name == payload["bundle_name"],
+                    ParseImportError.filename == payload["relative_fileloc"],
+                )
+            )
+            if has_import_error is None:
+                raise HTTPException(status.HTTP_404_NOT_FOUND, "File not 
found")
+            team_name = (
+                DagBundleModel.get_team_name(payload["bundle_name"], 
session=session)
+                if payload["bundle_name"]
+                else None
+            )

Review Comment:
   Shouldn't the auth check happen before the has_import_error check



##########
airflow-core/src/airflow/ui/src/pages/Dashboard/Stats/DagImportErrorsModal.tsx:
##########
@@ -121,7 +157,8 @@ export const DagImportErrorsModal = ({ onClose, open }: 
ImportDAGErrorModalProps
                   {importError.filename}
                 </HStack>
               </Accordion.ItemTrigger>
-              <Box alignItems="center" display="flex" flexShrink={0} pr={2}>
+              <Box alignItems="center" display="flex" flexShrink={0} gap={1} 
pr={2}>
+                <ReparseButton fileToken={importError.file_token} />

Review Comment:
   Eventually we should hide this button if the user doesn't have permissions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to