From e4633a1150450396157640f5262393bb52db280b Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Tue, 18 Feb 2020 02:43:47 -0600 Subject: move defang toggle to preferences instead of profile --- app/controllers/settings/preferences_controller.rb | 1 + app/controllers/settings/profiles_controller.rb | 2 +- app/models/account.rb | 2 -- app/models/user.rb | 6 ++++++ app/views/settings/preferences/show.html.haml | 6 ++++++ app/views/settings/profiles/show.html.haml | 6 ------ config/locales/simple_form.en.yml | 4 ++-- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index 6e3f22d7a..c64ae9ab7 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -55,6 +55,7 @@ class Settings::PreferencesController < Settings::BaseController :filter_timelines_only, :monsterpit_api, :allow_unknown_follows, + :defanged, chosen_languages: [] ) end diff --git a/app/controllers/settings/profiles_controller.rb b/app/controllers/settings/profiles_controller.rb index dab613085..6b3f0d311 100644 --- a/app/controllers/settings/profiles_controller.rb +++ b/app/controllers/settings/profiles_controller.rb @@ -25,7 +25,7 @@ class Settings::ProfilesController < Settings::BaseController private def account_params - params.require(:account).permit(:display_name, :note, :avatar, :header, :replies, :locked, :hidden, :unlisted, :block_anon, :gently, :kobold, :adult_content, :bot, :discoverable, :filter_undescribed, :user_defanged, fields_attributes: [:name, :value]) + params.require(:account).permit(:display_name, :note, :avatar, :header, :replies, :locked, :hidden, :unlisted, :block_anon, :gently, :kobold, :adult_content, :bot, :discoverable, :filter_undescribed, fields_attributes: [:name, :value]) end def set_account diff --git a/app/models/account.rb b/app/models/account.rb index 6f5a11ce0..20b93ddc5 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -136,8 +136,6 @@ class Account < ApplicationRecord :staff?, :can_moderate?, :defanged?, - :defanged, - :defanged=, :locale, :default_language, diff --git a/app/models/user.rb b/app/models/user.rb index 00e2af458..7f47ecc3f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -119,6 +119,7 @@ class User < ApplicationRecord before_validation :sanitize_languages before_create :set_approved + before_save :set_last_fanged_at # This avoids a deprecation warning from Rails 5.1 # It seems possible that a future release of devise-two-factor will @@ -532,6 +533,11 @@ class User < ApplicationRecord self.approved = open_registrations? || valid_invitation? || external? end + def set_last_fanged_at + return unless defanged_changed? && !last_fanged_at_changed? + self.last_fanged_at = (defanged? ? nil : Time.now.utc) + end + def open_registrations? Setting.registrations_mode == 'open' end diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml index 4d4941a2e..c51f91bde 100644 --- a/app/views/settings/preferences/show.html.haml +++ b/app/views/settings/preferences/show.html.haml @@ -11,6 +11,12 @@ = simple_form_for current_user, url: settings_preferences_path, html: { method: :put } do |f| = render 'shared/error_messages', object: current_user + - if current_user.can_moderate? + %hr/ + + .fields-group + = f.input :defanged, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.defanged') + %hr#settings_publishing/ .fields-group diff --git a/app/views/settings/profiles/show.html.haml b/app/views/settings/profiles/show.html.haml index ba2fd7495..4fabfb9f4 100644 --- a/app/views/settings/profiles/show.html.haml +++ b/app/views/settings/profiles/show.html.haml @@ -18,12 +18,6 @@ = f.input :avatar, wrapper: :with_label, input_html: { accept: AccountAvatar::IMAGE_MIME_TYPES.join(',') }, hint: t('simple_form.hints.defaults.avatar', dimensions: '400x400', size: number_to_human_size(AccountAvatar::LIMIT)) - - if @account.user_can_moderate? - %hr.spacer/ - - .fields-group - = f.input :user_defanged, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.user_defanged') - %hr.spacer/ .fields-group diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index a3c7748fe..f8ebb7a08 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -10,7 +10,7 @@ en: type_html: Choose what to do with %{acct} warning_preset_id: Optional. You can still add custom text to end of the preset defaults: - user_defanged: Disable this to access to moderation and admin features for 15 minutes. + defanged: Disable this to access to moderation and admin features for 15 minutes. block_anon: Links to your public roars are disabled unless they are made accessible by sharekey. Be aware that roars sent to other Fediverse servers can be publically indexed! unlisted: Excludes you from public repeated/admired by lists of *local* monsters autofollow: People who sign up through the invite will automatically join your pack @@ -84,7 +84,7 @@ en: suspend: Suspend and irreversibly delete account data warning_preset_id: Use a warning preset defaults: - user_defanged: Defanged mode + defanged: Defanged mode hidden: Invisible mode (affects outgoing federation and discovery!) adult_content: Contains adult content gently: Gently the kobolds -- cgit