-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/separate-client-vs-server-code-from-in…
…sights-layout
- Loading branch information
Showing
85 changed files
with
8,463 additions
and
1,457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
undecided: | ||
- calcom-monorepo | ||
- "@calcom/prisma" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
undecided: | ||
- "@calcom/app-store-cli" | ||
- "@calcom/platform-constants" | ||
- "@calcom/platform-enums" | ||
- "@calcom/platform-types" | ||
- "@calcom/platform-utils" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
apps/api/v2/src/modules/auth/decorators/get-optional-user/get-optional-user.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ApiAuthGuardUser } from "@/modules/auth/strategies/api-auth/api-auth.strategy"; | ||
import { ExecutionContext } from "@nestjs/common"; | ||
import { createParamDecorator } from "@nestjs/common"; | ||
|
||
export const GetOptionalUser = createParamDecorator< | ||
keyof ApiAuthGuardUser | (keyof ApiAuthGuardUser)[], | ||
ExecutionContext | ||
>((data, ctx) => { | ||
const request = ctx.switchToHttp().getRequest(); | ||
const user = request.user as ApiAuthGuardUser; | ||
|
||
if (!user) { | ||
return null; | ||
} | ||
|
||
if (Array.isArray(data)) { | ||
return data.reduce((prev, curr) => { | ||
return { | ||
...prev, | ||
[curr]: user[curr], | ||
}; | ||
}, {}); | ||
} | ||
|
||
if (data) { | ||
return user[data]; | ||
} | ||
|
||
return user; | ||
}); |
14 changes: 14 additions & 0 deletions
14
apps/api/v2/src/modules/auth/guards/optional-api-auth/optional-api-auth.guard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ApiAuthGuard } from "@/modules/auth/guards/api-auth/api-auth.guard"; | ||
import { NO_AUTH_PROVIDED_MESSAGE } from "@/modules/auth/strategies/api-auth/api-auth.strategy"; | ||
|
||
export class OptionalApiAuthGuard extends ApiAuthGuard { | ||
handleRequest(error: Error, user: any) { | ||
// note(Lauris): optional means that auth is not required but if it is invalid then still throw error. | ||
const noAuthProvided = error && error.message === NO_AUTH_PROVIDED_MESSAGE; | ||
if (user || noAuthProvided || !error) { | ||
return user || null; | ||
} else { | ||
throw error; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { MembershipsRepository } from "@/modules/memberships/memberships.repository"; | ||
import { MembershipsService } from "@/modules/memberships/services/memberships.service"; | ||
import { PrismaModule } from "@/modules/prisma/prisma.module"; | ||
import { Module } from "@nestjs/common"; | ||
|
||
@Module({ | ||
imports: [PrismaModule], | ||
providers: [MembershipsRepository], | ||
exports: [MembershipsRepository], | ||
providers: [MembershipsRepository, MembershipsService], | ||
exports: [MembershipsRepository, MembershipsService], | ||
}) | ||
export class MembershipsModule {} |
24 changes: 24 additions & 0 deletions
24
apps/api/v2/src/modules/memberships/services/memberships.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { MembershipsRepository } from "@/modules/memberships/memberships.repository"; | ||
import { Injectable } from "@nestjs/common"; | ||
import { intersectionBy } from "lodash"; | ||
|
||
@Injectable() | ||
export class MembershipsService { | ||
constructor(private readonly membershipsRepository: MembershipsRepository) {} | ||
|
||
async haveMembershipsInCommon(firstUserId: number, secondUserId: number) { | ||
const memberships = await this.membershipsInCommon(firstUserId, secondUserId); | ||
return memberships.length > 0; | ||
} | ||
|
||
async membershipsInCommon(firstUserId: number, secondUserId: number) { | ||
const firstUserMemberships = await this.membershipsRepository.findUserMemberships(firstUserId); | ||
const secondUserMemberships = await this.membershipsRepository.findUserMemberships(secondUserId); | ||
|
||
return intersectionBy( | ||
firstUserMemberships.filter((m) => m.accepted), | ||
secondUserMemberships.filter((m) => m.accepted), | ||
"teamId" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.