Skip to content

Commit 582a1a2

Browse files
authored
Fix profile changes (#144)
Removes Discord username support as modifying the `otherMails` property requires too many privileges. In the future, we can reimplement this within the application itself.
1 parent 90d618b commit 582a1a2

File tree

8 files changed

+19
-60
lines changed

8 files changed

+19
-60
lines changed

src/api/functions/entraId.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
EntraInvitationResponse,
2525
ProfilePatchRequest,
2626
} from "../../common/types/iam.js";
27-
import { UserProfileDataBase } from "common/types/msGraphApi.js";
27+
import { UserProfileData } from "common/types/msGraphApi.js";
2828
import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
2929
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
3030
import { checkPaidMembershipFromTable } from "./membership.js";
@@ -366,15 +366,15 @@ export async function listGroupMembers(
366366
* @param token - Entra ID token authorized to perform this action.
367367
* @param userId - The user ID to fetch the profile for.
368368
* @throws {EntraUserError} If fetching the user profile fails.
369-
* @returns {Promise<UserProfileDataBase>} The user's profile information.
369+
* @returns {Promise<UserProfileData>} The user's profile information.
370370
*/
371371
export async function getUserProfile(
372372
token: string,
373373
email: string,
374-
): Promise<UserProfileDataBase> {
374+
): Promise<UserProfileData> {
375375
const userId = await resolveEmailToOid(token, email);
376376
try {
377-
const url = `https://graph.microsoft.com/v1.0/users/${userId}?$select=userPrincipalName,givenName,surname,displayName,otherMails,mail`;
377+
const url = `https://graph.microsoft.com/v1.0/users/${userId}?$select=userPrincipalName,givenName,surname,displayName,mail`;
378378
const response = await fetch(url, {
379379
method: "GET",
380380
headers: {
@@ -392,7 +392,7 @@ export async function getUserProfile(
392392
email,
393393
});
394394
}
395-
return (await response.json()) as UserProfileDataBase;
395+
return (await response.json()) as UserProfileData;
396396
} catch (error) {
397397
if (error instanceof EntraFetchError) {
398398
throw error;

src/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ async function init(prettyPrint: boolean = false) {
275275
);
276276
await app.register(cors, {
277277
origin: app.environmentConfig.ValidCorsOrigins,
278+
methods: ["GET", "HEAD", "POST", "PATCH", "DELETE"],
278279
});
279280
app.log.info("Initialized new Fastify instance...");
280281
return app;

src/api/routes/iam.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
9292
const entraIdToken = await getEntraIdToken(
9393
await getAuthorizedClients(),
9494
fastify.environmentConfig.AadValidClientId,
95+
undefined,
96+
genericConfig.EntraSecretName,
9597
);
9698
await patchUserProfile(
9799
entraIdToken,

src/common/types/iam.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export const entraProfilePatchRequest = z.object({
7171
givenName: z.string().min(1),
7272
surname: z.string().min(1),
7373
mail: z.string().email(),
74-
otherMails: z.array(z.string()).min(1),
7574
});
7675

7776
export type ProfilePatchRequest = z.infer<typeof entraProfilePatchRequest>;

src/common/types/msGraphApi.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
export interface UserProfileDataBase {
1+
export interface UserProfileData {
22
userPrincipalName: string;
33
displayName?: string;
44
givenName?: string;
55
surname?: string;
66
mail?: string;
7-
otherMails?: string[];
8-
}
9-
10-
export interface UserProfileData extends UserProfileDataBase {
11-
discordUsername?: string;
127
}

src/ui/pages/profile/ManageProfile.page.tsx

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import { Container, Title } from "@mantine/core";
33
import { AuthGuard } from "@ui/components/AuthGuard";
44
import { useApi } from "@ui/util/api";
5-
import { UserProfileData, UserProfileDataBase } from "@common/types/msGraphApi";
5+
import { UserProfileData } from "@common/types/msGraphApi";
66
import { ManageProfileComponent } from "./ManageProfileComponent";
77
import { useNavigate, useSearchParams } from "react-router-dom";
88
import { useAuth } from "@ui/components/AuthContext";
@@ -19,43 +19,24 @@ export const ManageProfilePage: React.FC = () => {
1919
const getProfile = async () => {
2020
const raw = (
2121
await graphApi.get(
22-
"/v1.0/me?$select=userPrincipalName,givenName,surname,displayName,otherMails,mail",
22+
"/v1.0/me?$select=userPrincipalName,givenName,surname,displayName,mail",
2323
)
24-
).data as UserProfileDataBase;
25-
const discordUsername = raw.otherMails?.filter((x) =>
26-
x.endsWith("@discord"),
27-
);
28-
const enhanced = raw as UserProfileData;
29-
if (discordUsername?.length === 1) {
30-
enhanced.discordUsername = discordUsername[0].replace("@discord", "");
31-
enhanced.otherMails = enhanced.otherMails?.filter(
32-
(x) => !x.endsWith("@discord"),
33-
);
34-
}
35-
const normalizedName = transformCommaSeperatedName(
36-
enhanced.displayName || "",
37-
);
38-
const extractedFirstName =
39-
enhanced.givenName || normalizedName.split(" ")[0];
40-
let extractedLastName = enhanced.surname || normalizedName.split(" ")[1];
41-
if (!enhanced.surname) {
24+
).data as UserProfileData;
25+
const normalizedName = transformCommaSeperatedName(raw.displayName || "");
26+
const extractedFirstName = raw.givenName || normalizedName.split(" ")[0];
27+
let extractedLastName = raw.surname || normalizedName.split(" ")[1];
28+
if (!raw.surname) {
4229
extractedLastName = extractedLastName.slice(1, extractedLastName.length);
4330
}
4431
return {
45-
...enhanced,
32+
...raw,
4633
displayName: normalizedName,
4734
givenName: extractedFirstName,
4835
surname: extractedLastName,
4936
};
5037
};
5138

5239
const setProfile = async (data: UserProfileData) => {
53-
const newOtherEmails = [data.mail || data.userPrincipalName];
54-
if (data.discordUsername && data.discordUsername !== "") {
55-
newOtherEmails.push(`${data.discordUsername}@discord`);
56-
}
57-
data.otherMails = newOtherEmails;
58-
delete data.discordUsername;
5940
const response = await api.patch("/api/v1/iam/profile", data);
6041
if (response.status < 299 && firstTime) {
6142
setLoginStatus(true);

src/ui/pages/profile/ManageProfileComponent.test.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ describe("ManageProfileComponent tests", () => {
5151
givenName: "John",
5252
surname: "Doe",
5353
mail: "john.doe@example.com",
54-
discordUsername: "johndoe#1234",
5554
});
5655
const setProfile = vi.fn();
5756

@@ -63,9 +62,6 @@ describe("ManageProfileComponent tests", () => {
6362
expect(screen.getByTestId("edit-email")).toHaveValue(
6463
"john.doe@example.com",
6564
);
66-
expect(screen.getByTestId("edit-discordUsername")).toHaveValue(
67-
"johndoe#1234",
68-
);
6965
});
7066

7167
it("handles profile fetch failure gracefully", async () => {
@@ -94,7 +90,6 @@ describe("ManageProfileComponent tests", () => {
9490
givenName: "John",
9591
surname: "Doe",
9692
mail: "john.doe@example.com",
97-
discordUsername: "",
9893
});
9994
const setProfile = vi.fn().mockResolvedValue({});
10095

@@ -105,7 +100,6 @@ describe("ManageProfileComponent tests", () => {
105100
// Edit fields
106101
await user.clear(screen.getByTestId("edit-displayName"));
107102
await user.type(screen.getByTestId("edit-displayName"), "Jane Doe");
108-
await user.type(screen.getByTestId("edit-discordUsername"), "janedoe#5678");
109103

110104
// Save changes
111105
const saveButton = screen.getByRole("button", { name: "Save" });
@@ -116,7 +110,6 @@ describe("ManageProfileComponent tests", () => {
116110
givenName: "John",
117111
surname: "Doe",
118112
mail: "john.doe@example.com",
119-
discordUsername: "janedoe#5678",
120113
});
121114

122115
expect(notificationsMock).toHaveBeenCalledWith(
@@ -136,7 +129,6 @@ describe("ManageProfileComponent tests", () => {
136129
givenName: "",
137130
surname: "",
138131
mail: "new.user@example.com",
139-
discordUsername: "",
140132
});
141133
const setProfile = vi.fn();
142134

@@ -156,7 +148,6 @@ describe("ManageProfileComponent tests", () => {
156148
givenName: "John",
157149
surname: "Doe",
158150
mail: "john.doe@example.com",
159-
discordUsername: "",
160151
});
161152
const setProfile = vi
162153
.fn()

src/ui/pages/profile/ManageProfileComponent.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ export const ManageProfileComponent: React.FC<ManageProfileComponentProps> = ({
9595
}}
9696
>
9797
<TextInput
98-
label="Full Name"
98+
label="Display Name"
99+
description="This is how your name will be shown accross all ACM @ UIUC services."
99100
value={userProfile?.displayName || ""}
100101
onChange={(e) =>
101102
setUserProfile(
@@ -144,17 +145,6 @@ export const ManageProfileComponent: React.FC<ManageProfileComponentProps> = ({
144145
data-testid="edit-email"
145146
/>
146147

147-
<TextInput
148-
label="Discord Username"
149-
value={userProfile?.discordUsername || ""}
150-
onChange={(e) =>
151-
setUserProfile(
152-
(prev) => prev && { ...prev, discordUsername: e.target.value },
153-
)
154-
}
155-
data-testid="edit-discordUsername"
156-
/>
157-
158148
<Group mt="md">
159149
<Button
160150
type="submit"

0 commit comments

Comments
 (0)