({
ctx,
input,
}: InferProcedureOpts<typeof baseProcedure>)
| 23 | export const enableProcedure = once(() => baseProcedure.mutation(enable)); |
| 24 | |
| 25 | export async function enable({ |
| 26 | ctx, |
| 27 | input, |
| 28 | }: InferProcedureOpts<typeof baseProcedure>) { |
| 29 | return await ctx.usingLocks( |
| 30 | [[`user-lock:${ctx.userId}`], [`group-lock:${input.groupId}`]], |
| 31 | async (signals) => { |
| 32 | return await ctx.dataAbstraction.transaction(async (dtrx) => { |
| 33 | // Assert agent is subscribed |
| 34 | |
| 35 | await ctx.assertUserSubscribed({ userId: ctx.userId }); |
| 36 | |
| 37 | // Check if user can edit group settings |
| 38 | |
| 39 | await ctx.assertSufficientGroupPermissions({ |
| 40 | userId: ctx.userId, |
| 41 | groupId: input.groupId, |
| 42 | permission: 'editGroupSettings', |
| 43 | }); |
| 44 | |
| 45 | // Check if group is password protected |
| 46 | |
| 47 | if ( |
| 48 | await ctx.dataAbstraction.hget( |
| 49 | 'group', |
| 50 | input.groupId, |
| 51 | 'is-password-protected', |
| 52 | ) |
| 53 | ) { |
| 54 | throw new TRPCError({ |
| 55 | code: 'BAD_REQUEST', |
| 56 | message: 'This group is already password protected.', |
| 57 | }); |
| 58 | } |
| 59 | |
| 60 | // Enable password protection |
| 61 | |
| 62 | await ctx.dataAbstraction.patch( |
| 63 | 'group', |
| 64 | input.groupId, |
| 65 | { |
| 66 | encrypted_rehashed_password_hash: encryptGroupRehashedPasswordHash( |
| 67 | computePasswordHash(input.groupPasswordHash), |
| 68 | ), |
| 69 | |
| 70 | encrypted_content_keyring: input.groupEncryptedContentKeyring, |
| 71 | }, |
| 72 | { dtrx }, |
| 73 | ); |
| 74 | |
| 75 | checkRedlockSignalAborted(signals); |
| 76 | }); |
| 77 | }, |
| 78 | ); |
| 79 | } |
nothing calls this directly
no test coverage detected