fix(web): workflow org visibility issues
This commit is contained in:
		
							parent
							
								
									8190740abf
								
							
						
					
					
						commit
						40d9060fda
					
				@ -18,6 +18,7 @@ import {
 | 
			
		||||
import { getRelativeTime } from "@/lib/getRelativeTime";
 | 
			
		||||
import { getMachines } from "@/server/curdMachine";
 | 
			
		||||
import { findFirstTableWithVersion } from "@/server/findFirstTableWithVersion";
 | 
			
		||||
import { redirect } from "next/navigation";
 | 
			
		||||
 | 
			
		||||
export default async function Page({
 | 
			
		||||
  params,
 | 
			
		||||
 | 
			
		||||
@ -15,8 +15,8 @@ export default async function Layout({
 | 
			
		||||
        {workflow}
 | 
			
		||||
        {deployment}
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
      {runs}
 | 
			
		||||
      {children}
 | 
			
		||||
    </div>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										13
									
								
								web/src/app/(app)/workflows/[workflow_id]/page.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								web/src/app/(app)/workflows/[workflow_id]/page.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
import { findWorkflowById } from "@/server/findFirstTableWithVersion";
 | 
			
		||||
import { redirect } from "next/navigation";
 | 
			
		||||
 | 
			
		||||
export default async function Page({
 | 
			
		||||
  params,
 | 
			
		||||
}: {
 | 
			
		||||
  params: { workflow_id: string };
 | 
			
		||||
}) {
 | 
			
		||||
  const workflow = await findWorkflowById(params.workflow_id);
 | 
			
		||||
  if (!workflow) redirect("/workflows");
 | 
			
		||||
 | 
			
		||||
  return <></>;
 | 
			
		||||
}
 | 
			
		||||
@ -1,10 +1,35 @@
 | 
			
		||||
import { db } from "@/db/db";
 | 
			
		||||
import { workflowTable, workflowVersionTable } from "@/db/schema";
 | 
			
		||||
import { desc, eq } from "drizzle-orm";
 | 
			
		||||
import { auth } from "@clerk/nextjs";
 | 
			
		||||
import { and, desc, eq, isNull } from "drizzle-orm";
 | 
			
		||||
 | 
			
		||||
export async function findFirstTableWithVersion(workflow_id: string) {
 | 
			
		||||
  const { userId, orgId } = auth();
 | 
			
		||||
  if (!userId) throw new Error("No auth");
 | 
			
		||||
  return await db.query.workflowTable.findFirst({
 | 
			
		||||
    with: { versions: { orderBy: desc(workflowVersionTable.version) } },
 | 
			
		||||
    where: eq(workflowTable.id, workflow_id),
 | 
			
		||||
    where: and(
 | 
			
		||||
      eq(workflowTable.id, workflow_id),
 | 
			
		||||
      orgId
 | 
			
		||||
        ? eq(workflowTable.org_id, orgId)
 | 
			
		||||
        : and(eq(workflowTable.user_id, userId), isNull(workflowTable.org_id))
 | 
			
		||||
    ),
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function findWorkflowById(workflow_id: string) {
 | 
			
		||||
  const { userId, orgId } = auth();
 | 
			
		||||
  if (!userId) throw new Error("No auth");
 | 
			
		||||
 | 
			
		||||
  return db.query.workflowTable.findFirst({
 | 
			
		||||
    columns: {
 | 
			
		||||
      id: true,
 | 
			
		||||
    },
 | 
			
		||||
    where: and(
 | 
			
		||||
      eq(workflowTable.id, workflow_id),
 | 
			
		||||
      orgId
 | 
			
		||||
        ? eq(workflowTable.org_id, orgId)
 | 
			
		||||
        : and(eq(workflowTable.user_id, userId), isNull(workflowTable.org_id))
 | 
			
		||||
    ),
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user