refactor: v2 team event type assignAllTeamMembers (#20400)
* fix: platform seed data * fix: assignAllTeamMembers: true excludes team owners in platform * refactor: platform plan guard explicit error message * refactor: require either hosts or assignAllTeamMembers=true * refactor: require either hosts or assignAllTeamMembers=true * fix: before creating or updating team event type check if doesnt exist with that slug * chore: regenerate docs * test: can update round robin that had assign all team members true * fix: platform guard spec test * fix: seed platform membership role * fix: test ts error
This commit is contained in:
1 parent
17f493a488
commit
e67e073f04
14 files changed
+625
-35
No files matched your search
+35
-2
@@ -5,6 +5,7 @@ import {
|
||||
ApiExtraModels,
|
||||
} from "@nestjs/swagger";
|
||||
import { Type, Transform, Expose } from "class-transformer";
|
||||
import type { ValidationOptions, ValidationArguments } from "class-validator";
|
||||
import {
|
||||
IsString,
|
||||
IsInt,
|
||||
@@ -17,6 +18,7 @@ import {
|
||||
ValidateNested,
|
||||
ArrayNotEmpty,
|
||||
ArrayUnique,
|
||||
registerDecorator,
|
||||
} from "class-validator";
|
||||
|
||||
import { SchedulingType } from "@calcom/platform-enums";
|
||||
@@ -446,6 +448,32 @@ export class Host {
|
||||
priority?: keyof typeof HostPriority = "medium";
|
||||
}
|
||||
|
||||
function RequireHostsOrAssignAllMembers(validationOptions?: ValidationOptions) {
|
||||
return function (object: any) {
|
||||
registerDecorator({
|
||||
name: "requireHostsOrAssignAllMembers",
|
||||
target: object,
|
||||
propertyName: "hosts OR assignAllTeamMembers",
|
||||
options: validationOptions,
|
||||
constraints: [],
|
||||
validator: {
|
||||
validate(_value: any, args: ValidationArguments) {
|
||||
const obj = args.object as CreateTeamEventTypeInput_2024_06_14;
|
||||
|
||||
const hasHosts = !!obj.hosts && !!obj.hosts.length;
|
||||
const hasAssignAllTeamMembers = obj.assignAllTeamMembers === true;
|
||||
|
||||
return hasHosts || hasAssignAllTeamMembers;
|
||||
},
|
||||
defaultMessage(): string {
|
||||
return "Either hosts OR assignAllTeamMembers set to true is required";
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@RequireHostsOrAssignAllMembers()
|
||||
export class CreateTeamEventTypeInput_2024_06_14 extends BaseCreateEventTypeInput {
|
||||
@Transform(({ value }) => {
|
||||
if (value === "collective") {
|
||||
@@ -470,8 +498,13 @@ export class CreateTeamEventTypeInput_2024_06_14 extends BaseCreateEventTypeInpu
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => Host)
|
||||
@IsArray()
|
||||
@DocsProperty({ type: [Host] })
|
||||
hosts!: Host[];
|
||||
@IsOptional()
|
||||
@DocsPropertyOptional({
|
||||
type: [Host],
|
||||
description:
|
||||
"Hosts contain specific team members you want to assign to this event type, but if you want to assign all team members, use `assignAllTeamMembers: true` instead and omit this field. For platform customers the hosts can include userIds only of managed users.",
|
||||
})
|
||||
hosts?: Host[];
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
|
||||
@@ -163,20 +163,22 @@ async function createPlatformAndSetupUser({
|
||||
`👤 Upserted '${user.username}' with email "${user.email}" & password "${user.password}". Booking page 👉 ${process.env.NEXT_PUBLIC_WEBAPP_URL}/${user.username}`
|
||||
);
|
||||
|
||||
const { role = MembershipRole.OWNER, username } = platformUser;
|
||||
const { username } = platformUser;
|
||||
|
||||
const membershipRole = MembershipRole.OWNER;
|
||||
|
||||
if (!!team) {
|
||||
await associateUserAndOrg({
|
||||
teamId: team.id,
|
||||
userId: platformUser.id,
|
||||
role: role as MembershipRole,
|
||||
role: membershipRole,
|
||||
username: user.username,
|
||||
});
|
||||
|
||||
await prisma.platformBilling.create({
|
||||
data: {
|
||||
id: team?.id,
|
||||
plan: "STARTER",
|
||||
plan: "SCALE",
|
||||
customerId: "cus_123",
|
||||
subscriptionId: "sub_123",
|
||||
},
|
||||
@@ -194,7 +196,7 @@ async function createPlatformAndSetupUser({
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiQWNtZSAiLCJwZXJtaXNzaW9ucyI6MTAyMywicmVkaXJlY3RVcmlzIjpbImh0dHA6Ly9sb2NhbGhvc3Q6NDMyMSJdLCJib29raW5nUmVkaXJlY3RVcmkiOiIiLCJib29raW5nQ2FuY2VsUmVkaXJlY3RVcmkiOiIiLCJib29raW5nUmVzY2hlZHVsZVJlZGlyZWN0VXJpIjoiIiwiYXJlRW1haWxzRW5hYmxlZCI6dHJ1ZSwiaWF0IjoxNzE5NTk1ODA4fQ.L5_jSS14fcKLCD_9_DAOgtGd6lUSZlU5CEpCPaPt41I",
|
||||
},
|
||||
});
|
||||
console.log(`\t👤 Added '${teamInput.name}' membership for '${username}' with role '${role}'`);
|
||||
console.log(`\t👤 Added '${teamInput.name}' membership for '${username}' with role '${membershipRole}'`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -961,7 +963,7 @@ async function main() {
|
||||
password: "PLATFORMadmin2024!",
|
||||
username: "platform",
|
||||
name: "Platform Admin",
|
||||
role: "ADMIN",
|
||||
role: "USER",
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user