diff --git a/src/server/trpc/routers/feed/index.ts b/src/server/trpc/routers/feed/index.ts index 7e5c24c..d6b095c 100644 --- a/src/server/trpc/routers/feed/index.ts +++ b/src/server/trpc/routers/feed/index.ts @@ -3,7 +3,7 @@ import { OpenApiMetaInfo, publicProcedure, router, - workspaceOwnerProcedure, + workspaceAdminProcedure, workspaceProcedure, } from '../../trpc.js'; import { OPENAPI_TAG } from '../../../utils/const.js'; @@ -203,7 +203,7 @@ export const feedRouter = router({ nextCursor, }; }), - createChannel: workspaceOwnerProcedure + createChannel: workspaceAdminProcedure .meta( buildFeedOpenapi({ method: 'POST', @@ -253,7 +253,7 @@ export const feedRouter = router({ notificationIds: channel?.notifications.map((n) => n.id), }; }), - deleteChannel: workspaceOwnerProcedure + deleteChannel: workspaceAdminProcedure .meta( buildFeedOpenapi({ method: 'DELETE', @@ -313,7 +313,7 @@ export const feedRouter = router({ return event; }), - archiveEvent: workspaceOwnerProcedure + archiveEvent: workspaceAdminProcedure .meta( buildFeedPublicOpenapi({ method: 'PATCH', @@ -340,7 +340,7 @@ export const feedRouter = router({ }, }); }), - unarchiveEvent: workspaceOwnerProcedure + unarchiveEvent: workspaceAdminProcedure .meta( buildFeedPublicOpenapi({ method: 'PATCH', @@ -367,7 +367,7 @@ export const feedRouter = router({ }, }); }), - clearAllArchivedEvents: workspaceOwnerProcedure + clearAllArchivedEvents: workspaceAdminProcedure .meta( buildFeedPublicOpenapi({ method: 'PATCH', diff --git a/src/server/trpc/routers/monitor.ts b/src/server/trpc/routers/monitor.ts index 9bc4614..6e894e7 100644 --- a/src/server/trpc/routers/monitor.ts +++ b/src/server/trpc/routers/monitor.ts @@ -2,7 +2,7 @@ import { OpenApiMetaInfo, publicProcedure, router, - workspaceOwnerProcedure, + workspaceAdminProcedure, workspaceProcedure, } from '../trpc.js'; import { prisma } from '../../model/_client.js'; @@ -113,7 +113,7 @@ export const monitorRouter = router({ return getMonitorPublicInfos(monitorIds); }), - upsert: workspaceOwnerProcedure + upsert: workspaceAdminProcedure .meta( buildMonitorOpenapi({ method: 'POST', @@ -163,7 +163,7 @@ export const monitorRouter = router({ return monitor; }), - delete: workspaceOwnerProcedure + delete: workspaceAdminProcedure .meta( buildMonitorOpenapi({ method: 'DELETE', @@ -181,7 +181,7 @@ export const monitorRouter = router({ return monitorManager.delete(workspaceId, monitorId); }), - testCustomScript: workspaceOwnerProcedure + testCustomScript: workspaceAdminProcedure .input( z.object({ code: z.string(), @@ -235,7 +235,7 @@ export const monitorRouter = router({ new Date(endAt) ); }), - changeActive: workspaceOwnerProcedure + changeActive: workspaceAdminProcedure .meta( buildMonitorOpenapi({ method: 'PATCH', @@ -462,7 +462,7 @@ export const monitorRouter = router({ return list; }), - clearEvents: workspaceOwnerProcedure + clearEvents: workspaceAdminProcedure .meta( buildMonitorOpenapi({ method: 'DELETE', @@ -489,7 +489,7 @@ export const monitorRouter = router({ return count; }), - clearData: workspaceOwnerProcedure + clearData: workspaceAdminProcedure .meta( buildMonitorOpenapi({ method: 'DELETE', @@ -585,7 +585,7 @@ export const monitorRouter = router({ }, }); }), - createPage: workspaceOwnerProcedure + createPage: workspaceAdminProcedure .meta( buildMonitorOpenapi({ method: 'POST', @@ -655,7 +655,7 @@ export const monitorRouter = router({ return page; }), - editPage: workspaceOwnerProcedure + editPage: workspaceAdminProcedure .meta( buildMonitorOpenapi({ method: 'PATCH', @@ -733,7 +733,7 @@ export const monitorRouter = router({ return page; }), - deletePage: workspaceOwnerProcedure + deletePage: workspaceAdminProcedure .meta( buildMonitorOpenapi({ method: 'DELETE', diff --git a/src/server/trpc/routers/notification.ts b/src/server/trpc/routers/notification.ts index d1dbd1f..6579ea1 100644 --- a/src/server/trpc/routers/notification.ts +++ b/src/server/trpc/routers/notification.ts @@ -1,6 +1,6 @@ import { router, - workspaceOwnerProcedure, + workspaceAdminProcedure, workspaceProcedure, } from '../trpc.js'; import { z } from 'zod'; @@ -35,7 +35,7 @@ export const notificationRouter = router({ token.image('https://tianji.msgbyte.com/img/social-card.png'), ]); }), - upsert: workspaceOwnerProcedure + upsert: workspaceAdminProcedure .input( z.object({ id: z.string().optional(), @@ -72,7 +72,7 @@ export const notificationRouter = router({ }); } }), - delete: workspaceOwnerProcedure + delete: workspaceAdminProcedure .input( z.object({ id: z.string(), diff --git a/src/server/trpc/routers/serverStatus.ts b/src/server/trpc/routers/serverStatus.ts index 555c9a6..cb902b5 100644 --- a/src/server/trpc/routers/serverStatus.ts +++ b/src/server/trpc/routers/serverStatus.ts @@ -1,8 +1,8 @@ -import { router, workspaceOwnerProcedure } from '../trpc.js'; +import { router, workspaceAdminProcedure } from '../trpc.js'; import { clearOfflineServerStatus } from '../../model/serverStatus.js'; export const serverStatusRouter = router({ - clearOfflineServerStatus: workspaceOwnerProcedure.mutation( + clearOfflineServerStatus: workspaceAdminProcedure.mutation( async ({ input }) => { const workspaceId = input.workspaceId; diff --git a/src/server/trpc/routers/survey.ts b/src/server/trpc/routers/survey.ts index 8fe1f9f..1716a88 100644 --- a/src/server/trpc/routers/survey.ts +++ b/src/server/trpc/routers/survey.ts @@ -3,7 +3,7 @@ import { OpenApiMetaInfo, publicProcedure, router, - workspaceOwnerProcedure, + workspaceAdminProcedure, workspaceProcedure, } from '../trpc.js'; import { OPENAPI_TAG } from '../../utils/const.js'; @@ -220,7 +220,7 @@ export const surveyRouter = router({ return 'success'; }), - create: workspaceOwnerProcedure + create: workspaceAdminProcedure .meta( buildSurveyOpenapi({ method: 'POST', @@ -252,7 +252,7 @@ export const surveyRouter = router({ return res; }), - update: workspaceOwnerProcedure + update: workspaceAdminProcedure .meta( buildSurveyOpenapi({ method: 'PATCH', @@ -294,7 +294,7 @@ export const surveyRouter = router({ return res; }), - delete: workspaceOwnerProcedure + delete: workspaceAdminProcedure .meta( buildSurveyOpenapi({ method: 'DELETE', diff --git a/src/server/trpc/routers/telemetry.ts b/src/server/trpc/routers/telemetry.ts index 9105eb5..219ed1f 100644 --- a/src/server/trpc/routers/telemetry.ts +++ b/src/server/trpc/routers/telemetry.ts @@ -2,7 +2,7 @@ import { z } from 'zod'; import { OpenApiMetaInfo, router, - workspaceOwnerProcedure, + workspaceAdminProcedure, workspaceProcedure, } from '../trpc.js'; import { @@ -130,7 +130,7 @@ export const telemetryRouter = router({ return count; }), - upsert: workspaceOwnerProcedure + upsert: workspaceAdminProcedure .meta( buildTelemetryOpenapi({ method: 'POST', @@ -166,7 +166,7 @@ export const telemetryRouter = router({ }); } }), - delete: workspaceOwnerProcedure + delete: workspaceAdminProcedure .meta( buildTelemetryOpenapi({ method: 'POST', diff --git a/src/server/trpc/routers/website.ts b/src/server/trpc/routers/website.ts index 3e08237..5e54db0 100644 --- a/src/server/trpc/routers/website.ts +++ b/src/server/trpc/routers/website.ts @@ -2,7 +2,7 @@ import { OpenApiMetaInfo, publicProcedure, router, - workspaceOwnerProcedure, + workspaceAdminProcedure, workspaceProcedure, } from '../trpc.js'; import { z } from 'zod'; @@ -493,7 +493,7 @@ export const websiteRouter = router({ return []; }), - add: workspaceOwnerProcedure + add: workspaceAdminProcedure .meta({ openapi: { method: 'POST', @@ -522,7 +522,7 @@ export const websiteRouter = router({ return website; }), - delete: workspaceOwnerProcedure + delete: workspaceAdminProcedure .meta({ openapi: { method: 'DELETE', @@ -550,7 +550,7 @@ export const websiteRouter = router({ return website; }), - updateInfo: workspaceOwnerProcedure + updateInfo: workspaceAdminProcedure .meta( buildWebsiteOpenapi({ method: 'PUT', diff --git a/src/server/trpc/routers/workspace.ts b/src/server/trpc/routers/workspace.ts index 6e7f972..1fec176 100644 --- a/src/server/trpc/routers/workspace.ts +++ b/src/server/trpc/routers/workspace.ts @@ -3,6 +3,7 @@ import { protectProedure, publicProcedure, router, + workspaceAdminProcedure, workspaceOwnerProcedure, workspaceProcedure, } from '../trpc.js'; @@ -211,7 +212,7 @@ export const workspaceRouter = router({ return list; }), - invite: workspaceOwnerProcedure + invite: workspaceAdminProcedure .meta( buildWorkspaceOpenapi({ method: 'POST', diff --git a/src/server/trpc/trpc.ts b/src/server/trpc/trpc.ts index f9e1b07..d3ac504 100644 --- a/src/server/trpc/trpc.ts +++ b/src/server/trpc/trpc.ts @@ -82,6 +82,15 @@ export const workspaceProcedure = protectProedure }) ) .use(createWorkspacePermissionMiddleware()); + +export const workspaceAdminProcedure = protectProedure + .input( + z.object({ + workspaceId: z.string().cuid2(), + }) + ) + .use(createWorkspacePermissionMiddleware([ROLES.owner, ROLES.admin])); + export const workspaceOwnerProcedure = protectProedure .input( z.object({