Skip to content

Commit

Permalink
Backport 'Fix notifications page when vapid is not available' to v0.27 (
Browse files Browse the repository at this point in the history
#10940)

* Prepare 0.27.3 release

* Update the setup-chromedriver GitHub action to latest v1

* Fix notifications page when vapid is not available

* User's group endorsement no longer disappears after personal endorsement removed

* Fixed group endorsement removal when personal endorsement removed & tests

* test-fixes

* Fix the notification settings when vapid keys are not present

---------

Co-authored-by: JoonasAapro <110532525+JoonasAapro@users.noreply.github.com>

* Revert changes

---------

Co-authored-by: Alexandru Emil Lupu <contact@alecslupu.ro>
Co-authored-by: JoonasAapro <110532525+JoonasAapro@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 15, 2023
1 parent 7cadfc7 commit 9aa32e2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
Expand Up @@ -53,7 +53,7 @@ def user_is_moderator?(user)
end

def meet_push_notifications_requirements?
Rails.application.secrets.vapid[:enabled]
Rails.application.secrets.dig(:vapid, :enabled) || false
end
end
end
Expand Up @@ -16,7 +16,7 @@ class SendPushNotification
#
# Returns the result of the dispatch or nil if user or subscription are empty
def perform(notification)
return unless Rails.application.secrets.vapid[:enabled]
return unless Rails.application.secrets.dig(:vapid, :enabled)

I18n.with_locale(notification.user.locale || notification.user.organization.default_locale) do
notification.user.notifications_subscriptions.values.map do |subscription|
Expand Down
14 changes: 12 additions & 2 deletions decidim-core/spec/forms/notifications_settings_form_spec.rb
Expand Up @@ -188,17 +188,27 @@ module Decidim
describe "#meet_push_notifications_requirements?" do
context "when the notifications requirements are met" do
before do
allow(Rails.application.secrets).to receive("vapid").and_return({ enabled: true })
Rails.application.secrets[:vapid] = { enabled: true }
end

it "returns true" do
expect(subject.meet_push_notifications_requirements?).to be true
end
end

context "when vapid secrets are not present" do
before do
Rails.application.secrets.delete(:vapid)
end

it "returns false" do
expect(subject.meet_push_notifications_requirements?).to be false
end
end

context "when the notifications requirements aren't met" do
before do
allow(Rails.application.secrets).to receive("vapid").and_return({ enabled: false })
Rails.application.secrets[:vapid] = { enabled: false }
end

it "returns false" do
Expand Down
19 changes: 17 additions & 2 deletions decidim-core/spec/services/decidim/send_push_notification_spec.rb
Expand Up @@ -15,12 +15,27 @@
end

before do
allow(Rails.application.secrets).to receive("vapid").and_return({ enabled: true, public_key: "public_key", private_key: "private_key" })
Rails.application.secrets[:vapid] = { enabled: true, public_key: "public_key", private_key: "private_key" }
end

context "without vapid settings config" do
before do
allow(Rails.application.secrets).to receive("vapid").and_return({ enabled: false })
Rails.application.secrets.delete(:vapid)
end

describe "#perform" do
let(:user) { create(:user) }
let(:notification) { create :notification, user: user }

it "returns false" do
expect(subject.perform(notification)).to be_falsy
end
end
end

context "without vapid enabled" do
before do
Rails.application.secrets[:vapid] = { enabled: false }
end

describe "#perform" do
Expand Down
18 changes: 16 additions & 2 deletions decidim-core/spec/system/account_spec.rb
Expand Up @@ -308,7 +308,7 @@

context "when VAPID keys are set" do
before do
allow(Rails.application.secrets).to receive("vapid").and_return(vapid_keys)
Rails.application.secrets[:vapid] = vapid_keys
driven_by(:pwa_chrome)
switch_to_host(organization.host)
login_as user, scope: :user
Expand Down Expand Up @@ -339,9 +339,23 @@
end
end

context "when VAPID is disabled" do
before do
Rails.application.secrets[:vapid] = { enabled: false }
driven_by(:pwa_chrome)
switch_to_host(organization.host)
login_as user, scope: :user
visit decidim.notifications_settings_path
end

it "does not show the push notifications switch" do
expect(page).to have_no_selector(".push-notifications")
end
end

context "when VAPID keys are not set" do
before do
allow(Rails.application.secrets).to receive("vapid").and_return({})
Rails.application.secrets.delete(:vapid)
driven_by(:pwa_chrome)
switch_to_host(organization.host)
login_as user, scope: :user
Expand Down

0 comments on commit 9aa32e2

Please sign in to comment.