( ctx: Context, serverId: string, )
| 60 | } |
| 61 | |
| 62 | export 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 | |
| 98 | export function assertIsAdminOrOwnerOfServer( |
| 99 | ctx: Context, |
no test coverage detected