forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Secure connexion between TinyBird and webhookResponseGraph (twentyhq#…
…7913) TLDR: Secure connexion between tinybird and twenty using jwt when accessing datasource from tinybird. Solves: twentyhq/private-issues#73 In order to test: 1. Set ANALYTICS_ENABLED to true 2. Set TINYBIRD_JWT_TOKEN to the ADMIN token from the workspace twenty_analytics_playground 3. Set TINYBIRD_JWT_TOKEN to the datasource or your admin token from the workspace twenty_analytics_playground 4. Create a Webhook in twenty and set wich events it needs to track 5. Run twenty-worker in order to make the webhooks work. 6. Do your tasks in order to populate the data 7. Enter to settings> webhook>your webhook and the statistics section should be displayed. --------- Co-authored-by: Charles Bochet <[email protected]>
- Loading branch information
1 parent
edf4ae0
commit 373926b
Showing
19 changed files
with
178 additions
and
46 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
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 |
---|---|---|
|
@@ -45,5 +45,5 @@ | |
"search.exclude": { | ||
"**/.yarn": true, | ||
}, | ||
"eslint.debug": true | ||
"eslint.debug": true, | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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
47 changes: 47 additions & 0 deletions
47
.../src/modules/settings/developers/webhook/hooks/__tests__/useAnalyticsTinybirdJwt.test.tsx
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,47 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
|
||
import { CurrentUser, currentUserState } from '@/auth/states/currentUserState'; | ||
import { useAnalyticsTinybirdJwt } from '@/settings/developers/webhook/hooks/useAnalyticsTinybirdJwt'; | ||
import { act } from 'react'; | ||
import { useSetRecoilState } from 'recoil'; | ||
import { getJestMetadataAndApolloMocksWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksWrapper'; | ||
|
||
const Wrapper = getJestMetadataAndApolloMocksWrapper({ | ||
apolloMocks: [], | ||
}); | ||
|
||
describe('useAnalyticsTinybirdJwt', () => { | ||
it('should return the analytics jwt token', async () => { | ||
const { result } = renderHook( | ||
() => { | ||
const setCurrentUserState = useSetRecoilState(currentUserState); | ||
|
||
return { | ||
useAnalyticsTinybirdJwt: useAnalyticsTinybirdJwt(), | ||
setCurrentUserState, | ||
}; | ||
}, | ||
{ wrapper: Wrapper }, | ||
); | ||
|
||
act(() => { | ||
result.current.setCurrentUserState({ | ||
analyticsTinybirdJwt: 'jwt', | ||
} as CurrentUser); | ||
}); | ||
|
||
expect(result.current.useAnalyticsTinybirdJwt).toBe('jwt'); | ||
|
||
act(() => { | ||
result.current.setCurrentUserState(null); | ||
}); | ||
|
||
expect(result.current.useAnalyticsTinybirdJwt).toBeUndefined(); | ||
|
||
act(() => { | ||
result.current.setCurrentUserState({} as CurrentUser); | ||
}); | ||
|
||
expect(result.current.useAnalyticsTinybirdJwt).toBeUndefined(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
...ges/twenty-front/src/modules/settings/developers/webhook/hooks/useAnalyticsTinybirdJwt.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 { useRecoilValue } from 'recoil'; | ||
|
||
import { currentUserState } from '@/auth/states/currentUserState'; | ||
import { isNull } from '@sniptt/guards'; | ||
|
||
export const useAnalyticsTinybirdJwt = (): string | undefined => { | ||
const currentUser = useRecoilValue(currentUserState); | ||
|
||
if (!currentUser) { | ||
return undefined; | ||
} | ||
|
||
if (isNull(currentUser.analyticsTinybirdJwt)) { | ||
return undefined; | ||
} | ||
|
||
return currentUser.analyticsTinybirdJwt; | ||
}; |
8 changes: 8 additions & 0 deletions
8
packages/twenty-front/src/modules/settings/developers/webhook/hooks/useGraphData.tsx
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
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
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.