Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: organizations teams endpoints apiv2 #15586

Merged
merged 10 commits into from
Jun 27, 2024
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
Loading