Skip to content
Closed
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 packages/platform/examples/base/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ export default function App({ Component, pageProps }: AppProps) {
return (
<div className={`${poppins.className} text-black`}>
{options.length > 0 && (
<Select defaultValue={selectedUser} onChange={setSelectedUser} options={options} />
<Select
defaultValue={options.find((opt: TUser | null) => opt?.email.includes("lauris"))}
onChange={(opt: TUser | null) => setSelectedUser(opt)}
options={options}
Comment on lines +87 to +89
Copy link
Contributor Author

Choose a reason for hiding this comment

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

default value was not selected properly

/>
)}
<CalProvider
accessToken={accessToken}
Expand Down
25 changes: 15 additions & 10 deletions packages/platform/examples/base/src/pages/api/managed-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
throw new Error("Failed to create team. Probably your platform team does not have required plan.");
}

await createOrgTeamMembershipMember(+organizationId, team.id, managedUserResponseOne.user.id);
await createOrgTeamMembershipMember(+organizationId, team.id, managedUserResponseTwo.user.id);
await createOrgTeamMembershipMember(+organizationId, team.id, managedUserResponseThree.user.id);
await createOrgTeamMembershipMember(+organizationId, team.id, managedUserResponseFour.user.id);
await createOrgTeamMembershipMember(+organizationId, team.id, managedUserResponseOne.user.id, "MEMBER");
await createOrgTeamMembershipMember(+organizationId, team.id, managedUserResponseTwo.user.id, "MEMBER");
await createOrgTeamMembershipMember(+organizationId, team.id, managedUserResponseThree.user.id, "MEMBER");
await createOrgTeamMembershipMember(+organizationId, team.id, managedUserResponseFour.user.id, "MEMBER");

await createCollectiveEventType(+organizationId, team.id, [
managedUserResponseOne.user.id,
Expand All @@ -133,10 +133,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
await createOrgMembershipAdmin(+organizationId, managedUserResponseFive.user.id);

return res.status(200).json({
id: managedUserResponseOne?.user?.id,
email: (managedUserResponseOne.user.email as string) ?? "",
username: (managedUserResponseOne.user.username as string) ?? "",
accessToken: (managedUserResponseOne.accessToken as string) ?? "",
id: managedUserResponseFive?.user?.id,
email: (managedUserResponseFive.user.email as string) ?? "",
username: (managedUserResponseFive.user.username as string) ?? "",
accessToken: (managedUserResponseFive.accessToken as string) ?? "",
Comment on lines +136 to +139
Copy link
Contributor Author

Choose a reason for hiding this comment

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

managed user 5 is the admin with permission to create team event types

Comment on lines +136 to +139
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

Guard against undefined managed user response to avoid runtime crash; then return non-null fields.

managedUserResponseFive can be undefined if the upstream call fails; accessing .user.email or .accessToken will throw. Add a guard and use non-optional access in the response.

-    id: managedUserResponseFive?.user?.id,
-    email: (managedUserResponseFive.user.email as string) ?? "",
-    username: (managedUserResponseFive.user.username as string) ?? "",
-    accessToken: (managedUserResponseFive.accessToken as string) ?? "",
+    id: managedUserResponseFive.user.id,
+    email: managedUserResponseFive.user.email as string,
+    username: managedUserResponseFive.user.username as string,
+    accessToken: managedUserResponseFive.accessToken as string,

Add this guard just above the return (outside the hunk):

if (
  !managedUserResponseFive ||
  !managedUserResponseFive.user?.id ||
  !managedUserResponseFive.user?.email ||
  !managedUserResponseFive.user?.username ||
  !managedUserResponseFive.accessToken
) {
  throw new Error("Failed to create/select Lauris managed user: missing required fields.");
}
🤖 Prompt for AI Agents
In packages/platform/examples/base/src/pages/api/managed-user.ts around lines
136 to 139, the code dereferences managedUserResponseFive and its nested fields
without checking for undefined, risking runtime crashes; add a guard just above
the return that verifies managedUserResponseFive is defined and that
managedUserResponseFive.user.id, managedUserResponseFive.user.email,
managedUserResponseFive.user.username, and managedUserResponseFive.accessToken
are all present, and throw a clear Error if any are missing so the subsequent
return can safely use non-optional field access.

});
}

Expand Down Expand Up @@ -165,7 +165,12 @@ async function createTeam(orgId: number, name: string) {
return body.data;
}

async function createOrgTeamMembershipMember(orgId: number, teamId: number, userId: number) {
async function createOrgTeamMembershipMember(
orgId: number,
teamId: number,
userId: number,
role: "MEMBER" | "ADMIN" = "MEMBER"
) {
await fetch(
// eslint-disable-next-line turbo/no-undeclared-env-vars
`${process.env.NEXT_PUBLIC_CALCOM_API_URL ?? ""}/organizations/${orgId}/teams/${teamId}/memberships`,
Expand All @@ -182,7 +187,7 @@ async function createOrgTeamMembershipMember(orgId: number, teamId: number, user
body: JSON.stringify({
userId,
accepted: true,
role: "MEMBER",
role,
}),
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { test, expect } from "@playwright/test";
import { generateRandomText } from "../../src/lib/generateRandomText";

// eslint-disable-next-line playwright/no-skipped-test
test.skip("create team event using CreateTeamEventTypeAtom", async ({ page }) => {
test("create team event using CreateTeamEventTypeAtom", async ({ page }) => {
await page.goto("/");

await page.goto("/event-types");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const createHandler = async ({ ctx, input }: CreateOptions) => {

if (ctx.user.organizationId) {
try {
const orgPermissions = await getResourcePermissions({
/* const orgPermissions = await getResourcePermissions({
userId,
teamId: ctx.user.organizationId,
resource: Resource.EventType,
Expand All @@ -71,7 +71,8 @@ export const createHandler = async ({ ctx, input }: CreateOptions) => {
},
},
});
hasOrgEventTypeCreatePermission = orgPermissions.canCreate;
hasOrgEventTypeCreatePermission = orgPermissions.canCreate; */
hasOrgEventTypeCreatePermission = isOrgAdmin;
} catch (error) {
// If PBAC check fails, fall back to isOrgAdmin
hasOrgEventTypeCreatePermission = isOrgAdmin;
Expand Down
Loading