Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
add top level teams
Sara Vieira646062b51213
diff --git a/app/routes/rest/project/clone.$domain.ts b/app/routes/rest/project/clone.$domain.tsindex 9f5b37ff4b..69d58a52c8 100644--- a/app/routes/rest/project/clone.$domain.ts+++ b/app/routes/rest/project/clone.$domain.ts@@ -15,7 +15,7 @@ const ensureProject = async ({const projects = await db.project.loadManyByUserId(userId);if (projects.length !== 0) return projects[0];- return await db.project.clone(domain);+ return await db.project.clone(domain, userId);};/**diff --git a/app/shared/db/project.server.ts b/app/shared/db/project.server.tsindex dbe5da3d08..cc70e3a504 100644--- a/app/shared/db/project.server.ts+++ b/app/shared/db/project.server.ts@@ -39,7 +39,13 @@ export const loadByDomain = async (domain: string): Promise<Project | null> => {export const loadManyByUserId = async (userId: User["id"]): Promise<Array<Project>> => {- const projects = await prisma.project.findMany({ where: { userId } });+ const projects = await prisma.project.findMany({+ where: {+ User: {+ id: userId,+ },+ },+ });return projects.map(parseProject) as Project[];};@@ -75,26 +81,21 @@ export const create = async ({const tree = await db.tree.create(db.tree.createRootInstance(breakpoints));const project = await prisma.project.create({data: {- User: {- connectOrCreate: {- create: {- id: userId,- },- where: {- id: userId,- },- },- },+ userId,title,domain,devTreeId: tree.id,},});+await db.breakpoints.create(tree.id, breakpoints);return parseProject(project);};-export const clone = async (clonableDomain: string): Promise<Project> => {+export const clone = async (+ clonableDomain: string,+ userId: string+): Promise<Project> => {const clonableProject = await loadByDomain(clonableDomain);if (clonableProject === null) {throw new Error(`Not found project "${clonableDomain}"`);@@ -108,16 +109,7 @@ export const clone = async (clonableDomain: string): Promise<Project> => {const [project] = await Promise.all([prisma.project.create({data: {- User: {- connectOrCreate: {- create: {- id: clonableProject.userId,- },- where: {- id: clonableProject.userId,- },- },- },+ userId: userId,title: clonableProject.title,domain,devTreeId: tree.id,diff --git a/app/shared/db/user.server.ts b/app/shared/db/user.server.tsindex bcf121baa1..5524ec8e0a 100644--- a/app/shared/db/user.server.ts+++ b/app/shared/db/user.server.ts@@ -25,6 +25,20 @@ const genericCreateAccount = async (data: userData,});+ if (connectedUser.teamId) {+ return connectedUser;+ }++ await prisma.team.create({+ data: {+ users: {+ connect: {+ id: connectedUser.id,+ },+ },+ },+ });+return connectedUser;}@@ -35,17 +49,41 @@ const genericCreateAccount = async (});if (existingUserWithEmail) {+ if (existingUserWithEmail.teamId) {+ return existingUserWithEmail;+ }+ await prisma.team.create({+ data: {+ users: {+ connect: {+ id: existingUserWithEmail.id,+ },+ },+ },+ });+return existingUserWithEmail;}- const newUser = await prisma.user.create({+ const newTeam = await prisma.team.create({data: {- id: userId,- ...userData,+ users: {+ create: {+ id: userId,+ ...userData,+ },+ },+ },+ include: {+ users: {+ where: {+ id: userId,+ },+ },},});- return newUser;+ return newTeam.users[0];};export const createOrLoginWithGithub = async (diff --git a/package.json b/package.jsonindex db2877144e..e2fbf5bc4b 100644--- a/package.json+++ b/package.json@@ -4,7 +4,7 @@"description": "Webstudio Designer UI as a service","scripts": {"build": "remix build",- "dev": "yarn setup && node -r dotenv/config node_modules/.bin/remix dev",+ "dev": "node -r dotenv/config node_modules/.bin/remix dev","start": "remix-serve build","typecheck": "tsc -b","lint": "eslint . --ext .ts,.tsx --max-warnings 0",diff --git a/prisma/migrations/20220624214305_teams/migration.sql b/prisma/migrations/20220624214305_teams/migration.sqlnew file mode 100644index 0000000000..3c8d4f4759--- /dev/null+++ b/prisma/migrations/20220624214305_teams/migration.sql@@ -0,0 +1,21 @@+-- DropForeignKey+ALTER TABLE "Project" DROP CONSTRAINT "Project_userId_fkey";++-- AlterTable+ALTER TABLE "Project" ADD COLUMN "teamId" TEXT;++-- AlterTable+ALTER TABLE "User" ADD COLUMN "teamId" TEXT;++-- CreateTable+CREATE TABLE "Team" (+ "id" TEXT NOT NULL,++ CONSTRAINT "Team_pkey" PRIMARY KEY ("id")+);++-- AddForeignKey+ALTER TABLE "User" ADD CONSTRAINT "User_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE SET NULL ON UPDATE CASCADE;++-- AddForeignKey+ALTER TABLE "Project" ADD CONSTRAINT "Project_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE SET NULL ON UPDATE CASCADE;diff --git a/prisma/migrations/20220624215036_remove_userid/migration.sql b/prisma/migrations/20220624215036_remove_userid/migration.sqlnew file mode 100644index 0000000000..a86aec55b3--- /dev/null+++ b/prisma/migrations/20220624215036_remove_userid/migration.sql@@ -0,0 +1,8 @@+/*+ Warnings:++ - You are about to drop the column `userId` on the `Project` table. All the data in the column will be lost.++*/+-- AlterTable+ALTER TABLE "Project" DROP COLUMN "userId";diff --git a/prisma/migrations/20220624235138_users_have_projects/migration.sql b/prisma/migrations/20220624235138_users_have_projects/migration.sqlnew file mode 100644index 0000000000..e42fc55a49--- /dev/null+++ b/prisma/migrations/20220624235138_users_have_projects/migration.sql@@ -0,0 +1,15 @@+/*+ Warnings:++ - You are about to drop the column `teamId` on the `Project` table. All the data in the column will be lost.++*/+-- DropForeignKey+ALTER TABLE "Project" DROP CONSTRAINT "Project_teamId_fkey";++-- AlterTable+ALTER TABLE "Project" DROP COLUMN "teamId",+ADD COLUMN "userId" TEXT;++-- AddForeignKey+ALTER TABLE "Project" ADD CONSTRAINT "Project_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 926f331193..c7a5edb888 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -10,6 +10,12 @@ datasource db {url = env("DATABASE_URL")}+model Team {+ id String @id @default(uuid())+ users User[]++}+model User {id String @id @default(uuid())email String? @unique@@ -17,18 +23,20 @@ model User {image String?username String?createdAt DateTime @default(now())+ Team Team? @relation(fields: [teamId], references: [id])+ teamId String?projects Project[]}model Project {id String @id @default(uuid())- userId Stringtitle Stringdomain String @uniqueprodTreeId String? // exists when publisheddevTreeId StringprodTreeIdHistory String @default("[]")User User? @relation(fields: [userId], references: [id])+ userId String?}model Tree {