fix: possible to have same slug for team and user in an organization 9985 cal 2122 (#10170)
* Added rule to validate username vs team slugs in team considering orgs too * Validate valid username vs team slugs * Add or clause to find org team and child teams
This commit is contained in:
1 parent
7bee930983
commit
fb0e89ab22
3 files changed
+130
-69
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import slugify from "./slugify";
|
||||
|
||||
/** Scenarios:
|
||||
* 1 org 1 child team:
|
||||
* 1 org 2+ child teams:
|
||||
* 1 org 1 child team and 1 child team of first child team: Is this supported?
|
||||
*/
|
||||
|
||||
export const validateUsernameInOrg = async (usernameSlug: string, teamId: number): Promise<boolean> => {
|
||||
try {
|
||||
let takenSlugs = [];
|
||||
const teamsFound = await prisma.team.findMany({
|
||||
where: {
|
||||
OR: [{ id: teamId }, { parentId: teamId }],
|
||||
},
|
||||
select: {
|
||||
slug: true,
|
||||
parentId: true,
|
||||
},
|
||||
});
|
||||
|
||||
// If only one team is found and it has a parent, then it's an child team
|
||||
// and we can use the parent id to find all the teams that belong to this org
|
||||
if (teamsFound && teamsFound.length === 1 && teamsFound[0].parentId) {
|
||||
// Let's find all the teams that belong to this org
|
||||
const childTeams = await prisma.team.findMany({
|
||||
where: {
|
||||
// With this we include org team slug and child teams slugs
|
||||
OR: [{ id: teamsFound[0].parentId }, { parentId: teamsFound[0].parentId }],
|
||||
},
|
||||
select: {
|
||||
slug: true,
|
||||
},
|
||||
});
|
||||
takenSlugs = childTeams.map((team) => team.slug);
|
||||
} else {
|
||||
takenSlugs = teamsFound.map((team) => team.slug);
|
||||
}
|
||||
|
||||
return !takenSlugs.includes(slugify(usernameSlug));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -86,7 +86,7 @@ export const inviteMemberHandler = async ({ ctx, input }: InviteMemberOptions) =
|
||||
isCalcomMember: true,
|
||||
};
|
||||
/**
|
||||
* Here we want to redirect to a differnt place if onboarding has been completed or not. This prevents the flash of going to teams -> Then to onboarding - also show a differnt email template.
|
||||
* Here we want to redirect to a different place if onboarding has been completed or not. This prevents the flash of going to teams -> Then to onboarding - also show a different email template.
|
||||
* This only changes if the user is a CAL user and has not completed onboarding and has no password
|
||||
*/
|
||||
if (!invitee.completedOnboarding && !invitee.password && invitee.identityProvider === "CAL") {
|
||||
|
||||
Reference in new issue
Block a user