Skip to content

Commit e251c67

Browse files
committed
stash pop merge conflicts
1 parent 633d744 commit e251c67

File tree

4 files changed

+47
-48
lines changed

4 files changed

+47
-48
lines changed

src/api/functions/entraId.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export async function listGroupMembers(
366366
* @throws {EntraUserError} If fetching the user profile fails.
367367
* @returns {Promise<UserProfileDataBase>} The user's profile information.
368368
*/
369-
export async function getUserProfile(
369+
export async function getUserProflile(
370370
token: string,
371371
email: string,
372372
): Promise<UserProfileDataBase> {

src/api/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import mobileWalletRoute from "./routes/mobileWallet.js";
2626
import stripeRoutes from "./routes/stripe.js";
2727
import membershipPlugin from "./routes/membership.js";
2828
import path from "path"; // eslint-disable-line import/no-nodejs-modules
29+
import sigleadRoutes from "./routes/siglead.js";
2930

3031
dotenv.config();
3132

@@ -133,6 +134,7 @@ async function init(prettyPrint: boolean = false) {
133134
api.register(ticketsPlugin, { prefix: "/tickets" });
134135
api.register(mobileWalletRoute, { prefix: "/mobileWallet" });
135136
api.register(stripeRoutes, { prefix: "/stripe" });
137+
api.register(sigleadRoutes, { prefix: "/siglead" });
136138
if (app.runEnvironment === "dev") {
137139
api.register(vendingPlugin, { prefix: "/vending" });
138140
}

src/api/routes/siglead.ts

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FastifyPluginAsync } from "fastify";
1+
import { FastifyInstance, FastifyPluginAsync } from "fastify";
22
import { allAppRoles, AppRoles } from "../../common/roles.js";
33
import { zodToJsonSchema } from "zod-to-json-schema";
44
import {
@@ -38,48 +38,42 @@ import {
3838
AUTH_DECISION_CACHE_SECONDS,
3939
getGroupRoles,
4040
} from "../functions/authorization.js";
41+
import { OrganizationList } from "common/orgs.js";
42+
import { z } from "zod";
43+
44+
const OrganizationListEnum = z.enum(OrganizationList as [string, ...string[]]);
45+
export type Org = z.infer<typeof OrganizationListEnum>;
46+
47+
type Member = { name: string; email: string };
48+
type OrgMembersResponse = { org: Org; members: Member[] };
49+
50+
// const groupMappings = getRunEnvironmentConfig().KnownGroupMappings;
51+
// const groupOptions = Object.entries(groupMappings).map(([key, value]) => ({
52+
// label: userGroupMappings[key as keyof KnownGroups] || key,
53+
// value: `${key}_${value}`, // to ensure that the same group for multiple roles still renders
54+
// }));
4155

4256
const sigleadRoutes: FastifyPluginAsync = async (fastify, _options) => {
4357
fastify.get<{
44-
Querystring: { groupId: string };
45-
}>(
46-
"/groups/:groupId/roles",
47-
{
48-
schema: {
49-
querystring: {
50-
type: "object",
51-
properties: {
52-
groupId: {
53-
type: "string",
54-
},
55-
},
56-
},
58+
Reply: OrgMembersResponse[];
59+
}>("/groups", async (request, reply) => {
60+
const entraIdToken = await getEntraIdToken(
61+
{
62+
smClient: fastify.secretsManagerClient,
63+
dynamoClient: fastify.dynamoClient,
5764
},
58-
onRequest: async (request, reply) => {
59-
await fastify.authorize(request, reply, [AppRoles.IAM_ADMIN]);
60-
},
61-
},
62-
async (request, reply) => {
63-
try {
64-
const groupId = (request.params as Record<string, string>).groupId;
65-
const roles = await getGroupRoles(
66-
fastify.dynamoClient,
67-
fastify,
68-
groupId,
69-
);
70-
return reply.send(roles);
71-
} catch (e: unknown) {
72-
if (e instanceof BaseError) {
73-
throw e;
74-
}
65+
fastify.environmentConfig.AadValidClientId,
66+
);
67+
68+
const data = await Promise.all(
69+
OrganizationList.map(async (org) => {
70+
const members: Member[] = await listGroupMembers(entraIdToken, org);
71+
return { org, members } as OrgMembersResponse;
72+
}),
73+
);
7574

76-
request.log.error(e);
77-
throw new DatabaseFetchError({
78-
message: "An error occurred finding the group role mapping.",
79-
});
80-
}
81-
},
82-
);
75+
reply.status(200).send(data);
76+
});
8377

8478
// fastify.patch<{ Body: ProfilePatchRequest }>(
8579
// "/profile",

src/common/roles.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
export const runEnvironments = ["dev", "prod"] as const;
33
export type RunEnvironment = (typeof runEnvironments)[number];
44
export enum AppRoles {
5-
EVENTS_MANAGER = "manage:events",
6-
SIGLEAD_MANAGER = "manage:siglead",
7-
TICKETS_SCANNER = "scan:tickets",
8-
TICKETS_MANAGER = "manage:tickets",
9-
IAM_ADMIN = "admin:iam",
10-
IAM_INVITE_ONLY = "invite:iam",
11-
STRIPE_LINK_CREATOR = "create:stripeLink",
12-
BYPASS_OBJECT_LEVEL_AUTH = "bypass:ola",
5+
EVENTS_MANAGER = "manage:events",
6+
SIGLEAD_MANAGER = "manage:siglead",
7+
TICKETS_SCANNER = "scan:tickets",
8+
TICKETS_MANAGER = "manage:tickets",
9+
IAM_ADMIN = "admin:iam",
10+
IAM_INVITE_ONLY = "invite:iam",
11+
STRIPE_LINK_CREATOR = "create:stripeLink",
12+
BYPASS_OBJECT_LEVEL_AUTH = "bypass:ola",
1313
}
1414
export const allAppRoles = Object.values(AppRoles).filter(
15-
(value) => typeof value === "string",
15+
(value) => typeof value === "string",
1616
);
17+
18+
19+

0 commit comments

Comments
 (0)