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): add clientId to OP resources #535

Merged
merged 35 commits into from
Sep 20, 2022

Conversation

sabineschaller
Copy link
Member

@sabineschaller sabineschaller commented Aug 24, 2022

Changes proposed in this pull request

  • reference grant and client in incoming and outgoing payments
  • allow to all GET incoming and outgoing payments (read-all / list-all access) or only those belonging to a client (read / list access)

Context

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Documentation added
  • Make sure that all checks pass

@github-actions github-actions bot added pkg: backend Changes in the backend package. type: source Changes business logic type: tests Testing related labels Aug 24, 2022
@sabineschaller sabineschaller marked this pull request as ready for review September 13, 2022 15:50
packages/backend/src/shared/routes.test.ts Outdated Show resolved Hide resolved
description?: string
expiresAt?: Date
incomingAmount?: Amount
externalRef?: string
}

export interface IncomingPaymentService {
get(id: string): Promise<IncomingPayment | undefined>
get(id: string, clientId?: string): Promise<IncomingPayment | undefined>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
get(id: string, clientId?: string): Promise<IncomingPayment | undefined>
get(id: string): Promise<IncomingPayment | undefined>

What if the clientId check is moved out to the calling routes functions?
I'm thinking however/wherever we check clientId is where we'll also check the payment pointer, both of which are only relevant to the routes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Which check are you referring to?

Copy link
Contributor

Choose a reason for hiding this comment

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

Matching the clientId (and paymentPointerId)
What if incomingPaymentService.get still just took the id, and IncomingPaymentRoutes.get would check the clientId (and paymentPointerId) of the returned incoming payment.

packages/backend/src/open_payments/quote/service.test.ts Outdated Show resolved Hide resolved
packages/backend/src/open_payments/auth/middleware.ts Outdated Show resolved Hide resolved
await grantReferenceService.lock(grantRef.id, trx)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await new Promise((f: any) => setTimeout(f, 6000))
await grantReferenceService.get(grantRef.id, trx)
Copy link
Contributor

Choose a reason for hiding this comment

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

You could also just lock it and then do

await expect(grantReferenceService.get(grantRef.id, trx).skipLocked()).resolves.toBeUndefined()

Copy link
Member Author

Choose a reason for hiding this comment

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

That is probably the faster version. 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

So I can't do skipedLocked on the get method, instead I put

await GrantReference.transaction(async (trx) => {
  await grantReferenceService.lock(grantRef.id, trx)
   await expect(
    GrantReference.query(trx).findById(grantRef.id).skipLocked()
  ).resolves.toBeUndefined()
})

However, that resulted in Rejected to value: [Error: .skipLocked() can only be used after a call to .forShare() or .forUpdate()!].

Copy link
Contributor

Choose a reason for hiding this comment

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

You could add one of those to query or just leave the test as is.

Copy link
Member Author

Choose a reason for hiding this comment

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

That also didn't work. It queries it successfully. It probably has to do with the fact that we can't do forNoKeyUpdate() using objection. I'll just leave it as is.

options: CreateGrantReferenceOptions,
trx?: Transaction
): Promise<GrantReference>
lock(grantId: string, trx: TransactionOrKnex): Promise<void>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
lock(grantId: string, trx: TransactionOrKnex): Promise<void>
lock(grantId: string, trx: Transaction): Promise<void>

Copy link
Member Author

Choose a reason for hiding this comment

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

This has implications on the validateGrant function in the OutgoingPaymentService. Right now, one of its input parameters is deps:ServiceDependencies, which includes deps.knex:TransactionOrKnex. If we don't want to use that, I have to specifically pass the transaction to validateGrant. Do you think we should make that change?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: backend Changes in the backend package. type: source Changes business logic type: tests Testing related
Projects
None yet
2 participants