2024-05-03 13:22:20 +00:00
|
|
|
|
import React, { useContext, useEffect, useState } from "react";
|
2024-05-10 15:18:24 +00:00
|
|
|
|
import { InjectedRouter } from "react-router";
|
2024-05-03 13:22:20 +00:00
|
|
|
|
|
2024-05-10 15:18:24 +00:00
|
|
|
|
import PATHS from "router/paths";
|
Update UI for software self-service features (#19244)
Issues https://github.com/fleetdm/fleet/issues/17587,
https://github.com/fleetdm/fleet/issues/18836,
https://github.com/fleetdm/fleet/issues/18837,
https://github.com/fleetdm/fleet/pull/18339, and
https://github.com/fleetdm/fleet/pull/18340
# TODOS
- Integrate backend
- Unit/integration tests
- Various todos noted in comments
- Cleanup styles and organization of components (de-duplicating and
consolidating where possible)
- Activity feed updates (if any)
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
<!-- Note that API documentation changes are now addressed by the
product design team. -->
- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
---------
Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com>
2024-05-31 10:09:53 +00:00
|
|
|
|
import team, { APP_CONTEXT_ALL_TEAMS_ID } from "interfaces/team";
|
2024-05-03 13:22:20 +00:00
|
|
|
|
import { getErrorReason } from "interfaces/errors";
|
|
|
|
|
|
import softwareAPI from "services/entities/software";
|
|
|
|
|
|
import { NotificationContext } from "context/notification";
|
Update UI for software self-service features (#19244)
Issues https://github.com/fleetdm/fleet/issues/17587,
https://github.com/fleetdm/fleet/issues/18836,
https://github.com/fleetdm/fleet/issues/18837,
https://github.com/fleetdm/fleet/pull/18339, and
https://github.com/fleetdm/fleet/pull/18340
# TODOS
- Integrate backend
- Unit/integration tests
- Various todos noted in comments
- Cleanup styles and organization of components (de-duplicating and
consolidating where possible)
- Activity feed updates (if any)
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
<!-- Note that API documentation changes are now addressed by the
product design team. -->
- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
---------
Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com>
2024-05-31 10:09:53 +00:00
|
|
|
|
import { QueryParams, buildQueryStringFromParams } from "utilities/url";
|
2024-05-03 13:22:20 +00:00
|
|
|
|
|
|
|
|
|
|
import Modal from "components/Modal";
|
|
|
|
|
|
import Button from "components/buttons/Button";
|
|
|
|
|
|
|
|
|
|
|
|
import AddSoftwareForm from "../AddSoftwareForm";
|
|
|
|
|
|
import { IAddSoftwareFormData } from "../AddSoftwareForm/AddSoftwareForm";
|
|
|
|
|
|
|
|
|
|
|
|
// 2 minutes
|
|
|
|
|
|
const UPLOAD_TIMEOUT = 120000;
|
2024-05-15 19:32:20 +00:00
|
|
|
|
const MAX_FILE_SIZE_MB = 500;
|
|
|
|
|
|
const MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024;
|
2024-05-03 13:22:20 +00:00
|
|
|
|
|
|
|
|
|
|
const baseClass = "add-software-modal";
|
|
|
|
|
|
|
|
|
|
|
|
interface IAllTeamsMessageProps {
|
|
|
|
|
|
onExit: () => void;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AllTeamsMessage = ({ onExit }: IAllTeamsMessageProps) => {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
Please select a team first. Software can't be added when{" "}
|
|
|
|
|
|
<b>All teams</b> is selected.
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<div className="modal-cta-wrap">
|
|
|
|
|
|
<Button variant="brand" onClick={onExit}>
|
|
|
|
|
|
Done
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
interface IAddSoftwareModalProps {
|
|
|
|
|
|
teamId: number;
|
2024-05-10 15:18:24 +00:00
|
|
|
|
router: InjectedRouter;
|
2024-05-03 13:22:20 +00:00
|
|
|
|
onExit: () => void;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 15:18:24 +00:00
|
|
|
|
const AddSoftwareModal = ({
|
|
|
|
|
|
teamId,
|
|
|
|
|
|
router,
|
|
|
|
|
|
onExit,
|
|
|
|
|
|
}: IAddSoftwareModalProps) => {
|
2024-05-03 13:22:20 +00:00
|
|
|
|
const { renderFlash } = useContext(NotificationContext);
|
|
|
|
|
|
const [isUploading, setIsUploading] = useState(false);
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
let timeout: NodeJS.Timeout;
|
|
|
|
|
|
|
|
|
|
|
|
const beforeUnloadHandler = (e: BeforeUnloadEvent) => {
|
|
|
|
|
|
e.preventDefault();
|
2024-05-10 15:18:24 +00:00
|
|
|
|
// Next line with e.returnValue is included for legacy support
|
|
|
|
|
|
// e.g.Chrome / Edge < 119
|
2024-05-03 13:22:20 +00:00
|
|
|
|
e.returnValue = true;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// set up event listener to prevent user from leaving page while uploading
|
|
|
|
|
|
if (isUploading) {
|
|
|
|
|
|
addEventListener("beforeunload", beforeUnloadHandler);
|
|
|
|
|
|
timeout = setTimeout(() => {
|
|
|
|
|
|
removeEventListener("beforeunload", beforeUnloadHandler);
|
|
|
|
|
|
}, UPLOAD_TIMEOUT);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
removeEventListener("beforeunload", beforeUnloadHandler);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// clean up event listener and timeout on component unmount
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
removeEventListener("beforeunload", beforeUnloadHandler);
|
|
|
|
|
|
clearTimeout(timeout);
|
|
|
|
|
|
};
|
|
|
|
|
|
}, [isUploading]);
|
|
|
|
|
|
|
|
|
|
|
|
const onAddSoftware = async (formData: IAddSoftwareFormData) => {
|
|
|
|
|
|
setIsUploading(true);
|
|
|
|
|
|
|
2024-05-15 19:32:20 +00:00
|
|
|
|
if (formData.software && formData.software.size > MAX_FILE_SIZE_BYTES) {
|
|
|
|
|
|
renderFlash(
|
|
|
|
|
|
"error",
|
|
|
|
|
|
`Couldn’t add. The maximum file size is ${MAX_FILE_SIZE_MB} MB.`
|
|
|
|
|
|
);
|
|
|
|
|
|
onExit();
|
|
|
|
|
|
setIsUploading(false);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Update UI for software self-service features (#19244)
Issues https://github.com/fleetdm/fleet/issues/17587,
https://github.com/fleetdm/fleet/issues/18836,
https://github.com/fleetdm/fleet/issues/18837,
https://github.com/fleetdm/fleet/pull/18339, and
https://github.com/fleetdm/fleet/pull/18340
# TODOS
- Integrate backend
- Unit/integration tests
- Various todos noted in comments
- Cleanup styles and organization of components (de-duplicating and
consolidating where possible)
- Activity feed updates (if any)
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
<!-- Note that API documentation changes are now addressed by the
product design team. -->
- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
---------
Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com>
2024-05-31 10:09:53 +00:00
|
|
|
|
// TODO: confirm we are deleting the second sentence (not modifying it) for non-self-service installers
|
2024-05-03 13:22:20 +00:00
|
|
|
|
try {
|
|
|
|
|
|
await softwareAPI.addSoftwarePackage(formData, teamId);
|
2024-05-10 15:18:24 +00:00
|
|
|
|
renderFlash(
|
|
|
|
|
|
"success",
|
|
|
|
|
|
<>
|
Update UI for software self-service features (#19244)
Issues https://github.com/fleetdm/fleet/issues/17587,
https://github.com/fleetdm/fleet/issues/18836,
https://github.com/fleetdm/fleet/issues/18837,
https://github.com/fleetdm/fleet/pull/18339, and
https://github.com/fleetdm/fleet/pull/18340
# TODOS
- Integrate backend
- Unit/integration tests
- Various todos noted in comments
- Cleanup styles and organization of components (de-duplicating and
consolidating where possible)
- Activity feed updates (if any)
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
<!-- Note that API documentation changes are now addressed by the
product design team. -->
- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
---------
Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com>
2024-05-31 10:09:53 +00:00
|
|
|
|
<b>{formData.software?.name}</b> successfully added.
|
|
|
|
|
|
{formData.selfService
|
|
|
|
|
|
? " The end user can install from Fleet Desktop."
|
|
|
|
|
|
: ""}
|
2024-05-10 15:18:24 +00:00
|
|
|
|
</>
|
|
|
|
|
|
);
|
|
|
|
|
|
onExit();
|
Update UI for software self-service features (#19244)
Issues https://github.com/fleetdm/fleet/issues/17587,
https://github.com/fleetdm/fleet/issues/18836,
https://github.com/fleetdm/fleet/issues/18837,
https://github.com/fleetdm/fleet/pull/18339, and
https://github.com/fleetdm/fleet/pull/18340
# TODOS
- Integrate backend
- Unit/integration tests
- Various todos noted in comments
- Cleanup styles and organization of components (de-duplicating and
consolidating where possible)
- Activity feed updates (if any)
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
<!-- Note that API documentation changes are now addressed by the
product design team. -->
- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
---------
Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com>
2024-05-31 10:09:53 +00:00
|
|
|
|
|
|
|
|
|
|
const newQueryParams: QueryParams = { team_id: teamId };
|
|
|
|
|
|
if (formData.selfService) {
|
|
|
|
|
|
newQueryParams.self_service = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
newQueryParams.available_for_install = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-10 15:18:24 +00:00
|
|
|
|
router.push(
|
Update UI for software self-service features (#19244)
Issues https://github.com/fleetdm/fleet/issues/17587,
https://github.com/fleetdm/fleet/issues/18836,
https://github.com/fleetdm/fleet/issues/18837,
https://github.com/fleetdm/fleet/pull/18339, and
https://github.com/fleetdm/fleet/pull/18340
# TODOS
- Integrate backend
- Unit/integration tests
- Various todos noted in comments
- Cleanup styles and organization of components (de-duplicating and
consolidating where possible)
- Activity feed updates (if any)
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
<!-- Note that API documentation changes are now addressed by the
product design team. -->
- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
---------
Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com>
2024-05-31 10:09:53 +00:00
|
|
|
|
`${PATHS.SOFTWARE_TITLES}?${buildQueryStringFromParams(newQueryParams)}`
|
2024-05-10 15:18:24 +00:00
|
|
|
|
);
|
2024-05-03 13:22:20 +00:00
|
|
|
|
} catch (e) {
|
|
|
|
|
|
renderFlash("error", getErrorReason(e));
|
2024-05-10 15:18:24 +00:00
|
|
|
|
onExit();
|
2024-05-03 13:22:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setIsUploading(false);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Modal
|
|
|
|
|
|
title="Add software"
|
|
|
|
|
|
onExit={onExit}
|
|
|
|
|
|
width="large"
|
|
|
|
|
|
className={baseClass}
|
|
|
|
|
|
>
|
|
|
|
|
|
<>
|
|
|
|
|
|
{teamId === APP_CONTEXT_ALL_TEAMS_ID ? (
|
|
|
|
|
|
<AllTeamsMessage onExit={onExit} />
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<AddSoftwareForm
|
|
|
|
|
|
isUploading={isUploading}
|
|
|
|
|
|
onCancel={onExit}
|
|
|
|
|
|
onSubmit={onAddSoftware}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</>
|
|
|
|
|
|
</Modal>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default AddSoftwareModal;
|