Skip to content

Commit 8e706f1

Browse files
committed
get enrollment profile
1 parent 35813ee commit 8e706f1

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

frontend/pages/ManageControlsPage/SetupExperience/cards/SetupAssistant/SetupAssistant.tsx

+18-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import React, { useState } from "react";
22
import { useQuery } from "react-query";
33

44
import { IConfig } from "interfaces/config";
5-
import team, { API_NO_TEAM_ID, ITeam, ITeamConfig } from "interfaces/team";
5+
import { API_NO_TEAM_ID, ITeam, ITeamConfig } from "interfaces/team";
66
import configAPI from "services/entities/config";
77
import teamsAPI, { ILoadTeamResponse } from "services/entities/teams";
8+
import mdmAPI, {
9+
IAppleSetupEnrollmentProfileResponse,
10+
} from "services/entities/mdm";
811

912
import SectionHeader from "components/SectionHeader";
1013
import Spinner from "components/Spinner";
@@ -15,6 +18,8 @@ import SetupAssistantProfileUploader from "./components/SetupAssistantProfileUpl
1518
import SetuAssistantProfileCard from "./components/SetupAssistantProfileCard/SetupAssistantProfileCard";
1619
import DeleteAutoEnrollmentProfile from "./components/DeleteAutoEnrollmentProfile";
1720
import AdvancedOptionsForm from "./components/AdvancedOptionsForm";
21+
import { DEFAULT_USE_QUERY_OPTIONS } from "utilities/constants";
22+
import { Axios, AxiosError } from "axios";
1823

1924
const baseClass = "setup-assistant";
2025

@@ -45,6 +50,16 @@ const StartupAssistant = ({ currentTeamId }: ISetupAssistantProps) => {
4550
select: (res) => res.team,
4651
});
4752

53+
const {
54+
data: enrollmentProfileData,
55+
isLoading: isLoadingEnrollmentProfile,
56+
isError: isErrorEnrollmentProfile,
57+
} = useQuery<IAppleSetupEnrollmentProfileResponse, AxiosError>(
58+
["enrollment_profile", currentTeamId],
59+
() => mdmAPI.getSetupEnrollmentProfile(currentTeamId),
60+
DEFAULT_USE_QUERY_OPTIONS
61+
);
62+
4863
const getReleaseDeviceSetting = () => {
4964
if (currentTeamId === API_NO_TEAM_ID) {
5065
return (
@@ -54,10 +69,6 @@ const StartupAssistant = ({ currentTeamId }: ISetupAssistantProps) => {
5469
return teamConfig?.mdm?.macos_setup.enable_release_device_manually || false;
5570
};
5671

57-
const isLoading = false;
58-
59-
const noPackageUploaded = true;
60-
6172
const onUpload = () => {};
6273

6374
const onDelete = () => {};
@@ -67,7 +78,7 @@ const StartupAssistant = ({ currentTeamId }: ISetupAssistantProps) => {
6778
return (
6879
<div className={baseClass}>
6980
<SectionHeader title="Setup assistant" />
70-
{isLoading ? (
81+
{isLoadingEnrollmentProfile ? (
7182
<Spinner />
7283
) : (
7384
<div className={`${baseClass}__content`}>
@@ -81,7 +92,7 @@ const StartupAssistant = ({ currentTeamId }: ISetupAssistantProps) => {
8192
newTab
8293
/>
8394
</p>
84-
{true ? (
95+
{!enrollmentProfileData ? (
8596
<SetupAssistantProfileUploader
8697
currentTeamId={currentTeamId}
8798
onUpload={() => 1}

frontend/services/entities/mdm.ts

+35
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ export interface IUploadProfileApiParams {
4949
labels?: string[];
5050
}
5151

52+
export interface IAppleSetupEnrollmentProfileResponse {
53+
team_id: number | null;
54+
name: string;
55+
uploaded_at: string;
56+
// enrollment profile is an object with keys found here https://developer.apple.com/documentation/devicemanagement/profile.
57+
enrollment_profile: Record<string, any>;
58+
}
59+
5260
const mdmService = {
5361
downloadDeviceUserEnrollmentProfile: (token: string) => {
5462
const { DEVICE_USER_MDM_ENROLLMENT_PROFILE } = endpoints;
@@ -241,6 +249,33 @@ const mdmService = {
241249

242250
return teamAPI.updateConfig(body, teamId);
243251
},
252+
getSetupEnrollmentProfile: (teamId?: number) => {
253+
const { MDM_APPLE_SETUP_ENROLLMENT_PROFILE } = endpoints;
254+
if (!teamId || teamId === API_NO_TEAM_ID) {
255+
return sendRequest("GET", MDM_APPLE_SETUP_ENROLLMENT_PROFILE);
256+
}
257+
258+
const path = `${MDM_APPLE_SETUP_ENROLLMENT_PROFILE}?${buildQueryStringFromParams(
259+
{ team_id: teamId }
260+
)}`;
261+
return sendRequest("GET", path);
262+
},
263+
uploadSetupEnrollmentProfile: (file: File, teamId: number) => {
264+
const { MDM_APPLE_SETUP_ENROLLMENT_PROFILE } = endpoints;
265+
266+
const formData = new FormData();
267+
formData.append("profile", file);
268+
formData.append("team_id", teamId.toString());
269+
270+
return sendRequest("POST", MDM_APPLE_SETUP_ENROLLMENT_PROFILE, formData);
271+
},
272+
deleteSetupEnrollmentProfile: (teamId: number) => {
273+
const { MDM_APPLE_SETUP_ENROLLMENT_PROFILE } = endpoints;
274+
const path = `${MDM_APPLE_SETUP_ENROLLMENT_PROFILE}?${buildQueryStringFromParams(
275+
{ team_id: teamId }
276+
)}`;
277+
return sendRequest("DELETE", path);
278+
},
244279
};
245280

246281
export default mdmService;

frontend/utilities/endpoints.ts

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export default {
7979
}
8080
return `/api/mdm/apple/enroll?${query}`;
8181
},
82+
MDM_APPLE_SETUP_ENROLLMENT_PROFILE: `/${API_VERSION}/fleet/mdm/apple/enrollment_profile`,
8283
MDM_BOOTSTRAP_PACKAGE_METADATA: (teamId: number) =>
8384
`/${API_VERSION}/fleet/mdm/bootstrap/${teamId}/metadata`,
8485
MDM_BOOTSTRAP_PACKAGE: `/${API_VERSION}/fleet/mdm/bootstrap`,

0 commit comments

Comments
 (0)