fix: allow team with same slug for diff cases (#24029)
* fix: aalow team with slug for diff cases * addressed review * fix type error * update test * addressed review * fix test * Update team.ts --------- Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
6 files changed
+201
-27
No files matched your search
@@ -466,7 +466,12 @@ const TeamProfileForm = ({ team, teamId }: TeamProfileFormProps) => {
|
||||
<p className="text-default mt-2 text-sm">{t("team_description")}</p>
|
||||
</div>
|
||||
<SectionBottomActions align="end">
|
||||
<Button color="primary" type="submit" loading={mutation.isPending} disabled={isDisabled}>
|
||||
<Button
|
||||
color="primary"
|
||||
type="submit"
|
||||
loading={mutation.isPending}
|
||||
disabled={isDisabled}
|
||||
data-testid="update-team-profile">
|
||||
{t("update")}
|
||||
</Button>
|
||||
{IS_TEAM_BILLING_ENABLED &&
|
||||
|
||||
@@ -411,4 +411,30 @@ export class TeamRepository {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async isSlugAvailableForUpdate({
|
||||
slug,
|
||||
teamId,
|
||||
parentId,
|
||||
}: {
|
||||
slug: string;
|
||||
teamId: number;
|
||||
parentId?: number | null;
|
||||
}) {
|
||||
const whereClause: Prisma.TeamWhereInput = {
|
||||
slug: {
|
||||
equals: slug,
|
||||
mode: "insensitive",
|
||||
},
|
||||
parentId: parentId ?? null,
|
||||
NOT: { id: teamId },
|
||||
};
|
||||
|
||||
const conflictingTeam = await this.prismaClient.team.findFirst({
|
||||
where: whereClause,
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
return !conflictingTeam;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { IS_TEAM_BILLING_ENABLED } from "@calcom/lib/constants";
|
||||
import type { IntervalLimit } from "@calcom/lib/intervalLimits/intervalLimitSchema";
|
||||
import { validateIntervalLimitOrder } from "@calcom/lib/intervalLimits/validateIntervalLimitOrder";
|
||||
import { uploadLogo } from "@calcom/lib/server/avatar";
|
||||
import { TeamRepository } from "@calcom/lib/server/repository/team";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { MembershipRole, RedirectType, RRTimestampBasis } from "@calcom/prisma/enums";
|
||||
@@ -39,12 +40,16 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
|
||||
}
|
||||
|
||||
if (input.slug) {
|
||||
const userConflict = await prisma.team.findMany({
|
||||
where: {
|
||||
slug: input.slug,
|
||||
},
|
||||
const orgId = ctx.user.organizationId;
|
||||
const teamRepository = new TeamRepository(prisma);
|
||||
const isSlugAvailable = await teamRepository.isSlugAvailableForUpdate({
|
||||
slug: input.slug,
|
||||
teamId: input.id,
|
||||
parentId: orgId,
|
||||
});
|
||||
if (userConflict.some((t) => t.id !== input.id)) return;
|
||||
if (!isSlugAvailable) {
|
||||
throw new TRPCError({ code: "CONFLICT", message: "Slug already in use." });
|
||||
}
|
||||
}
|
||||
|
||||
const prevTeam = await prisma.team.findUnique({
|
||||
|
||||
Reference in new issue
Block a user