| 1 | import { |
| 2 | Body, |
| 3 | Controller, |
| 4 | Delete, |
| 5 | Get, |
| 6 | HttpCode, |
| 7 | HttpStatus, |
| 8 | Param, |
| 9 | Post, |
| 10 | Put, |
| 11 | Session, |
| 12 | } from '@nestjs/common'; |
| 13 | import { |
| 14 | ApiCreatedResponse, |
| 15 | ApiForbiddenResponse, |
| 16 | ApiNoContentResponse, |
| 17 | ApiNotFoundResponse, |
| 18 | ApiOkResponse, |
| 19 | ApiOperation, |
| 20 | ApiTags, |
| 21 | } from '@nestjs/swagger'; |
| 22 | import type { UserSession |
| 23 | |
| 24 | import { ErrorResponseDTO } |
| 25 | import { |
| 26 | DecideOauthAppAccessDTO, |
| 27 | ListOauthAppAccessResponseDTO, |
| 28 | ListOauthAppOrganizationAccessResponseDTO, |
| 29 | OauthAppAccessDTO, |
| 30 | } from './dto/oauth-app-access.dto.js'; |
| 31 | import { OauthAppAccessService } |
| 32 | |
| 33 | /** An organization's OAuth app access restrictions, turned on in its settings. */ |
| 34 | @ApiTags('Organizations') |
| 35 | @Controller('organizations/:slug/oauth-app-access') |
| 36 | export class OauthAppAccessController |
| 37 | constructor(private readonly |
| 38 | |
| 39 | @Get() |
| 40 | @ApiOperation({ |
| 41 | summary: 'The OAuth apps members asked for, and the answers. Admins only.', |
| 42 | }) |
| 43 | @ApiOkResponse({ type |
| 44 | @ApiForbiddenResponse({ type |
| 45 | @ApiNotFoundResponse({ type |
| 46 | list(@Param( |
| 47 | return this.access |
| 48 | } |
| 49 | |
| 50 | @Put(':clientId' |
| 51 | @ApiOperation({ |
| 52 | summary: 'Approve or deny an OAuth app. Admins only.', |
| 53 | description: 'Whether or not anyone asked for it.', |
| 54 | }) |
| 55 | @ApiOkResponse({ type |
| 56 | @ApiForbiddenResponse({ type |
| 57 | @ApiNotFoundResponse({ type |
| 58 | decide( |
| 59 | @Param('slug' |
| 60 | @Param('clientId' |
| 61 | @Body() body |
| 62 | @Session() session |
| 63 | ) { |
| 64 | return this.access |
| 65 | } |
| 66 | |
| 67 | @Delete(':clientId' |
| 68 | @HttpCode(HttpStatus. |
| 69 | @ApiOperation({ |
| 70 | summary: 'Revoke an answer about an OAuth app. Admins only.', |
| 71 | description: |
| 72 | 'A revoked approval blocks the app again; a revoked denial lets members ask again.', |
| 73 | }) |
| 74 | @ApiNoContentResponse() |
| 75 | @ApiForbiddenResponse({ type |
| 76 | @ApiNotFoundResponse({ type |
| 77 | revoke( |
| 78 | @Param('slug' |
| 79 | @Param('clientId' |
| 80 | @Session() session |
| 81 | ) { |
| 82 | return this.access |
| 83 | } |
| 84 | |
| 85 | @Post(':clientId/request' |
| 86 | @ApiOperation({ |
| 87 | summary: "Ask the organization's admins to approve an OAuth app", |
| 88 | description: 'Any member may ask. An answer already given stands.', |
| 89 | }) |
| 90 | @ApiCreatedResponse({ type |
| 91 | @ApiNotFoundResponse({ type |
| 92 | request( |
| 93 | @Param('slug' |
| 94 | @Param('clientId' |
| 95 | @Session() session |
| 96 | ) { |
| 97 | return this.access |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /** Where an OAuth app reaches among the signed-in account's organizations. */ |
| 102 | @ApiTags('OAuth apps') |
| 103 | @Controller('oauth-apps/:clientId/organizations') |
| 104 | export class OauthAppOrganizationsController |
| 105 | constructor(private readonly |
| 106 | |
| 107 | @Get() |
| 108 | @ApiOperation({ |
| 109 | summary: "Whether an OAuth app reaches each of the account's organizations", |
| 110 | description: |
| 111 | 'For the approval screen and the authorized apps page, where a member asks for a restricted app.', |
| 112 | }) |
| 113 | @ApiOkResponse({ type |
| 114 | @ApiNotFoundResponse({ type |
| 115 | list(@Param( |
| 116 | return this.access |
| 117 | } |
| 118 | } |