From 1435ebec8fede44289a1c8a9213ff336c614f68d Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Thu, 13 Feb 2020 15:32:43 -0600 Subject: (reso: report #201) add option to strip embed cards from sensitive posts, make default --- app/controllers/settings/preferences_controller.rb | 1 + app/lib/user_settings_decorator.rb | 5 +++-- app/models/user.rb | 5 +++++ app/serializers/rest/status_serializer.rb | 6 +++++- app/views/settings/preferences/show.html.haml | 1 + 5 files changed, 15 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index e5a122de0..6e3f22d7a 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -99,6 +99,7 @@ class Settings::PreferencesController < Settings::BaseController :setting_boost_interval_to, :setting_show_cursor, :setting_allow_rss, + :setting_hide_sensitive_cards, :setting_default_privacy, :setting_default_sensitive, diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index 0a4e1af33..8e95f518a 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -53,6 +53,7 @@ class UserSettingsDecorator user.settings['boost_interval_to'] = boost_interval_to_preference if change?('setting_boost_interval_to') user.settings['show_cursor'] = show_cursor_preference if change?('setting_show_cursor') user.settings['allow_rss'] = allow_rss_preference if change?('setting_allow_rss') + user.settings['hide_sensitive_cards']= hide_sensitive_cards_preference if change?('setting_hide_sensitive_cards') user.settings['notification_emails'] = merged_notification_emails if change?('notification_emails') user.settings['interactions'] = merged_interactions if change?('interactions') @@ -204,8 +205,8 @@ class UserSettingsDecorator settings['setting_boost_interval_to'] end - def delayed_for_preference - settings['setting_delayed_for'] + def hide_sensitive_cards_preference + boolean_cast_setting 'setting_hide_sensitive_cards' end def allow_rss_preference diff --git a/app/models/user.rb b/app/models/user.rb index 38f8341dd..7c4f6553b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -160,6 +160,7 @@ class User < ApplicationRecord :boost_interval_to, :show_cursor, :allow_rss, + :setting_hide_sensitive_cards, :auto_play_gif, :default_sensitive, @@ -391,6 +392,10 @@ class User < ApplicationRecord @allows_rss ||= (settings.allow_rss || false) end + def hides_sensitive_cards? + @hide_sensitive_cards ||= (setting.hide_sensitive_cards || true) + end + def defaults_to_local_only? @defaults_to_local_only ||= (settings.default_local || false) end diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb index de8d08528..931904636 100644 --- a/app/serializers/rest/status_serializer.rb +++ b/app/serializers/rest/status_serializer.rb @@ -32,7 +32,7 @@ class REST::StatusSerializer < ActiveModel::Serializer has_many :tags has_many :emojis, serializer: REST::CustomEmojiSerializer - has_one :preview_card, key: :card, serializer: REST::PreviewCardSerializer + has_one :preview_card, key: :card, serializer: REST::PreviewCardSerializer, if: :card_not_filtered? has_one :preloadable_poll, key: :poll, serializer: REST::PollSerializer def trans @@ -152,6 +152,10 @@ class REST::StatusSerializer < ActiveModel::Serializer instance_options[:source_requested] end + def card_not_filtered? + !(current_user? && current_user.hides_sensitive_cards? && object.sensitive?) + end + def ordered_mentions object.active_mentions.to_a.sort_by(&:id) end diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml index d9262fb3b..4d4941a2e 100644 --- a/app/views/settings/preferences/show.html.haml +++ b/app/views/settings/preferences/show.html.haml @@ -80,6 +80,7 @@ = f.input :hide_boosts, as: :boolean, wrapper: :with_label = f.input :media_only, as: :boolean, wrapper: :with_label = f.input :filter_undescribed, as: :boolean, wrapper: :with_label + = f.input :setting_hide_sensitive_cards, as: :boolean, wrapper: :with_label .fields-group = f.input :setting_rawr_federated, as: :boolean, wrapper: :with_label -- cgit