Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ test_unit: install
terraform -chdir=terraform/envs/qa init -reconfigure -backend=false -upgrade
terraform -chdir=terraform/envs/qa fmt -check
terraform -chdir=terraform/envs/qa validate
terraform -chdir=terraform/envs/prod init -reconfigure -backend=false
terraform -chdir=terraform/envs/prod init -reconfigure -backend=false -upgrade
terraform -chdir=terraform/envs/prod fmt -check
terraform -chdir=terraform/envs/prod validate
yarn prettier
Expand All @@ -96,3 +96,7 @@ prod_health_check:
lock_terraform:
terraform -chdir=terraform/envs/qa providers lock -platform=windows_amd64 -platform=darwin_amd64 -platform=darwin_arm64 -platform=linux_amd64 -platform=linux_arm64
terraform -chdir=terraform/envs/prod providers lock -platform=windows_amd64 -platform=darwin_amd64 -platform=darwin_arm64 -platform=linux_amd64 -platform=linux_arm64

upgrade_terraform:
terraform -chdir=terraform/envs/qa init -reconfigure -backend=false -upgrade
terraform -chdir=terraform/envs/prod init -reconfigure -backend=false -upgrade
24 changes: 21 additions & 3 deletions src/ui/components/AuthGuard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { AcmAppShell, AcmAppShellProps } from "@ui/components/AppShell";
import FullScreenLoader from "@ui/components/AuthContext/LoadingScreen";
import { getRunEnvironmentConfig, ValidService } from "@ui/config";
import { useApi } from "@ui/util/api";
import { AppRoles } from "@common/roles";
import { AppRoles, OrgRoleDefinition } from "@common/roles";

export const CACHE_KEY_PREFIX = "auth_response_cache_";
const CACHE_DURATION = 2 * 60 * 60 * 1000; // 2 hours in milliseconds
const CACHE_DURATION = 30 * 60 * 1000; // 30 minutes in milliseconds

type CacheData = {
data: any; // Just the JSON response data
Expand Down Expand Up @@ -87,7 +87,6 @@ export const clearAuthCache = () => {
/**
* Retrieves the user's roles from the session cache for a specific service.
* @param service The service to check the cache for.
* @param route The authentication check route.
* @returns A promise that resolves to an array of roles, or null if not found in cache.
*/
export const getUserRoles = async (
Expand All @@ -105,6 +104,25 @@ export const getUserRoles = async (
return null;
};

/**
* Retrieves the user's org roles from the session cache for Core API.
* @returns A promise that resolves to an array of roles, or null if not found in cache.
*/
export const getCoreOrgRoles = async (): Promise<
OrgRoleDefinition[] | null
> => {
const { authCheckRoute } =
getRunEnvironmentConfig().ServiceConfiguration.core;
if (!authCheckRoute) {
throw new Error("no auth check route");
}
const cachedData = await getCachedResponse("core", authCheckRoute);
if (cachedData?.data?.orgRoles && Array.isArray(cachedData.data.orgRoles)) {
return cachedData.data.orgRoles;
}
return null;
};

export const AuthGuard: React.FC<
{
resourceDef: ResourceDefinition;
Expand Down
16 changes: 11 additions & 5 deletions src/ui/pages/organization/OrgInfo.page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { useState, useEffect } from "react";
import { Title, Stack, Container, Select } from "@mantine/core";
import { AuthGuard, getUserRoles } from "@ui/components/AuthGuard";
import {
AuthGuard,
getUserRoles,
getCoreOrgRoles,
} from "@ui/components/AuthGuard";
import { useApi } from "@ui/util/api";
import { AppRoles } from "@common/roles";
import { notifications } from "@mantine/notifications";
import { IconAlertCircle } from "@tabler/icons-react";
import FullScreenLoader from "@ui/components/AuthContext/LoadingScreen";
import { AllOrganizationNameList, OrganizationName } from "@acm-uiuc/js-shared";
import { useAuth } from "@ui/components/AuthContext";
import { ManageOrganizationForm } from "./ManageOrganizationForm";
import {
LeadEntry,
Expand All @@ -21,7 +24,6 @@ type OrganizationData = z.infer<typeof setOrganizationMetaBody>;

export const OrgInfoPage = () => {
const api = useApi("core");
const { orgRoles } = useAuth();
const [searchParams, setSearchParams] = useSearchParams();
const [manageableOrgs, setManagableOrgs] = useState<
OrganizationName[] | null
Expand Down Expand Up @@ -112,15 +114,19 @@ export const OrgInfoPage = () => {
useEffect(() => {
(async () => {
const appRoles = await getUserRoles("core");
if (appRoles?.includes(AppRoles.ALL_ORG_MANAGER)) {
const orgRoles = await getCoreOrgRoles();
if (appRoles === null || orgRoles === null) {
return;
}
if (appRoles.includes(AppRoles.ALL_ORG_MANAGER)) {
setManagableOrgs(AllOrganizationNameList);
return;
}
setManagableOrgs(
orgRoles.filter((x) => x.role === "LEAD").map((x) => x.org),
);
})();
}, [orgRoles]);
}, []);

// Update URL when selected org changes
const handleOrgChange = (org: OrganizationName | null) => {
Expand Down
22 changes: 19 additions & 3 deletions src/ui/pages/roomRequest/RoomRequestLanding.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ import {
type RoomRequestStatus,
} from "@common/types/roomRequest";
import { OrganizationName } from "@acm-uiuc/js-shared";
import { useSearchParams } from "react-router-dom";

export const ManageRoomRequestsPage: React.FC = () => {
const api = useApi("core");
const [semester, setSemester] = useState<string | null>(null); // TODO: Create a selector for this
const [semester, setSemesterState] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false);
const nextSemesters = getSemesters();
const semesterOptions = [...getPreviousSemesters(), ...nextSemesters];
const [searchParams, setSearchParams] = useSearchParams();
const setSemester = (semester: string | null) => {
setSemesterState(semester);
if (semester) {
setSearchParams({ semester });
}
};
const createRoomRequest = async (
payload: RoomRequestFormValues,
): Promise<RoomRequestPostResponse> => {
Expand All @@ -45,8 +53,16 @@ export const ManageRoomRequestsPage: React.FC = () => {
};

useEffect(() => {
setSemester(nextSemesters[0].value);
}, []);
const semeseterFromUrl = searchParams.get("semester") as string | null;
if (
semeseterFromUrl &&
semesterOptions.map((x) => x.value).includes(semeseterFromUrl)
) {
setSemester(semeseterFromUrl);
} else {
setSemester(nextSemesters[0].value);
}
}, [searchParams, semesterOptions, nextSemesters]);
return (
<AuthGuard
resourceDef={{
Expand Down
42 changes: 21 additions & 21 deletions terraform/envs/prod/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion terraform/envs/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.18.0"
version = "= 6.19.0"
}
}

Expand Down
42 changes: 21 additions & 21 deletions terraform/envs/qa/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion terraform/envs/qa/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.18.0"
version = "= 6.19.0"
}
}

Expand Down
7 changes: 5 additions & 2 deletions tests/e2e/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {
GetSecretValueCommand,
} from "@aws-sdk/client-secrets-manager";

export interface RecursiveRecord
extends Record<string, any | RecursiveRecord> {}

export const getSecretValue = async (
secretId: string,
): Promise<Record<string, string | number | boolean> | null> => {
Expand Down Expand Up @@ -71,12 +74,12 @@ export async function getUpcomingEvents() {
const data = await fetch(
"https://core.aws.qa.acmuiuc.org/api/v1/events?upcomingOnly=true",
);
return (await data.json()) as Record<string, string>[];
return (await data.json()) as RecursiveRecord[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify that API responses contain nested structures.

The return type was broadened from Record<string, string>[] to RecursiveRecord[], allowing nested objects. Ensure this change accurately reflects the actual API response structure.

Run the following script to inspect the actual API response shape:

Also applies to: 82-82


🏁 Script executed:

#!/bin/bash
# Fetch sample API responses to verify nested structure

echo "=== Upcoming Events Response ==="
curl -s "https://core.aws.qa.acmuiuc.org/api/v1/events?upcomingOnly=true" | jq 'if type == "array" then .[0] else . end | .. | select(type == "object" or type == "array") | type' | sort | uniq -c

echo -e "\n=== All Events Response ==="
curl -s "https://core.aws.qa.acmuiuc.org/api/v1/events" | jq 'if type == "array" then .[0] else . end | .. | select(type == "object" or type == "array") | type' | sort | uniq -c

Length of output: 95


I need to inspect the actual API response structure more directly. Let me gather additional information:

Now let me inspect the codebase to find the RecursiveRecord definition and verify the actual API response:


---

🏁 Script executed:

```shell
#!/bin/bash
# Find RecursiveRecord type definition
rg -n "RecursiveRecord" --type ts --type tsx -B2 -A5

Length of output: 27


🏁 Script executed:

#!/bin/bash
# Get actual API response to inspect structure
echo "=== Upcoming Events Response (pretty-printed) ==="
curl -s "https://core.aws.qa.acmuiuc.org/api/v1/events?upcomingOnly=true" | jq '.[0]' 2>/dev/null | head -50

echo -e "\n=== Response type info ==="
curl -s "https://core.aws.qa.acmuiuc.org/api/v1/events?upcomingOnly=true" | jq 'type'

Length of output: 361


Let me search for the RecursiveRecord definition and check the test file context:


🏁 Script executed:

#!/bin/bash
# Find RecursiveRecord type definition (fix file type error)
rg -n "RecursiveRecord" --type ts -B2 -A5

Length of output: 2826


🏁 Script executed:

#!/bin/bash
# Check the test file for context around the type change
cat tests/e2e/base.ts | head -100

Length of output: 2793


Revert type to more specific definition for events responses.

The events API responses are flat structures containing only primitive values (strings, booleans), not nested objects. The change to RecursiveRecord[] is overly broad and reduces type safety. Use a more specific type like Record<string, string | boolean>[] that accurately reflects the actual API response structure.

🤖 Prompt for AI Agents
In tests/e2e/base.ts around line 77, the return type is overly broad
(RecursiveRecord[]) for events API responses which are flat primitives; change
the type to a specific array of records containing only string or boolean values
by replacing RecursiveRecord[] with Record<string, string | boolean>[] so the
function returns (await data.json()) as Record<string, string | boolean>[] and
restores stricter type safety.

}

export async function getAllEvents() {
const data = await fetch("https://core.aws.qa.acmuiuc.org/api/v1/events");
return (await data.json()) as Record<string, string>[];
return (await data.json()) as RecursiveRecord[];
}

export const test = base.extend<{ becomeUser: (page: Page) => Promise<void> }>({
Expand Down
72 changes: 72 additions & 0 deletions tests/e2e/orgInfo.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { expect } from "@playwright/test";
import { RecursiveRecord, test } from "./base.js";
import { describe } from "node:test";

describe("Organization Info Tests", () => {
test("A user can update org metadata", async ({ page, becomeUser }) => {
const date = new Date().toISOString();
await becomeUser(page);
await expect(
page.locator("a").filter({ hasText: "Management Portal DEV ENV" }),
).toBeVisible();
await expect(
page.locator("a").filter({ hasText: "Organization Info" }),
).toBeVisible();
await page.locator("a").filter({ hasText: "Organization Info" }).click();
await expect(page.getByRole("heading")).toContainText(
"Manage Organization Info",
);
await page.getByRole("textbox", { name: "Select an organization" }).click();
await page.getByText("Infrastructure Committee").click();
await page.getByRole("textbox", { name: "Description" }).click();
await page
.getByRole("textbox", { name: "Description" })
.fill(`Populated by E2E tests on ${date}`);
await page
.getByRole("textbox", { name: "Website" })
.fill(`https://infra.acm.illinois.edu?date=${date}`);

const existingOtherLink = page.locator("text=Other").first();
const hasExistingOther = await existingOtherLink
.isVisible()
.catch(() => false);

if (!hasExistingOther) {
await page.getByRole("button", { name: "Add Link" }).click();
await page.getByRole("textbox", { name: "Type" }).click();
await page.getByRole("option", { name: "Other" }).click();
}

await page.getByRole("textbox", { name: "URL" }).click();
await page
.getByRole("textbox", { name: "URL" })
.fill(`https://infra.acm.illinois.edu/e2e?date=${date}`);
await page
.locator("form")
.getByRole("button", { name: "Save Changes" })
.click();
await expect(
page.getByText("Infrastructure Committee updated"),
).toBeVisible();

const data = await fetch(
`https://core.aws.qa.acmuiuc.org/api/v1/organizations?date=${date}`,
);
const json = (await data.json()) as RecursiveRecord[];
const infraEntry = json.find((x) => x.id === "Infrastructure Committee");

expect(infraEntry).toBeDefined();
expect(infraEntry?.description).toBe(`Populated by E2E tests on ${date}`);
expect(infraEntry?.website).toBe(
`https://infra.acm.illinois.edu?date=${date}`,
);

const links = infraEntry?.links as RecursiveRecord[];
expect(links).toBeDefined();
const otherLink = links.find((link) => link.type === "OTHER");
expect(otherLink).toBeDefined();
expect(otherLink?.url).toBe(
`https://infra.acm.illinois.edu/e2e?date=${date}`,
);
});
});
Loading