Skip to content

Commit

Permalink
Merge branch 'main' into fix-create-platform-handler
Browse files Browse the repository at this point in the history
Signed-off-by: zomars <zomars@me.com>

# Conflicts:
#	packages/trpc/server/routers/viewer/organizations/create.handler.ts
  • Loading branch information
zomars committed Apr 4, 2024
2 parents 97f4cf0 + 844076b commit 386968f
Show file tree
Hide file tree
Showing 475 changed files with 8,475 additions and 2,841 deletions.
7 changes: 5 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ STRIPE_WEBHOOK_SECRET=
STRIPE_WEBHOOK_SECRET_APPS=
STRIPE_PRIVATE_KEY=
STRIPE_CLIENT_ID=
PAYMENT_FEE_FIXED=
PAYMENT_FEE_PERCENTAGE=


# Use for internal Public API Keys and optional
API_KEY_PREFIX=cal_
Expand Down Expand Up @@ -213,6 +212,10 @@ E2E_TEST_MAILHOG_ENABLED=

# **********************************************************************************************************

# Cloudflare Turnstile
NEXT_PUBLIC_CLOUDFLARE_SITEKEY=
CLOUDFLARE_TURNSTILE_SECRET=

# Set the following value to true if you wish to enable Team Impersonation
NEXT_PUBLIC_TEAM_IMPERSONATION=false

Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
**/**/public
packages/prisma/zod
apps/web/public/embed
packages/ui/components/icon/dynamicIconImports.tsx
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ packages/prisma/zod
packages/prisma/enums
apps/web/public/embed
apps/api/v2/swagger/documentation.json
packages/ui/components/icon/dynamicIconImports.tsx
15 changes: 13 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ Contributions are what makes the open source community such an amazing place to
- Issues from non-core members automatically receive the `🚨 needs approval` label.
- We greatly value new feature ideas. To ensure consistency in the product's direction, they undergo review and approval.



## Priorities

<table>
Expand Down Expand Up @@ -178,11 +176,15 @@ If you get errors, be sure to fix them before committing.
Do not commit your `yarn.lock` unless you've made changes to the `package.json`. If you've already committed `yarn.lock` unintentionally, follow these steps to undo:

If your last commit has the `yarn.lock` file alongside other files and you only wish to uncommit the `yarn.lock`:

```bash
git checkout HEAD~1 yarn.lock
git commit -m "Revert yarn.lock changes"
```

_NB_: You may have to bypass the pre-commit hook with by appending `--no-verify` to the git commit
If you've pushed the commit with the `yarn.lock`:

1. Correct the commit locally using the above method.
2. Carefully force push:

Expand All @@ -194,26 +196,35 @@ If `yarn.lock` was committed a while ago and there have been several commits sin

1. **Checkout a Previous Version**:
- Find the commit hash before the `yarn.lock` was unintentionally committed. You can do this by viewing the Git log:

```bash
git log yarn.lock
```

- Once you have identified the commit hash, use it to checkout the previous version of `yarn.lock`:

```bash
git checkout <commit_hash> yarn.lock
```

2. **Commit the Reverted Version**:
- After checking out the previous version of the `yarn.lock`, commit this change:

```bash
git commit -m "Revert yarn.lock to its state before unintended changes"
```

3. **Proceed with Caution**:
- If you need to push this change, first pull the latest changes from your remote branch to ensure you're not overwriting other recent changes:

```bash
git pull origin <your-branch-name>
```

- Then push the updated branch:

```bash
git push origin <your-branch-name>
```

Lastly, make sure to keep the branches updated (e.g. click the `Update branch` button on GitHub PR).
3 changes: 1 addition & 2 deletions apps/api/v1/lib/helpers/rateLimitApiKey.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { NextMiddleware } from "next-api-middleware";

import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
import { API_KEY_RATE_LIMIT } from "@calcom/lib/rateLimit";

export const rateLimitApiKey: NextMiddleware = async (req, res, next) => {
if (!req.query.apiKey) return res.status(401).json({ message: "No apiKey provided" });
Expand All @@ -11,7 +10,7 @@ export const rateLimitApiKey: NextMiddleware = async (req, res, next) => {
identifier: req.query.apiKey as string,
rateLimitingType: "api",
onRateLimiterResponse: (response) => {
res.setHeader("X-RateLimit-Limit", API_KEY_RATE_LIMIT);
res.setHeader("X-RateLimit-Limit", response.limit);
res.setHeader("X-RateLimit-Remaining", response.remaining);
res.setHeader("X-RateLimit-Reset", response.reset);
},
Expand Down
5 changes: 3 additions & 2 deletions apps/api/v1/pages/api/teams/[teamId]/_patch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Prisma } from "@prisma/client";
import type { NextApiRequest } from "next";

import { purchaseTeamSubscription } from "@calcom/features/ee/teams/lib/payments";
import { purchaseTeamOrOrgSubscription } from "@calcom/features/ee/teams/lib/payments";
import { IS_TEAM_BILLING_ENABLED } from "@calcom/lib/constants";
import { HttpError } from "@calcom/lib/http-error";
import { defaultResponder } from "@calcom/lib/server";
Expand Down Expand Up @@ -105,10 +105,11 @@ export async function patchHandler(req: NextApiRequest) {
};
delete data.slug;
if (IS_TEAM_BILLING_ENABLED) {
const checkoutSession = await purchaseTeamSubscription({
const checkoutSession = await purchaseTeamOrOrgSubscription({
teamId: _team.id,
seats: _team.members.length,
userId,
pricePerSeat: null,
});
if (!checkoutSession.url)
throw new TRPCError({
Expand Down
4 changes: 3 additions & 1 deletion apps/api/v1/pages/api/teams/_post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { NextApiRequest } from "next";

import { getStripeCustomerIdFromUserId } from "@calcom/app-store/stripepayment/lib/customer";
import stripe from "@calcom/app-store/stripepayment/lib/server";
import { IS_PRODUCTION } from "@calcom/lib/constants";
import { IS_TEAM_BILLING_ENABLED, WEBAPP_URL } from "@calcom/lib/constants";
import { HttpError } from "@calcom/lib/http-error";
import { defaultResponder } from "@calcom/lib/server";
Expand Down Expand Up @@ -197,8 +198,9 @@ const generateTeamCheckoutSession = async ({
customer_update: {
address: "auto",
},
// Disabled when testing locally as usually developer doesn't setup Tax in Stripe Test mode
automatic_tax: {
enabled: true,
enabled: IS_PRODUCTION,
},
metadata: {
pendingPaymentTeamId,
Expand Down
2 changes: 1 addition & 1 deletion apps/api/v2/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LOG_LEVEL=
NEXTAUTH_SECRET=
DATABASE_URL=
JWT_SECRET=
SENTRY_DNS=
SENTRY_DSN=

# KEEP THIS EMPTY, DISABLE SENTRY CLIENT INSIDE OF LIBRARIES USED BY APIv2
NEXT_PUBLIC_SENTRY_DSN=
2 changes: 1 addition & 1 deletion apps/api/v2/nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"plugins": [
{
"name": "@nestjs/swagger",
"options": { "dtoFileNameSuffix": ".input.ts", "classValidatorShim": true }
"options": { "dtoFileNameSuffix": [".input.ts", ".output.ts", ".dto.ts"], "classValidatorShim": true }
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion apps/api/v2/src/app.logger.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class AppLoggerMiddleware implements NestMiddleware {
private logger = new Logger("HTTP");

use(request: Request, response: Response, next: NextFunction): void {
const { ip, method, protocol, originalUrl, path: url } = request;
const { ip, method, originalUrl } = request;
const userAgent = request.get("user-agent") || "";

response.on("close", () => {
Expand Down
4 changes: 2 additions & 2 deletions apps/api/v2/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export const bootstrap = (app: NestExpressApplication): NestExpressApplication =
})
);

if (process.env.SENTRY_DNS) {
if (process.env.SENTRY_DSN) {
Sentry.init({
dsn: getEnv("SENTRY_DNS"),
dsn: getEnv("SENTRY_DSN"),
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CreateBookingInput } from "@/ee/bookings/inputs/create-booking.input";
import { IsBoolean, IsNumber, IsString, IsOptional, IsArray } from "class-validator";
import { IsBoolean, IsNumber, IsOptional } from "class-validator";

import type { AppsStatus } from "@calcom/platform-libraries";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CalendarsService } from "@/ee/calendars/services/calendars.service";
import { GetUser } from "@/modules/auth/decorators/get-user/get-user.decorator";
import { AccessTokenGuard } from "@/modules/auth/guards/access-token/access-token.guard";
import { UserWithProfile } from "@/modules/users/users.repository";
import { Controller, Get, Logger, UseGuards, Query } from "@nestjs/common";
import { Controller, Get, UseGuards, Query } from "@nestjs/common";

import { SUCCESS_STATUS } from "@calcom/platform-constants";
import { ConnectedDestinationCalendars } from "@calcom/platform-libraries";
Expand All @@ -16,8 +16,6 @@ import { EventBusyDate } from "@calcom/types/Calendar";
})
@UseGuards(AccessTokenGuard)
export class CalendarsController {
private readonly logger = new Logger("ee overlay calendars controller");

constructor(private readonly calendarsService: CalendarsService) {}

@Get("/busy-times")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { bootstrap } from "@/app";
import { AppModule } from "@/app.module";
import { EventTypesModule } from "@/ee/event-types/event-types.module";
import { CreateEventTypeInput } from "@/ee/event-types/inputs/create-event-type.input";
import { UpdateEventTypeInput } from "@/ee/event-types/inputs/update-event-type.input";
import { HttpExceptionFilter } from "@/filters/http-exception.filter";
import { PrismaExceptionFilter } from "@/filters/prisma-exception.filter";
import { PermissionsGuard } from "@/modules/auth/guards/permissions/permissions.guard";
Expand Down Expand Up @@ -61,7 +63,7 @@ describe("Event types Endpoints", () => {
let eventTypesRepositoryFixture: EventTypesRepositoryFixture;

const userEmail = "event-types-test-e2e@api.com";
const name = "bob";
const name = "bob the builder";
const username = name;
let eventType: EventType;
let user: User;
Expand All @@ -86,6 +88,7 @@ describe("Event types Endpoints", () => {
oauthClientRepositoryFixture = new OAuthClientRepositoryFixture(moduleRef);
userRepositoryFixture = new UserRepositoryFixture(moduleRef);
teamRepositoryFixture = new TeamRepositoryFixture(moduleRef);
eventTypesRepositoryFixture = new EventTypesRepositoryFixture(moduleRef);

organization = await teamRepositoryFixture.create({ name: "organization" });
oAuthClient = await createOAuthClient(organization.id);
Expand All @@ -95,17 +98,6 @@ describe("Event types Endpoints", () => {
username,
});

eventTypesRepositoryFixture = new EventTypesRepositoryFixture(moduleRef);

eventType = await eventTypesRepositoryFixture.create(
{
length: 60,
title: "peer coding session",
slug: "peer-coding",
},
user.id
);

await app.init();
});

Expand All @@ -129,6 +121,50 @@ describe("Event types Endpoints", () => {
expect(user).toBeDefined();
});

it("should create an event type", async () => {
const body: CreateEventTypeInput = {
title: "Test Event Type",
slug: "test-event-type",
description: "A description of the test event type.",
length: 60,
hidden: false,
locations: [
{
type: "Online",
link: "https://example.com/meet",
displayLocationPublicly: true,
},
],
};

return request(app.getHttpServer())
.post("/api/v2/event-types")
.send(body)
.expect(201)
.then(async (response) => {
const responseBody: ApiSuccessResponse<EventType> = response.body;
expect(responseBody.data).toHaveProperty("id");
expect(responseBody.data.title).toEqual(body.title);
eventType = responseBody.data;
});
});

it("should update event type", async () => {
const newTitle = "Updated title";

const body: UpdateEventTypeInput = {
title: newTitle,
};

return request(app.getHttpServer())
.patch(`/api/v2/event-types/${eventType.id}`)
.send(body)
.expect(200)
.then(async () => {
eventType.title = newTitle;
});
});

it(`/GET/:id`, async () => {
const response = await request(app.getHttpServer())
.get(`/api/v2/event-types/${eventType.id}`)
Expand All @@ -154,10 +190,8 @@ describe("Event types Endpoints", () => {
.expect(200);

const responseBody: ApiSuccessResponse<EventTypesByViewer> = response.body;

expect(responseBody.status).toEqual(SUCCESS_STATUS);
expect(responseBody.data).toBeDefined();
console.log("asap responseBody.data", responseBody.data);
expect(responseBody.data.eventTypeGroups).toBeDefined();
expect(responseBody.data.eventTypeGroups).toBeDefined();
expect(responseBody.data.eventTypeGroups[0]).toBeDefined();
Expand All @@ -178,7 +212,6 @@ describe("Event types Endpoints", () => {

expect(responseBody.status).toEqual(SUCCESS_STATUS);
expect(responseBody.data).toBeDefined();
console.log("asap responseBody.data", responseBody.data);
expect(responseBody.data).toBeDefined();
expect(responseBody.data.length).toEqual(1);
expect(responseBody.data[0].id).toEqual(eventType.id);
Expand All @@ -192,10 +225,18 @@ describe("Event types Endpoints", () => {
.expect(404);
});

it("should delete schedule", async () => {
return request(app.getHttpServer()).delete(`/api/v2/event-types/${eventType.id}`).expect(200);
});

afterAll(async () => {
await oauthClientRepositoryFixture.delete(oAuthClient.id);
await teamRepositoryFixture.delete(organization.id);
await eventTypesRepositoryFixture.delete(eventType.id);
try {
await eventTypesRepositoryFixture.delete(eventType.id);
} catch (e) {
// Event type might have been deleted by the test
}
try {
await userRepositoryFixture.delete(user.id);
} catch (e) {
Expand Down

0 comments on commit 386968f

Please sign in to comment.