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
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue