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

Allow optional signature when registering notifications #1797

Merged
merged 48 commits into from
Aug 19, 2024

Conversation

iamacook
Copy link
Member

@iamacook iamacook commented Aug 1, 2024

Summary

It should be possible to register for "public" notifications, e.g. incoming/outgoing assets, without a signing key.

This adapts the POST /v2/register/notifications endpoint to make the accessToken optional and, if not present, register for notifications as a non-owner/delegate with no signer_address saved. When notifications are dispatched, if no signer_address is present, only "public" notifications are therefore dispatch to the related Firebase token.

Changes

  • Make notification_subscriptions['signer_address'] column nullable
  • Allow upsertion of subscriptions without a signer address, adapting the logic to first clear the subscription if the signer address matches or is undefined in order to "align" subscriptions.
  • Add/adjust tests accordingly.

@iamacook iamacook self-assigned this Aug 1, 2024
Comment on lines +62 to +75
// 1. Delete previous subscriptions (and by cascade, notification types)
// to avoid duplicates, and clearing "unknown" subscriptions
await sql`
DELETE FROM notification_subscriptions
WHERE chain_id = ${safe.chainId}
AND safe_address = ${safe.address}
AND (
signer_address = ${args.signerAddress ?? null}
OR (
signer_address IS NULL
)
)
AND push_notification_device_id = ${device.id}
`;
Copy link
Member Author

Choose a reason for hiding this comment

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

The subscription is still device based so this shouldn't cause issues of "unsubscriptions".

@coveralls
Copy link

coveralls commented Aug 1, 2024

Pull Request Test Coverage Report for Build 10452769483

Details

  • 6 of 19 (31.58%) changed or added relevant lines in 5 files are covered.
  • 5 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.04%) to 46.903%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/datasources/notifications/notifications.datasource.ts 0 1 0.0%
src/domain/hooks/helpers/event-notifications.helper.ts 0 6 0.0%
src/routes/auth/guards/optional-auth.guard.ts 4 10 40.0%
Files with Coverage Reduction New Missed Lines %
src/datasources/notifications/notifications.datasource.ts 2 8.33%
src/domain/hooks/helpers/event-notifications.helper.ts 3 6.25%
Totals Coverage Status
Change from base Build 10279577349: -0.04%
Covered Lines: 4549
Relevant Lines: 7814

💛 - Coveralls

Base automatically changed from notifications-routes to main August 7, 2024 06:53
@iamacook iamacook marked this pull request as ready for review August 7, 2024 08:06
@iamacook iamacook requested a review from a team as a code owner August 7, 2024 08:06
Copy link
Member

@hectorgomezv hectorgomezv left a comment

Choose a reason for hiding this comment

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

👏🏻

src/routes/notifications/guards/notifications.guard.ts Outdated Show resolved Hide resolved
src/routes/notifications/guards/notifications.guard.ts Outdated Show resolved Hide resolved
Comment on lines 142 to 146
return this.notificationsDatasource.deleteSubscription({
deviceUuid: args.deviceUuid,
chainId: args.chainId,
safeAddress: args.safeAddress,
});
Copy link
Member

Choose a reason for hiding this comment

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

Another small nit, but this could remain as this.notificationsDatasource.deleteSubscription(args), couldn't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed in da9bf55.

@iamacook iamacook merged commit b423384 into main Aug 19, 2024
16 checks passed
@iamacook iamacook deleted the notifications-optional-signature branch August 19, 2024 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants