chore: Chore team metadata table + isOrganization migration from metadata (#12828)
* Migration+schema changes * Remove org utils from schema * Users fixture * Auth signup handlers * checkIsOrg fn * use team.isOrganization > metadata * Add isOrganization to getTeamWithMembers query * list handler + optimise queries * Update trpc handlers to use team.isOrganization && orgSettings table * Update fixture * Fix typo in prisma.schema * next auth options use organizationSettings instread of tema metadata * Admin tooling * Updating components to use orgsettings over metadata * Add unique index + fix org lib files * validateUsername * Add a seperate unique constraint between isOrg and slug * Invite Member Logic * fix resend file * force isOrg to exist * Team settings * update createOrUpdateMemberships * fix: admin get handler * fix: team list handler - improve select * fix: update admin update handler * fix: settings layout - team get select * organziationSettings Schema + adminupdate * organziationSettings Schema + adminupdate * typefix onSubtmi * Fix:team repo throwing error if no metadata is found * fix: add onDelete to be cascade instead of restri * fix: org - team invite e2e * fix: team invites not working in subteam context * rename to organizationID * fix user fixture team names * Fix the organization created in tests * fix: update organization metadata * variable rename * Reuse isOrganization * variable rename * Remove unnecessary optional chaining * Update packages/trpc/server/routers/viewer/organizations/adminUpdate.handler.ts Co-authored-by: Hariom Balhara <[email protected]> * Update packages/trpc/server/routers/viewer/organizations/adminUpdate.handler.ts Co-authored-by: Hariom Balhara <[email protected]> * Update packages/trpc/server/routers/viewer/organizations/create.handler.ts --------- Co-authored-by: Hariom <[email protected]> Co-authored-by: Keith Williams <[email protected]>
This commit is contained in:
46 files changed
+323
-249
No files matched your search
@@ -0,0 +1,43 @@
|
||||
ALTER TABLE "Team" ADD COLUMN "isOrganization" BOOLEAN NOT NULL DEFAULT false;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "OrganizationSettings" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"organizationId" INTEGER NOT NULL,
|
||||
"isOrganizationConfigured" BOOLEAN NOT NULL DEFAULT false,
|
||||
"isOrganizationVerified" BOOLEAN NOT NULL DEFAULT false,
|
||||
"orgAutoAcceptEmail" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "OrganizationSettings_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "OrganizationSettings_organizationId_key" ON "OrganizationSettings"("organizationId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Team_slug_isOrganization_key" ON "Team"("slug", "isOrganization");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "OrganizationSettings" ADD CONSTRAINT "OrganizationSettings_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
-- -- Set team field to notify if it is an organization -> Easier than metadata.parse(X).isOrganization
|
||||
UPDATE "Team"
|
||||
SET "isOrganization" = (metadata ->> 'isOrganization')::BOOLEAN
|
||||
WHERE
|
||||
metadata ->> 'isOrganization' = 'true';
|
||||
|
||||
-- -- Insert data into org settings
|
||||
INSERT INTO "OrganizationSettings" ("organizationId", "isOrganizationConfigured", "orgAutoAcceptEmail", "isOrganizationVerified")
|
||||
SELECT
|
||||
t.id,
|
||||
(t.metadata ->> 'isOrganizationConfigured')::BOOLEAN AS "isOrganizationConfigured",
|
||||
t.metadata ->> 'orgAutoAcceptEmail' AS "orgAutoAcceptEmail",
|
||||
(t.metadata ->> 'isOrganizationVerified')::BOOLEAN AS "isOrganizationVerified"
|
||||
FROM (
|
||||
SELECT
|
||||
id,
|
||||
metadata
|
||||
FROM
|
||||
"Team"
|
||||
WHERE
|
||||
metadata ->> 'isOrganization' = 'true'
|
||||
) AS t;
|
||||
@@ -315,9 +315,21 @@ model Team {
|
||||
apiKeys ApiKey[]
|
||||
credentials Credential[]
|
||||
accessCodes AccessCode[]
|
||||
isOrganization Boolean @default(false)
|
||||
organizationSettings OrganizationSettings?
|
||||
instantMeetingTokens InstantMeetingToken[]
|
||||
|
||||
@@unique([slug, parentId])
|
||||
@@unique([slug, isOrganization])
|
||||
}
|
||||
|
||||
model OrganizationSettings {
|
||||
id Int @id @default(autoincrement())
|
||||
organization Team @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
||||
organizationId Int @unique
|
||||
isOrganizationConfigured Boolean @default(false)
|
||||
isOrganizationVerified Boolean @default(false)
|
||||
orgAutoAcceptEmail String
|
||||
}
|
||||
|
||||
enum MembershipRole {
|
||||
|
||||
@@ -332,6 +332,13 @@ export const userMetadata = z
|
||||
})
|
||||
.nullable();
|
||||
|
||||
export const orgSettingsSchema = z
|
||||
.object({
|
||||
isOrganizationVerified: z.boolean().optional(),
|
||||
isOrganizationConfigured: z.boolean().optional(),
|
||||
orgAutoAcceptEmail: z.string().optional(),
|
||||
})
|
||||
.nullable();
|
||||
export type userMetadataType = z.infer<typeof userMetadata>;
|
||||
|
||||
export const teamMetadataSchema = z
|
||||
@@ -340,10 +347,6 @@ export const teamMetadataSchema = z
|
||||
paymentId: z.string(),
|
||||
subscriptionId: z.string().nullable(),
|
||||
subscriptionItemId: z.string().nullable(),
|
||||
isOrganization: z.boolean().nullable(),
|
||||
isOrganizationVerified: z.boolean().nullable(),
|
||||
isOrganizationConfigured: z.boolean().nullable(),
|
||||
orgAutoAcceptEmail: z.string().nullable(),
|
||||
migratedToOrgFrom: z
|
||||
.object({
|
||||
teamSlug: z.string().or(z.null()).optional(),
|
||||
|
||||
Reference in new issue
Block a user