feat: add admin role and change most owner permission to admin

because only a little action real need owner permission.
This commit is contained in:
moonrailgun 2024-09-22 01:10:25 +08:00
parent 4f4f9b5d3f
commit 79ed059d99
9 changed files with 43 additions and 33 deletions

View File

@ -3,7 +3,7 @@ import {
OpenApiMetaInfo, OpenApiMetaInfo,
publicProcedure, publicProcedure,
router, router,
workspaceOwnerProcedure, workspaceAdminProcedure,
workspaceProcedure, workspaceProcedure,
} from '../../trpc.js'; } from '../../trpc.js';
import { OPENAPI_TAG } from '../../../utils/const.js'; import { OPENAPI_TAG } from '../../../utils/const.js';
@ -203,7 +203,7 @@ export const feedRouter = router({
nextCursor, nextCursor,
}; };
}), }),
createChannel: workspaceOwnerProcedure createChannel: workspaceAdminProcedure
.meta( .meta(
buildFeedOpenapi({ buildFeedOpenapi({
method: 'POST', method: 'POST',
@ -253,7 +253,7 @@ export const feedRouter = router({
notificationIds: channel?.notifications.map((n) => n.id), notificationIds: channel?.notifications.map((n) => n.id),
}; };
}), }),
deleteChannel: workspaceOwnerProcedure deleteChannel: workspaceAdminProcedure
.meta( .meta(
buildFeedOpenapi({ buildFeedOpenapi({
method: 'DELETE', method: 'DELETE',
@ -313,7 +313,7 @@ export const feedRouter = router({
return event; return event;
}), }),
archiveEvent: workspaceOwnerProcedure archiveEvent: workspaceAdminProcedure
.meta( .meta(
buildFeedPublicOpenapi({ buildFeedPublicOpenapi({
method: 'PATCH', method: 'PATCH',
@ -340,7 +340,7 @@ export const feedRouter = router({
}, },
}); });
}), }),
unarchiveEvent: workspaceOwnerProcedure unarchiveEvent: workspaceAdminProcedure
.meta( .meta(
buildFeedPublicOpenapi({ buildFeedPublicOpenapi({
method: 'PATCH', method: 'PATCH',
@ -367,7 +367,7 @@ export const feedRouter = router({
}, },
}); });
}), }),
clearAllArchivedEvents: workspaceOwnerProcedure clearAllArchivedEvents: workspaceAdminProcedure
.meta( .meta(
buildFeedPublicOpenapi({ buildFeedPublicOpenapi({
method: 'PATCH', method: 'PATCH',

View File

@ -2,7 +2,7 @@ import {
OpenApiMetaInfo, OpenApiMetaInfo,
publicProcedure, publicProcedure,
router, router,
workspaceOwnerProcedure, workspaceAdminProcedure,
workspaceProcedure, workspaceProcedure,
} from '../trpc.js'; } from '../trpc.js';
import { prisma } from '../../model/_client.js'; import { prisma } from '../../model/_client.js';
@ -113,7 +113,7 @@ export const monitorRouter = router({
return getMonitorPublicInfos(monitorIds); return getMonitorPublicInfos(monitorIds);
}), }),
upsert: workspaceOwnerProcedure upsert: workspaceAdminProcedure
.meta( .meta(
buildMonitorOpenapi({ buildMonitorOpenapi({
method: 'POST', method: 'POST',
@ -163,7 +163,7 @@ export const monitorRouter = router({
return monitor; return monitor;
}), }),
delete: workspaceOwnerProcedure delete: workspaceAdminProcedure
.meta( .meta(
buildMonitorOpenapi({ buildMonitorOpenapi({
method: 'DELETE', method: 'DELETE',
@ -181,7 +181,7 @@ export const monitorRouter = router({
return monitorManager.delete(workspaceId, monitorId); return monitorManager.delete(workspaceId, monitorId);
}), }),
testCustomScript: workspaceOwnerProcedure testCustomScript: workspaceAdminProcedure
.input( .input(
z.object({ z.object({
code: z.string(), code: z.string(),
@ -235,7 +235,7 @@ export const monitorRouter = router({
new Date(endAt) new Date(endAt)
); );
}), }),
changeActive: workspaceOwnerProcedure changeActive: workspaceAdminProcedure
.meta( .meta(
buildMonitorOpenapi({ buildMonitorOpenapi({
method: 'PATCH', method: 'PATCH',
@ -462,7 +462,7 @@ export const monitorRouter = router({
return list; return list;
}), }),
clearEvents: workspaceOwnerProcedure clearEvents: workspaceAdminProcedure
.meta( .meta(
buildMonitorOpenapi({ buildMonitorOpenapi({
method: 'DELETE', method: 'DELETE',
@ -489,7 +489,7 @@ export const monitorRouter = router({
return count; return count;
}), }),
clearData: workspaceOwnerProcedure clearData: workspaceAdminProcedure
.meta( .meta(
buildMonitorOpenapi({ buildMonitorOpenapi({
method: 'DELETE', method: 'DELETE',
@ -585,7 +585,7 @@ export const monitorRouter = router({
}, },
}); });
}), }),
createPage: workspaceOwnerProcedure createPage: workspaceAdminProcedure
.meta( .meta(
buildMonitorOpenapi({ buildMonitorOpenapi({
method: 'POST', method: 'POST',
@ -655,7 +655,7 @@ export const monitorRouter = router({
return page; return page;
}), }),
editPage: workspaceOwnerProcedure editPage: workspaceAdminProcedure
.meta( .meta(
buildMonitorOpenapi({ buildMonitorOpenapi({
method: 'PATCH', method: 'PATCH',
@ -733,7 +733,7 @@ export const monitorRouter = router({
return page; return page;
}), }),
deletePage: workspaceOwnerProcedure deletePage: workspaceAdminProcedure
.meta( .meta(
buildMonitorOpenapi({ buildMonitorOpenapi({
method: 'DELETE', method: 'DELETE',

View File

@ -1,6 +1,6 @@
import { import {
router, router,
workspaceOwnerProcedure, workspaceAdminProcedure,
workspaceProcedure, workspaceProcedure,
} from '../trpc.js'; } from '../trpc.js';
import { z } from 'zod'; import { z } from 'zod';
@ -35,7 +35,7 @@ export const notificationRouter = router({
token.image('https://tianji.msgbyte.com/img/social-card.png'), token.image('https://tianji.msgbyte.com/img/social-card.png'),
]); ]);
}), }),
upsert: workspaceOwnerProcedure upsert: workspaceAdminProcedure
.input( .input(
z.object({ z.object({
id: z.string().optional(), id: z.string().optional(),
@ -72,7 +72,7 @@ export const notificationRouter = router({
}); });
} }
}), }),
delete: workspaceOwnerProcedure delete: workspaceAdminProcedure
.input( .input(
z.object({ z.object({
id: z.string(), id: z.string(),

View File

@ -1,8 +1,8 @@
import { router, workspaceOwnerProcedure } from '../trpc.js'; import { router, workspaceAdminProcedure } from '../trpc.js';
import { clearOfflineServerStatus } from '../../model/serverStatus.js'; import { clearOfflineServerStatus } from '../../model/serverStatus.js';
export const serverStatusRouter = router({ export const serverStatusRouter = router({
clearOfflineServerStatus: workspaceOwnerProcedure.mutation( clearOfflineServerStatus: workspaceAdminProcedure.mutation(
async ({ input }) => { async ({ input }) => {
const workspaceId = input.workspaceId; const workspaceId = input.workspaceId;

View File

@ -3,7 +3,7 @@ import {
OpenApiMetaInfo, OpenApiMetaInfo,
publicProcedure, publicProcedure,
router, router,
workspaceOwnerProcedure, workspaceAdminProcedure,
workspaceProcedure, workspaceProcedure,
} from '../trpc.js'; } from '../trpc.js';
import { OPENAPI_TAG } from '../../utils/const.js'; import { OPENAPI_TAG } from '../../utils/const.js';
@ -220,7 +220,7 @@ export const surveyRouter = router({
return 'success'; return 'success';
}), }),
create: workspaceOwnerProcedure create: workspaceAdminProcedure
.meta( .meta(
buildSurveyOpenapi({ buildSurveyOpenapi({
method: 'POST', method: 'POST',
@ -252,7 +252,7 @@ export const surveyRouter = router({
return res; return res;
}), }),
update: workspaceOwnerProcedure update: workspaceAdminProcedure
.meta( .meta(
buildSurveyOpenapi({ buildSurveyOpenapi({
method: 'PATCH', method: 'PATCH',
@ -294,7 +294,7 @@ export const surveyRouter = router({
return res; return res;
}), }),
delete: workspaceOwnerProcedure delete: workspaceAdminProcedure
.meta( .meta(
buildSurveyOpenapi({ buildSurveyOpenapi({
method: 'DELETE', method: 'DELETE',

View File

@ -2,7 +2,7 @@ import { z } from 'zod';
import { import {
OpenApiMetaInfo, OpenApiMetaInfo,
router, router,
workspaceOwnerProcedure, workspaceAdminProcedure,
workspaceProcedure, workspaceProcedure,
} from '../trpc.js'; } from '../trpc.js';
import { import {
@ -130,7 +130,7 @@ export const telemetryRouter = router({
return count; return count;
}), }),
upsert: workspaceOwnerProcedure upsert: workspaceAdminProcedure
.meta( .meta(
buildTelemetryOpenapi({ buildTelemetryOpenapi({
method: 'POST', method: 'POST',
@ -166,7 +166,7 @@ export const telemetryRouter = router({
}); });
} }
}), }),
delete: workspaceOwnerProcedure delete: workspaceAdminProcedure
.meta( .meta(
buildTelemetryOpenapi({ buildTelemetryOpenapi({
method: 'POST', method: 'POST',

View File

@ -2,7 +2,7 @@ import {
OpenApiMetaInfo, OpenApiMetaInfo,
publicProcedure, publicProcedure,
router, router,
workspaceOwnerProcedure, workspaceAdminProcedure,
workspaceProcedure, workspaceProcedure,
} from '../trpc.js'; } from '../trpc.js';
import { z } from 'zod'; import { z } from 'zod';
@ -493,7 +493,7 @@ export const websiteRouter = router({
return []; return [];
}), }),
add: workspaceOwnerProcedure add: workspaceAdminProcedure
.meta({ .meta({
openapi: { openapi: {
method: 'POST', method: 'POST',
@ -522,7 +522,7 @@ export const websiteRouter = router({
return website; return website;
}), }),
delete: workspaceOwnerProcedure delete: workspaceAdminProcedure
.meta({ .meta({
openapi: { openapi: {
method: 'DELETE', method: 'DELETE',
@ -550,7 +550,7 @@ export const websiteRouter = router({
return website; return website;
}), }),
updateInfo: workspaceOwnerProcedure updateInfo: workspaceAdminProcedure
.meta( .meta(
buildWebsiteOpenapi({ buildWebsiteOpenapi({
method: 'PUT', method: 'PUT',

View File

@ -3,6 +3,7 @@ import {
protectProedure, protectProedure,
publicProcedure, publicProcedure,
router, router,
workspaceAdminProcedure,
workspaceOwnerProcedure, workspaceOwnerProcedure,
workspaceProcedure, workspaceProcedure,
} from '../trpc.js'; } from '../trpc.js';
@ -211,7 +212,7 @@ export const workspaceRouter = router({
return list; return list;
}), }),
invite: workspaceOwnerProcedure invite: workspaceAdminProcedure
.meta( .meta(
buildWorkspaceOpenapi({ buildWorkspaceOpenapi({
method: 'POST', method: 'POST',

View File

@ -82,6 +82,15 @@ export const workspaceProcedure = protectProedure
}) })
) )
.use(createWorkspacePermissionMiddleware()); .use(createWorkspacePermissionMiddleware());
export const workspaceAdminProcedure = protectProedure
.input(
z.object({
workspaceId: z.string().cuid2(),
})
)
.use(createWorkspacePermissionMiddleware([ROLES.owner, ROLES.admin]));
export const workspaceOwnerProcedure = protectProedure export const workspaceOwnerProcedure = protectProedure
.input( .input(
z.object({ z.object({