Skip to content

Send push notifications to client#8774

Merged
ahukkanen merged 99 commits intodevelopfrom
feature/push-notifications-to-client
May 17, 2022
Merged

Send push notifications to client#8774
ahukkanen merged 99 commits intodevelopfrom
feature/push-notifications-to-client

Conversation

@quinHD
Copy link
Copy Markdown
Contributor

@quinHD quinHD commented Feb 2, 2022

🎩 What? Why?

This PR solves two issues.
first of all, it allow users to configure their push notification settings.
allow users to receive push notifications when a new notification is created in the app. It implements the necessary logic to perform this task.

📌 Related Issues

Issue #8490
Issue #8489

Testing

To allow push notifications:
You can test this feature visiting /notifications_settings. When you enable Push notifications you have to allow also notifications in the browser popup.

To sendd push notification:
You can trigger a notification login in the app with a user and from other browser (or incognito) make a comment quoting the first user. This way a new comment push notification will prompt.

Acceptance criteria
  • Given that I'm a registered participant and my browser allows push notifications
    When I go to "My account" -> "Notifications settings"
    Then I see a section called "Push notifications"
    and when I check this setting
    Then I get asked for permission to receive Push notifications
  • Given that I'm a registered participant and my browser don't allows push notifications
    When I go to "My account" -> "Notifications settings"
    Then I don't see the "Push notifications" section.
  • Given that I'm a registered participant, my browser allows push notifications and I've revoked this permission in my browser
    When I go to "My account" -> "Notifications settings"
    Then I see a section called "Push notifications" with the following message:
 To get notifications from Decidim, you\u2019ll need to allow them in your browser settings first.
  • Given that I'm a registered participant, my browser allows push notifications and I've accepted the Push notifications
    When I go to "My account" -> "Notifications settings"
    Then I see a section called "Push notifications"
    and when I uncheck this setting
    Then I've revoked permission to receive Push notifications

  • Given that I'm a participant that has given permissions to receive push notifications,
    When I get a new notification in /notifications
    Then I also receive it in my device
    and this notification has a title and body
    and has a link to the resource
    and has the icon of the organization.

📋 Checklist

🚨 Please review the guidelines for contributing to this repository.

  • CONSIDER adding a unit test if your PR resolves an issue.
  • ✔️ DO check open PR's to avoid duplicates.
  • ✔️ DO keep pull requests small so they can be easily reviewed.
  • ✔️ DO build locally before pushing.
  • ✔️ DO make sure tests pass.
  • ✔️ DO make sure any new changes are documented in docs/.
  • ✔️ DO add and modify seeds if necessary.
  • ✔️ DO add CHANGELOG upgrade notes if required.
  • ✔️ DO add to GraphQL API if there are new public fields.
  • ✔️ DO add link to MetaDecidim if it's a new feature.
  • AVOID breaking the continuous integration build.
  • AVOID making significant changes to the overall architecture.

📷 Screenshots

Please add screenshots of the changes you're proposing
image
image

♥️ Thank you!

@quinHD quinHD self-assigned this Feb 2, 2022
@quinHD quinHD changed the title Feature/push notifications to client Send push notifications to client Feb 2, 2022
@quinHD quinHD force-pushed the feature/push-notifications-to-client branch from 288c81d to 428df07 Compare February 2, 2022 16:49
@quinHD quinHD marked this pull request as ready for review February 3, 2022 18:38
@quinHD quinHD linked an issue Feb 4, 2022 that may be closed by this pull request
1 task
@andreslucena andreslucena requested a review from ferblape February 7, 2022 08:39
@andreslucena
Copy link
Copy Markdown
Member

Can you fill the PR template @quinHD 🙏🏽?

@andreslucena andreslucena added project: PWA Barcelona City Council contract module: core type: feature labels Feb 7, 2022
@quinHD
Copy link
Copy Markdown
Contributor Author

quinHD commented Feb 7, 2022

Can you fill the PR template @quinHD 🙏🏽?

sure!

Copy link
Copy Markdown
Contributor

@ferblape ferblape left a comment

Choose a reason for hiding this comment

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

Just a couple of comments and a request:

in the Notifications page, the notifications link to the comment of the notification (with the anchor to the comment itself) while the push notification takes me to the container resource. Would it be possible to include the anchor too?

ahukkanen
ahukkanen previously approved these changes May 16, 2022
Copy link
Copy Markdown
Contributor

@ahukkanen ahukkanen left a comment

Choose a reason for hiding this comment

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

LGTM!

The only thing that was still bothering me a bit is that the user subscribes to the notifications straight after they switch the "Push notifications" enabled.

This can be a bit confusing as I have not saved my changes with the button shown below the toggle element:
Toggle with button

That said, I understand perfectly well why you do this. It's because the subscription needs to happen at the client side and not at the server side.

If we didn't do that, we would have to wait for the page to reload and do some front-end logic to subscribe/unsubscribe from the notifications which can get pretty complex.

So, I would say we can live with this issue. Just to keep in mind that we may hear back about this in future accessibility evaluations (as they typically complain about this kind of stuff).

@ahukkanen ahukkanen requested a review from andreslucena May 16, 2022 16:12
@ahukkanen
Copy link
Copy Markdown
Contributor

Before merging this, I'd still like to hear @andreslucena opinion about the comment I made above in my review.

For me it's all good for now but just that you are also aware of this potential issue. We may need to come back to this later.

Copy link
Copy Markdown
Member

@andreslucena andreslucena left a comment

Choose a reason for hiding this comment

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

Just a small typo to change and a general comment, great job!

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>
@andreslucena
Copy link
Copy Markdown
Member

So, I would say we can live with this issue. Just to keep in mind that we may hear back about this in future accessibility evaluations (as they typically complain about this kind of stuff).

I know that this behavior is a bit weird. Other platforms that implement this kind of configurations client-side (like Twitter), for what I've seen they don't have this problem as all the user settings forms are updated with AJAX.

We'll need to take this flow into account for the redesign, for sure. As I said, I think is weird, but is the best that we've come up to until now.

cc/ @furilo @rober-gd

@andreslucena
Copy link
Copy Markdown
Member

There are conflicts after merging #8833, can you resolve them please @ferblape? Thanks

ahukkanen
ahukkanen previously approved these changes May 17, 2022
@ferblape
Copy link
Copy Markdown
Contributor

@andreslucena done!

andreslucena
andreslucena previously approved these changes May 17, 2022
@ferblape ferblape dismissed stale reviews from andreslucena and ahukkanen via dfbc580 May 17, 2022 09:54
Copy link
Copy Markdown
Member

@andreslucena andreslucena left a comment

Choose a reason for hiding this comment

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

👍🏽

@ahukkanen ahukkanen merged commit 38c5cfc into develop May 17, 2022
@ahukkanen ahukkanen deleted the feature/push-notifications-to-client branch May 17, 2022 11:59
andreslucena added a commit that referenced this pull request May 19, 2022
* Add push notifications request to user

* Fix 18n spec

* push permissions refactor js

* Fix lint and specs

* Fix gemfile.lock

* Restore Gemfile.lock

* Move webpush from dev to core

* Fix Gemfile.lock in engines

* Use vapid keys through secrets

* Add notification suscription

* Add send push notification service

* saving possible non-existent dom code

* open tab or focus existing when notification clicked

* simplify things

* Move url to data in notification params

* Add specs to send_push_notification

* Fix lint

* Fix lint

* Fix erb lint

* Add unsubscription to push notificaionts

* Add better vapid keys presence validation

* Make delete subscription more safe

* Add CSRF token in js subscriptions requests

* Add vapid validations in webpush service

* Fix subscriptions spec

* Add notifications enabled? check before subscription

* Add allow push notification check

* Fix spec

* Fix spam a2hs button

* Fix lint

* Add notifications subscriptions to user settings

* Fix spec

* Fix enable notifications button functionality

* Fix lint

* Fix lint

* Add push notifications request to user

* Fix 18n spec

* push permissions refactor js

* Fix lint and specs

* Fix gemfile.lock

* Restore Gemfile.lock

* Use vapid keys through secrets

* Fix overlaping button

* Hide sw mandatory elements when there's no sw

* Fix remove element when no present

* Add js revisions

* Fix if to avoid null issues

* Reverse the loding order for sw mandatory items

* Fix await bug

* Fix selectors for push notifications

* Fix spec

* Remove duplicate attribute

* Remove allow notifications attribute

* Fix lint

* Remove html safe calls

* Update generator task

* Changelog

* Only render vapid keys when enabled

* Complete specs

* Check returns notification

* Make methods private

* Comment clarification

* Capture webpush exceptions

* Refactor JS to run only when scope node is present

* Revert "Refactor JS to run only when scope node is present"

This reverts commit 9966259.

* Remove extra div

* Refactor JS

* Test subscriptions

* Fix lint issues

* Sync gemfiles

* Remove deprecation warning

* Activate display for chrome driver headed

* Run tests with xvfb

* Remove unnecessary partial

* Update xvfb parameters

* Fix lint issues

* Export display

* Run xvfb in the same run

* Don't launch chromedriver

* Fix wrong merge

* Comments

* Use env var

* Fix deprecation warning

* Arrow function

Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>

* Double start operator after Ruby 3 upgrade

Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>

* Log Webpush exception

* Fix opera mini user agents

* Show setting by default

* Typo

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>

* Limit route to specific actions

Co-authored-by: Hugoren Martinako <aumpfbahn@gmail.com>
Co-authored-by: Fernando Blat <fernando@blat.es>
Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>
Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>
andreslucena added a commit that referenced this pull request May 19, 2022
* Add push notifications request to user

* Fix 18n spec

* push permissions refactor js

* Fix lint and specs

* Fix gemfile.lock

* Restore Gemfile.lock

* Move webpush from dev to core

* Fix Gemfile.lock in engines

* Use vapid keys through secrets

* Add notification suscription

* Add send push notification service

* saving possible non-existent dom code

* open tab or focus existing when notification clicked

* simplify things

* Move url to data in notification params

* Add specs to send_push_notification

* Fix lint

* Fix lint

* Fix erb lint

* Add unsubscription to push notificaionts

* Add better vapid keys presence validation

* Make delete subscription more safe

* Add CSRF token in js subscriptions requests

* Add vapid validations in webpush service

* Fix subscriptions spec

* Add notifications enabled? check before subscription

* Add allow push notification check

* Fix spec

* Fix spam a2hs button

* Fix lint

* Add notifications subscriptions to user settings

* Fix spec

* Fix enable notifications button functionality

* Fix lint

* Fix lint

* Add push notifications request to user

* Fix 18n spec

* push permissions refactor js

* Fix lint and specs

* Fix gemfile.lock

* Restore Gemfile.lock

* Use vapid keys through secrets

* Fix overlaping button

* Hide sw mandatory elements when there's no sw

* Fix remove element when no present

* Add js revisions

* Fix if to avoid null issues

* Reverse the loding order for sw mandatory items

* Fix await bug

* Fix selectors for push notifications

* Fix spec

* Remove duplicate attribute

* Remove allow notifications attribute

* Fix lint

* Remove html safe calls

* Update generator task

* Changelog

* Only render vapid keys when enabled

* Complete specs

* Check returns notification

* Make methods private

* Comment clarification

* Capture webpush exceptions

* Refactor JS to run only when scope node is present

* Revert "Refactor JS to run only when scope node is present"

This reverts commit 9966259.

* Remove extra div

* Refactor JS

* Test subscriptions

* Fix lint issues

* Sync gemfiles

* Remove deprecation warning

* Activate display for chrome driver headed

* Run tests with xvfb

* Remove unnecessary partial

* Update xvfb parameters

* Fix lint issues

* Export display

* Run xvfb in the same run

* Don't launch chromedriver

* Fix wrong merge

* Comments

* Use env var

* Fix deprecation warning

* Arrow function

Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>

* Double start operator after Ruby 3 upgrade

Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>

* Log Webpush exception

* Fix opera mini user agents

* Show setting by default

* Typo

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>

* Limit route to specific actions

Co-authored-by: Hugoren Martinako <aumpfbahn@gmail.com>
Co-authored-by: Fernando Blat <fernando@blat.es>
Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>
Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>
eliegaboriau pushed a commit to eliegaboriau/decidim that referenced this pull request Oct 25, 2022
* Add push notifications request to user

* Fix 18n spec

* push permissions refactor js

* Fix lint and specs

* Fix gemfile.lock

* Restore Gemfile.lock

* Move webpush from dev to core

* Fix Gemfile.lock in engines

* Use vapid keys through secrets

* Add notification suscription

* Add send push notification service

* saving possible non-existent dom code

* open tab or focus existing when notification clicked

* simplify things

* Move url to data in notification params

* Add specs to send_push_notification

* Fix lint

* Fix lint

* Fix erb lint

* Add unsubscription to push notificaionts

* Add better vapid keys presence validation

* Make delete subscription more safe

* Add CSRF token in js subscriptions requests

* Add vapid validations in webpush service

* Fix subscriptions spec

* Add notifications enabled? check before subscription

* Add allow push notification check

* Fix spec

* Fix spam a2hs button

* Fix lint

* Add notifications subscriptions to user settings

* Fix spec

* Fix enable notifications button functionality

* Fix lint

* Fix lint

* Add push notifications request to user

* Fix 18n spec

* push permissions refactor js

* Fix lint and specs

* Fix gemfile.lock

* Restore Gemfile.lock

* Use vapid keys through secrets

* Fix overlaping button

* Hide sw mandatory elements when there's no sw

* Fix remove element when no present

* Add js revisions

* Fix if to avoid null issues

* Reverse the loding order for sw mandatory items

* Fix await bug

* Fix selectors for push notifications

* Fix spec

* Remove duplicate attribute

* Remove allow notifications attribute

* Fix lint

* Remove html safe calls

* Update generator task

* Changelog

* Only render vapid keys when enabled

* Complete specs

* Check returns notification

* Make methods private

* Comment clarification

* Capture webpush exceptions

* Refactor JS to run only when scope node is present

* Revert "Refactor JS to run only when scope node is present"

This reverts commit 9966259.

* Remove extra div

* Refactor JS

* Test subscriptions

* Fix lint issues

* Sync gemfiles

* Remove deprecation warning

* Activate display for chrome driver headed

* Run tests with xvfb

* Remove unnecessary partial

* Update xvfb parameters

* Fix lint issues

* Export display

* Run xvfb in the same run

* Don't launch chromedriver

* Fix wrong merge

* Comments

* Use env var

* Fix deprecation warning

* Arrow function

Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>

* Double start operator after Ruby 3 upgrade

Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>

* Log Webpush exception

* Fix opera mini user agents

* Show setting by default

* Typo

Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>

* Limit route to specific actions

Co-authored-by: Hugoren Martinako <aumpfbahn@gmail.com>
Co-authored-by: Fernando Blat <fernando@blat.es>
Co-authored-by: Antti Hukkanen <antti.hukkanen@mainiotech.fi>
Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>
@ahukkanen
Copy link
Copy Markdown
Contributor

@ferblape Sorry to bother but we have a question regarding the port range you introduced for Capybara server in this commit:
7e774ae

Is there some particular reason you decided to use the port range of 5000-6999?

We have a recurring problem right now in the CI due to this port range and we already figured out a solution to that (#10435). But just out of interest, if you have any insight why you decided to use this particular range, it might be valuable information for the future.

@ferblape
Copy link
Copy Markdown
Contributor

No special reason I can remember, I just wanted a range of ports above the 1024. So I guess the range can be modified without any consequences in the correct setup of Capybara.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: core project: PWA Barcelona City Council contract release: v0.27 Issues or PRs that need to be tackled for v0.27

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send notification to client with Push Notifications Ask permission to client for Push Notifications

6 participants