Fixes in teams and avatar across org (#12070)

This commit is contained in:
Hariom Balhara authored and GitHub committed 2023-10-25 15:57:29 +05:30
1 parent 79c1aa60a2
commit af801df421
4 files changed
+12 -59

No files matched your search

@@ -30,6 +30,7 @@ const userSelect = Prisma.validator<Prisma.UserSelect>()({
id: true,
username: true,
name: true,
organizationId: true,
});
const userEventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
@@ -1,4 +1,3 @@
import { isOrganisationAdmin } from "@calcom/lib/server/queries/organisations";
import { prisma } from "@calcom/prisma";
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
@@ -11,42 +10,12 @@ type ListOptions = {
};
export const listHandler = async ({ ctx }: ListOptions) => {
if (ctx.user?.organization?.id) {
const membershipsWithoutParent = await prisma.membership.findMany({
where: {
userId: ctx.user.id,
team: {
parent: {
is: {
id: ctx.user?.organization?.id,
},
},
},
},
include: {
team: {
include: {
inviteTokens: true,
},
},
},
orderBy: { role: "desc" },
});
const isOrgAdmin = !!(await isOrganisationAdmin(ctx.user.id, ctx.user.organization.id)); // Org id exists here as we're inside a conditional TS complaining for some reason
return membershipsWithoutParent.map(({ team: { inviteTokens, ..._team }, ...membership }) => ({
role: membership.role,
accepted: membership.accepted,
isOrgAdmin,
..._team,
/** To prevent breaking we only return non-email attached token here, if we have one */
inviteToken: inviteTokens.find((token) => token.identifier === `invite-link-for-teamId-${_team.id}`),
}));
}
const memberships = await prisma.membership.findMany({
where: {
// Show all the teams this user belongs to regardless of the team being part of the user's org or not
// We don't want to restrict in the listing here. If we need to restrict a situation where a user is part of the org along with being part of a non-org team, we should do that instead of filtering out from here
// This became necessary when we started migrating user to Org, without migrating some teams of the user to the org
// Also, we would allow a user to be part of multiple orgs, then also it would be necessary.
userId: ctx.user.id,
},
include: {