Add privacy tab in profile settings (#26484)
Co-authored-by: Eugen Rochko <eugen@zeonfederated.com>
This commit is contained in:
parent
3a8370e1f4
commit
fc5ab2dc83
130 changed files with 131 additions and 689 deletions
27
app/controllers/settings/privacy_controller.rb
Normal file
27
app/controllers/settings/privacy_controller.rb
Normal 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, settings: UserSettings.keys)
|
||||
end
|
||||
|
||||
def set_account
|
||||
@account = current_account
|
||||
end
|
||||
end
|
|
@ -20,7 +20,7 @@ class Settings::ProfilesController < Settings::BaseController
|
|||
private
|
||||
|
||||
def account_params
|
||||
params.require(:account).permit(:display_name, :note, :avatar, :header, :locked, :bot, :discoverable, :hide_collections, fields_attributes: [:name, :value])
|
||||
params.require(:account).permit(:display_name, :note, :avatar, :header, :bot, fields_attributes: [:name, :value])
|
||||
end
|
||||
|
||||
def set_account
|
||||
|
|
|
@ -16,6 +16,8 @@ class UserSettings
|
|||
setting :default_sensitive, default: false
|
||||
setting :default_privacy, default: nil, in: %w(public unlisted private)
|
||||
|
||||
setting_inverse_alias :indexable, :noindex
|
||||
|
||||
namespace :web do
|
||||
setting :advanced_layout, default: false
|
||||
setting :trends, default: true
|
||||
|
@ -55,31 +57,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
|
||||
|
||||
|
|
|
@ -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 ||= {}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -8,9 +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 :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')
|
||||
|
||||
|
@ -26,9 +23,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.public_timelines'
|
||||
|
||||
.fields-group
|
||||
|
|
43
app/views/settings/privacy/show.html.haml
Normal file
43
app/views/settings/privacy/show.html.haml
Normal file
|
@ -0,0 +1,43 @@
|
|||
- 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
|
||||
|
||||
.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
|
|
@ -56,17 +56,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
|
||||
|
||||
.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')
|
||||
|
||||
%h4= t('edit_profile.other')
|
||||
|
||||
.fields-group
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue