Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Disabling delete data view for data frame analytics and transforms wizards #119732

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const DeleteActionModal: FC<DeleteAction> = ({
toggleDeleteIndex,
toggleDeleteIndexPattern,
userCanDeleteIndex,
userCanDeleteDataView,
}) => {
if (item === undefined) {
return null;
Expand Down Expand Up @@ -85,6 +86,7 @@ export const DeleteActionModal: FC<DeleteAction> = ({
})}
checked={deleteIndexPattern}
onChange={toggleDeleteIndexPattern}
disabled={userCanDeleteDataView === false}
/>
)}
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ export const useDeleteAction = (canDeleteDataFrameAnalytics: boolean) => {
const [deleteTargetIndex, setDeleteTargetIndex] = useState<boolean>(true);
const [deleteIndexPattern, setDeleteIndexPattern] = useState<boolean>(true);
const [userCanDeleteIndex, setUserCanDeleteIndex] = useState<boolean>(false);
const [userCanDeleteDataView, setUserCanDeleteDataView] = useState<boolean>(false);
const [indexPatternExists, setIndexPatternExists] = useState<boolean>(false);
const [isLoading, setIsLoading] = useState<boolean>(false);

const {
data: { dataViews },
application: { capabilities },
} = useMlKibana().services;

const indexName = item?.config.dest.index ?? '';
Expand Down Expand Up @@ -83,6 +85,14 @@ export const useDeleteAction = (canDeleteDataFrameAnalytics: boolean) => {
if (userCanDelete) {
setUserCanDeleteIndex(true);
}

const canDeleteDataView =
capabilities.savedObjectsManagement.delete === true ||
capabilities.indexPatterns.save === true;
setUserCanDeleteDataView(canDeleteDataView);
if (canDeleteDataView === false) {
setDeleteIndexPattern(false);
}
} catch (e) {
const error = extractErrorMessage(e);
setIsLoading(false);
Expand Down Expand Up @@ -180,5 +190,6 @@ export const useDeleteAction = (canDeleteDataFrameAnalytics: boolean) => {
toggleDeleteIndex,
toggleDeleteIndexPattern,
userCanDeleteIndex,
userCanDeleteDataView,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ export const useDeleteIndexAndTargetIndex = (items: TransformListRow[]) => {
http,
savedObjects,
ml: { extractErrorMessage },
application: { capabilities },
} = useAppDependencies();
const toastNotifications = useToastNotifications();

const [deleteDestIndex, setDeleteDestIndex] = useState<boolean>(true);
const [deleteIndexPattern, setDeleteIndexPattern] = useState<boolean>(true);
const [userCanDeleteIndex, setUserCanDeleteIndex] = useState<boolean>(false);
const [indexPatternExists, setIndexPatternExists] = useState<boolean>(false);
const [userCanDeleteDataView, setUserCanDeleteDataView] = useState<boolean>(false);

const toggleDeleteIndex = useCallback(
() => setDeleteDestIndex(!deleteDestIndex),
Expand Down Expand Up @@ -70,6 +72,13 @@ export const useDeleteIndexAndTargetIndex = (items: TransformListRow[]) => {
if (userCanDelete) {
setUserCanDeleteIndex(true);
}
const canDeleteDataView =
capabilities.savedObjectsManagement.delete === true ||
capabilities.indexPatterns.save === true;
setUserCanDeleteDataView(canDeleteDataView);
if (canDeleteDataView === false) {
setDeleteIndexPattern(false);
}
} catch (e) {
toastNotifications.addDanger(
i18n.translate(
Expand All @@ -80,7 +89,7 @@ export const useDeleteIndexAndTargetIndex = (items: TransformListRow[]) => {
)
);
}
}, [http, toastNotifications]);
}, [http, toastNotifications, capabilities]);

useEffect(() => {
checkUserIndexPermission();
Expand All @@ -99,6 +108,7 @@ export const useDeleteIndexAndTargetIndex = (items: TransformListRow[]) => {

return {
userCanDeleteIndex,
userCanDeleteDataView,
deleteDestIndex,
indexPatternExists,
deleteIndexPattern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const DeleteActionModal: FC<DeleteAction> = ({
toggleDeleteIndex,
toggleDeleteIndexPattern,
userCanDeleteIndex,
userCanDeleteDataView,
}) => {
const isBulkAction = items.length > 1;

Expand Down Expand Up @@ -74,6 +75,7 @@ export const DeleteActionModal: FC<DeleteAction> = ({
)}
checked={deleteIndexPattern}
onChange={toggleDeleteIndexPattern}
disabled={userCanDeleteDataView === false}
/>
}
</EuiFlexItem>
Expand Down Expand Up @@ -114,6 +116,7 @@ export const DeleteActionModal: FC<DeleteAction> = ({
)}
checked={deleteIndexPattern}
onChange={toggleDeleteIndexPattern}
disabled={userCanDeleteDataView === false}
/>
</EuiFlexItem>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const useDeleteAction = (forceDisable: boolean) => {

const {
userCanDeleteIndex,
userCanDeleteDataView,
deleteDestIndex,
indexPatternExists,
deleteIndexPattern,
Expand All @@ -50,7 +51,7 @@ export const useDeleteAction = (forceDisable: boolean) => {

const shouldDeleteDestIndex = userCanDeleteIndex && deleteDestIndex;
const shouldDeleteDestIndexPattern =
userCanDeleteIndex && indexPatternExists && deleteIndexPattern;
userCanDeleteIndex && userCanDeleteDataView && indexPatternExists && deleteIndexPattern;
// if we are deleting multiple transforms, then force delete all if at least one item has failed
// else, force delete only when the item user picks has failed
const forceDelete = isBulkAction
Expand Down Expand Up @@ -113,5 +114,6 @@ export const useDeleteAction = (forceDisable: boolean) => {
toggleDeleteIndex,
toggleDeleteIndexPattern,
userCanDeleteIndex,
userCanDeleteDataView,
};
};