fleet/frontend/services/entities/device_user.ts

186 lines
5.1 KiB
TypeScript
Raw Normal View History

import { IDeviceUserResponse } from "interfaces/host";
import { IListOptions } from "interfaces/list_options";
import { IDeviceSoftware, ISetupSoftwareStatus } from "interfaces/software";
import { IHostCertificate } from "interfaces/certificates";
2022-03-21 13:38:59 +00:00
import sendRequest from "services";
import endpoints from "utilities/endpoints";
import {
buildQueryStringFromParams,
getPathWithQueryParams,
} from "utilities/url";
import { IMdmCommandResult } from "interfaces/mdm";
import { createMockSetupSoftwareStatusesResponse } from "__mocks__/deviceUserMock";
import { IHostSoftwareQueryParams } from "./hosts";
2022-03-21 13:38:59 +00:00
export type ILoadHostDetailsExtension = "macadmins";
2022-03-21 13:38:59 +00:00
export interface IDeviceSoftwareQueryKey extends IHostSoftwareQueryParams {
scope: "device_software";
id: string;
softwareUpdatedAt?: string;
}
export interface IGetDeviceSoftwareResponse {
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
software: IDeviceSoftware[];
count: number;
meta: {
has_next_results: boolean;
has_previous_results: boolean;
};
}
interface IGetDeviceDetailsRequest {
token: string;
exclude_software?: boolean;
}
export interface IGetDeviceCertificatesResponse {
certificates: IHostCertificate[];
meta: {
has_next_results: boolean;
has_previous_results: boolean;
};
count: number;
}
export interface IGetDeviceCertsRequestParams extends IListOptions {
token: string;
}
export interface IGetVppInstallCommandResultsResponse {
results: IMdmCommandResult[];
}
export interface IGetSetupSoftwareStatusesResponse {
setup_experience_results: { software?: ISetupSoftwareStatus[] };
}
export interface IGetSetupSoftwareStatusesParams {
token: string;
}
2022-03-21 13:38:59 +00:00
export default {
loadHostDetails: ({
token,
exclude_software,
}: IGetDeviceDetailsRequest): Promise<IDeviceUserResponse> => {
2022-03-21 13:38:59 +00:00
const { DEVICE_USER_DETAILS } = endpoints;
let path = `${DEVICE_USER_DETAILS}/${token}`;
if (exclude_software) {
path += "?exclude_software=true";
}
2022-03-21 13:38:59 +00:00
return sendRequest("GET", path);
},
loadHostDetailsExtension: (
deviceAuthToken: string,
extension: ILoadHostDetailsExtension
) => {
const { DEVICE_USER_DETAILS } = endpoints;
const path = `${DEVICE_USER_DETAILS}/${deviceAuthToken}/${extension}`;
return sendRequest("GET", path);
},
refetch: (deviceAuthToken: string) => {
const { DEVICE_USER_DETAILS } = endpoints;
const path = `${DEVICE_USER_DETAILS}/${deviceAuthToken}/refetch`;
return sendRequest("POST", path);
},
getDeviceSoftware: (
params: IDeviceSoftwareQueryKey
): Promise<IGetDeviceSoftwareResponse> => {
const { DEVICE_SOFTWARE } = endpoints;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { id, scope, ...rest } = params;
const path = getPathWithQueryParams(DEVICE_SOFTWARE(id), rest);
return sendRequest("GET", path);
},
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
// getSoftwareIcon doesn't need its own service function because the logic is encapsulated in
// softwareAPI.getSoftwareIconFromApiUrl in /entities/software.ts
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
installSelfServiceSoftware: (
deviceToken: string,
softwareTitleId: number
) => {
const { DEVICE_SOFTWARE_INSTALL } = endpoints;
const path = DEVICE_SOFTWARE_INSTALL(deviceToken, softwareTitleId);
return sendRequest("POST", path);
},
uninstallSelfServiceSoftware: (
deviceToken: string,
softwareTitleId: number
) => {
const { DEVICE_SOFTWARE_UNINSTALL } = endpoints;
return sendRequest(
"POST",
DEVICE_SOFTWARE_UNINSTALL(deviceToken, softwareTitleId)
);
},
/** Gets more info on FMA/custom package install for device user */
getSoftwareInstallResult: (deviceToken: string, uuid: string) => {
const { DEVICE_SOFTWARE_INSTALL_RESULTS } = endpoints;
const path = DEVICE_SOFTWARE_INSTALL_RESULTS(deviceToken, uuid);
return sendRequest("GET", path);
},
/** Gets more info on FMA/custom package uninstall for device user */
getSoftwareUninstallResult: (
deviceToken: string,
scriptExecutionId: string
) => {
const { DEVICE_SOFTWARE_UNINSTALL_RESULTS } = endpoints;
const path = DEVICE_SOFTWARE_UNINSTALL_RESULTS(
deviceToken,
scriptExecutionId
);
return sendRequest("GET", path);
},
/** Gets more info on VPP install for device user */
getVppCommandResult: (
deviceToken: string,
uuid: string
): Promise<IGetVppInstallCommandResultsResponse> => {
const { DEVICE_VPP_COMMAND_RESULTS } = endpoints;
const path = DEVICE_VPP_COMMAND_RESULTS(deviceToken, uuid);
return sendRequest("GET", path);
},
getDeviceCertificates: ({
token,
page,
per_page,
order_key,
order_direction,
}: IGetDeviceCertsRequestParams): Promise<IGetDeviceCertificatesResponse> => {
const { DEVICE_CERTIFICATES } = endpoints;
const path = `${DEVICE_CERTIFICATES(token)}?${buildQueryStringFromParams({
page,
per_page,
order_key,
order_direction,
})}`;
return sendRequest("GET", path);
},
getSetupSoftwareStatuses: ({
token,
}: IGetSetupSoftwareStatusesParams): Promise<IGetSetupSoftwareStatusesResponse> => {
const { DEVICE_SETUP_SOFTWARE_STATUSES } = endpoints;
const path = DEVICE_SETUP_SOFTWARE_STATUSES(token);
return sendRequest("POST", path);
},
2022-03-21 13:38:59 +00:00
};