Merge commit 'fc5ab2dc83' into kb_migration

This commit is contained in:
KMY 2023-08-15 18:17:59 +09:00
commit 9d38301bfa
132 changed files with 145 additions and 696 deletions

View file

@ -0,0 +1,27 @@
# frozen_string_literal: true
class Settings::PrivacyController < Settings::BaseController
before_action :set_account
def show; end
def update
if UpdateAccountService.new.call(@account, account_params.except(:settings))
current_user.update!(settings_attributes: account_params[:settings])
ActivityPub::UpdateDistributionWorker.perform_async(@account.id)
redirect_to settings_privacy_path, notice: I18n.t('generic.changes_saved_msg')
else
render :show
end
end
private
def account_params
params.require(:account).permit(:discoverable, :locked, :hide_collections, :dissubscribable, settings: UserSettings.keys)
end
def set_account
@account = current_account
end
end

View file

@ -20,7 +20,8 @@ class Settings::ProfilesController < Settings::BaseController
private
def account_params
params.require(:account).permit(:display_name, :note, :bio_markdown, :avatar, :header, :locked, :my_actor_type, :searchability, :dissubscribable, :group_allow_private_message, :discoverable, :discoverable_local, :hide_collections, fields_attributes: [:name, :value])
# params.require(:account).permit(:display_name, :note, :bio_markdown, :avatar, :header, :locked, :my_actor_type, :searchability, :dissubscribable, :group_allow_private_message, :discoverable, :discoverable_local, :hide_collections, fields_attributes: [:name, :value])
params.require(:account).permit(:display_name, :note, :bio_markdown, :avatar, :header, :bot, :my_actor_type, :group_allow_private_message, :dissubscribable, fields_attributes: [:name, :value])
end
def set_account

View file

@ -33,6 +33,8 @@ class UserSettings
setting :emoji_reaction_streaming_notify_impl2, default: false
setting :unsafe_limited_distribution, default: false
setting_inverse_alias :indexable, :noindex
namespace :web do
setting :advanced_layout, default: false
setting :trends, default: true
@ -82,31 +84,26 @@ class UserSettings
end
def [](key)
key = key.to_sym
definition = self.class.definition_for(key)
raise KeyError, "Undefined setting: #{key}" unless self.class.definition_for?(key)
raise KeyError, "Undefined setting: #{key}" if definition.nil?
if @original_hash.key?(key)
@original_hash[key]
else
self.class.definition_for(key).default_value
end
definition.value_for(key, @original_hash[definition.key])
end
def []=(key, value)
key = key.to_sym
definition = self.class.definition_for(key)
raise KeyError, "Undefined setting: #{key}" unless self.class.definition_for?(key)
raise KeyError, "Undefined setting: #{key}" if definition.nil?
setting_definition = self.class.definition_for(key)
typecast_value = setting_definition.type_cast(value)
typecast_value = definition.type_cast(value)
raise ArgumentError, "Invalid value for setting #{key}: #{typecast_value}" if setting_definition.in.present? && setting_definition.in.exclude?(typecast_value)
raise ArgumentError, "Invalid value for setting #{definition.key}: #{typecast_value}" if definition.in.present? && definition.in.exclude?(typecast_value)
if typecast_value.nil?
@original_hash.delete(key)
@original_hash.delete(definition.key)
else
@original_hash[key] = typecast_value
@original_hash[definition.key] = definition.value_for(key, typecast_value)
end
end

View file

@ -10,6 +10,10 @@ module UserSettings::DSL
end
end
def setting_inverse_alias(key, original_key)
@definitions[key] = @definitions[original_key].inverse_of(key)
end
def namespace(key, &block)
@definitions ||= {}

View file

@ -10,6 +10,27 @@ class UserSettings::Setting
@in = options[:in]
end
def inverse_of(name)
@inverse_of = name.to_sym
self
end
def value_for(name, original_value)
value = begin
if original_value.nil?
default_value
else
original_value
end
end
if !@inverse_of.nil? && @inverse_of == name.to_sym
!value
else
value
end
end
def default_value
if @default_value.respond_to?(:call)
@default_value.call

View file

@ -10,11 +10,6 @@ class UpdateAccountService < BaseService
params.delete(:bio_markdown)
account.user.send(update_method, user_params)
end
if account.user && params.key?(:discoverable_local)
user_params = { settings_attributes: { discoverable_local: params['discoverable_local'] } }
params.delete(:discoverable_local)
account.user.send(update_method, user_params)
end
account.send(update_method, params).tap do |ret|
next unless ret

View file

@ -32,6 +32,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 :noai, as: :boolean, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_noai'), hint: I18n.t('simple_form.hints.defaults.setting_noai')
%h4= t('admin.settings.discovery.publish_statistics')
.fields-group

View file

@ -8,12 +8,6 @@
= render 'shared/error_messages', object: current_user
= f.simple_fields_for :settings, current_user.settings do |ff|
.fields-group
= ff.input :noindex, wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_noindex'), hint: I18n.t('simple_form.hints.defaults.setting_noindex')
.fields-group
= ff.input :noai, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_noai'), hint: I18n.t('simple_form.hints.defaults.setting_noai')
.fields-group
= ff.input :aggregate_reblogs, wrapper: :with_label, recommended: true, label: I18n.t('simple_form.labels.defaults.setting_aggregate_reblogs'), hint: I18n.t('simple_form.hints.defaults.setting_aggregate_reblogs')
@ -45,9 +39,6 @@
.fields-group
= ff.input :default_sensitive, wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_default_sensitive'), hint: I18n.t('simple_form.hints.defaults.setting_default_sensitive')
.fields-group
= ff.input :show_application, wrapper: :with_label, recommended: true, label: I18n.t('simple_form.labels.defaults.setting_show_application'), hint: I18n.t('simple_form.hints.defaults.setting_show_application')
%h4= t 'preferences.stop_deliver'
.fields-group
@ -78,3 +69,6 @@
.actions
= f.button :button, t('generic.save_changes'), type: :submit
.fields-group
= ff.input :show_application, wrapper: :with_label, recommended: true, label: I18n.t('simple_form.labels.defaults.setting_show_application'), hint: I18n.t('simple_form.hints.defaults.setting_show_application')

View file

@ -0,0 +1,50 @@
- content_for :page_title do
= t('privacy.title')
- content_for :heading do
%h2= t('settings.profile')
= render partial: 'settings/shared/profile_navigation'
= simple_form_for @account, url: settings_privacy_path, html: { method: :put } do |f|
= render 'shared/error_messages', object: @account
%p.lead= t('privacy.hint_html')
%h4= t('privacy.reach')
%p.lead= t('privacy.reach_hint_html')
.fields-group
= f.input :discoverable, as: :boolean, wrapper: :with_label, recommended: true
= f.simple_fields_for :settings, current_user.settings do |ff|
.fields-group
= ff.input :discoverable_local, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.discoverable_local'), hint: I18n.t('simple_form.hints.defaults.discoverable_local')
.fields-group
= f.input :dissubscribable, as: :boolean, wrapper: :with_label, kmyblue: true, hint: t('simple_form.hints.defaults.dissubscribable')
.fields-group
= f.input :locked, as: :boolean, wrapper: :with_label
%h4= t('privacy.search')
%p.lead= t('privacy.search_hint_html')
= f.simple_fields_for :settings, current_user.settings do |ff|
.fields-group
= ff.input :indexable, wrapper: :with_label
%h4= t('privacy.privacy')
%p.lead= t('privacy.privacy_hint_html')
.fields-group
= f.input :hide_collections, as: :boolean, wrapper: :with_label
= f.simple_fields_for :settings, current_user.settings do |ff|
.fields-group
= ff.input :show_application, wrapper: :with_label
.actions
= f.button :button, t('generic.save_changes'), type: :submit

View file

@ -59,24 +59,6 @@
= fa_icon 'trash fw'
= t('generic.delete')
%h4= t('edit_profile.safety_and_privacy')
.fields-group
= f.input :discoverable, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.discoverable'), recommended: true
= f.simple_fields_for :settings, current_user.settings do |ff|
.fields-group
= ff.input :discoverable_local, input_html: { name: 'account[discoverable_local]' }, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.discoverable_local'), hint: I18n.t('simple_form.hints.defaults.discoverable_local')
.fields-group
= f.input :locked, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.locked')
.fields-group
= f.input :hide_collections, as: :boolean, wrapper: :with_label, label: t('simple_form.labels.defaults.setting_hide_network'), hint: t('simple_form.hints.defaults.setting_hide_network')
.fields-group
= f.input :dissubscribable, as: :boolean, wrapper: :with_label, kmyblue: true, hint: t('simple_form.hints.defaults.dissubscribable')
%h4= t('edit_profile.other')
.fields-group

View file

@ -2,5 +2,6 @@
= render_navigation renderer: :links do |primary|
:ruby
primary.item :profile, safe_join([fa_icon('user fw'), t('settings.edit_profile')]), settings_profile_path
primary.item :privacy, safe_join([fa_icon('lock fw'), t('privacy.title')]), settings_privacy_path
primary.item :verification, safe_join([fa_icon('check fw'), t('verification.verification')]), settings_verification_path
primary.item :featured_tags, safe_join([fa_icon('hashtag fw'), t('settings.featured_tags')]), settings_featured_tags_path