Merge pull request #6076 from johanndev1208/adds-notifications-managment

Add setting to require consent for notifications
This commit is contained in:
Javi Martín
2025-10-09 15:36:27 +02:00
committed by GitHub
11 changed files with 141 additions and 20 deletions

View File

@@ -26,6 +26,7 @@ class Admin::Settings::FeaturesTabComponent < ApplicationComponent
feature.sdg feature.sdg
feature.machine_learning feature.machine_learning
feature.remove_investments_supports feature.remove_investments_supports
feature.gdpr.require_consent_for_notifications
feature.dashboard.notification_emails feature.dashboard.notification_emails
] ]
end end

View File

@@ -91,6 +91,7 @@ class Setting < ApplicationRecord
"feature.machine_learning": false, "feature.machine_learning": false,
"feature.remove_investments_supports": true, "feature.remove_investments_supports": true,
"feature.cookies_consent": false, "feature.cookies_consent": false,
"feature.gdpr.require_consent_for_notifications": false,
"homepage.widgets.feeds.debates": true, "homepage.widgets.feeds.debates": true,
"homepage.widgets.feeds.processes": true, "homepage.widgets.feeds.processes": true,
"homepage.widgets.feeds.proposals": true, "homepage.widgets.feeds.proposals": true,

View File

@@ -1,6 +1,10 @@
class User < ApplicationRecord class User < ApplicationRecord
include Verification include Verification
attribute :registering_from_web, default: false attribute :registering_from_web, default: false
%i[newsletter email_digest email_on_direct_message public_activity recommended_debates
recommended_proposals].each do |field|
attribute field, :boolean, default: -> { !Setting["feature.gdpr.require_consent_for_notifications"] }
end
devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable,
:trackable, :validatable, :omniauthable, :password_expirable, :secure_validatable, :trackable, :validatable, :omniauthable, :password_expirable, :secure_validatable,

View File

@@ -140,6 +140,9 @@ en:
sdg_description: Enable Sustainable Development Goals sections in the administration menu and in the Global Settings. sdg_description: Enable Sustainable Development Goals sections in the administration menu and in the Global Settings.
cookies_consent: Cookies consent banner cookies_consent: Cookies consent banner
cookies_consent_description: Enable the cookies consent banner to inform users about the cookies the application uses. cookies_consent_description: Enable the cookies consent banner to inform users about the cookies the application uses.
gdpr:
require_consent_for_notifications: Explicit consent for notifications
require_consent_for_notifications_description: Require explicit user consent in order to send them newsletters and similar information as required by the General Data Protection Regulation (GDPR).
remote_census: remote_census:
general: general:
endpoint: "Endpoint" endpoint: "Endpoint"

View File

@@ -140,6 +140,9 @@ es:
sdg_description: Habilitar secciones relacionadas con Objetivos de Desarrollo Sostenible en el menú de administración y en la sección de Configuración Global. sdg_description: Habilitar secciones relacionadas con Objetivos de Desarrollo Sostenible en el menú de administración y en la sección de Configuración Global.
cookies_consent: Banner de consentimiento de cookies cookies_consent: Banner de consentimiento de cookies
cookies_consent_description: Activa el banner de consentimiento de cookies para informar a los usuarios sobre las cookies que utiliza la aplicación. cookies_consent_description: Activa el banner de consentimiento de cookies para informar a los usuarios sobre las cookies que utiliza la aplicación.
gdpr:
require_consent_for_notifications: Consentimiento explícito para notificaciones
require_consent_for_notifications_description: Requerir que los usuarios tengan que dar consentimiento explícito para enviarles boletines e información similar tal y como describe Reglamento General de Protección de Datos (RGPD).
remote_census: remote_census:
general: general:
endpoint: "Endpoint" endpoint: "Endpoint"

View File

@@ -0,0 +1,9 @@
class RemoveDefaultValueInUserNotifications < ActiveRecord::Migration[7.1]
def change
change_table :users do |t|
t.change_default :newsletter, from: true, to: nil
t.change_default :email_digest, from: true, to: nil
t.change_default :email_on_direct_message, from: true, to: nil
end
end
end

View File

@@ -0,0 +1,8 @@
class RemoveDefaultValueInUserRecommendations < ActiveRecord::Migration[7.1]
def change
change_table :users do |t|
t.change_default :recommended_debates, from: true, to: nil
t.change_default :recommended_proposals, from: true, to: nil
end
end
end

View File

@@ -0,0 +1,7 @@
class RemoveDefaultValueInUserPublicActivity < ActiveRecord::Migration[7.1]
def change
change_table :users do |t|
t.change_default :public_activity, from: true, to: nil
end
end
end

View File

@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2025_09_09_145207) do ActiveRecord::Schema[7.1].define(version: 2025_10_09_085528) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm" enable_extension "pg_trgm"
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -1608,8 +1608,8 @@ ActiveRecord::Schema[7.1].define(version: 2025_09_09_145207) do
t.datetime "level_two_verified_at", precision: nil t.datetime "level_two_verified_at", precision: nil
t.string "erase_reason" t.string "erase_reason"
t.datetime "erased_at", precision: nil t.datetime "erased_at", precision: nil
t.boolean "public_activity", default: true t.boolean "public_activity"
t.boolean "newsletter", default: true t.boolean "newsletter"
t.integer "notifications_count", default: 0 t.integer "notifications_count", default: 0
t.boolean "registering_with_oauth", default: false t.boolean "registering_with_oauth", default: false
t.string "locale" t.string "locale"
@@ -1617,16 +1617,16 @@ ActiveRecord::Schema[7.1].define(version: 2025_09_09_145207) do
t.integer "geozone_id" t.integer "geozone_id"
t.string "gender", limit: 10 t.string "gender", limit: 10
t.datetime "date_of_birth", precision: nil t.datetime "date_of_birth", precision: nil
t.boolean "email_digest", default: true t.boolean "email_digest"
t.boolean "email_on_direct_message", default: true t.boolean "email_on_direct_message"
t.boolean "official_position_badge", default: false t.boolean "official_position_badge", default: false
t.datetime "password_changed_at", precision: nil, default: "2015-01-01 01:01:01", null: false t.datetime "password_changed_at", precision: nil, default: "2015-01-01 01:01:01", null: false
t.boolean "created_from_signature", default: false t.boolean "created_from_signature", default: false
t.integer "failed_email_digests_count", default: 0 t.integer "failed_email_digests_count", default: 0
t.text "former_users_data_log", default: "" t.text "former_users_data_log", default: ""
t.boolean "public_interests", default: false t.boolean "public_interests", default: false
t.boolean "recommended_debates", default: true t.boolean "recommended_debates"
t.boolean "recommended_proposals", default: true t.boolean "recommended_proposals"
t.string "subscriptions_token" t.string "subscriptions_token"
t.integer "failed_attempts", default: 0, null: false t.integer "failed_attempts", default: 0, null: false
t.datetime "locked_at", precision: nil t.datetime "locked_at", precision: nil

View File

@@ -7,7 +7,6 @@ FactoryBot.define do
terms_of_service { "1" } terms_of_service { "1" }
confirmed_at { Time.current } confirmed_at { Time.current }
date_of_birth { 20.years.ago } date_of_birth { 20.years.ago }
public_activity { true }
trait :incomplete_verification do trait :incomplete_verification do
after :create do |user| after :create do |user|

View File

@@ -92,37 +92,103 @@ describe User do
end end
describe "preferences" do describe "preferences" do
describe "email_on_comment" do describe "#email_on_comment" do
it "is false by default" do it "is false by default" do
expect(subject.email_on_comment).to be false expect(subject.email_on_comment).to be false
end end
end end
describe "email_on_comment_reply" do describe "#email_on_comment_reply" do
it "is false by default" do it "is false by default" do
expect(subject.email_on_comment_reply).to be false expect(subject.email_on_comment_reply).to be false
end end
end end
describe "subscription_to_website_newsletter" do describe "#newsletter" do
it "is true by default" do it "is true by default when the consent for notifications setting is disabled" do
expect(subject.newsletter).to be true Setting["feature.gdpr.require_consent_for_notifications"] = false
expect(build(:user).newsletter).to be true
end
it "is false by default when the consent for notifications setting is enabled" do
Setting["feature.gdpr.require_consent_for_notifications"] = true
expect(build(:user).newsletter).to be false
end end
end end
describe "email_digest" do describe "#email_digest" do
it "is true by default" do it "is true by default when the consent for notifications setting is disabled" do
expect(subject.email_digest).to be true Setting["feature.gdpr.require_consent_for_notifications"] = false
expect(build(:user).email_digest).to be true
end
it "is false by default when the consent for notifications setting is enabled" do
Setting["feature.gdpr.require_consent_for_notifications"] = true
expect(build(:user).email_digest).to be false
end end
end end
describe "email_on_direct_message" do describe "#email_on_direct_message" do
it "is true by default" do it "is true by default when the consent for notifications setting is disabled" do
expect(subject.email_on_direct_message).to be true Setting["feature.gdpr.require_consent_for_notifications"] = false
expect(build(:user).email_on_direct_message).to be true
end
it "is false by default when the consent for notifications setting is enabled" do
Setting["feature.gdpr.require_consent_for_notifications"] = true
expect(build(:user).email_on_direct_message).to be false
end end
end end
describe "official_position_badge" do describe "#public_activity" do
it "is true by default when the consent for notifications setting is disabled" do
Setting["feature.gdpr.require_consent_for_notifications"] = false
expect(build(:user).public_activity).to be true
end
it "is false by default when the consent for notifications setting is enabled" do
Setting["feature.gdpr.require_consent_for_notifications"] = true
expect(build(:user).public_activity).to be false
end
end
describe "#recommended_debates" do
it "is true by default when the consent for notifications setting is disabled" do
Setting["feature.gdpr.require_consent_for_notifications"] = false
expect(build(:user).recommended_debates).to be true
end
it "is false by default when the consent for notifications setting is enabled" do
Setting["feature.gdpr.require_consent_for_notifications"] = true
expect(build(:user).recommended_debates).to be false
end
end
describe "#recommended_proposals" do
it "is true by default when the consent for notifications setting is disabled" do
Setting["feature.gdpr.require_consent_for_notifications"] = false
expect(build(:user).recommended_proposals).to be true
end
it "is false by default when the consent for notifications setting is enabled" do
Setting["feature.gdpr.require_consent_for_notifications"] = true
expect(build(:user).recommended_proposals).to be false
end
end
describe "#official_position_badge" do
it "is false by default" do it "is false by default" do
expect(subject.official_position_badge).to be false expect(subject.official_position_badge).to be false
end end
@@ -402,6 +468,26 @@ describe User do
end end
end end
describe ".newsletter" do
it "returns users subscribed to the newsletter" do
create(:user, newsletter: true, username: "Subscriber1")
create(:user, newsletter: true, username: "Subscriber2")
create(:user, newsletter: false, username: "NonSubscriber")
expect(User.newsletter.pluck(:username)).to eq ["Subscriber1", "Subscriber2"]
end
end
describe ".email_digest" do
it "returns users subscribed to email digests" do
create(:user, email_digest: true, username: "Digester1")
create(:user, email_digest: true, username: "Digester2")
create(:user, email_digest: false, username: "NonDigester")
expect(User.email_digest.pluck(:username)).to eq ["Digester1", "Digester2"]
end
end
describe ".by_username_email_or_document_number" do describe ".by_username_email_or_document_number" do
let!(:larry) do let!(:larry) do
create(:user, email: "larry@consul.dev", username: "Larry Bird", document_number: "12345678Z") create(:user, email: "larry@consul.dev", username: "Larry Bird", document_number: "12345678Z")