feat: v2 managed organizations (#19341)
* refactor: allow non unique PlatformBilling customerId * feat: add PlatformBilling managed organizations fields * feat: ManagedOrganization table * refactor: bill overdue based on teamId * refactor: restructure organizations module * wip: organizations endpoints * Revert "wip: organizations endpoints" This reverts commit 0e9e66fc74f31da436f12930c1b6597c650ed621. * refactor: unique index for managed organizations * wip: organizations endpoints * wip: create managed organization * remove unecessary membership check because we have guard * feat: create managed org * feat: get managed org and orgs * feat: update and delete managed orgs * wip: api key logic * feat: allow variable api key length * feat: refresh managed org api key * feat: create managed org OAuth clients using api key * finish merge main * chore: bump platform libraries * tests: fix and add more tests to api-auth.strategy.e2e * refactor: dont request managed org slug and handle metadata as object * revert: billing service and repository update overdue based on sub and customer ids * refactor: v2 OAuth client permissions (#19501) * refactor: v2 permissions as string array * refactor: frontend work with permissions as string * tests: test '*' permissions * fix:managed org creator have profile & test can fetch oauth client * fix: tests * fix: OAuthClientCard on frontend * fix: tests
This commit is contained in:
1 parent
e4ab8d87c4
commit
a44bcafcf2
192 files changed
+9103
-619
No files matched your search
@@ -239,3 +239,5 @@ export { getBookingFieldsWithSystemFields };
|
||||
export { getRoutedUrl };
|
||||
|
||||
export { getTeamMemberEmailForResponseOrContactUsingUrlQuery };
|
||||
|
||||
export { createHandler as createApiKeyHandler } from "@calcom/trpc/server/routers/viewer/apiKeys/create.handler";
|
||||
@@ -11,3 +11,4 @@ export * from "./organizations";
|
||||
export * from "./teams";
|
||||
export * from "./embed";
|
||||
export * from "./routing-forms";
|
||||
export * from "./me";
|
||||
@@ -0,0 +1,15 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const userSchemaResponse = z.object({
|
||||
id: z.number().int(),
|
||||
email: z.string(),
|
||||
timeFormat: z.number().int().default(12),
|
||||
defaultScheduleId: z.number().int().nullable(),
|
||||
weekStart: z.string(),
|
||||
timeZone: z.string().default("Europe/London"),
|
||||
username: z.string(),
|
||||
organizationId: z.number().nullable(),
|
||||
organization: z.object({ isPlatform: z.boolean(), id: z.number() }).optional(),
|
||||
});
|
||||
|
||||
export type UserResponse = z.infer<typeof userSchemaResponse>;
|
||||
@@ -1,63 +0,0 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsArray, IsNumber, IsOptional, IsBoolean, IsString } from "class-validator";
|
||||
import { z } from "zod";
|
||||
|
||||
export class CreateOAuthClientInput {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional()
|
||||
logo?: string;
|
||||
|
||||
@IsString()
|
||||
@ApiProperty()
|
||||
name!: string;
|
||||
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
@ApiProperty({ type: [String] })
|
||||
redirectUris!: string[];
|
||||
|
||||
@IsNumber()
|
||||
@ApiProperty()
|
||||
permissions!: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional()
|
||||
bookingRedirectUri?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional()
|
||||
bookingCancelRedirectUri?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional()
|
||||
bookingRescheduleRedirectUri?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@ApiPropertyOptional()
|
||||
areEmailsEnabled?: boolean;
|
||||
}
|
||||
|
||||
export class DeleteOAuthClientInput {
|
||||
@IsString()
|
||||
@ApiProperty()
|
||||
id!: string;
|
||||
}
|
||||
|
||||
export const userSchemaResponse = z.object({
|
||||
id: z.number().int(),
|
||||
email: z.string(),
|
||||
timeFormat: z.number().int().default(12),
|
||||
defaultScheduleId: z.number().int().nullable(),
|
||||
weekStart: z.string(),
|
||||
timeZone: z.string().default("Europe/London"),
|
||||
username: z.string(),
|
||||
organizationId: z.number().nullable(),
|
||||
organization: z.object({ isPlatform: z.boolean(), id: z.number() }).optional(),
|
||||
});
|
||||
|
||||
export type UserResponse = z.infer<typeof userSchemaResponse>;
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./inputs";
|
||||
export * from "./outputs";
|
||||
@@ -0,0 +1,50 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsArray, IsEnum, IsOptional, IsBoolean, IsString } from "class-validator";
|
||||
|
||||
import { PERMISSION_MAP } from "@calcom/platform-constants";
|
||||
|
||||
export class CreateOAuthClientInput {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional()
|
||||
logo?: string;
|
||||
|
||||
@IsString()
|
||||
@ApiProperty()
|
||||
name!: string;
|
||||
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
@ApiProperty({ type: [String] })
|
||||
redirectUris!: string[];
|
||||
|
||||
@IsArray()
|
||||
@IsEnum([...Object.keys(PERMISSION_MAP), "*"], { each: true })
|
||||
@ApiProperty({
|
||||
type: [String],
|
||||
description:
|
||||
'Array of permission keys like ["BOOKING_READ", "BOOKING_WRITE"]. Use ["*"] to grant all permissions.',
|
||||
enum: [...Object.keys(PERMISSION_MAP), "*"],
|
||||
})
|
||||
permissions!: Array<keyof typeof PERMISSION_MAP | "*">;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional()
|
||||
bookingRedirectUri?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional()
|
||||
bookingCancelRedirectUri?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional()
|
||||
bookingRescheduleRedirectUri?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@ApiPropertyOptional()
|
||||
areEmailsEnabled?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsString } from "class-validator";
|
||||
|
||||
export class DeleteOAuthClientInput {
|
||||
@IsString()
|
||||
@ApiProperty()
|
||||
id!: string;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from "./create-oauth-client.input";
|
||||
export * from "./delete-oauth-client.input";
|
||||
export * from "./update-oauth-client.input";
|
||||
@@ -0,0 +1,40 @@
|
||||
import { ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsArray, IsBoolean, IsOptional, IsString } from "class-validator";
|
||||
|
||||
export class UpdateOAuthClientInput {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional()
|
||||
logo?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiPropertyOptional()
|
||||
name?: string;
|
||||
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
@IsString({ each: true })
|
||||
@ApiPropertyOptional({ type: [String] })
|
||||
redirectUris?: string[];
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional()
|
||||
bookingRedirectUri?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional()
|
||||
bookingCancelRedirectUri?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional()
|
||||
bookingRescheduleRedirectUri?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@ApiPropertyOptional()
|
||||
areEmailsEnabled?: boolean;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./oauth-client.output";
|
||||
@@ -0,0 +1,66 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
||||
import { IsArray, IsEnum, IsString, IsNumber, IsOptional, IsDate, IsBoolean, IsUrl } from "class-validator";
|
||||
|
||||
import { PERMISSION_MAP } from "@calcom/platform-constants";
|
||||
|
||||
export class PlatformOAuthClientDto {
|
||||
@ApiProperty({ example: "clsx38nbl0001vkhlwin9fmt0" })
|
||||
@IsString()
|
||||
id!: string;
|
||||
|
||||
@ApiProperty({ example: "MyClient" })
|
||||
@IsString()
|
||||
name!: string;
|
||||
|
||||
@ApiProperty({ example: "secretValue" })
|
||||
@IsString()
|
||||
secret!: string;
|
||||
|
||||
@ApiProperty({ example: ["BOOKING_READ", "BOOKING_WRITE"] })
|
||||
@IsArray()
|
||||
@IsEnum(PERMISSION_MAP, { each: true })
|
||||
@ApiProperty({
|
||||
type: [String],
|
||||
description: 'Array of permission keys like ["BOOKING_READ", "BOOKING_WRITE"]',
|
||||
enum: Object.keys(PERMISSION_MAP),
|
||||
})
|
||||
permissions!: Array<keyof typeof PERMISSION_MAP>;
|
||||
|
||||
@ApiPropertyOptional({ example: "https://example.com/logo.png" })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
logo!: string | null;
|
||||
|
||||
@ApiProperty({ example: ["https://example.com/callback"] })
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
redirectUris!: string[];
|
||||
|
||||
@ApiProperty({ example: 1 })
|
||||
@IsNumber()
|
||||
organizationId!: number;
|
||||
|
||||
@ApiProperty({ example: "2024-03-23T08:33:21.851Z", type: Date })
|
||||
@IsDate()
|
||||
createdAt!: Date;
|
||||
|
||||
@ApiPropertyOptional({ example: "https://example.com/booking-redirect" })
|
||||
@IsOptional()
|
||||
@IsUrl()
|
||||
bookingRedirectUri?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: "https://example.com/booking-cancel" })
|
||||
@IsOptional()
|
||||
@IsUrl()
|
||||
bookingCancelRedirectUri?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: "https://example.com/booking-reschedule" })
|
||||
@IsOptional()
|
||||
@IsUrl()
|
||||
bookingRescheduleRedirectUri?: string;
|
||||
|
||||
@ApiPropertyOptional({ example: false })
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
areEmailsEnabled?: boolean;
|
||||
}
|
||||
Reference in new issue
Block a user