Skip to content

Commit

Permalink
🐛 Fix jwt routes
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Aug 6, 2024
1 parent 9fec88f commit e3170bb
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 124 deletions.
32 changes: 16 additions & 16 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,22 @@ services:
# volumes:
# - pgadmin-data:/var/lib/pgadmin

# ngrok:
# image: ngrok/ngrok:latest
# restart: always
# command:
# - "start"
# - "--all"
# - "--config"
# - "/etc/ngrok.yml"
# volumes:
# - ./ngrok.yml:/etc/ngrok.yml
# ports:
# - 4040:4040
# depends_on:
# api:
# condition: service_healthy
# network_mode: "host"
ngrok:
image: ngrok/ngrok:latest
restart: always
command:
- "start"
- "--all"
- "--config"
- "/etc/ngrok.yml"
volumes:
- ./ngrok.yml:/etc/ngrok.yml
ports:
- 4040:4040
depends_on:
api:
condition: service_healthy
network_mode: "host"

docs:
build:
Expand Down
4 changes: 2 additions & 2 deletions docs/open-source/contributors/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ We made a docker file that builds Panora from sources, specifically to help you

<Steps>
<Step title="Copy env variables">
<Note>Check environment variables reference [here](/open-source/selfhost/envVariables) !</Note>
<Note>Check environment variables reference [here](/open-source/self_hosting/envVariables) !</Note>
```bash
cp .env.example .env
```
Expand All @@ -27,7 +27,7 @@ We made a docker file that builds Panora from sources, specifically to help you
</Step>
<Step title="(Optional) Enable Grok">
If you have to create an oAuth app for a provider and needs an **https** redirect uri you must enable Grok service and use your secure domain from them (it proxies requests to `localhost:3000`).
Check this [quick guide](/open-source/selfhost/ngrok) to set it up !
Check this [quick guide](/open-source/self_hosting/ngrok) to set it up !
</Step>
<Step title="Start the Dockerfile">
```bash
Expand Down
2 changes: 1 addition & 1 deletion docs/open-source/contributors/test.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ icon: "star"
Now you must test Panora unified endpoints with the new connector built.
<Steps>
<Step title="Create a connection using the magic link">
You need a set of credentials that you'll set in `.env` if you use oAuth (check [here](/open-source/selfhost/envVariables#providers-specific-credentials) how it works).
You need a set of credentials that you'll set in `.env` if you use oAuth (check [here](/open-source/self_hosting/envVariables#providers-specific-credentials) how it works).
Check [this guide](/core-concepts/magic-links) to create a connection through it.
To activate your new connector on the magic link, visit this [**file**](https://github.com/panoratech/Panora/blob/main/packages/shared/src/connectors/metadata.ts#L6) :
and change your connector status to `active: true`.
Expand Down
2 changes: 1 addition & 1 deletion docs/open-source/self_hosting/envVariables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ description: ""

## Ingress

<Note>Check [here](/selfhost/ngrok) to set up Ngrok ! </Note>
<Note>Check [here](/self_hosting/ngrok) to set up Ngrok ! </Note>

| Variable | Example | Purpose |
| -------- | ------------------------------------- | ------------------------------------- |
Expand Down
2 changes: 1 addition & 1 deletion docs/open-source/self_hosting/guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ git clone https://github.com/panoratech/Panora.git
</Step>

<Step title="Prepare the installation:">
<Note> Check [here](/open-source/selfhost/envVariables) to fill the right env variables ! </Note>
<Note> Check [here](/open-source/self_hosting/envVariables) to fill the right env variables ! </Note>
```bash
cd Panora && cp .env.example .env
```
Expand Down
54 changes: 27 additions & 27 deletions packages/api/src/@core/field-mapping/field-mapping.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,16 @@ export class FieldMappingController {
);
}

@ApiOperation({
operationId: 'definitions',
summary: 'Define target Field',
})
@ApiBody({ type: DefineTargetFieldDto })
@ApiOperation({ operationId: 'map', summary: 'Map Custom Field' })
@ApiBody({ type: MapFieldToProviderDto })
@ApiPostCustomResponse(CustomFieldResponse)
@Post('define')
@UseGuards(ApiKeyAuthGuard)
defineTargetField(
@Request() req: any,
@Body() defineTargetFieldDto: DefineTargetFieldDto,
@UseGuards(JwtAuthGuard)
@ApiExcludeEndpoint()
@Post('internal/map')
mapInternalFieldToProvider(
@Body() mapFieldToProviderDto: MapFieldToProviderDto,
) {
const { id_project } = req.user;
return this.fieldMappingService.defineTargetField(
defineTargetFieldDto,
id_project,
);
return this.fieldMappingService.mapFieldToProvider(mapFieldToProviderDto);
}

@ApiOperation({
Expand All @@ -129,6 +122,25 @@ export class FieldMappingController {
return this.fieldMappingService.createCustomField(data, id_project);
}

@ApiOperation({
operationId: 'definitions',
summary: 'Define target Field',
})
@ApiBody({ type: DefineTargetFieldDto })
@ApiPostCustomResponse(CustomFieldResponse)
@Post('define')
@UseGuards(ApiKeyAuthGuard)
defineTargetField(
@Request() req: any,
@Body() defineTargetFieldDto: DefineTargetFieldDto,
) {
const { id_project } = req.user;
return this.fieldMappingService.defineTargetField(
defineTargetFieldDto,
id_project,
);
}

@ApiOperation({
operationId: 'defineCustomField',
summary: 'Create Custom Field',
Expand All @@ -142,18 +154,6 @@ export class FieldMappingController {
return this.fieldMappingService.createCustomField(data, id_project);
}

@ApiOperation({ operationId: 'map', summary: 'Map Custom Field' })
@ApiBody({ type: MapFieldToProviderDto })
@ApiPostCustomResponse(CustomFieldResponse)
@UseGuards(JwtAuthGuard)
@ApiExcludeEndpoint()
@Post('internal/map')
mapInternalFieldToProvider(
@Body() mapFieldToProviderDto: MapFieldToProviderDto,
) {
return this.fieldMappingService.mapFieldToProvider(mapFieldToProviderDto);
}

@ApiOperation({ operationId: 'map', summary: 'Map Custom Field' })
@ApiBody({ type: MapFieldToProviderDto })
@ApiPostCustomResponse(CustomFieldResponse)
Expand Down
141 changes: 70 additions & 71 deletions packages/api/src/@core/linked-users/linked-users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
ApiPostArrayCustomResponse,
ApiPostCustomResponse,
} from '@@core/utils/dtos/openapi.respone.dto';

@ApiTags('linkedUsers')
@Controller('linked_users')
export class LinkedUsersController {
Expand All @@ -44,21 +43,32 @@ export class LinkedUsersController {
}

@ApiOperation({
operationId: 'createLinkedUser',
summary: 'Create Linked Users',
operationId: 'listLinkedUsers',
summary: 'Retrieve Linked Users',
})
@ApiResponse({ status: 200 })
@UseGuards(JwtAuthGuard)
@ApiExcludeEndpoint()
@Get('internal')
fetchLinkedUsersInternal(@Request() req: any) {
const { id_project } = req.user;
return this.linkedUsersService.getLinkedUsers(id_project);
}

@ApiOperation({ operationId: 'createLinkedUser', summary: 'Add Linked User' })
@ApiBody({ type: CreateLinkedUserDto })
@ApiPostCustomResponse(LinkedUserResponse)
@UseGuards(ApiKeyAuthGuard)
@Post()
addLinkedUser(
@ApiResponse({ status: 201 })
@ApiExcludeEndpoint()
@UseGuards(JwtAuthGuard)
@Post('internal')
addLinkedUserInternal(
@Request() req: any,
@Body() linkedUserCreateDto: CreateLinkedUserDto,
) {
const projectId = req.user.id_project;
const { id_project } = req.user;
return this.linkedUsersService.addLinkedUser(
linkedUserCreateDto,
projectId,
id_project,
);
}

Expand All @@ -67,43 +77,33 @@ export class LinkedUsersController {
summary: 'Add Batch Linked Users',
})
@ApiBody({ type: CreateBatchLinkedUserDto })
@ApiPostArrayCustomResponse(LinkedUserResponse)
@UseGuards(ApiKeyAuthGuard)
@Post('batch')
addBatchLinkedUsers(
@ApiResponse({ status: 201 })
@ApiExcludeEndpoint()
@UseGuards(JwtAuthGuard)
@Post('internal/batch')
addBatchLinkedUsersInternal(
@Request() req: any,
@Body() data: CreateBatchLinkedUserDto,
) {
const projectId = req.user.id_project;
return this.linkedUsersService.addBatchLinkedUsers(data, projectId);
}

@ApiOperation({
operationId: 'listLinkedUsers',
summary: 'List Linked Users',
})
@ApiGetArrayCustomResponse(LinkedUserResponse)
@UseGuards(ApiKeyAuthGuard)
@Get()
listLinkedUsers(@Request() req: any) {
const { id_project } = req.user;
return this.linkedUsersService.getLinkedUsers(id_project);
return this.linkedUsersService.addBatchLinkedUsers(data, id_project);
}

@ApiOperation({
operationId: 'retrieveLinkedUser',
summary: 'Retrieve Linked Users',
summary: 'Retrieve a Linked User',
})
@ApiParam({
@ApiQuery({
name: 'id',
required: true,
example: '801f9ede-c698-4e66-a7fc-48d19eebaa4f',
required: true,
type: String,
})
@ApiGetCustomResponse(LinkedUserResponse)
@UseGuards(ApiKeyAuthGuard)
@Get(':id')
getLinkedUser(@Param('id') id: string) {
@ApiResponse({ status: 200 })
@UseGuards(JwtAuthGuard)
@ApiExcludeEndpoint()
@Get('internal/single')
getLinkedUserInternal(@Query('id') id: string) {
// validate project_id against user
return this.linkedUsersService.getLinkedUser(id);
}
Expand All @@ -113,28 +113,31 @@ export class LinkedUsersController {
summary: 'Retrieve a Linked User From A Remote Id',
})
@ApiQuery({ name: 'remoteId', example: 'id_1', required: true, type: String })
@ApiGetCustomResponse(LinkedUserResponse)
@UseGuards(ApiKeyAuthGuard)
@Get('fromRemoteId')
linkedUserFromRemoteId(@Query('remoteId') id: string) {
@ApiResponse({ status: 200 })
@ApiExcludeEndpoint()
@UseGuards(JwtAuthGuard)
@Get('internal/fromRemoteId')
linkedUserFromRemoteIdInternal(@Query('remoteId') id: string) {
// validate project_id against user
return this.linkedUsersService.getLinkedUserV2(id);
}

@ApiOperation({ operationId: 'createLinkedUser', summary: 'Add Linked User' })
@ApiOperation({
operationId: 'createLinkedUser',
summary: 'Create Linked Users',
})
@ApiBody({ type: CreateLinkedUserDto })
@ApiResponse({ status: 201 })
@ApiExcludeEndpoint()
@UseGuards(JwtAuthGuard)
@Post('internal')
addLinkedUserInternal(
@ApiPostCustomResponse(LinkedUserResponse)
@UseGuards(ApiKeyAuthGuard)
@Post()
addLinkedUser(
@Request() req: any,
@Body() linkedUserCreateDto: CreateLinkedUserDto,
) {
const { id_project } = req.user;
const projectId = req.user.id_project;
return this.linkedUsersService.addLinkedUser(
linkedUserCreateDto,
id_project,
projectId,
);
}

Expand All @@ -143,46 +146,43 @@ export class LinkedUsersController {
summary: 'Add Batch Linked Users',
})
@ApiBody({ type: CreateBatchLinkedUserDto })
@ApiResponse({ status: 201 })
@ApiExcludeEndpoint()
@UseGuards(JwtAuthGuard)
@Post('internal/batch')
addBatchLinkedUsersInternal(
@ApiPostArrayCustomResponse(LinkedUserResponse)
@UseGuards(ApiKeyAuthGuard)
@Post('batch')
addBatchLinkedUsers(
@Request() req: any,
@Body() data: CreateBatchLinkedUserDto,
) {
const { id_project } = req.user;
return this.linkedUsersService.addBatchLinkedUsers(data, id_project);
const projectId = req.user.id_project;
return this.linkedUsersService.addBatchLinkedUsers(data, projectId);
}

@ApiOperation({
operationId: 'listLinkedUsers',
summary: 'Retrieve Linked Users',
summary: 'List Linked Users',
})
@ApiResponse({ status: 200 })
@UseGuards(JwtAuthGuard)
@ApiExcludeEndpoint()
@Get('internal')
fetchLinkedUsersInternal(@Request() req: any) {
@ApiGetArrayCustomResponse(LinkedUserResponse)
@UseGuards(ApiKeyAuthGuard)
@Get()
listLinkedUsers(@Request() req: any) {
const { id_project } = req.user;
return this.linkedUsersService.getLinkedUsers(id_project);
}

@ApiOperation({
operationId: 'retrieveLinkedUser',
summary: 'Retrieve a Linked User',
summary: 'Retrieve Linked Users',
})
@ApiQuery({
@ApiParam({
name: 'id',
example: '801f9ede-c698-4e66-a7fc-48d19eebaa4f',
required: true,
example: '801f9ede-c698-4e66-a7fc-48d19eebaa4f',
type: String,
})
@ApiResponse({ status: 200 })
@UseGuards(JwtAuthGuard)
@ApiExcludeEndpoint()
@Get('internal/single')
getLinkedUserInternal(@Query('id') id: string) {
@ApiGetCustomResponse(LinkedUserResponse)
@UseGuards(ApiKeyAuthGuard)
@Get(':id')
getLinkedUser(@Param('id') id: string) {
// validate project_id against user
return this.linkedUsersService.getLinkedUser(id);
}
Expand All @@ -192,11 +192,10 @@ export class LinkedUsersController {
summary: 'Retrieve a Linked User From A Remote Id',
})
@ApiQuery({ name: 'remoteId', example: 'id_1', required: true, type: String })
@ApiResponse({ status: 200 })
@ApiExcludeEndpoint()
@UseGuards(JwtAuthGuard)
@Get('internal/fromRemoteId')
linkedUserFromRemoteIdInternal(@Query('remoteId') id: string) {
@ApiGetCustomResponse(LinkedUserResponse)
@UseGuards(ApiKeyAuthGuard)
@Get('fromRemoteId')
linkedUserFromRemoteId(@Query('remoteId') id: string) {
// validate project_id against user
return this.linkedUsersService.getLinkedUserV2(id);
}
Expand Down
Loading

0 comments on commit e3170bb

Please sign in to comment.