Fix #5095: Add more user configuration to the body element

This commit is contained in:
evazion
2022-05-02 01:21:05 -05:00
parent 2d9bba4abb
commit 5e923e266b
3 changed files with 29 additions and 54 deletions

View File

@@ -1,6 +1,16 @@
# frozen_string_literal: true # frozen_string_literal: true
module ApplicationHelper module ApplicationHelper
USER_DATA_ATTRIBUTES = %i[
id name level level_string theme comment_threshold default_image_size time_zone per_page
] + User::ACTIVE_BOOLEAN_ATTRIBUTES + User::Roles.map { |role| :"is_#{role}?" }
COOKIE_DATA_ATTRIBUTES = %i[
news-ticker hide_upgrade_account_notice hide_verify_account_notice
hide_dmail_notice dab show-relationship-previews post_preview_size
post_preview_show_votes
]
def listing_type(*fields, member_check: true, types: [:revert, :standard]) def listing_type(*fields, member_check: true, types: [:revert, :standard])
(fields.reduce(false) { |acc, field| acc || params.dig(:search, field).present? } && (!member_check || CurrentUser.is_member?) ? types[0] : types[1]) (fields.reduce(false) { |acc, field| acc || params.dig(:search, field).present? } && (!member_check || CurrentUser.is_member?) ? types[0] : types[1])
end end
@@ -291,35 +301,13 @@ module ApplicationHelper
layout: layout, layout: layout,
"current-user-ip-addr": request.remote_ip, "current-user-ip-addr": request.remote_ip,
"current-user-save-data": CurrentUser.save_data, "current-user-save-data": CurrentUser.save_data,
**current_user_data_attributes(current_user), **data_attributes_for(current_user, "current-user", USER_DATA_ATTRIBUTES),
**cookie_data_attributes, **data_attributes_for(cookies, "cookie", COOKIE_DATA_ATTRIBUTES),
**extra_attributes, **extra_attributes,
} }
} }
end end
def current_user_data_attributes(user)
attributes = %i[
id name level level_string theme always_resize_images can_upload_free
can_approve_posts disable_categorized_saved_searches
disable_mobile_gestures disable_post_tooltips enable_safe_mode
show_deleted_posts show_deleted_children style_usernames
default_image_size
] + User::Roles.map { |role| :"is_#{role}?" }
data_attributes_for(user, "current-user", attributes)
end
def cookie_data_attributes
attributes = %i[
news-ticker hide_upgrade_account_notice hide_verify_account_notice
hide_dmail_notice dab show-relationship-previews post_preview_size
post_preview_show_votes
]
data_attributes_for(cookies, "cookie", attributes)
end
def current_item_data_attributes(current_item) def current_item_data_attributes(current_item)
if current_item.present? && current_item.respond_to?(:html_data_attributes) && current_item.respond_to?(:model_name) if current_item.present? && current_item.respond_to?(:html_data_attributes) && current_item.respond_to?(:model_name)
model_name = current_item.model_name.singular.dasherize model_name = current_item.model_name.singular.dasherize

View File

@@ -20,54 +20,42 @@ class User < ApplicationRecord
# Used for `before_action :<role>_only`. Must have a corresponding `is_<role>?` method. # Used for `before_action :<role>_only`. Must have a corresponding `is_<role>?` method.
Roles = Levels.constants.map(&:downcase) + %i[banned approver] Roles = Levels.constants.map(&:downcase) + %i[banned approver]
# candidates for removal:
# - enable_post_navigation (disabled by 700)
# - new_post_navigation_layout (disabled by 1364)
# - enable_sequential_post_navigation (disabled by 680)
# - hide_deleted_posts (enabled by 1904)
# - disable_categorized_saved_searches (enabled by 2291)
# - disable_tagged_filenames (enabled by 387)
# - enable_recent_searches (enabled by 499)
# - disable_cropped_thumbnails (enabled by 22)
# - has_saved_searches
# - opt_out_tracking
# - enable_recommended_posts
# - has_mail
# - is_super_voter
BOOLEAN_ATTRIBUTES = %w[ BOOLEAN_ATTRIBUTES = %w[
is_banned is_banned
has_mail _unused_has_mail
receive_email_notifications receive_email_notifications
always_resize_images _unused_always_resize_images
enable_post_navigation _unused_enable_post_navigation
new_post_navigation_layout new_post_navigation_layout
enable_private_favorites enable_private_favorites
enable_sequential_post_navigation _unused_enable_sequential_post_navigation
hide_deleted_posts _unused_hide_deleted_posts
style_usernames style_usernames
enable_auto_complete _unused_enable_auto_complete
show_deleted_children show_deleted_children
has_saved_searches _unused_has_saved_searches
can_approve_posts can_approve_posts
can_upload_free can_upload_free
disable_categorized_saved_searches disable_categorized_saved_searches
is_super_voter _unused_is_super_voter
disable_tagged_filenames disable_tagged_filenames
enable_recent_searches _unused_enable_recent_searches
disable_cropped_thumbnails _unused_disable_cropped_thumbnails
disable_mobile_gestures disable_mobile_gestures
enable_safe_mode enable_safe_mode
enable_desktop_mode enable_desktop_mode
disable_post_tooltips disable_post_tooltips
enable_recommended_posts _unused_enable_recommended_posts
opt_out_tracking _unused_opt_out_tracking
no_flagging _unused_no_flagging
no_feedback _unused_no_feedback
requires_verification requires_verification
is_verified is_verified
show_deleted_posts show_deleted_posts
] ]
ACTIVE_BOOLEAN_ATTRIBUTES = BOOLEAN_ATTRIBUTES.grep_v(/unused/)
DEFAULT_BLACKLIST = ["guro", "scat", "furry -rating:s"].join("\n") DEFAULT_BLACKLIST = ["guro", "scat", "furry -rating:s"].join("\n")
attribute :id attribute :id
@@ -690,7 +678,6 @@ class User < ApplicationRecord
def initialize_attributes def initialize_attributes
self.new_post_navigation_layout = true self.new_post_navigation_layout = true
self.always_resize_images = true
end end
def presenter def presenter

View File

@@ -45,7 +45,7 @@ class UserPolicy < ApplicationPolicy
%i[ %i[
comment_threshold default_image_size favorite_tags comment_threshold default_image_size favorite_tags
blacklisted_tags time_zone per_page custom_style theme blacklisted_tags time_zone per_page custom_style theme
receive_email_notifications always_resize_images receive_email_notifications
new_post_navigation_layout enable_private_favorites new_post_navigation_layout enable_private_favorites
style_usernames show_deleted_posts show_deleted_children style_usernames show_deleted_posts show_deleted_children
disable_categorized_saved_searches disable_tagged_filenames disable_categorized_saved_searches disable_tagged_filenames