fleet/frontend/services/entities/teams.ts

201 lines
5.2 KiB
TypeScript
Raw Normal View History

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import sendRequest from "services";
2022-06-10 18:29:45 +00:00
import endpoints from "utilities/endpoints";
import { pick } from "lodash";
import { buildQueryStringFromParams } from "utilities/url";
import { IEnrollSecret } from "interfaces/enroll_secret";
17445 calendar events modal (#17717) Addresses #17445 Follow-up iteration: - Finalize styling of dropdown tooltips - All `//TODO`s <img width="1393" alt="Screenshot 2024-03-20 at 1 43 54 PM" src="https://github.com/fleetdm/fleet/assets/61553566/9b792cf0-058a-4ae6-8f5f-a49eb936ebef"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 01 PM" src="https://github.com/fleetdm/fleet/assets/61553566/86195dcf-ec28-4cf0-ab8b-d785d12372ed"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 21 PM" src="https://github.com/fleetdm/fleet/assets/61553566/01effdec-ca20-49ec-a442-5fe754a5e12b"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 26 PM" src="https://github.com/fleetdm/fleet/assets/61553566/b6de6891-6eae-426e-bbff-b01184094ac9"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 33 PM" src="https://github.com/fleetdm/fleet/assets/61553566/96e167dd-752c-4b49-a1a7-69fe9b4f42ac"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 43 PM" src="https://github.com/fleetdm/fleet/assets/61553566/feedbda5-e915-4e5e-84ee-2316db49434a"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 47 PM" src="https://github.com/fleetdm/fleet/assets/61553566/c4b5ac47-3357-43ef-95ca-dd0953994f6f"> <img width="1393" alt="Screenshot 2024-03-20 at 1 45 02 PM" src="https://github.com/fleetdm/fleet/assets/61553566/17838415-5bf4-46f0-9bde-522deb0f0886"> <img width="1393" alt="Screenshot 2024-03-20 at 1 45 10 PM" src="https://github.com/fleetdm/fleet/assets/61553566/b7228484-bb9f-4119-9fbf-a60ce990ba0e"> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2024-03-20 20:53:34 +00:00
import { ITeamIntegrations } from "interfaces/integration";
import {
API_NO_TEAM_ID,
INewTeamUsersBody,
IRemoveTeamUserBody,
ITeamConfig,
ITeamWebhookSettings,
} from "interfaces/team";
2022-06-10 18:29:45 +00:00
interface ILoadTeamsParams {
page?: number;
perPage?: number;
globalFilter?: string;
}
/**
* The response body expected for the "Get team" endpoint.
* See https://fleetdm.com/docs/using-fleet/rest-api#get-team
*/
export interface ILoadTeamResponse {
team: ITeamConfig;
}
2022-06-10 18:29:45 +00:00
export interface ILoadTeamsResponse {
teams: ITeamConfig[];
2022-06-10 18:29:45 +00:00
}
export interface ITeamFormData {
name: string;
}
export interface IUpdateTeamFormData {
name: string;
webhook_settings: Partial<ITeamWebhookSettings>;
17445 calendar events modal (#17717) Addresses #17445 Follow-up iteration: - Finalize styling of dropdown tooltips - All `//TODO`s <img width="1393" alt="Screenshot 2024-03-20 at 1 43 54 PM" src="https://github.com/fleetdm/fleet/assets/61553566/9b792cf0-058a-4ae6-8f5f-a49eb936ebef"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 01 PM" src="https://github.com/fleetdm/fleet/assets/61553566/86195dcf-ec28-4cf0-ab8b-d785d12372ed"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 21 PM" src="https://github.com/fleetdm/fleet/assets/61553566/01effdec-ca20-49ec-a442-5fe754a5e12b"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 26 PM" src="https://github.com/fleetdm/fleet/assets/61553566/b6de6891-6eae-426e-bbff-b01184094ac9"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 33 PM" src="https://github.com/fleetdm/fleet/assets/61553566/96e167dd-752c-4b49-a1a7-69fe9b4f42ac"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 43 PM" src="https://github.com/fleetdm/fleet/assets/61553566/feedbda5-e915-4e5e-84ee-2316db49434a"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 47 PM" src="https://github.com/fleetdm/fleet/assets/61553566/c4b5ac47-3357-43ef-95ca-dd0953994f6f"> <img width="1393" alt="Screenshot 2024-03-20 at 1 45 02 PM" src="https://github.com/fleetdm/fleet/assets/61553566/17838415-5bf4-46f0-9bde-522deb0f0886"> <img width="1393" alt="Screenshot 2024-03-20 at 1 45 10 PM" src="https://github.com/fleetdm/fleet/assets/61553566/b7228484-bb9f-4119-9fbf-a60ce990ba0e"> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2024-03-20 20:53:34 +00:00
integrations: ITeamIntegrations;
2023-01-27 22:25:53 +00:00
mdm: {
macos_updates?: {
2023-01-27 22:25:53 +00:00
minimum_version: string;
deadline: string;
};
windows_updates?: {
deadline_days: number;
grace_period_days: number;
};
2023-01-27 22:25:53 +00:00
};
host_expiry_settings: {
host_expiry_enabled: boolean;
host_expiry_window: number; // days
};
}
export default {
2022-06-10 18:29:45 +00:00
create: (formData: ITeamFormData) => {
const { TEAMS } = endpoints;
return sendRequest("POST", TEAMS, formData);
},
destroy: (teamId: number) => {
const { TEAMS } = endpoints;
const path = `${TEAMS}/${teamId}`;
return sendRequest("DELETE", path);
},
load: (teamId: number | undefined): Promise<ILoadTeamResponse> => {
if (!teamId || teamId <= API_NO_TEAM_ID) {
return Promise.reject(
new Error(
`Invalid team id: ${teamId} must be greater than ${API_NO_TEAM_ID}`
)
);
}
const { TEAMS } = endpoints;
const path = `${TEAMS}/${teamId}`;
return sendRequest("GET", path);
},
loadAll: ({
globalFilter = "",
2022-06-10 18:29:45 +00:00
}: ILoadTeamsParams = {}): Promise<ILoadTeamsResponse> => {
const queryParams = {
query: globalFilter,
};
const queryString = buildQueryStringFromParams(queryParams);
const endpoint = endpoints.TEAMS;
const path = `${endpoint}?${queryString}`;
return sendRequest("GET", path);
},
update: (
{
name,
webhook_settings,
integrations,
mdm,
host_expiry_settings,
}: Partial<IUpdateTeamFormData>,
teamId?: number
): Promise<ITeamConfig> => {
if (typeof teamId === "undefined") {
2022-06-10 18:29:45 +00:00
return Promise.reject("Invalid usage: missing team id");
}
const { TEAMS } = endpoints;
const path = `${TEAMS}/${teamId}`;
const requestBody: Record<string, unknown> = {};
if (name) {
requestBody.name = name;
}
if (webhook_settings) {
requestBody.webhook_settings = webhook_settings;
}
if (integrations) {
17445 calendar events modal (#17717) Addresses #17445 Follow-up iteration: - Finalize styling of dropdown tooltips - All `//TODO`s <img width="1393" alt="Screenshot 2024-03-20 at 1 43 54 PM" src="https://github.com/fleetdm/fleet/assets/61553566/9b792cf0-058a-4ae6-8f5f-a49eb936ebef"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 01 PM" src="https://github.com/fleetdm/fleet/assets/61553566/86195dcf-ec28-4cf0-ab8b-d785d12372ed"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 21 PM" src="https://github.com/fleetdm/fleet/assets/61553566/01effdec-ca20-49ec-a442-5fe754a5e12b"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 26 PM" src="https://github.com/fleetdm/fleet/assets/61553566/b6de6891-6eae-426e-bbff-b01184094ac9"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 33 PM" src="https://github.com/fleetdm/fleet/assets/61553566/96e167dd-752c-4b49-a1a7-69fe9b4f42ac"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 43 PM" src="https://github.com/fleetdm/fleet/assets/61553566/feedbda5-e915-4e5e-84ee-2316db49434a"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 47 PM" src="https://github.com/fleetdm/fleet/assets/61553566/c4b5ac47-3357-43ef-95ca-dd0953994f6f"> <img width="1393" alt="Screenshot 2024-03-20 at 1 45 02 PM" src="https://github.com/fleetdm/fleet/assets/61553566/17838415-5bf4-46f0-9bde-522deb0f0886"> <img width="1393" alt="Screenshot 2024-03-20 at 1 45 10 PM" src="https://github.com/fleetdm/fleet/assets/61553566/b7228484-bb9f-4119-9fbf-a60ce990ba0e"> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2024-03-20 20:53:34 +00:00
const { jira, zendesk, google_calendar } = integrations;
const teamIntegrationProps = [
"enable_failing_policies",
"group_id",
"project_key",
"url",
];
requestBody.integrations = {
jira: jira?.map((j) => pick(j, teamIntegrationProps)),
zendesk: zendesk?.map((z) => pick(z, teamIntegrationProps)),
17445 calendar events modal (#17717) Addresses #17445 Follow-up iteration: - Finalize styling of dropdown tooltips - All `//TODO`s <img width="1393" alt="Screenshot 2024-03-20 at 1 43 54 PM" src="https://github.com/fleetdm/fleet/assets/61553566/9b792cf0-058a-4ae6-8f5f-a49eb936ebef"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 01 PM" src="https://github.com/fleetdm/fleet/assets/61553566/86195dcf-ec28-4cf0-ab8b-d785d12372ed"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 21 PM" src="https://github.com/fleetdm/fleet/assets/61553566/01effdec-ca20-49ec-a442-5fe754a5e12b"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 26 PM" src="https://github.com/fleetdm/fleet/assets/61553566/b6de6891-6eae-426e-bbff-b01184094ac9"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 33 PM" src="https://github.com/fleetdm/fleet/assets/61553566/96e167dd-752c-4b49-a1a7-69fe9b4f42ac"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 43 PM" src="https://github.com/fleetdm/fleet/assets/61553566/feedbda5-e915-4e5e-84ee-2316db49434a"> <img width="1393" alt="Screenshot 2024-03-20 at 1 44 47 PM" src="https://github.com/fleetdm/fleet/assets/61553566/c4b5ac47-3357-43ef-95ca-dd0953994f6f"> <img width="1393" alt="Screenshot 2024-03-20 at 1 45 02 PM" src="https://github.com/fleetdm/fleet/assets/61553566/17838415-5bf4-46f0-9bde-522deb0f0886"> <img width="1393" alt="Screenshot 2024-03-20 at 1 45 10 PM" src="https://github.com/fleetdm/fleet/assets/61553566/b7228484-bb9f-4119-9fbf-a60ce990ba0e"> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2024-03-20 20:53:34 +00:00
google_calendar,
};
}
2023-01-27 22:25:53 +00:00
if (mdm) {
requestBody.mdm = mdm;
}
if (host_expiry_settings) {
requestBody.host_expiry_settings = host_expiry_settings;
}
return sendRequest("PATCH", path, requestBody);
},
/**
* updates the team config. This can take any partial data that is in the team config.
*/
updateConfig: (data: any, teamId: number): Promise<ITeamConfig> => {
const { TEAMS } = endpoints;
const path = `${TEAMS}/${teamId}`;
return sendRequest("PATCH", path, data);
},
addUsers: (teamId: number | undefined, newUsers: INewTeamUsersBody) => {
if (!teamId || teamId <= API_NO_TEAM_ID) {
return Promise.reject(
new Error(
`Invalid team id: ${teamId} must be greater than ${API_NO_TEAM_ID}`
)
);
}
const { TEAM_USERS } = endpoints;
const path = TEAM_USERS(teamId);
return sendRequest("PATCH", path, newUsers);
},
removeUsers: (
teamId: number | undefined,
removeUsers: IRemoveTeamUserBody
) => {
if (!teamId || teamId <= API_NO_TEAM_ID) {
return Promise.reject(
new Error(
`Invalid team id: ${teamId} must be greater than ${API_NO_TEAM_ID}`
)
);
}
const { TEAM_USERS } = endpoints;
const path = TEAM_USERS(teamId);
return sendRequest("DELETE", path, removeUsers);
},
transferHosts: (teamId: number, hostIds: number[]) => {
const { TEAMS_TRANSFER_HOSTS } = endpoints;
const path = TEAMS_TRANSFER_HOSTS(teamId);
return sendRequest("POST", path, { id: hostIds });
},
getEnrollSecrets: (teamId: number) => {
const { TEAMS_ENROLL_SECRETS } = endpoints;
const path = TEAMS_ENROLL_SECRETS(teamId);
return sendRequest("GET", path);
},
modifyEnrollSecrets: (teamId: number, secrets: IEnrollSecret[]) => {
const { TEAMS_ENROLL_SECRETS } = endpoints;
const path = TEAMS_ENROLL_SECRETS(teamId);
return sendRequest("PATCH", path, { secrets });
},
};