revoke invites and remove users from organizations

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-06-14 21:56:29 +02:00
parent 1dcd501b13
commit ee88c9e391
28 changed files with 220 additions and 90 deletions

View File

@@ -66,6 +66,38 @@ export const organizationRouter = createTRPCRouter({
});
}),
removeMember: protectedProcedure
.input(
z.object({
organizationId: z.string(),
userId: z.string(),
})
)
.mutation(async ({ input, ctx }) => {
if (ctx.session.userId === input.userId) {
throw new Error('You cannot remove yourself from the organization');
}
const organization = await clerkClient.organizations.getOrganization({
organizationId: input.organizationId,
});
if (!organization?.slug) {
throw new Error('Organization not found');
}
await db.projectAccess.deleteMany({
where: {
userId: input.userId,
organizationSlug: organization.slug,
},
});
return clerkClient.organizations.deleteOrganizationMembership({
organizationId: input.organizationId,
userId: input.userId,
});
}),
updateMemberAccess: protectedProcedure
.input(
z.object({

View File

@@ -1,7 +1,7 @@
import { z } from 'zod';
import { db } from '@openpanel/db';
import { zChartInput } from '@openpanel/validation';
import { zReportInput } from '@openpanel/validation';
import { createTRPCRouter, protectedProcedure } from '../trpc';
@@ -9,7 +9,7 @@ export const reportRouter = createTRPCRouter({
create: protectedProcedure
.input(
z.object({
report: zChartInput.omit({ projectId: true }),
report: zReportInput.omit({ projectId: true }),
dashboardId: z.string(),
})
)
@@ -38,7 +38,7 @@ export const reportRouter = createTRPCRouter({
.input(
z.object({
reportId: z.string(),
report: zChartInput.omit({ projectId: true }),
report: zReportInput.omit({ projectId: true }),
})
)
.mutation(({ input: { report, reportId } }) => {