[deploy] Add ability to turn off reaction notifications in notification settings (#9435)
* Add ability to turn off reaction notifications in notification settings * Rename article_reaction_notifications to react-Notifications * Rename platform notification settings to general notification settings and add reactions toggle * Fix new_reaction_worker_spec Co-authored-by: rhymes <rhymes@hey.com> Co-authored-by: Molly Struve <mollylbs@gmail.com>
This commit is contained in:
parent
c0d86649a4
commit
34e5b68182
7 changed files with 42 additions and 5 deletions
|
|
@ -1,5 +1,6 @@
|
|||
class UserPolicy < ApplicationPolicy
|
||||
PERMITTED_ATTRIBUTES = %i[
|
||||
reaction_notifications
|
||||
available_for
|
||||
behance_url
|
||||
bg_color_hex
|
||||
|
|
|
|||
|
|
@ -68,13 +68,17 @@
|
|||
|
||||
<div class="crayons-card mb-6 grid gap-6 p-6">
|
||||
<header>
|
||||
<h3 class="mb-2">Platform Notification Settings</h3>
|
||||
<h3 class="mb-2">General Notification Settings</h3>
|
||||
<p>Notifications that only appear on the <a href="<%= notifications_path %>">notifications page</a>.</p>
|
||||
</header>
|
||||
<div class="crayons-field crayons-field--checkbox">
|
||||
<%= f.check_box :welcome_notifications, class: "crayons-checkbox" %>
|
||||
<%= f.label :welcome_notifications, "Send me occasional tips on how to enhance my #{community_name} experience", class: "crayons-field__label" %>
|
||||
</div>
|
||||
<div class="crayons-field crayons-field--checkbox">
|
||||
<%= f.check_box :reaction_notifications, class: "crayons-checkbox" %>
|
||||
<%= f.label :reaction_notifications, "Send notifications when someone reacts to my comments or posts", class: "crayons-field__label" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% if current_user.trusted %>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,14 @@ module Notifications
|
|||
return unless %w[User Organization].include?(receiver_klass)
|
||||
|
||||
receiver = receiver_klass.constantize.find_by(id: receiver_data.fetch(:id))
|
||||
Notifications::Reactions::Send.call(reaction_data, receiver) if receiver
|
||||
Notifications::Reactions::Send.call(reaction_data, receiver) if should_send?(receiver, receiver_klass)
|
||||
end
|
||||
|
||||
def should_send?(receiver, receiver_klass)
|
||||
return false unless receiver
|
||||
return true if receiver_klass == "Organization"
|
||||
|
||||
receiver.reaction_notifications
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
class AddReactionNotificationsToUsers < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :users, :reaction_notifications, :boolean, default: true
|
||||
end
|
||||
end
|
||||
|
|
@ -1276,6 +1276,7 @@ ActiveRecord::Schema.define(version: 2020_08_20_093752) do
|
|||
t.string "profile_image"
|
||||
t.datetime "profile_updated_at", default: "2017-01-01 05:00:00"
|
||||
t.integer "rating_votes_count", default: 0, null: false
|
||||
t.boolean "reaction_notifications", default: true
|
||||
t.integer "reactions_count", default: 0, null: false
|
||||
t.boolean "registered", default: true
|
||||
t.datetime "registered_at"
|
||||
|
|
|
|||
|
|
@ -180,6 +180,11 @@ RSpec.describe "UserSettings", type: :request do
|
|||
expect(user.reload.profile_updated_at).to be > 2.minutes.ago
|
||||
end
|
||||
|
||||
it "disables reaction notifications" do
|
||||
put "/users/#{user.id}", params: { user: { tab: "notifications", reaction_notifications: 0 } }
|
||||
expect(user.reload.reaction_notifications).to be(false)
|
||||
end
|
||||
|
||||
it "enables community-success notifications" do
|
||||
put "/users/#{user.id}", params: { user: { tab: "notifications", mod_roundrobin_notifications: 1 } }
|
||||
expect(user.reload.mod_roundrobin_notifications).to be(true)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,11 @@ require "rails_helper"
|
|||
RSpec.describe Notifications::NewReactionWorker, type: :worker do
|
||||
let(:reaction_data) { { reactable_type: "Comment", reactable_id: 1, reactable_user_id: 2 } }
|
||||
let(:org) { create(:organization) }
|
||||
let(:receiver_data) { { klass: "Organization", id: org.id } }
|
||||
let(:user) { create(:user) }
|
||||
let(:user_disabled) { create(:user, reaction_notifications: false) }
|
||||
let(:receiver_data_org) { { klass: "Organization", id: org.id } }
|
||||
let(:receiver_data_user) { { klass: "User", id: user.id } }
|
||||
let(:receiver_data_user_disabled) { { klass: "User", id: user_disabled.id } }
|
||||
let(:worker) { subject }
|
||||
|
||||
include_examples "#enqueues_on_correct_queue", "medium_priority", [{}, {}]
|
||||
|
|
@ -13,11 +17,21 @@ RSpec.describe Notifications::NewReactionWorker, type: :worker do
|
|||
|
||||
before { allow(reaction_service).to receive(:call) }
|
||||
|
||||
it "calls the service" do
|
||||
worker.perform(reaction_data, receiver_data)
|
||||
it "calls the service if receiver is an organization" do
|
||||
worker.perform(reaction_data, receiver_data_org)
|
||||
allow(reaction_service).to receive(:call).with(reaction_data, org).once
|
||||
end
|
||||
|
||||
it "calls the service if receiver is a user" do
|
||||
worker.perform(reaction_data, receiver_data_user)
|
||||
allow(reaction_service).to receive(:call).with(reaction_data, user).once
|
||||
end
|
||||
|
||||
it "doesn't call if reaction notifications are turned off for user" do
|
||||
worker.perform(reaction_data, receiver_data_user_disabled)
|
||||
expect(reaction_service).not_to have_received(:call)
|
||||
end
|
||||
|
||||
it "doesn't call if is a receiver is of a wrong class" do
|
||||
worker.perform(reaction_data, klass: "Tag", id: 10)
|
||||
expect(reaction_service).not_to have_received(:call)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue