Skip to content

Commit

Permalink
feat: organizations teams endpoints apiv2 (calcom#15586)
Browse files Browse the repository at this point in the history
* feat: organizations teams endpoints apiv2

* fixup! Merge branch 'main' into feat-api-v2-org-teams-endpoints

* chore: add roles guard to endpoints

* add tests

* fixup! Merge branch 'main' into feat-api-v2-org-teams-endpoints

* fixup! fixup! Merge branch 'main' into feat-api-v2-org-teams-endpoints

* fixup! fixup! fixup! Merge branch 'main' into feat-api-v2-org-teams-endpoints
  • Loading branch information
ThyMinimalDev authored and p6l-richard committed Jul 22, 2024
1 parent c254d63 commit 1cdecc0
Show file tree
Hide file tree
Showing 11 changed files with 868 additions and 39 deletions.
18 changes: 14 additions & 4 deletions apps/api/v2/src/modules/auth/guards/teams/is-team-in-org.guard.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { OrganizationsRepository } from "@/modules/organizations/organizations.repository";
import { Injectable, CanActivate, ExecutionContext, ForbiddenException } from "@nestjs/common";
import { OrganizationsTeamsRepository } from "@/modules/organizations/repositories/organizations-teams.repository";
import {
Injectable,
CanActivate,
ExecutionContext,
ForbiddenException,
NotFoundException,
} from "@nestjs/common";
import { Request } from "express";

import { Team } from "@calcom/prisma/client";

@Injectable()
export class IsTeamInOrg implements CanActivate {
constructor(private organizationsRepository: OrganizationsRepository) {}
constructor(private organizationsTeamsRepository: OrganizationsTeamsRepository) {}

async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest<Request & { team: Team }>();
Expand All @@ -21,13 +27,17 @@ export class IsTeamInOrg implements CanActivate {
throw new ForbiddenException("No team id found in request params.");
}

const team = await this.organizationsRepository.findOrgTeam(Number(orgId), Number(teamId));
const team = await this.organizationsTeamsRepository.findOrgTeam(Number(orgId), Number(teamId));

if (team && !team.isOrganization && team.parentId === Number(orgId)) {
request.team = team;
return true;
}

if (!team) {
throw new NotFoundException(`Team (${teamId}) not found.`);
}

return false;
}
}
Loading

0 comments on commit 1cdecc0

Please sign in to comment.