fix: #16028 Org Settings - SEOIndexing,Disable Org Url (#16075)

Co-authored-by: Amit Sharma <[email protected]>
Co-authored-by: Hariom <[email protected]>
Co-authored-by: Syed Ali Shahbaz <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-11-29 10:21:14 +05:30
1 parent b5c6d7af91
commit f631abfdc4
20 files changed
+454 -23

No files matched your search

@@ -43,6 +43,12 @@ const OrgAppearanceView = ({
} = themeForm;
const [hideBrandingValue, setHideBrandingValue] = useState(currentOrg?.hideBranding ?? false);
const [allowSEOIndexingValue, setAllowSEOIndexingValue] = useState(
currentOrg?.organizationSettings?.allowSEOIndexing ?? false
);
const [orgProfileRedirectsToVerifiedDomainValue, setOrgProfileRedirectsToVerifiedDomainValue] = useState(
currentOrg?.organizationSettings?.orgProfileRedirectsToVerifiedDomain ?? false
);
const brandColorsFormMethods = useForm<BrandColorsFormValues>({
defaultValues: {
@@ -153,6 +159,36 @@ const OrgAppearanceView = ({
}}
switchContainerClassName="mt-6"
/>
<SettingsToggle
data-testid={`${currentOrg?.id}-seo-indexing-switch`}
toggleSwitchAtTheEnd={true}
title={t("seo_indexing")}
description={t("allow_seo_indexing")}
disabled={mutation.isPending}
checked={allowSEOIndexingValue}
onCheckedChange={(checked) => {
setAllowSEOIndexingValue(checked);
mutation.mutate({ allowSEOIndexing: checked });
}}
switchContainerClassName="mt-6"
/>
<SettingsToggle
toggleSwitchAtTheEnd={true}
title={t("disable_org_url_label")}
description={t("disable_org_url_description", {
orgSlug: currentOrg?.slug,
destination: currentOrg?.organizationSettings?.orgAutoAcceptEmail,
})}
disabled={mutation.isPending}
checked={orgProfileRedirectsToVerifiedDomainValue}
onCheckedChange={(checked) => {
setOrgProfileRedirectsToVerifiedDomainValue(checked);
mutation.mutate({ orgProfileRedirectsToVerifiedDomain: checked });
}}
switchContainerClassName="mt-6"
/>
</div>
);
};
@@ -101,6 +101,13 @@ export async function getTeamWithMembers(args: {
isOrganization: true,
logoUrl: true,
metadata: true,
organizationSettings: {
select: {
allowSEOIndexing: true,
orgProfileRedirectsToVerifiedDomain: true,
orgAutoAcceptEmail: true,
},
},
},
},
parentId: true,
@@ -158,6 +165,13 @@ export async function getTeamWithMembers(args: {
identifier: true,
},
},
organizationSettings: {
select: {
allowSEOIndexing: true,
orgProfileRedirectsToVerifiedDomain: true,
orgAutoAcceptEmail: true,
},
},
},
} as const;
@@ -3,6 +3,7 @@ import { IS_TEAM_BILLING_ENABLED } from "@calcom/lib/constants";
import logger from "@calcom/lib/logger";
import { safeStringify } from "@calcom/lib/safeStringify";
import { prisma } from "@calcom/prisma";
import type { OrganizationSettings } from "@calcom/prisma/client";
import { MembershipRole } from "@calcom/prisma/enums";
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
@@ -10,6 +11,11 @@ import { createAProfileForAnExistingUser } from "../../createAProfileForAnExisti
import { getParsedTeam } from "./teamUtils";
import { UserRepository } from "./user";
type MinimumOrganizationSettings = Pick<
OrganizationSettings,
"orgAutoAcceptEmail" | "orgProfileRedirectsToVerifiedDomain" | "allowSEOIndexing"
>;
type SEOOrganizationSettings = Pick<OrganizationSettings, "allowSEOIndexing">;
const orgSelect = {
id: true,
name: true,
@@ -215,6 +221,9 @@ export class OrganizationRepository {
lockEventTypeCreationForUsers: true,
adminGetsNoSlotsNotification: true,
isAdminReviewed: true,
allowSEOIndexing: true,
orgProfileRedirectsToVerifiedDomain: true,
orgAutoAcceptEmail: true,
},
});
@@ -229,6 +238,9 @@ export class OrganizationRepository {
organizationSettings: {
lockEventTypeCreationForUsers: organizationSettings?.lockEventTypeCreationForUsers,
adminGetsNoSlotsNotification: organizationSettings?.adminGetsNoSlotsNotification,
allowSEOIndexing: organizationSettings?.allowSEOIndexing,
orgProfileRedirectsToVerifiedDomain: organizationSettings?.orgProfileRedirectsToVerifiedDomain,
orgAutoAcceptEmail: organizationSettings?.orgAutoAcceptEmail,
},
user: {
role: membership?.role,
@@ -311,4 +323,38 @@ export class OrganizationRepository {
return org?.calVideoLogo;
}
static utils = {
/**
* Gets the organization setting if the team is an organization.
* If not, it gets the organization setting of the parent organization.
*/
getOrganizationSettings: (team: {
isOrganization: boolean;
organizationSettings: MinimumOrganizationSettings | null;
parent: {
organizationSettings: MinimumOrganizationSettings | null;
} | null;
}) => {
if (!team) return null;
if (team.isOrganization) return team.organizationSettings ?? null;
if (!team.parent) return null;
return team.parent.organizationSettings ?? null;
},
getOrganizationSEOSettings: (team: {
isOrganization: boolean;
organizationSettings: SEOOrganizationSettings | null;
parent: {
organizationSettings: SEOOrganizationSettings | null;
} | null;
}) => {
if (!team) return null;
if (team.isOrganization) return team.organizationSettings ?? null;
if (!team.parent) return null;
return team.parent.organizationSettings ?? null;
},
getVerifiedDomain(settings: Pick<OrganizationSettings, "orgAutoAcceptEmail">) {
return settings.orgAutoAcceptEmail;
},
};
}
+12 -1
View File
@@ -36,6 +36,10 @@ const membershipSelect = Prisma.validator<Prisma.MembershipSelect>()({
});
const log = logger.getSubLogger({ prefix: ["repository/profile"] });
const organizationSettingsSelect = Prisma.validator<Prisma.OrganizationSettingsSelect>()({
allowSEOIndexing: true,
orgProfileRedirectsToVerifiedDomain: true,
});
const organizationSelect = {
id: true,
slug: true,
@@ -45,6 +49,12 @@ const organizationSelect = {
bannerUrl: true,
isPlatform: true,
};
const organizationWithSettingsSelect = {
...organizationSelect,
organizationSettings: {
select: organizationSettingsSelect,
},
};
export enum LookupTarget {
User,
@@ -373,6 +383,7 @@ export class ProfileRepository {
organizationSettings: {
select: {
lockEventTypeCreationForUsers: true,
allowSEOIndexing: true,
},
},
members: {
@@ -416,7 +427,7 @@ export class ProfileRepository {
select: userSelect,
},
organization: {
select: organizationSelect,
select: organizationWithSettingsSelect,
},
},
});
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "OrganizationSettings" ADD COLUMN "allowSEOIndexing" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "orgProfileRedirectsToVerifiedDomain" BOOLEAN NOT NULL DEFAULT false;
+15 -11
View File
@@ -469,20 +469,24 @@ model Team {
}
model OrganizationSettings {
id Int @id @default(autoincrement())
organization Team @relation(fields: [organizationId], references: [id], onDelete: Cascade)
organizationId Int @unique
isOrganizationConfigured Boolean @default(false)
id Int @id @default(autoincrement())
organization Team @relation(fields: [organizationId], references: [id], onDelete: Cascade)
organizationId Int @unique
isOrganizationConfigured Boolean @default(false)
// It decides if new organization members can be auto-accepted or not
isOrganizationVerified Boolean @default(false)
orgAutoAcceptEmail String
lockEventTypeCreationForUsers Boolean @default(false)
adminGetsNoSlotsNotification Boolean @default(false)
isOrganizationVerified Boolean @default(false)
// It is a domain e.g "acme.com". Any email with this domain might be auto-accepted
// Also, it is the domain to which the organization profile is redirected.
orgAutoAcceptEmail String
lockEventTypeCreationForUsers Boolean @default(false)
adminGetsNoSlotsNotification Boolean @default(false)
// It decides if instance ADMIN has reviewed the organization or not.
// It is used to allow super sensitive operations like 'impersonation of Org members by Org admin'
isAdminReviewed Boolean @default(false)
dSyncData DSyncData?
isAdminAPIEnabled Boolean @default(false)
isAdminReviewed Boolean @default(false)
dSyncData DSyncData?
isAdminAPIEnabled Boolean @default(false)
allowSEOIndexing Boolean @default(false)
orgProfileRedirectsToVerifiedDomain Boolean @default(false)
}
enum MembershipRole {
@@ -91,6 +91,7 @@ export const meHandler = async ({ ctx, input }: MeOptions) => {
username: user.profile?.username ?? user.username ?? null,
profile: user.profile ?? null,
profiles: allUserEnrichedProfiles,
organizationSettings: user?.profile?.organization?.organizationSettings,
};
return {
@@ -41,6 +41,14 @@ const updateOrganizationSettings = async ({
data.adminGetsNoSlotsNotification = input.adminGetsNoSlotsNotification;
}
if (input.hasOwnProperty("allowSEOIndexing")) {
data.allowSEOIndexing = input.allowSEOIndexing;
}
if (input.hasOwnProperty("orgProfileRedirectsToVerifiedDomain")) {
data.orgProfileRedirectsToVerifiedDomain = input.orgProfileRedirectsToVerifiedDomain;
}
// If no settings values have changed lets skip this update
if (Object.keys(data).length === 0) return;
@@ -131,7 +139,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
if (!prevOrganisation) throw new TRPCError({ code: "NOT_FOUND", message: "Organisation not found." });
const { mergeMetadata } = getMetadataHelpers(teamMetadataSchema.unwrap(), prevOrganisation.metadata);
const { mergeMetadata } = getMetadataHelpers(teamMetadataSchema.unwrap(), prevOrganisation.metadata ?? {});
const data: Prisma.TeamUpdateArgs["data"] = {
logoUrl: input.logoUrl,
@@ -31,6 +31,8 @@ export const ZUpdateInputSchema = z.object({
lockEventTypeCreation: z.boolean().optional(),
lockEventTypeCreationOptions: z.enum(["DELETE", "HIDE"]).optional(),
adminGetsNoSlotsNotification: z.boolean().optional(),
allowSEOIndexing: z.boolean().optional(),
orgProfileRedirectsToVerifiedDomain: z.boolean().optional(),
});
export type TUpdateInputSchema = z.infer<typeof ZUpdateInputSchema>;