generated from xgeekshq/oss-template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Cátia Antunes <c.antunes@kigroup.de> Co-authored-by: Rui Silva <r.silva@kigroup.de>
- Loading branch information
1 parent
d3ffbab
commit 8005b98
Showing
19 changed files
with
339 additions
and
92 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,26 @@ | ||
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; | ||
import { Reflector } from '@nestjs/core'; | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { Model } from 'mongoose'; | ||
|
||
import TeamUser, { TeamUserDocument } from '../../modules/teams/schemas/team.user.schema'; | ||
|
||
@Injectable() | ||
export class TeamUserGuard implements CanActivate { | ||
constructor( | ||
private readonly reflector: Reflector, | ||
@InjectModel(TeamUser.name) private teamUserModel: Model<TeamUserDocument> | ||
) {} | ||
|
||
async canActivate(context: ExecutionContext) { | ||
const permission = this.reflector.get<string>('permission', context.getHandler()); | ||
const request = context.switchToHttp().getRequest(); | ||
|
||
const user = request.user; | ||
const team: string = request.params.teamId; | ||
|
||
const userFound = await this.teamUserModel.findOne({ user: user._id, teamId: team }).exec(); | ||
|
||
return user.isSAdmin || permission === userFound?.role; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/src/modules/teams/applications/update.team.application.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,18 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
|
||
import TeamUserDto from '../dto/team.user.dto'; | ||
import { UpdateTeamApplicationInterface } from '../interfaces/applications/update.team.application.interface'; | ||
import { UpdateTeamServiceInterface } from '../interfaces/services/update.team.service.interface'; | ||
import { TYPES } from '../interfaces/types'; | ||
|
||
@Injectable() | ||
export class UpdateTeamApplication implements UpdateTeamApplicationInterface { | ||
constructor( | ||
@Inject(TYPES.services.UpdateTeamService) | ||
private updateTeamService: UpdateTeamServiceInterface | ||
) {} | ||
|
||
updateTeamUser(teamData: TeamUserDto) { | ||
return this.updateTeamService.updateTeamUser(teamData); | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
backend/src/modules/teams/interfaces/applications/update.team.application.interface.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,8 @@ | ||
import { LeanDocument } from 'mongoose'; | ||
|
||
import TeamUserDto from '../../dto/team.user.dto'; | ||
import { TeamUserDocument } from '../../schemas/team.user.schema'; | ||
|
||
export interface UpdateTeamApplicationInterface { | ||
updateTeamUser(teamData: TeamUserDto): Promise<LeanDocument<TeamUserDocument> | null>; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { LeanDocument } from 'mongoose'; | ||
|
||
import TeamUserDto from '../../dto/team.user.dto'; | ||
import { TeamUserDocument } from '../../schemas/team.user.schema'; | ||
|
||
export interface UpdateTeamServiceInterface { | ||
updateTeamUser(teamData: TeamUserDto): Promise<LeanDocument<TeamUserDocument> | null>; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { LeanDocument, Model } from 'mongoose'; | ||
|
||
import TeamUserDto from '../dto/team.user.dto'; | ||
import { UpdateTeamServiceInterface } from '../interfaces/services/update.team.service.interface'; | ||
import TeamUser, { TeamUserDocument } from '../schemas/team.user.schema'; | ||
|
||
@Injectable() | ||
export default class UpdateTeamService implements UpdateTeamServiceInterface { | ||
constructor(@InjectModel(TeamUser.name) private teamUserModel: Model<TeamUserDocument>) {} | ||
|
||
updateTeamUser(teamData: TeamUserDto): Promise<LeanDocument<TeamUserDocument> | null> { | ||
return this.teamUserModel | ||
.findOneAndUpdate( | ||
{ user: teamData.user, team: teamData.team }, | ||
{ $set: { role: teamData.role, isNewJoiner: teamData.isNewJoiner } }, | ||
{ new: true } | ||
) | ||
.lean() | ||
.exec(); | ||
} | ||
} |
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
Oops, something went wrong.