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

@@ -7,8 +7,8 @@ import type {
IChartBreakdown,
IChartEvent,
IChartEventFilter,
IChartInput,
IChartLineType,
IChartProps,
IChartRange,
} from '@openpanel/validation';
@@ -46,7 +46,7 @@ export function transformReportEvent(
export function transformReport(
report: DbReport
): IChartInput & { id: string } {
): IChartProps & { id: string } {
return {
id: report.id,
projectId: report.projectId,

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 } }) => {

View File

@@ -60,9 +60,7 @@ export const zMetric = z.enum(objectToZodEnums(metrics));
export const zRange = z.enum(objectToZodEnums(timeWindows));
export const zChartInput = z.object({
name: z.string().default(''),
chartType: zChartType.default('linear'),
lineType: zLineType.default('monotone'),
interval: zTimeInterval.default('day'),
events: zChartEvents,
breakdowns: zChartBreakdowns.default([]),
@@ -70,13 +68,17 @@ export const zChartInput = z.object({
previous: z.boolean().default(false),
formula: z.string().optional(),
metric: zMetric.default('sum'),
unit: z.string().optional(),
previousIndicatorInverted: z.boolean().optional(),
projectId: z.string(),
startDate: z.string().nullish(),
endDate: z.string().nullish(),
});
export const zReportInput = zChartInput.extend({
name: z.string(),
lineType: zLineType,
unit: z.string().optional(),
});
export const zInviteUser = z.object({
email: z.string().email(),
organizationSlug: z.string(),

View File

@@ -8,10 +8,17 @@ import type {
zLineType,
zMetric,
zRange,
zReportInput,
zTimeInterval,
} from './index';
export type IChartInput = z.infer<typeof zChartInput>;
export type IChartProps = z.infer<typeof zReportInput> & {
name: string;
lineType: IChartLineType;
unit?: string;
previousIndicatorInverted?: boolean;
};
export type IChartEvent = z.infer<typeof zChartEvent>;
export type IChartEventFilter = IChartEvent['filters'][number];
export type IChartEventFilterValue =