Skip to content

Commit 05f5cd2

Browse files
authored
Upgrade to using the new version of js-shared (#321)
This has unique IDs implemented for orgs at least so we can migrate later
1 parent ac0f400 commit 05f5cd2

File tree

16 files changed

+69
-78
lines changed

16 files changed

+69
-78
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"test:e2e-ui": "playwright test --ui"
3333
},
3434
"dependencies": {
35-
"@acm-uiuc/js-shared": "^2.4.0"
35+
"@acm-uiuc/js-shared": "^3.1.0"
3636
},
3737
"devDependencies": {
3838
"@eslint/compat": "^1.3.2",

src/api/components/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AppRoleHumanMapper, AppRoles } from "common/roles.js";
22
import { FastifyZodOpenApiSchema } from "fastify-zod-openapi";
33
import * as z from "zod/v4";
4-
import { AllOrganizationList } from "@acm-uiuc/js-shared";
4+
import { AllOrganizationNameList } from "@acm-uiuc/js-shared";
55
export {
66
illinoisSemesterId as semesterId,
77
illinoisNetId,
@@ -21,7 +21,7 @@ export const groupId = z.string().min(1).meta({
2121
});
2222

2323
export const acmCoreOrganization = z
24-
.enum(AllOrganizationList as [string, ...string[]])
24+
.enum(AllOrganizationNameList as [string, ...string[]])
2525
.meta({
2626
description: "ACM Organization",
2727
id: "AcmOrganization",

src/api/functions/organizations.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AllOrganizationList } from "@acm-uiuc/js-shared";
1+
import { AllOrganizationNameList, OrganizationName } from "@acm-uiuc/js-shared";
22
import {
33
QueryCommand,
44
ScanCommand,
@@ -154,14 +154,14 @@ export async function getUserOrgRoles({
154154
logger.warn(`Invalid role in role definition: ${JSON.stringify(item)}`);
155155
continue;
156156
}
157-
if (!AllOrganizationList.includes(org)) {
157+
if (!AllOrganizationNameList.includes(org as OrganizationName)) {
158158
logger.warn(`Invalid org in role definition: ${JSON.stringify(item)}`);
159159
continue;
160160
}
161161
cleanedRoles.push({
162162
org,
163163
role,
164-
} as { org: (typeof AllOrganizationList)[number]; role: OrgRole });
164+
} as { org: OrganizationName; role: OrgRole });
165165
}
166166
return cleanedRoles;
167167
} catch (e) {

src/api/routes/ics.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import ical, {
1414
} from "ical-generator";
1515
import moment from "moment";
1616
import { getVtimezoneComponent } from "@touch4it/ical-timezones";
17-
import { CoreOrganizationList } from "@acm-uiuc/js-shared";
17+
import { AllOrganizationNameList, OrganizationName } from "@acm-uiuc/js-shared";
1818
import { CLIENT_HTTP_CACHE_POLICY, EventRepeatOptions } from "./events.js";
1919
import rateLimiter from "api/plugins/rateLimiter.js";
2020
import { getCacheCounter } from "api/functions/cache.js";
@@ -43,7 +43,7 @@ function generateHostName(host: string) {
4343

4444
const icalPlugin: FastifyPluginAsync = async (fastify, _options) => {
4545
fastify.register(rateLimiter, {
46-
limit: CoreOrganizationList.length,
46+
limit: AllOrganizationNameList.length,
4747
duration: 30,
4848
rateLimitIdentifier: "ical",
4949
});
@@ -87,7 +87,7 @@ const icalPlugin: FastifyPluginAsync = async (fastify, _options) => {
8787
reply.header("etag", etag);
8888
}
8989
if (host) {
90-
if (!CoreOrganizationList.includes(host)) {
90+
if (!AllOrganizationNameList.includes(host as OrganizationName)) {
9191
throw new ValidationError({
9292
message: `Invalid host parameter "${host}" in path.`,
9393
});

src/api/routes/organizations.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { FastifyError, FastifyPluginAsync } from "fastify";
22
import {
3-
ACMOrganization,
4-
AllOrganizationList,
5-
OrganizationShortIdentifierMapping,
3+
AllOrganizationNameList,
4+
getOrgByName,
5+
Organizations,
66
} from "@acm-uiuc/js-shared";
77
import rateLimiter from "api/plugins/rateLimiter.js";
88
import { withRoles, withTags } from "api/components/index.js";
@@ -142,7 +142,7 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
142142
isAuthenticated = false;
143143
}
144144
}
145-
const promises = AllOrganizationList.map((x) =>
145+
const promises = AllOrganizationNameList.map((x) =>
146146
getOrgInfo({
147147
id: x,
148148
dynamoClient: fastify.dynamoClient,
@@ -161,7 +161,7 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
161161
leadsEntraGroupId: undefined,
162162
}));
163163
}
164-
const unknownIds = AllOrganizationList.filter(
164+
const unknownIds = AllOrganizationNameList.filter(
165165
(x) => !successIds.includes(x),
166166
).map((x) => ({ id: x }));
167167
return reply.send([...successOnly, ...unknownIds]);
@@ -185,7 +185,7 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
185185
"Get information about a specific ACM @ UIUC sub-organization.",
186186
params: z.object({
187187
orgId: z
188-
.enum(AllOrganizationList)
188+
.enum(AllOrganizationNameList)
189189
.meta({ description: "ACM @ UIUC organization to query." }),
190190
}),
191191
response: {
@@ -236,7 +236,7 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
236236
summary: "Set metadata for an ACM @ UIUC sub-organization.",
237237
params: z.object({
238238
orgId: z
239-
.enum(AllOrganizationList)
239+
.enum(AllOrganizationNameList)
240240
.meta({ description: "ACM @ UIUC organization to modify." }),
241241
}),
242242
body: setOrganizationMetaBody,
@@ -325,7 +325,7 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
325325
summary: "Set leads for an ACM @ UIUC sub-organization.",
326326
params: z.object({
327327
orgId: z
328-
.enum(AllOrganizationList)
328+
.enum(AllOrganizationNameList)
329329
.meta({ description: "ACM @ UIUC organization to modify." }),
330330
}),
331331
body: patchOrganizationLeadsBody,
@@ -424,7 +424,13 @@ const organizationsPlugin: FastifyPluginAsync = async (fastify, _options) => {
424424

425425
const shouldCreateNewEntraGroup = !entraGroupId;
426426
const grpDisplayName = `${request.params.orgId} Admin`;
427-
const grpShortName = `${OrganizationShortIdentifierMapping[request.params.orgId as keyof typeof OrganizationShortIdentifierMapping]}-adm`;
427+
const orgInfo = getOrgByName(request.params.orgId);
428+
if (!orgInfo) {
429+
throw new InternalServerError({
430+
message: `Organization ${request.params.orgId} could not be resolved.`,
431+
});
432+
}
433+
const grpShortName = `${orgInfo?.shortcode}-adm`;
428434

429435
// Create Entra group if needed
430436
if (shouldCreateNewEntraGroup) {

src/common/policies/events.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as z from "zod/v4";
22
import { createPolicy } from "./evaluator.js";
3-
import { CoreOrganizationList } from "@acm-uiuc/js-shared";
3+
import { AllOrganizationNameList, OrganizationName } from "@acm-uiuc/js-shared";
44
import { FastifyRequest } from "fastify";
55

66
export const hostRestrictionPolicy = createPolicy(
77
"EventsHostRestrictionPolicy",
8-
z.object({ host: z.array(z.enum(CoreOrganizationList)) }),
9-
(request: FastifyRequest & {username?: string;}, params) => {
8+
z.object({ host: z.array(z.enum(AllOrganizationNameList)) }),
9+
(request: FastifyRequest & { username?: string; }, params) => {
1010
if (request.method === "GET") {
1111
return {
1212
allowed: true,
@@ -21,7 +21,7 @@ export const hostRestrictionPolicy = createPolicy(
2121
cacheKey: null
2222
};
2323
}
24-
const typedBody = request.body as {host: string;featured: boolean;};
24+
const typedBody = request.body as { host: string; featured: boolean; };
2525
if (!typedBody || !typedBody["host"]) {
2626
return {
2727
allowed: true,
@@ -36,7 +36,7 @@ export const hostRestrictionPolicy = createPolicy(
3636
cacheKey: request.username || null
3737
};
3838
}
39-
if (!params.host.includes(typedBody["host"])) {
39+
if (!params.host.includes(typedBody["host"] as OrganizationName)) {
4040
return {
4141
allowed: false,
4242
message: `Denied by policy "EventsHostRestrictionPolicy". Host must be one of: ${params.host.toString()}.`,
@@ -49,4 +49,4 @@ export const hostRestrictionPolicy = createPolicy(
4949
cacheKey: request.username || null
5050
};
5151
}
52-
);
52+
);

src/common/roles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AllOrganizationList } from "@acm-uiuc/js-shared";
1+
import { AllOrganizationNameList } from "@acm-uiuc/js-shared";
22

33
/* eslint-disable import/prefer-default-export */
44
export const runEnvironments = ["dev", "prod"] as const;
@@ -27,7 +27,7 @@ export const PSUEDO_ROLES = [AppRoles.AT_LEAST_ONE_ORG_MANAGER]
2727
export const orgRoles = ["LEAD", "MEMBER"] as const;
2828
export type OrgRole = typeof orgRoles[number];
2929
export type OrgRoleDefinition = {
30-
org: typeof AllOrganizationList[number],
30+
org: typeof AllOrganizationNameList[number],
3131
role: OrgRole
3232
}
3333

src/common/types/organizations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AllOrganizationList } from "@acm-uiuc/js-shared";
1+
import { AllOrganizationNameList } from "@acm-uiuc/js-shared";
22
import { AppRoleHumanMapper, AppRoles } from "../roles.js";
33
import { z } from "zod/v4";
44

@@ -28,7 +28,7 @@ export const orgLinkEntry = z.object({
2828
export const enforcedOrgLeadEntry = orgLeadEntry.extend({ name: z.string().min(1), title: z.string().min(1) })
2929

3030
export const getOrganizationInfoResponse = z.object({
31-
id: z.enum(AllOrganizationList),
31+
id: z.enum(AllOrganizationNameList),
3232
description: z.optional(z.string()),
3333
website: z.optional(z.url()),
3434
leads: z.optional(z.array(orgLeadEntry)),

src/common/types/roomRequest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as z from "zod/v4";
2-
import { AllOrganizationList } from "@acm-uiuc/js-shared";
2+
import { AllOrganizationNameList } from "@acm-uiuc/js-shared";
33
import { illinoisSemesterId } from "./generic.js"
44

55
export const eventThemeOptions = [
@@ -146,7 +146,7 @@ export const roomRequestPostResponse = z.object({
146146
});
147147

148148
export const roomRequestBaseSchema = z.object({
149-
host: z.enum(AllOrganizationList),
149+
host: z.enum(AllOrganizationNameList),
150150
title: z.string().min(2, "Title must have at least 2 characters"),
151151
semester: illinoisSemesterId
152152
});

src/ui/pages/events/ManageEvent.page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { useNavigate, useParams } from "react-router-dom";
2222
import * as z from "zod/v4";
2323
import { AuthGuard } from "@ui/components/AuthGuard";
2424
import { useApi } from "@ui/util/api";
25-
import { AllOrganizationList as orgList } from "@acm-uiuc/js-shared";
25+
import { AllOrganizationNameList as orgList } from "@acm-uiuc/js-shared";
2626
import { AppRoles } from "@common/roles";
2727
import { EVENT_CACHED_DURATION } from "@common/config";
2828
import {
@@ -176,7 +176,7 @@ export const ManageEventPage: React.FC = () => {
176176
end: new Date(startDate + 3.6e6),
177177
location: "ACM Room (Siebel CS 1104)",
178178
locationLink: "https://maps.app.goo.gl/dwbBBBkfjkgj8gvA8",
179-
host: userPrimaryOrg,
179+
host: userPrimaryOrg || "",
180180
featured: false,
181181
repeats: undefined,
182182
repeatEnds: undefined,

0 commit comments

Comments
 (0)