chore(root): rename organizationSlug to organizationId (#91)
This commit is contained in:
committed by
GitHub
parent
0221948aab
commit
cd16ac878d
@@ -12,7 +12,7 @@ export async function getProjectAccess({
|
||||
try {
|
||||
// Check if user has access to the project
|
||||
const project = await getProjectById(projectId);
|
||||
if (!project?.organizationSlug) {
|
||||
if (!project?.organizationId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@ export async function getProjectAccess({
|
||||
db.projectAccess.findMany({
|
||||
where: {
|
||||
userId,
|
||||
organizationId: project.organizationSlug,
|
||||
organizationId: project.organizationId,
|
||||
},
|
||||
}),
|
||||
db.member.findFirst({
|
||||
where: {
|
||||
organizationId: project.organizationSlug,
|
||||
organizationId: project.organizationId,
|
||||
userId,
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -46,7 +46,7 @@ export const clientRouter = createTRPCRouter({
|
||||
z.object({
|
||||
name: z.string(),
|
||||
projectId: z.string(),
|
||||
organizationSlug: z.string(),
|
||||
organizationId: z.string(),
|
||||
cors: z.string().nullable(),
|
||||
crossDomain: z.boolean().optional(),
|
||||
type: z.enum(['read', 'write', 'root']).optional(),
|
||||
@@ -55,8 +55,7 @@ export const clientRouter = createTRPCRouter({
|
||||
.mutation(async ({ input }) => {
|
||||
const secret = `sec_${crypto.randomBytes(10).toString('hex')}`;
|
||||
const data: Prisma.ClientCreateArgs['data'] = {
|
||||
organizationSlug: input.organizationSlug,
|
||||
organizationId: input.organizationSlug,
|
||||
organizationId: input.organizationId,
|
||||
projectId: input.projectId,
|
||||
name: input.name,
|
||||
type: input.type ?? 'write',
|
||||
|
||||
@@ -50,7 +50,6 @@ export const dashboardRouter = createTRPCRouter({
|
||||
data: {
|
||||
id: await getId('dashboard', input.name),
|
||||
projectId: input.projectId,
|
||||
organizationSlug: project.organizationId!,
|
||||
organizationId: project.organizationId,
|
||||
name: input.name,
|
||||
},
|
||||
|
||||
@@ -13,8 +13,8 @@ async function createOrGetOrganization(
|
||||
input: z.infer<typeof zOnboardingProject>,
|
||||
userId: string,
|
||||
) {
|
||||
if (input.organizationSlug) {
|
||||
return await getOrganizationBySlug(input.organizationSlug);
|
||||
if (input.organizationId) {
|
||||
return await getOrganizationBySlug(input.organizationId);
|
||||
}
|
||||
|
||||
if (input.organization) {
|
||||
@@ -92,7 +92,6 @@ export const onboardingRouter = createTRPCRouter({
|
||||
data: {
|
||||
id: await getId('project', input.project),
|
||||
name: input.project,
|
||||
organizationSlug: organization.id,
|
||||
organizationId: organization.id,
|
||||
types,
|
||||
},
|
||||
@@ -102,7 +101,6 @@ export const onboardingRouter = createTRPCRouter({
|
||||
const client = await db.client.create({
|
||||
data: {
|
||||
name: `${project.name} Client`,
|
||||
organizationSlug: organization.id,
|
||||
organizationId: organization.id,
|
||||
projectId: project.id,
|
||||
type: 'write',
|
||||
|
||||
@@ -42,7 +42,7 @@ export const organizationRouter = createTRPCRouter({
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const access = await getOrganizationAccess({
|
||||
userId: ctx.session.userId,
|
||||
organizationId: input.organizationSlug,
|
||||
organizationId: input.organizationId,
|
||||
});
|
||||
|
||||
if (access?.role !== 'org:admin') {
|
||||
@@ -72,7 +72,7 @@ export const organizationRouter = createTRPCRouter({
|
||||
return db.member.create({
|
||||
data: {
|
||||
email,
|
||||
organizationId: input.organizationSlug,
|
||||
organizationId: input.organizationId,
|
||||
role: input.role,
|
||||
invitedById: ctx.session.userId,
|
||||
meta: {
|
||||
@@ -175,7 +175,7 @@ export const organizationRouter = createTRPCRouter({
|
||||
.input(
|
||||
z.object({
|
||||
userId: z.string(),
|
||||
organizationSlug: z.string(),
|
||||
organizationId: z.string(),
|
||||
access: z.array(z.string()),
|
||||
}),
|
||||
)
|
||||
@@ -186,7 +186,7 @@ export const organizationRouter = createTRPCRouter({
|
||||
|
||||
const access = await getOrganizationAccess({
|
||||
userId: ctx.session.userId,
|
||||
organizationId: input.organizationSlug,
|
||||
organizationId: input.organizationId,
|
||||
});
|
||||
|
||||
if (access?.role !== 'org:admin') {
|
||||
@@ -197,14 +197,13 @@ export const organizationRouter = createTRPCRouter({
|
||||
db.projectAccess.deleteMany({
|
||||
where: {
|
||||
userId: input.userId,
|
||||
organizationId: input.organizationSlug,
|
||||
organizationId: input.organizationId,
|
||||
},
|
||||
}),
|
||||
db.projectAccess.createMany({
|
||||
data: input.access.map((projectId) => ({
|
||||
userId: input.userId,
|
||||
organizationSlug: input.organizationSlug,
|
||||
organizationId: input.organizationSlug,
|
||||
organizationId: input.organizationId,
|
||||
projectId: projectId,
|
||||
level: 'read',
|
||||
})),
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
db,
|
||||
getId,
|
||||
getProjectByIdCached,
|
||||
getProjectsByOrganizationSlug,
|
||||
getProjectsByOrganizationId,
|
||||
} from '@openpanel/db';
|
||||
|
||||
import { getProjectAccess } from '../access';
|
||||
@@ -15,12 +15,12 @@ export const projectRouter = createTRPCRouter({
|
||||
list: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
organizationSlug: z.string().nullable(),
|
||||
organizationId: z.string().nullable(),
|
||||
}),
|
||||
)
|
||||
.query(async ({ input: { organizationSlug } }) => {
|
||||
if (organizationSlug === null) return [];
|
||||
return getProjectsByOrganizationSlug(organizationSlug);
|
||||
.query(async ({ input: { organizationId } }) => {
|
||||
if (organizationId === null) return [];
|
||||
return getProjectsByOrganizationId(organizationId);
|
||||
}),
|
||||
|
||||
update: protectedProcedure
|
||||
@@ -54,15 +54,14 @@ export const projectRouter = createTRPCRouter({
|
||||
.input(
|
||||
z.object({
|
||||
name: z.string().min(1),
|
||||
organizationSlug: z.string(),
|
||||
organizationId: z.string(),
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ input: { name, organizationSlug } }) => {
|
||||
.mutation(async ({ input: { name, organizationId } }) => {
|
||||
return db.project.create({
|
||||
data: {
|
||||
id: await getId('project', name),
|
||||
organizationSlug: organizationSlug,
|
||||
organizationId: organizationSlug,
|
||||
organizationId,
|
||||
name: name,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -17,8 +17,7 @@ export const shareRouter = createTRPCRouter({
|
||||
},
|
||||
create: {
|
||||
id: uid.rnd(),
|
||||
organizationSlug: input.organizationSlug,
|
||||
organizationId: input.organizationSlug,
|
||||
organizationId: input.organizationId,
|
||||
projectId: input.projectId,
|
||||
public: input.public,
|
||||
password: input.password || null,
|
||||
|
||||
@@ -88,17 +88,6 @@ const enforceAccess = t.middleware(async ({ ctx, next, rawInput }) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (has('organizationSlug', rawInput)) {
|
||||
const access = await getOrganizationAccessCached({
|
||||
userId: ctx.session.userId!,
|
||||
organizationId: rawInput.organizationSlug as string,
|
||||
});
|
||||
|
||||
if (!access) {
|
||||
throw TRPCAccessError('You do not have access to this organization');
|
||||
}
|
||||
}
|
||||
|
||||
return next();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user