Compare commits

...

3 Commits

Author SHA1 Message Date
Claire
f2aad1ca01
Merge 5d74414e9b into 8b34daf254 2025-05-03 11:04:45 +00:00
Jonny Saunders
8b34daf254
Fix: Use strings not symbols to access totalItems in interaction collections (#34594)
Some checks failed
Check i18n / check-i18n (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (ruby) (push) Has been cancelled
Check formatting / lint (push) Has been cancelled
Ruby Linting / lint (push) Has been cancelled
Historical data migration test / test (14-alpine) (push) Has been cancelled
Historical data migration test / test (15-alpine) (push) Has been cancelled
Historical data migration test / test (16-alpine) (push) Has been cancelled
Historical data migration test / test (17-alpine) (push) Has been cancelled
Ruby Testing / build (production) (push) Has been cancelled
Ruby Testing / build (test) (push) Has been cancelled
Ruby Testing / test (.ruby-version) (push) Has been cancelled
Ruby Testing / test (3.2) (push) Has been cancelled
Ruby Testing / test (3.3) (push) Has been cancelled
Ruby Testing / Libvips tests (.ruby-version) (push) Has been cancelled
Ruby Testing / Libvips tests (3.2) (push) Has been cancelled
Ruby Testing / Libvips tests (3.3) (push) Has been cancelled
Ruby Testing / End to End testing (.ruby-version) (push) Has been cancelled
Ruby Testing / End to End testing (3.2) (push) Has been cancelled
Ruby Testing / End to End testing (3.3) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Has been cancelled
Bundler Audit / security (push) Has been cancelled
2025-05-03 10:37:06 +00:00
Claire
5d74414e9b Add interstitial for Terms of Service updates 2025-04-28 11:20:18 +02:00
13 changed files with 83 additions and 6 deletions

View File

@ -8,6 +8,7 @@ module WebAppControllerConcern
before_action :redirect_unauthenticated_to_permalinks!
before_action :set_referer_header
before_action :redirect_to_tos_interstitial!
content_security_policy do |p|
policy = ContentSecurityPolicy.new
@ -45,6 +46,12 @@ module WebAppControllerConcern
protected
def redirect_to_tos_interstitial!
return unless current_user&.require_tos_interstitial
redirect_to(terms_of_service_interstitial_url)
end
def set_referer_header
response.set_header('Referrer-Policy', Setting.allow_referrer_origin ? 'strict-origin-when-cross-origin' : 'same-origin')
end

View File

@ -4,8 +4,19 @@ class TermsOfServiceController < ApplicationController
include WebAppControllerConcern
skip_before_action :require_functional!
skip_before_action :redirect_to_tos_interstitial!
before_action :clear_redirect_interstitial!
def show
expires_in(15.seconds, public: true, stale_while_revalidate: 30.seconds, stale_if_error: 1.day) unless user_signed_in?
end
private
def clear_redirect_interstitial!
return unless user_signed_in?
current_user.update(require_tos_interstitial: false)
end
end

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
class TermsOfServiceInterstitialController < ApplicationController
vary_by 'Accept-Language'
def show
@terms_of_service = TermsOfService.published.first
render 'terms_of_service_interstitial/show', layout: 'auth'
end
end

View File

@ -95,11 +95,11 @@ class ActivityPub::Parser::StatusParser
end
def favourites_count
@object.dig(:likes, :totalItems)
@object.dig('likes', 'totalItems')
end
def reblogs_count
@object.dig(:shares, :totalItems)
@object.dig('shares', 'totalItems')
end
def quote_policy

View File

@ -23,6 +23,8 @@ class TermsOfService < ApplicationRecord
validate :effective_date_cannot_be_in_the_past
NOTIFICATION_ACTIVITY_CUTOFF = 1.year.freeze
def published?
published_at.present?
end
@ -39,8 +41,20 @@ class TermsOfService < ApplicationRecord
notification_sent_at.present?
end
def base_user_scope
User.confirmed.where(created_at: ..published_at).joins(:account)
end
def email_notification_cutoff
published_at - NOTIFICATION_ACTIVITY_CUTOFF
end
def scope_for_interstitial
base_user_scope.merge(Account.suspended).or(base_user_scope.where(current_sign_in_at: [nil, ...email_notification_cutoff]))
end
def scope_for_notification
User.confirmed.joins(:account).merge(Account.without_suspended).where(created_at: (..published_at))
base_user_scope.merge(Account.without_suspended).where(current_sign_in_at: email_notification_cutoff...)
end
private

View File

@ -25,6 +25,7 @@
# otp_backup_codes :string is an Array
# otp_required_for_login :boolean default(FALSE), not null
# otp_secret :string
# require_tos_interstitial :boolean default(FALSE), not null
# reset_password_sent_at :datetime
# reset_password_token :string
# settings :text

View File

@ -0,0 +1,14 @@
- content_for :header_tags do
%meta{ name: 'robots', content: 'noindex, noarchive' }/
- content_for :body_classes, 'app-body'
.simple_form
%h1.title= t('terms_of_service_interstitial.title', domain: site_hostname)
%p.lead= t('terms_of_service_interstitial.preamble_html', date: l(@terms_of_service.effective_date || Time.zone.today))
%p.lead= t('user_mailer.terms_of_service_changed.agreement', domain: site_hostname)
.stacked-actions
= link_to t('terms_of_service_interstitial.review_link'), terms_of_service_path, class: 'button'

View File

@ -6,6 +6,8 @@ class Admin::DistributeTermsOfServiceNotificationWorker
def perform(terms_of_service_id)
terms_of_service = TermsOfService.find(terms_of_service_id)
terms_of_service.scope_for_interstitial.in_batches.update_all(require_tos_interstitial: true)
terms_of_service.scope_for_notification.find_each do |user|
UserMailer.terms_of_service_changed(user, terms_of_service).deliver_later!
end

View File

@ -1912,6 +1912,10 @@ en:
does_not_match_previous_name: does not match the previous name
terms_of_service:
title: Terms of Service
terms_of_service_interstitial:
preamble_html: We're making some changes to our terms of service, effective <strong>%{date}</strong>. We encourage you to review the updated terms.
review_link: Review terms of service
title: The terms of service of %{domain} are changing
themes:
contrast: Mastodon (High contrast)
default: Mastodon (Dark)

View File

@ -208,6 +208,7 @@ Rails.application.routes.draw do
get '/privacy-policy', to: 'privacy#show', as: :privacy_policy
get '/terms-of-service', to: 'terms_of_service#show', as: :terms_of_service
get '/terms-of-service/:date', to: 'terms_of_service#show', as: :terms_of_service_version
get '/terms-of-service-update', to: 'terms_of_service_interstitial#show', as: :terms_of_service_interstitial
get '/terms', to: redirect('/terms-of-service')
match '/', via: [:post, :put, :patch, :delete], to: 'application#raise_not_found', format: false

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddRequireTosInterstitialToUsers < ActiveRecord::Migration[8.0]
def change
add_column :users, :require_tos_interstitial, :boolean, null: false, default: false
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_04_28_095029) do
ActiveRecord::Schema[8.0].define(version: 2025_04_28_104538) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
@ -1222,6 +1222,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_04_28_095029) do
t.string "time_zone"
t.string "otp_secret"
t.datetime "age_verified_at"
t.boolean "require_tos_interstitial", default: false, null: false
t.index ["account_id"], name: "index_users_on_account_id"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["created_by_application_id"], name: "index_users_on_created_by_application_id", where: "(created_by_application_id IS NOT NULL)"

View File

@ -14,9 +14,10 @@ RSpec.describe Admin::DistributeTermsOfServiceNotificationWorker do
context 'with valid terms' do
let(:terms) { Fabricate(:terms_of_service) }
let!(:user) { Fabricate :user, confirmed_at: 3.days.ago }
let!(:user) { Fabricate(:user, confirmed_at: 3.days.ago) }
let!(:old_user) { Fabricate(:user, confirmed_at: 2.years.ago, current_sign_in_at: 2.years.ago) }
it 'sends the terms update via email', :inline_jobs do
it 'sends the terms update via email and change the old user to require an interstitial', :inline_jobs do
emails = capture_emails { worker.perform(terms.id) }
expect(emails.size)
@ -26,6 +27,9 @@ RSpec.describe Admin::DistributeTermsOfServiceNotificationWorker do
to: [user.email],
subject: I18n.t('user_mailer.terms_of_service_changed.subject')
)
expect(user.reload.require_tos_interstitial).to be false
expect(old_user.reload.require_tos_interstitial).to be true
end
end
end