feat: editmode availbility slider (#11197)

* Add loading data and banner

* [WIP] hasEditPerms middleware

* fix: type error in booker (#11011)

* New Crowdin translations by Github Action

* refactor: removed redundant test (#10785)

Co-authored-by: gitstart-calcom <[email protected]>
Co-authored-by: Shivam Kalra <[email protected]>

* feat: 2fa backup codes (#10600)

Co-authored-by: Peer Richelsen <[email protected]>

* Delete add-PRs-to-project-reviewing-PRs.yml (#11008)

Co-authored-by: alannnc <[email protected]>

* New Crowdin translations by Github Action

* fix: multiple duration when booking (#11032)

* fix: other reported issues (#11015)

* fix: weird margin top in avatar

* fix: pending users are shown on booking page

* fix: avatar and naming issues

* fix: toast alignment and removing unneeded titles

* missing changes from toast improvements

* feat: empty state for teams without event types

* Removing console.log

* feat: cal ai (#10992)

Co-authored-by: nicktrn <[email protected]>
Co-authored-by: tedspare <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>

* New Crowdin translations by Github Action

* fix: meeting ended trigger for webhooks and zapier sometimes not working (#10946)

Co-authored-by: mohammed gehad <[email protected]>
Co-authored-by: Monto <[email protected]>
Co-authored-by: Carina Wollendorfer <[email protected]>

* feat: team admin: see connected apps of team members (#11036)

* added feature:team admin can see connected apps of members

* fixed the type error

* Update packages/lib/server/queries/teams/index.ts

* Minor fixes

---------

Co-authored-by: alannnc <[email protected]>

* fix: lower case slugs in teams (#11026)

* fix: lower case slugs in teams

Signed-off-by: Udit Takkar <[email protected]>

* fix: use slugify

Signed-off-by: Udit Takkar <[email protected]>

---------

Signed-off-by: Udit Takkar <[email protected]>

* refactor: improvements on german translation (#10898)

* fix: fix-tablet-menu-not-centered-sidebar (#11020)

Co-authored-by: Udit Takkar <[email protected]>

* chore: add Popover in storybook (#11021)

Co-authored-by: gitstart-calcom <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>

* fix: Set mobile availability (#11027)

* chore: add ColorPicker in storybook (CALCOM-10760) (#10866)

Co-authored-by: gitstart-calcom <[email protected]>

* feat: adds next cold start profiler (#11014)

* Handle disabling of ORGANIZATIONS_ENABLED flag (#11041)

* New Crowdin translations by Github Action

* styles:dark mode color fix (#11004)

* chore: sheet darkmode and improve responsive (#11047)

* fix: handle collective multiple host on destinationCalendar (#10967)

* fix: include app data and credentials from DB (#11048)

* include app data and credentials from DB

* Improve performance

* fix: Error when running storybook (#11037)

Co-authored-by: gitstart-calcom <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>

* fix: broken company profile link on team booking page (#10978)

* chore: add ErrorBoundary in storybook (CALCOM-10760) (#10872)

Co-authored-by: gitstart-calcom <[email protected]>

* feat: sorting for workflow and routing forms (#10780)

Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>

* resolve zod versions across child packages (#11052)

* fix: List storybook file is empty (fix-list) (#10965)

Co-authored-by: gitstart-calcom <[email protected]>

* fix: admin org list without members (#11051)

Co-authored-by: Peer Richelsen <[email protected]>

* chore: add ToggleGroup in storybook (#10802)

Co-authored-by: gitstart-calcom <[email protected]>
Co-authored-by: sean-brydon <[email protected]>

* fix: add metadata to stripe payment intent (#11053)

* fix: Logo storybook file with invalid icons (fix-logo) (#11018)

Co-authored-by: gitstart-calcom <[email protected]>

* fix: Add controls for Select Field storybook file (#10936)

Co-authored-by: gitstart-calcom <[email protected]>

* fix: Fix tooltip control on ButtonPlayground storybook file (fix-ButtonTooltip) (#10937)

Co-authored-by: gitstart-calcom <[email protected]>

* fix: email embed – remove collapsible and permanently show times (#10996)

Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: Mehul <[email protected]>

* chore: add Timezone Select in storybook (CALCOM-10760) (#10966)

Co-authored-by: gitstart-calcom <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>

* chore: add Switch in storybook (CALCOM-10760) (#10804)

Co-authored-by: gitstart-calcom <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>

* Sync packages

* fix: zod utils due to upgrade

* easy fix (#11054)

* fix sub quantity update stripe (#11057)

* v3.2.7

* Revert "feat: adds next cold start profiler (#11014)" (#11072)

This reverts commit 05631d093f.

* fix: Fixes username invite issue (#10998)

* Fixes username invite issue

* Ensure we only suggest email invites in org members

---------

Co-authored-by: Udit Takkar <[email protected]>

* Fix sheet layout

* WIP permissions when userschedule doesnt match

* WIP get handler weird behaviour

* Update toast

* add disabled - handle membership overlap

* Handle permissions + perf improvments

* use input uid

* Remove Console.log

* Clean up

* Revert changes accidental

* Fix merge artifacts

* Remove dead code

* Remove code after return

* Update read permission check

* Revert avatar changes as fixed elsewhere

* Handle if user has not completed onboarding

* Disable button

* Update packages/lib/hasEditPermissionForUser.ts

* Correct Error throwing

* Update packages/features/timezone-buddy/components/AvailabilityEditSheet.tsx

* Fix type erro

* Add i18n

* Improve Spacing

* Update yarn.lock

---------

Signed-off-by: Udit Takkar <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Crowdin Bot <[email protected]>
Co-authored-by: GitStart-Cal.com <[email protected]>
Co-authored-by: gitstart-calcom <[email protected]>
Co-authored-by: Shivam Kalra <[email protected]>
Co-authored-by: nicktrn <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: alannnc <[email protected]>
Co-authored-by: Leo Giovanetti <[email protected]>
Co-authored-by: DexterStorey <[email protected]>
Co-authored-by: tedspare <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
Co-authored-by: Monto <[email protected]>
Co-authored-by: mohammed gehad <[email protected]>
Co-authored-by: Monto <[email protected]>
Co-authored-by: Carina Wollendorfer <[email protected]>
Co-authored-by: Abhijeet Singh <[email protected]>
Co-authored-by: Kamil B. Demirci <[email protected]>
Co-authored-by: Denzil Samuel <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Anik Dhabal Babu <[email protected]>
Co-authored-by: Omar López <[email protected]>
Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: Sahil Padvi <[email protected]>
Co-authored-by: Patel Divyesh <[email protected]>
Co-authored-by: neo773 <[email protected]>
Co-authored-by: Mehul <[email protected]>
This commit is contained in:
18 files changed
+502 -42

No files matched your search

@@ -4,6 +4,7 @@ import { ZCreateInputSchema } from "./create.schema";
import { ZDeleteInputSchema } from "./delete.schema";
import { ZScheduleDuplicateSchema } from "./duplicate.schema";
import { ZGetInputSchema } from "./get.schema";
import { ZGetByUserIdInputSchema } from "./getScheduleByUserId.schema";
import { ZUpdateInputSchema } from "./update.schema";
type ScheduleRouterHandlerCache = {
@@ -12,6 +13,7 @@ type ScheduleRouterHandlerCache = {
delete?: typeof import("./delete.handler").deleteHandler;
update?: typeof import("./update.handler").updateHandler;
duplicate?: typeof import("./duplicate.handler").duplicateHandler;
getScheduleByUserId?: typeof import("./getScheduleByUserId.handler").getScheduleByUserIdHandler;
};
const UNSTABLE_HANDLER_CACHE: ScheduleRouterHandlerCache = {};
@@ -98,4 +100,22 @@ export const scheduleRouter = router({
input,
});
}),
getScheduleByUserId: authedProcedure.input(ZGetByUserIdInputSchema).query(async ({ input, ctx }) => {
if (!UNSTABLE_HANDLER_CACHE.getScheduleByUserId) {
UNSTABLE_HANDLER_CACHE.getScheduleByUserId = await import("./getScheduleByUserId.handler").then(
(mod) => mod.getScheduleByUserIdHandler
);
}
// Unreachable code but required for type safety
if (!UNSTABLE_HANDLER_CACHE.getScheduleByUserId) {
throw new Error("Failed to load handler");
}
return UNSTABLE_HANDLER_CACHE.getScheduleByUserId({
ctx,
input,
});
}),
});
@@ -1,6 +1,7 @@
import dayjs from "@calcom/dayjs";
import { getWorkingHours } from "@calcom/lib/availability";
import { yyyymmdd } from "@calcom/lib/date-fns";
import { hasReadPermissionsForUserId } from "@calcom/lib/hasEditPermissionForUser";
import { prisma } from "@calcom/prisma";
import type { TimeRange } from "@calcom/types/schedule";
@@ -30,25 +31,22 @@ export const getHandler = async ({ ctx, input }: GetOptions) => {
name: true,
availability: true,
timeZone: true,
eventType: {
select: {
id: true,
eventName: true,
team: {
select: { members: { select: { userId: true } } },
},
},
},
},
});
const isCurrentUserPartOfTeam = schedule?.eventType.some((eventType) =>
eventType.team?.members.some((teamMember) => teamMember.userId === user.id)
);
if (!schedule) {
throw new TRPCError({
code: "UNAUTHORIZED",
});
}
const isCurrentUserPartOfTeam = hasReadPermissionsForUserId({
ctx,
input: { memberId: schedule?.userId },
});
const isCurrentUserOwner = schedule?.userId === user.id;
if (!schedule || (!isCurrentUserOwner && !isCurrentUserPartOfTeam)) {
if (!isCurrentUserPartOfTeam && !isCurrentUserOwner) {
throw new TRPCError({
code: "UNAUTHORIZED",
});
@@ -0,0 +1,52 @@
import type { TrpcSessionUser } from "../../../../trpc";
import { getHandler } from "./get.handler";
import type { TGetByUserIdInputSchema } from "./getScheduleByUserId.schema";
type GetOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TGetByUserIdInputSchema;
};
const EMPTY_SCHEDULE = [[], [], [], [], [], [], []];
export const getScheduleByUserIdHandler = async ({ ctx, input }: GetOptions) => {
const foundUserDefaultId = await prisma.user.findUnique({
where: {
id: input.userId,
},
select: {
defaultScheduleId: true,
},
});
try {
// This looks kinda weird that we throw straight in the catch - its so that we can return a default schedule if the user has not completed onboarding @shiraz will loveme for this
if (!foundUserDefaultId?.defaultScheduleId) {
throw new Error("NOT_FOUND");
}
const schedule = await getHandler({
ctx,
input: {
scheduleId: foundUserDefaultId?.defaultScheduleId,
},
});
return {
...schedule,
hasDefaultSchedule: true,
};
} catch (e) {
return {
id: -1,
name: "Working Hourse",
availability: EMPTY_SCHEDULE,
dateOverrides: [],
timeZone: ctx.user.timeZone || "Europe/London",
workingHours: [],
isDefault: true,
hasDefaultSchedule: false, // This is the path that we take if the user has not completed onboarding
};
}
};
@@ -0,0 +1,7 @@
import { z } from "zod";
export const ZGetByUserIdInputSchema = z.object({
userId: z.optional(z.number()),
});
export type TGetByUserIdInputSchema = z.infer<typeof ZGetByUserIdInputSchema>;
@@ -1,4 +1,5 @@
import { getAvailabilityFromSchedule } from "@calcom/lib/availability";
import { hasEditPermissionForUserID } from "@calcom/lib/hasEditPermissionForUser";
import { prisma } from "@calcom/prisma";
import { TRPCError } from "@trpc/server";
@@ -38,14 +39,24 @@ export const updateHandler = async ({ input, ctx }: UpdateOptions) => {
},
});
if (userSchedule?.userId !== user.id) throw new TRPCError({ code: "UNAUTHORIZED" });
if (!userSchedule || userSchedule.userId !== user.id) {
if (!userSchedule) {
throw new TRPCError({
code: "UNAUTHORIZED",
});
}
if (userSchedule?.userId !== user.id) {
const hasEditPermission = await hasEditPermissionForUserID({
ctx,
input: { memberId: userSchedule.userId },
});
if (!hasEditPermission) {
throw new TRPCError({
code: "UNAUTHORIZED",
});
}
}
let updatedUser;
if (input.isDefault) {
const setupDefault = await setupDefaultSchedule(user.id, input.scheduleId, prisma);
@@ -65,6 +65,7 @@ async function buildMember(member: Member, dateFrom: Dayjs, dateTo: Dayjs) {
email: member.user.email,
timeZone: member.user.timeZone,
role: member.role,
defaultScheduleId: -1,
dateRanges: [] as DateRange[],
};
}
@@ -88,6 +89,7 @@ async function buildMember(member: Member, dateFrom: Dayjs, dateTo: Dayjs) {
email: member.user.email,
timeZone,
role: member.role,
defaultScheduleId: member.user.defaultScheduleId ?? -1,
dateRanges,
};
}
@@ -9,6 +9,7 @@ import { ZDeleteInviteInputSchema } from "./deleteInvite.schema";
import { ZGetInputSchema } from "./get.schema";
import { ZGetMemberAvailabilityInputSchema } from "./getMemberAvailability.schema";
import { ZGetMembershipbyUserInputSchema } from "./getMembershipbyUser.schema";
import { ZHasEditPermissionForUserSchema } from "./hasEditPermissionForUser.schema";
import { ZInviteMemberInputSchema } from "./inviteMember/inviteMember.schema";
import { ZInviteMemberByTokenSchemaInputSchema } from "./inviteMemberByToken.schema";
import { ZListMembersInputSchema } from "./listMembers.schema";
@@ -41,6 +42,7 @@ type TeamsRouterHandlerCache = {
setInviteExpiration?: typeof import("./setInviteExpiration.handler").setInviteExpirationHandler;
deleteInvite?: typeof import("./deleteInvite.handler").deleteInviteHandler;
inviteMemberByToken?: typeof import("./inviteMemberByToken.handler").inviteMemberByTokenHandler;
hasEditPermissionForUser?: typeof import("./hasEditPermissionForUser.handler").hasEditPermissionForUser;
};
const UNSTABLE_HANDLER_CACHE: TeamsRouterHandlerCache = {};
@@ -433,4 +435,23 @@ export const viewerTeamsRouter = router({
input,
});
}),
hasEditPermissionForUser: authedProcedure
.input(ZHasEditPermissionForUserSchema)
.query(async ({ ctx, input }) => {
if (!UNSTABLE_HANDLER_CACHE.hasEditPermissionForUser) {
UNSTABLE_HANDLER_CACHE.hasEditPermissionForUser = await import(
"./hasEditPermissionForUser.handler"
).then((mod) => mod.hasEditPermissionForUser);
}
// Unreachable code but required for type safety
if (!UNSTABLE_HANDLER_CACHE.hasEditPermissionForUser) {
throw new Error("Failed to load handler");
}
return UNSTABLE_HANDLER_CACHE.hasEditPermissionForUser({
ctx,
input,
});
}),
});
@@ -0,0 +1,19 @@
import { hasEditPermissionForUserID as $hasEditPermissionForUser } from "@calcom/lib/hasEditPermissionForUser";
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
import type { THasEditPermissionForUserSchema } from "./hasEditPermissionForUser.schema";
type HasEditPermissionForUserOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: THasEditPermissionForUserSchema;
};
export const hasEditPermissionForUser = async ({ ctx, input }: HasEditPermissionForUserOptions) => {
// Calculate if the logged in User has edit permission for the given User.
return $hasEditPermissionForUser({
ctx,
input,
});
};
@@ -0,0 +1,7 @@
import { z } from "zod";
export const ZHasEditPermissionForUserSchema = z.object({
memberId: z.number(),
});
export type THasEditPermissionForUserSchema = z.infer<typeof ZHasEditPermissionForUserSchema>;