| 1 | import { |
| 2 | Body, |
| 3 | Controller, |
| 4 | Delete, |
| 5 | Get, |
| 6 | HttpCode, |
| 7 | HttpStatus, |
| 8 | Param, |
| 9 | Put, |
| 10 | Session, |
| 11 | } from '@nestjs/common'; |
| 12 | import { |
| 13 | ApiBadRequestResponse, |
| 14 | ApiForbiddenResponse, |
| 15 | ApiNoContentResponse, |
| 16 | ApiNotFoundResponse, |
| 17 | ApiOkResponse, |
| 18 | ApiOperation, |
| 19 | ApiTags, |
| 20 | } from '@nestjs/swagger'; |
| 21 | import type { UserSession |
| 22 | |
| 23 | import { ErrorResponseDTO } |
| 24 | import { CollaboratorsService } |
| 25 | import { |
| 26 | CollaboratorDTO, |
| 27 | InviteCollaboratorRequestDTO, |
| 28 | ListCollaboratorsResponseDTO, |
| 29 | } from './dto/collaborator.dto.js'; |
| 30 | |
| 31 | @ApiTags('Collaborators') |
| 32 | @Controller('repositories/:username/:repo/collaborators') |
| 33 | export class CollaboratorsController |
| 34 | constructor(private readonly |
| 35 | |
| 36 | @Get() |
| 37 | @ApiOperation({ |
| 38 | summary: 'List collaborators', |
| 39 | description: 'Collaborators and pending invitations. Admins only.', |
| 40 | }) |
| 41 | @ApiOkResponse({ type |
| 42 | @ApiForbiddenResponse({ type |
| 43 | @ApiNotFoundResponse({ type |
| 44 | list( |
| 45 | @Param('username' |
| 46 | @Param('repo' |
| 47 | @Session() session |
| 48 | ): Promise<ListCollaboratorsResponseDTO |
| 49 | return this.collaborators |
| 50 | username, |
| 51 | repo, |
| 52 | requesterId: session.user |
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | @Put(':collaborator' |
| 57 | @ApiOperation({ |
| 58 | summary: 'Invite a collaborator or change their role', |
| 59 | description: |
| 60 | 'Invites the user, who gets access once they accept. For someone already invited or collaborating, changes the role. Admins only.', |
| 61 | }) |
| 62 | @ApiOkResponse({ type |
| 63 | @ApiBadRequestResponse({ type |
| 64 | @ApiForbiddenResponse({ type |
| 65 | @ApiNotFoundResponse({ type |
| 66 | invite( |
| 67 | @Param('username' |
| 68 | @Param('repo' |
| 69 | @Param('collaborator' |
| 70 | @Body() body |
| 71 | @Session() session |
| 72 | ): Promise<CollaboratorDTO |
| 73 | return this.collaborators |
| 74 | username, |
| 75 | repo, |
| 76 | requesterId: session.user |
| 77 | collaborator, |
| 78 | role: body.role |
| 79 | }); |
| 80 | } |
| 81 | |
| 82 | @Delete(':collaborator' |
| 83 | @HttpCode(HttpStatus. |
| 84 | @ApiOperation({ |
| 85 | summary: 'Remove a collaborator', |
| 86 | description: |
| 87 | 'Removes a collaborator or withdraws an invitation. Admins only, except that collaborators may remove themselves.', |
| 88 | }) |
| 89 | @ApiNoContentResponse() |
| 90 | @ApiForbiddenResponse({ type |
| 91 | @ApiNotFoundResponse({ type |
| 92 | remove( |
| 93 | @Param('username' |
| 94 | @Param('repo' |
| 95 | @Param('collaborator' |
| 96 | @Session() session |
| 97 | ): Promise<void |
| 98 | return this.collaborators |
| 99 | username, |
| 100 | repo, |
| 101 | requesterId: session.user |
| 102 | collaborator, |
| 103 | }); |
| 104 | } |
| 105 | } |