MCPcopy Index your code
hub / github.com/AnswerOverflow/AnswerOverflow / assertCanEditServer

Function assertCanEditServer

packages/api/src/utils/permissions.ts:62–96  ·  view source on GitHub ↗
(
	ctx: Context,
	serverId: string,
)

Source from the content-addressed store, hash-verified

60}
61
62export function assertCanEditServer(
63 ctx: Context,
64 serverId: string,
65): PermissionCheckResult {
66 if (isSuperUser(ctx)) return;
67 if (!ctx.userServers) {
68 return new TRPCError({
69 code: 'UNAUTHORIZED',
70 message:
71 'User servers missing, cannot verify if user has permission to edit server',
72 });
73 }
74
75 const serverToCheckPermissionsOf = ctx.userServers.find(
76 (userServer) => userServer.id === serverId,
77 );
78 if (!serverToCheckPermissionsOf) {
79 return new TRPCError({
80 code: 'FORBIDDEN',
81 message:
82 'You are not a member of the server you are trying to create channel settings for',
83 });
84 }
85 const hasPermsToEdit = PermissionsBitField.any(
86 BigInt(serverToCheckPermissionsOf.permissions),
87 ['Administrator', 'ManageGuild'],
88 );
89 if (!(hasPermsToEdit || serverToCheckPermissionsOf.owner)) {
90 return new TRPCError({
91 code: 'FORBIDDEN',
92 message: MISSING_PERMISSIONS_TO_EDIT_SERVER_MESSAGE,
93 });
94 }
95 return;
96}
97
98export function assertIsAdminOrOwnerOfServer(
99 ctx: Context,

Callers 5

dashboard.tsFile · 0.90
channel.tsFile · 0.90
mutateServerFunction · 0.90
server.tsFile · 0.90

Calls 1

isSuperUserFunction · 0.85

Tested by

no test coverage detected