Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend): tenant support for wallet address (#3114) #3152

Open
wants to merge 63 commits into
base: 2893/multi-tenancy-v1
Choose a base branch
from

Conversation

koekiebox
Copy link
Collaborator

@koekiebox koekiebox commented Dec 5, 2024

Changes proposed in this pull request

Context

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Make sure that all checks pass
  • Bruno collection updated (if necessary)
  • Documentation issue created with user-docs label (if necessary)
  • OpenAPI specs updated (if necessary)

@koekiebox koekiebox added the do not merge Do not merge PRs with these label label Dec 5, 2024
@koekiebox koekiebox self-assigned this Dec 5, 2024
@github-actions github-actions bot added type: tests Testing related pkg: backend Changes in the backend package. pkg: frontend Changes in the frontend package. type: source Changes business logic pkg: mock-ase pkg: mock-account-service-lib labels Dec 5, 2024
@koekiebox koekiebox changed the title 3114/tenanted wallet addresses feat(backend): tenant support for wallet address (#3114) Dec 5, 2024
@koekiebox koekiebox changed the base branch from 2893/multi-tenancy-v1 to nl/3123/backend-tenant-service December 5, 2024 13:25
@github-actions github-actions bot added the pkg: auth Changes in the GNAP auth package. label Dec 9, 2024
# Conflicts:
#	packages/backend/src/app.ts
#	packages/backend/src/config/app.ts
#	packages/backend/src/tenants/service.test.ts
#	packages/backend/src/tests/tableManager.ts
@koekiebox koekiebox marked this pull request as ready for review January 17, 2025 18:42
# Conflicts:
#	packages/backend/src/graphql/resolvers/walletAddressKey.test.ts
@@ -27,6 +27,5 @@ export const CONFIG: Config = {
authServerDomain: process.env.AUTH_SERVER_DOMAIN || 'http://localhost:3006',
graphqlUrl: process.env.GRAPHQL_URL,
idpSecret: process.env.IDP_SECRET,
operatorTenantId:
process.env.OPERATOR_TENANT_ID || '438fa74a-fa7d-4317-9ced-dde32ece1787'
operatorTenantId: process.env.OPERATOR_TENANT_ID || ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably make this required (throw if not provided)

@@ -634,6 +694,68 @@ describe('Wallet Address Resolvers', (): void => {
)
}
})

test('bad input data when not allowed to perform cross tenant update', async (): Promise<void> => {
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto with the expect.assertions(...) here as well

return {
...tenantApiSignatureResult,
container: this.container,
logger: await this.container.use('logger')
logger: await this.container.use('logger'),
forTenantId: this.config.operatorTenantId
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including the operator id by default feels less safe, we should either let it be undefined (and just declare this as the TenantedApolloContext, or have ForTenantIdContext let tenantId be undefined)

Comment on lines +51 to +55
.filter(
(wa: WalletAddress) =>
tenantIdToProceed(ctx.isOperator, ctx.tenant.id, wa.tenantId) !=
undefined
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this works from the client perspective, since we could get into a situation where we set the limit to be e.g. 20 and then because of the filter, end up filtering out a few results. Then we have a situation where we got 15 results, but hasNextPage is still true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can have the service methods be able to take in a list of tenantIds? That way we can pass in both the operator tenant id and the (on behalf id if necessary)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkurapov, I agree with your first statement. Then the second, I was thinking the opposite. We make the tenantId an optional argument for the WalletAddressesConnection.
This enables us to do the following:

  • When the args.input.tenantId is set, we do the usual ctx.forTenantId - This allows for specific tenant paging when the operator is permitted
  • When the caller isOperator and args.input.tenantId is not provided, "default" paging is performed where tenantId is undefined and not part of the selection criteria
  • When the caller !isOperator, then we always use: ctx.forTenantId - this enforces that the caller is only able to see their own tenant data

Again, we can determine most of this from the resolver. So that we only need to update getPage to have an optional parameter for tenantId.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge Do not merge PRs with these label pkg: backend Changes in the backend package. pkg: frontend Changes in the frontend package. pkg: mock-account-service-lib pkg: mock-ase type: source Changes business logic type: tests Testing related
Projects
None yet
4 participants