Skip to content

Commit eb53057

Browse files
committed
only check dynamo for paid membership
1 parent 0f07cd5 commit eb53057

File tree

6 files changed

+26
-41
lines changed

6 files changed

+26
-41
lines changed

src/api/functions/entraId.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
import { UserProfileDataBase } from "common/types/msGraphApi.js";
2727
import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
2828
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
29+
import { checkPaidMembershipFromTable } from "./membership.js";
2930

3031
function validateGroupId(groupId: string): boolean {
3132
const groupIdPattern = /^[a-zA-Z0-9-]+$/; // Adjust the pattern as needed
@@ -198,6 +199,7 @@ export async function resolveEmailToOid(
198199
* @param email - The email address of the user to add or remove.
199200
* @param group - The group ID to take action on.
200201
* @param action - Whether to add or remove the user from the group.
202+
* @param dynamoClient - DynamoDB client
201203
* @throws {EntraGroupError} If the group action fails.
202204
* @returns {Promise<boolean>} True if the action was successful.
203205
*/
@@ -206,6 +208,7 @@ export async function modifyGroup(
206208
email: string,
207209
group: string,
208210
action: EntraGroupActions,
211+
dynamoClient: DynamoDBClient,
209212
): Promise<boolean> {
210213
email = email.toLowerCase().replace(/\s/g, "");
211214
if (!email.endsWith("@illinois.edu")) {
@@ -228,14 +231,8 @@ export async function modifyGroup(
228231
action === EntraGroupActions.ADD
229232
) {
230233
const netId = email.split("@")[0];
231-
const response = await fetch(
232-
`https://membership.acm.illinois.edu/api/v1/checkMembership?netId=${netId}`,
233-
);
234-
const membershipStatus = (await response.json()) as {
235-
netId: string;
236-
isPaidMember: boolean;
237-
};
238-
if (!membershipStatus["isPaidMember"]) {
234+
const isPaidMember = checkPaidMembershipFromTable(netId, dynamoClient); // we assume users have been provisioned into the table.
235+
if (!isPaidMember) {
239236
throw new EntraGroupError({
240237
message: `${netId} is not a paid member. This group requires that all members are paid members.`,
241238
group,

src/api/functions/membership.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,10 @@ import {
66
} from "@aws-sdk/client-dynamodb";
77
import { marshall } from "@aws-sdk/util-dynamodb";
88
import { genericConfig } from "common/config.js";
9-
import { FastifyBaseLogger } from "fastify";
109
import { isUserInGroup, modifyGroup } from "./entraId.js";
1110
import { EntraGroupError } from "common/errors/index.js";
1211
import { EntraGroupActions } from "common/types/iam.js";
1312

14-
export async function checkPaidMembership(
15-
endpoint: string,
16-
log: FastifyBaseLogger,
17-
netId: string,
18-
) {
19-
const membershipApiPayload = (await (
20-
await fetch(`${endpoint}?netId=${netId}`)
21-
).json()) as { netId: string; isPaidMember: boolean };
22-
log.trace(`Got Membership API Payload for ${netId}: ${membershipApiPayload}`);
23-
try {
24-
return membershipApiPayload["isPaidMember"];
25-
} catch (e: unknown) {
26-
if (!(e instanceof Error)) {
27-
log.error(
28-
"Failed to get response from membership API (unknown error type.)",
29-
);
30-
throw e;
31-
}
32-
log.error(`Failed to get response from membership API: ${e.toString()}`);
33-
throw e;
34-
}
35-
}
36-
3713
export async function checkPaidMembershipFromTable(
3814
netId: string,
3915
dynamoClient: DynamoDBClient,
@@ -140,6 +116,7 @@ export async function setPaidMembership({
140116
`${netId}@illinois.edu`,
141117
paidMemberGroup,
142118
EntraGroupActions.ADD,
119+
dynamoClient,
143120
);
144121

145122
return { updated: true };

src/api/functions/mobileWallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export async function issueAppleWalletMembershipCard(
104104
pkpass.backFields.push({
105105
label: "Verification URL",
106106
key: "iss",
107-
value: `https://membership.acm.illinois.edu/verify/${email.split("@")[0]}`,
107+
value: "https://membership.acm.illinois.edu",
108108
});
109109
} else {
110110
pkpass.backFields.push({

src/api/routes/iam.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,24 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
314314
);
315315
const addResults = await Promise.allSettled(
316316
request.body.add.map((email) =>
317-
modifyGroup(entraIdToken, email, groupId, EntraGroupActions.ADD),
317+
modifyGroup(
318+
entraIdToken,
319+
email,
320+
groupId,
321+
EntraGroupActions.ADD,
322+
fastify.dynamoClient,
323+
),
318324
),
319325
);
320326
const removeResults = await Promise.allSettled(
321327
request.body.remove.map((email) =>
322-
modifyGroup(entraIdToken, email, groupId, EntraGroupActions.REMOVE),
328+
modifyGroup(
329+
entraIdToken,
330+
email,
331+
groupId,
332+
EntraGroupActions.REMOVE,
333+
fastify.dynamoClient,
334+
),
323335
),
324336
);
325337
const response: Record<string, Record<string, string>[]> = {

src/api/routes/mobileWallet.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ValidationError,
66
} from "../../common/errors/index.js";
77
import { z } from "zod";
8-
import { checkPaidMembership } from "../functions/membership.js";
8+
import { checkPaidMembershipFromTable } from "../functions/membership.js";
99
import {
1010
AvailableSQSFunctions,
1111
SQSPayload,
@@ -62,10 +62,9 @@ const mobileWalletRoute: FastifyPluginAsync = async (fastify, _options) => {
6262
const isPaidMember =
6363
(fastify.runEnvironment === "dev" &&
6464
request.query.email === "[email protected]") ||
65-
(await checkPaidMembership(
66-
fastify.environmentConfig.MembershipApiEndpoint,
67-
request.log,
65+
(await checkPaidMembershipFromTable(
6866
request.query.email.replace("@illinois.edu", ""),
67+
fastify.dynamoClient,
6968
));
7069
if (!isPaidMember) {
7170
throw new UnauthenticatedError({

src/common/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const environmentConfig: EnvironmentConfigType = {
8585
PasskitIdentifier: "pass.org.acmuiuc.qa.membership",
8686
PasskitSerialNumber: "0",
8787
MembershipApiEndpoint:
88-
"https://infra-membership-api.aws.qa.acmuiuc.org/api/v1/checkMembership",
88+
"https://core.aws.qa.acmuiuc.org/api/v1/membership",
8989
EmailDomain: "aws.qa.acmuiuc.org",
9090
SqsQueueUrl:
9191
"https://sqs.us-east-1.amazonaws.com/427040638965/infra-core-api-sqs",
@@ -104,7 +104,7 @@ const environmentConfig: EnvironmentConfigType = {
104104
PasskitIdentifier: "pass.edu.illinois.acm.membership",
105105
PasskitSerialNumber: "0",
106106
MembershipApiEndpoint:
107-
"https://infra-membership-api.aws.acmuiuc.org/api/v1/checkMembership",
107+
"https://core.acm.illinois.edu/api/v1/membership",
108108
EmailDomain: "acm.illinois.edu",
109109
SqsQueueUrl:
110110
"https://sqs.us-east-1.amazonaws.com/298118738376/infra-core-api-sqs",

0 commit comments

Comments
 (0)