From 427596ab0171bb1c5c40614c8aa71b81fb917f30 Mon Sep 17 00:00:00 2001 From: Darius Kazemi Date: Sat, 3 Dec 2022 22:01:19 -0800 Subject: [PATCH] Adding a `norss` user preference There is now a `norss` user preference for a user to opt out of having an RSS feed of their public posts. This operates on the exact same logic as the existing `noindex` for the search engine opt-out: the admin can check a box in Site Settings for a default setting for users. If a user has never touched their RSS opt-out setting then it is equal to whatever the default is. But individual users can override the default in their Preferences -> Other menu. So a privacy-minded server admin could opt everyone out by default, but the overall default behavior is to have RSS feeds of public posts for everyone, which is the default Mastodon behavior anyway. The `norss`, like `noindex`, is just a key on a pre-existing `settings` object that is a key-value store, so there doesn't even need to be a database migration for this! Fixes #1232 --- app/controllers/accounts_controller.rb | 5 +++++ app/controllers/settings/preferences_controller.rb | 1 + app/lib/settings/scoped_settings.rb | 1 + app/lib/user_settings_decorator.rb | 5 +++++ app/models/form/admin_settings.rb | 2 ++ app/models/user.rb | 2 +- app/views/accounts/show.html.haml | 3 ++- app/views/admin/settings/edit.html.haml | 3 +++ app/views/settings/preferences/other/show.html.haml | 3 +++ config/locales/en.yml | 3 +++ config/locales/simple_form.en.yml | 1 + config/settings.yml | 1 + 12 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index a19125f60..610456d8a 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -45,6 +45,11 @@ class AccountsController < ApplicationController format.rss do expires_in 1.minute, public: true + if @account&.user&.setting_norss == true + @statuses = [] + next + end + limit = params[:limit].present? ? [params[:limit].to_i, PAGE_SIZE_MAX].min : PAGE_SIZE @statuses = filtered_statuses.without_reblogs.without_local_only.limit(limit) @statuses = cache_collection(@statuses, Status) diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index e47ff5c48..08e63c49c 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -47,6 +47,7 @@ class Settings::PreferencesController < Settings::BaseController :setting_disable_swiping, :setting_system_font_ui, :setting_noindex, + :setting_norss, :setting_theme, :setting_aggregate_reblogs, :setting_show_application, diff --git a/app/lib/settings/scoped_settings.rb b/app/lib/settings/scoped_settings.rb index 1e18d6d46..4eeb8ed8c 100644 --- a/app/lib/settings/scoped_settings.rb +++ b/app/lib/settings/scoped_settings.rb @@ -5,6 +5,7 @@ module Settings DEFAULTING_TO_UNSCOPED = %w( theme noindex + norss ).freeze def initialize(object) diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index 70f9bc81d..d529de5a9 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -31,6 +31,7 @@ class UserSettingsDecorator user.settings['disable_swiping'] = disable_swiping_preference if change?('setting_disable_swiping') user.settings['system_font_ui'] = system_font_ui_preference if change?('setting_system_font_ui') user.settings['noindex'] = noindex_preference if change?('setting_noindex') + user.settings['norss'] = norss_preference if change?('setting_norss') user.settings['theme'] = theme_preference if change?('setting_theme') user.settings['aggregate_reblogs'] = aggregate_reblogs_preference if change?('setting_aggregate_reblogs') user.settings['show_application'] = show_application_preference if change?('setting_show_application') @@ -102,6 +103,10 @@ class UserSettingsDecorator boolean_cast_setting 'setting_noindex' end + def norss_preference + boolean_cast_setting 'setting_norss' + end + def show_application_preference boolean_cast_setting 'setting_show_application' end diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 6fc7c56fd..4213cb0f8 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -33,6 +33,7 @@ class Form::AdminSettings show_domain_blocks show_domain_blocks_rationale noindex + norss require_invite_text ).freeze @@ -48,6 +49,7 @@ class Form::AdminSettings trends trendable_by_default noindex + norss require_invite_text ).freeze diff --git a/app/models/user.rb b/app/models/user.rb index 46afa85d3..25ea3ee4d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -129,7 +129,7 @@ class User < ApplicationRecord has_many :session_activations, dependent: :destroy delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :delete_modal, - :reduce_motion, :system_font_ui, :noindex, :theme, :display_media, + :reduce_motion, :system_font_ui, :noindex, :norss, :theme, :display_media, :expand_spoilers, :default_language, :aggregate_reblogs, :show_application, :advanced_layout, :use_blurhash, :use_pending_items, :trends, :crop_images, :disable_swiping, :default_federation, :always_send_emails, diff --git a/app/views/accounts/show.html.haml b/app/views/accounts/show.html.haml index 72e9c6611..f770872de 100644 --- a/app/views/accounts/show.html.haml +++ b/app/views/accounts/show.html.haml @@ -5,7 +5,8 @@ - if @account.user&.setting_noindex %meta{ name: 'robots', content: 'noindex, noarchive' }/ - %link{ rel: 'alternate', type: 'application/rss+xml', href: @rss_url }/ + - if !@account.user&.setting_norss + %link{ rel: 'alternate', type: 'application/rss+xml', href: @rss_url }/ %link{ rel: 'alternate', type: 'application/activity+json', href: ActivityPub::TagManager.instance.uri_for(@account) }/ - if @older_url diff --git a/app/views/admin/settings/edit.html.haml b/app/views/admin/settings/edit.html.haml index 66ba77d36..d0dbdb628 100644 --- a/app/views/admin/settings/edit.html.haml +++ b/app/views/admin/settings/edit.html.haml @@ -91,6 +91,9 @@ .fields-group = f.input :noindex, as: :boolean, wrapper: :with_label, label: t('admin.settings.default_noindex.title'), hint: t('admin.settings.default_noindex.desc_html') + .fields-group + = f.input :norss, as: :boolean, wrapper: :with_label, label: t('admin.settings.default_norss.title'), hint: t('admin.settings.default_norss.desc_html') + %hr.spacer/ .fields-group diff --git a/app/views/settings/preferences/other/show.html.haml b/app/views/settings/preferences/other/show.html.haml index 086308594..92734ec7d 100644 --- a/app/views/settings/preferences/other/show.html.haml +++ b/app/views/settings/preferences/other/show.html.haml @@ -10,6 +10,9 @@ .fields-group = f.input :setting_noindex, as: :boolean, wrapper: :with_label + .fields-group + = f.input :setting_norss, as: :boolean, wrapper: :with_label + .fields-group = f.input :setting_aggregate_reblogs, as: :boolean, wrapper: :with_label, recommended: true diff --git a/config/locales/en.yml b/config/locales/en.yml index 10e2d6c74..e344186dc 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -671,6 +671,9 @@ en: default_noindex: desc_html: Affects all users who have not changed this setting themselves title: Opt users out of search engine indexing by default + default_norss: + desc_html: Affects all users who have not changed this setting themselves + title: Opt users out of having an RSS feed of their public posts by default domain_blocks: all: To everyone disabled: To no one diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index d727eb495..651095a13 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -170,6 +170,7 @@ en: setting_expand_spoilers: Always expand posts marked with content warnings setting_hide_network: Hide your social graph setting_noindex: Opt-out of search engine indexing + setting_norss: Opt-out of an RSS feed for your public posts setting_reduce_motion: Reduce motion in animations setting_show_application: Disclose application used to send posts setting_system_font_ui: Use system's default font diff --git a/config/settings.yml b/config/settings.yml index 7912341ed..71a672272 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -30,6 +30,7 @@ defaults: &defaults show_application: true system_font_ui: false noindex: false + norss: false theme: 'default' aggregate_reblogs: true advanced_layout: false