feat: Round robin reassignment via round robin algorithm [CAL-3138] (#14308)
* add reassign host to edit dropdown * add dialog to reassign rr host * Design improvements * add translations * only show reassign for admin/owner * add first version of email template * Init rr assign endpoint * Pass booking information to rr assign endpoint * Only allow attendee of booking to reassign themselves * Send email to reassigned and cancelled member * On reassign change calendar events * Add workflows for new host * On reassign new host - rr * Fix icon * Abstract reassignment logic * Update calendar invite * Add tests * Clean up * Merge with `main` * Type fixes * Add back dialog and handle no available hosts * Handle if rr host is not organizer * Fix calendar invites when organizer doesn't change * Clean up * Clean up * Type fixes * Type fixes * Type fixes * Type fixes * Type fix * Type fixes * Type fixes * Add custom responses to evt object * Type fixes * Type fix * Type fix * Type fixes * Type fixes * Type fix * Type fix * Update tests * Type fixes * Fix tests * Fix tests * Add booking repository * Fix tests * Fix tests * Add doesUserIdHaveAccessToBooking for user * Add check if user is team admin * Check user permission tRPC route * Type fixes * Correct Promise.all * UI fixes * UI fixes * Remove unused assigned hosts prop * Type fix * Remove unused frontend code * Include user priority * Fallback to event type users for older event types * Get booking workflow reminder * Revert back to eventType.hosts * Fix lint * Handle changing workflows * Type fixes * Type fixes * Type fix * Fix tests * Update new booking imports * Fix imports * Type fix * Type fix * Fix adding all members to reassignment emails * Fix cancelled RR emails to show old host * Ensure consistent event titles * Send new event workflows to new host * Change event name if organizer changed * Fix query error * Delete old booking reference when reassigning * Type fixes * Type fixes * Fix test * Rename func isAdminOfTeamOrParentOrg * Select specific workflow fields * Address workflow feedback * Delete const * Address feedback --------- Co-authored-by: CarinaWolli <[email protected]>
This commit is contained in:
1 parent
3aca72fb06
commit
8fa39f2ae5
21 files changed
+1154
-64
No files matched your search
@@ -179,6 +179,7 @@ export async function getBookings({
|
||||
metadata: true,
|
||||
seatsShowAttendees: true,
|
||||
seatsShowAvailabilityCount: true,
|
||||
schedulingType: true,
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
@@ -190,6 +191,7 @@ export async function getBookings({
|
||||
},
|
||||
status: true,
|
||||
paid: true,
|
||||
|
||||
payment: {
|
||||
select: {
|
||||
paymentOption: true,
|
||||
|
||||
@@ -18,6 +18,7 @@ import { hasTeamPlan } from "./procedures/hasTeamPlan";
|
||||
import { ZPublishInputSchema } from "./publish.schema";
|
||||
import { ZRemoveMemberInputSchema } from "./removeMember.schema";
|
||||
import { ZResendInvitationInputSchema } from "./resendInvitation.schema";
|
||||
import { ZRoundRobinReassignInputSchema } from "./roundRobin/roundRobinReassign.schema";
|
||||
import { ZSetInviteExpirationInputSchema } from "./setInviteExpiration.schema";
|
||||
import { ZUpdateInputSchema } from "./update.schema";
|
||||
import { ZUpdateMembershipInputSchema } from "./updateMembership.schema";
|
||||
@@ -154,4 +155,11 @@ export const viewerTeamsRouter = router({
|
||||
);
|
||||
return handler(opts);
|
||||
}),
|
||||
roundRobinReassign: authedProcedure.input(ZRoundRobinReassignInputSchema).mutation(async (opts) => {
|
||||
const handler = await importHandler(
|
||||
namespaced("roundRobinReassign"),
|
||||
() => import("./roundRobin/roundRobinReassign.handler")
|
||||
);
|
||||
return handler(opts);
|
||||
}),
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
import { roundRobinReassignment } from "@calcom/features/ee/round-robin/roundRobinReassignment";
|
||||
import { BookingRepository } from "@calcom/lib/server/repository/booking";
|
||||
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
|
||||
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import type { TRoundRobinReassignInputSchema } from "./roundRobinReassign.schema";
|
||||
|
||||
type RoundRobinReassignOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
};
|
||||
input: TRoundRobinReassignInputSchema;
|
||||
};
|
||||
|
||||
export const roundRobinReassignHandler = async ({ ctx, input }: RoundRobinReassignOptions) => {
|
||||
const { bookingId } = input;
|
||||
|
||||
// Check if user has access to change booking
|
||||
const isAllowed = await BookingRepository.doesUserIdHaveAccessToBooking({ userId: ctx.user.id, bookingId });
|
||||
|
||||
if (!isAllowed) {
|
||||
throw new TRPCError({ code: "FORBIDDEN", message: "You do not have permission" });
|
||||
}
|
||||
|
||||
await roundRobinReassignment({ bookingId });
|
||||
};
|
||||
|
||||
export default roundRobinReassignHandler;
|
||||
@@ -0,0 +1,8 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const ZRoundRobinReassignInputSchema = z.object({
|
||||
teamId: z.number(),
|
||||
bookingId: z.number(),
|
||||
});
|
||||
|
||||
export type TRoundRobinReassignInputSchema = z.infer<typeof ZRoundRobinReassignInputSchema>;
|
||||
Reference in new issue
Block a user