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,
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',

View File

@ -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',

View File

@ -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(),

View File

@ -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;

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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({