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