Skip to content

Commit

Permalink
get enrollment profile
Browse files Browse the repository at this point in the history
  • Loading branch information
ghernandez345 committed Mar 21, 2024
1 parent 35813ee commit 8e706f1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import React, { useState } from "react";
import { useQuery } from "react-query";

import { IConfig } from "interfaces/config";
import team, { API_NO_TEAM_ID, ITeam, ITeamConfig } from "interfaces/team";
import { API_NO_TEAM_ID, ITeam, ITeamConfig } from "interfaces/team";
import configAPI from "services/entities/config";
import teamsAPI, { ILoadTeamResponse } from "services/entities/teams";
import mdmAPI, {
IAppleSetupEnrollmentProfileResponse,
} from "services/entities/mdm";

import SectionHeader from "components/SectionHeader";
import Spinner from "components/Spinner";
Expand All @@ -15,6 +18,8 @@ import SetupAssistantProfileUploader from "./components/SetupAssistantProfileUpl
import SetuAssistantProfileCard from "./components/SetupAssistantProfileCard/SetupAssistantProfileCard";
import DeleteAutoEnrollmentProfile from "./components/DeleteAutoEnrollmentProfile";
import AdvancedOptionsForm from "./components/AdvancedOptionsForm";
import { DEFAULT_USE_QUERY_OPTIONS } from "utilities/constants";

Check failure on line 21 in frontend/pages/ManageControlsPage/SetupExperience/cards/SetupAssistant/SetupAssistant.tsx

View workflow job for this annotation

GitHub Actions / lint-js (ubuntu-latest)

Absolute imports should come before relative imports
import { Axios, AxiosError } from "axios";

Check failure on line 22 in frontend/pages/ManageControlsPage/SetupExperience/cards/SetupAssistant/SetupAssistant.tsx

View workflow job for this annotation

GitHub Actions / lint-js (ubuntu-latest)

Absolute imports should come before relative imports

const baseClass = "setup-assistant";

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

const {
data: enrollmentProfileData,
isLoading: isLoadingEnrollmentProfile,
isError: isErrorEnrollmentProfile,
} = useQuery<IAppleSetupEnrollmentProfileResponse, AxiosError>(
["enrollment_profile", currentTeamId],
() => mdmAPI.getSetupEnrollmentProfile(currentTeamId),
DEFAULT_USE_QUERY_OPTIONS
);

const getReleaseDeviceSetting = () => {
if (currentTeamId === API_NO_TEAM_ID) {
return (
Expand All @@ -54,10 +69,6 @@ const StartupAssistant = ({ currentTeamId }: ISetupAssistantProps) => {
return teamConfig?.mdm?.macos_setup.enable_release_device_manually || false;
};

const isLoading = false;

const noPackageUploaded = true;

const onUpload = () => {};

Check failure on line 72 in frontend/pages/ManageControlsPage/SetupExperience/cards/SetupAssistant/SetupAssistant.tsx

View workflow job for this annotation

GitHub Actions / lint-js (ubuntu-latest)

Unexpected empty arrow function

const onDelete = () => {};

Check failure on line 74 in frontend/pages/ManageControlsPage/SetupExperience/cards/SetupAssistant/SetupAssistant.tsx

View workflow job for this annotation

GitHub Actions / lint-js (ubuntu-latest)

Unexpected empty arrow function
Expand All @@ -67,7 +78,7 @@ const StartupAssistant = ({ currentTeamId }: ISetupAssistantProps) => {
return (
<div className={baseClass}>
<SectionHeader title="Setup assistant" />
{isLoading ? (
{isLoadingEnrollmentProfile ? (
<Spinner />
) : (
<div className={`${baseClass}__content`}>
Expand All @@ -81,7 +92,7 @@ const StartupAssistant = ({ currentTeamId }: ISetupAssistantProps) => {
newTab
/>
</p>
{true ? (
{!enrollmentProfileData ? (
<SetupAssistantProfileUploader
currentTeamId={currentTeamId}
onUpload={() => 1}
Expand Down
35 changes: 35 additions & 0 deletions frontend/services/entities/mdm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ export interface IUploadProfileApiParams {
labels?: string[];
}

export interface IAppleSetupEnrollmentProfileResponse {
team_id: number | null;
name: string;
uploaded_at: string;
// enrollment profile is an object with keys found here https://developer.apple.com/documentation/devicemanagement/profile.
enrollment_profile: Record<string, any>;
}

const mdmService = {
downloadDeviceUserEnrollmentProfile: (token: string) => {
const { DEVICE_USER_MDM_ENROLLMENT_PROFILE } = endpoints;
Expand Down Expand Up @@ -241,6 +249,33 @@ const mdmService = {

return teamAPI.updateConfig(body, teamId);
},
getSetupEnrollmentProfile: (teamId?: number) => {
const { MDM_APPLE_SETUP_ENROLLMENT_PROFILE } = endpoints;
if (!teamId || teamId === API_NO_TEAM_ID) {
return sendRequest("GET", MDM_APPLE_SETUP_ENROLLMENT_PROFILE);
}

const path = `${MDM_APPLE_SETUP_ENROLLMENT_PROFILE}?${buildQueryStringFromParams(
{ team_id: teamId }
)}`;
return sendRequest("GET", path);
},
uploadSetupEnrollmentProfile: (file: File, teamId: number) => {
const { MDM_APPLE_SETUP_ENROLLMENT_PROFILE } = endpoints;

const formData = new FormData();
formData.append("profile", file);
formData.append("team_id", teamId.toString());

return sendRequest("POST", MDM_APPLE_SETUP_ENROLLMENT_PROFILE, formData);
},
deleteSetupEnrollmentProfile: (teamId: number) => {
const { MDM_APPLE_SETUP_ENROLLMENT_PROFILE } = endpoints;
const path = `${MDM_APPLE_SETUP_ENROLLMENT_PROFILE}?${buildQueryStringFromParams(
{ team_id: teamId }
)}`;
return sendRequest("DELETE", path);
},
};

export default mdmService;
1 change: 1 addition & 0 deletions frontend/utilities/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default {
}
return `/api/mdm/apple/enroll?${query}`;
},
MDM_APPLE_SETUP_ENROLLMENT_PROFILE: `/${API_VERSION}/fleet/mdm/apple/enrollment_profile`,
MDM_BOOTSTRAP_PACKAGE_METADATA: (teamId: number) =>
`/${API_VERSION}/fleet/mdm/bootstrap/${teamId}/metadata`,
MDM_BOOTSTRAP_PACKAGE: `/${API_VERSION}/fleet/mdm/bootstrap`,
Expand Down

0 comments on commit 8e706f1

Please sign in to comment.