Team Impersonation (#3450)
* Team Impersonation * Refactor - Disable Imeprsonate button * Change copy * Add .env toggle * Fix eslint * Update role selection Co-authored-by: Omar López <[email protected]> * New 'admin' seed user, improve flow ImpersonationProvider * Fix impersonation string * Adds fullstop Co-authored-by: Sean Brydon <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Omar López <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
11 files changed
+305
-42
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { MembershipRole, Prisma, UserPlan } from "@prisma/client";
|
||||
import { randomBytes } from "crypto";
|
||||
import { resolve } from "path";
|
||||
import { z } from "zod";
|
||||
|
||||
import { getUserAvailability } from "@calcom/core/getUserAvailability";
|
||||
@@ -460,4 +461,54 @@ export const viewerTeamsRouter = createProtectedRouter()
|
||||
async resolve({ ctx, input }) {
|
||||
return await ensureSubscriptionQuantityCorrectness(ctx.user.id, input.teamId);
|
||||
},
|
||||
})
|
||||
.query("getMembershipbyUser", {
|
||||
input: z.object({
|
||||
teamId: z.number(),
|
||||
memberId: z.number(),
|
||||
}),
|
||||
async resolve({ ctx, input }) {
|
||||
if (ctx.user.id !== input.memberId) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "You cannot view memberships that are not your own.",
|
||||
});
|
||||
}
|
||||
|
||||
return await ctx.prisma.membership.findUnique({
|
||||
where: {
|
||||
userId_teamId: {
|
||||
userId: input.memberId,
|
||||
teamId: input.teamId,
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
})
|
||||
.mutation("updateMembership", {
|
||||
input: z.object({
|
||||
teamId: z.number(),
|
||||
memberId: z.number(),
|
||||
disableImpersonation: z.boolean(),
|
||||
}),
|
||||
async resolve({ ctx, input }) {
|
||||
if (ctx.user.id !== input.memberId) {
|
||||
throw new TRPCError({
|
||||
code: "UNAUTHORIZED",
|
||||
message: "You cannot edit memberships that are not your own.",
|
||||
});
|
||||
}
|
||||
|
||||
return await ctx.prisma.membership.update({
|
||||
where: {
|
||||
userId_teamId: {
|
||||
userId: input.memberId,
|
||||
teamId: input.teamId,
|
||||
},
|
||||
},
|
||||
data: {
|
||||
disableImpersonation: input.disableImpersonation,
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user