Fix #5095: Add more user configuration to the body element
This commit is contained in:
@@ -1,6 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
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])
|
||||
(fields.reduce(false) { |acc, field| acc || params.dig(:search, field).present? } && (!member_check || CurrentUser.is_member?) ? types[0] : types[1])
|
||||
end
|
||||
@@ -291,35 +301,13 @@ module ApplicationHelper
|
||||
layout: layout,
|
||||
"current-user-ip-addr": request.remote_ip,
|
||||
"current-user-save-data": CurrentUser.save_data,
|
||||
**current_user_data_attributes(current_user),
|
||||
**cookie_data_attributes,
|
||||
**data_attributes_for(current_user, "current-user", USER_DATA_ATTRIBUTES),
|
||||
**data_attributes_for(cookies, "cookie", COOKIE_DATA_ATTRIBUTES),
|
||||
**extra_attributes,
|
||||
}
|
||||
}
|
||||
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)
|
||||
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
|
||||
|
||||
@@ -20,54 +20,42 @@ class User < ApplicationRecord
|
||||
# Used for `before_action :<role>_only`. Must have a corresponding `is_<role>?` method.
|
||||
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[
|
||||
is_banned
|
||||
has_mail
|
||||
_unused_has_mail
|
||||
receive_email_notifications
|
||||
always_resize_images
|
||||
enable_post_navigation
|
||||
_unused_always_resize_images
|
||||
_unused_enable_post_navigation
|
||||
new_post_navigation_layout
|
||||
enable_private_favorites
|
||||
enable_sequential_post_navigation
|
||||
hide_deleted_posts
|
||||
_unused_enable_sequential_post_navigation
|
||||
_unused_hide_deleted_posts
|
||||
style_usernames
|
||||
enable_auto_complete
|
||||
_unused_enable_auto_complete
|
||||
show_deleted_children
|
||||
has_saved_searches
|
||||
_unused_has_saved_searches
|
||||
can_approve_posts
|
||||
can_upload_free
|
||||
disable_categorized_saved_searches
|
||||
is_super_voter
|
||||
_unused_is_super_voter
|
||||
disable_tagged_filenames
|
||||
enable_recent_searches
|
||||
disable_cropped_thumbnails
|
||||
_unused_enable_recent_searches
|
||||
_unused_disable_cropped_thumbnails
|
||||
disable_mobile_gestures
|
||||
enable_safe_mode
|
||||
enable_desktop_mode
|
||||
disable_post_tooltips
|
||||
enable_recommended_posts
|
||||
opt_out_tracking
|
||||
no_flagging
|
||||
no_feedback
|
||||
_unused_enable_recommended_posts
|
||||
_unused_opt_out_tracking
|
||||
_unused_no_flagging
|
||||
_unused_no_feedback
|
||||
requires_verification
|
||||
is_verified
|
||||
show_deleted_posts
|
||||
]
|
||||
|
||||
ACTIVE_BOOLEAN_ATTRIBUTES = BOOLEAN_ATTRIBUTES.grep_v(/unused/)
|
||||
|
||||
DEFAULT_BLACKLIST = ["guro", "scat", "furry -rating:s"].join("\n")
|
||||
|
||||
attribute :id
|
||||
@@ -690,7 +678,6 @@ class User < ApplicationRecord
|
||||
|
||||
def initialize_attributes
|
||||
self.new_post_navigation_layout = true
|
||||
self.always_resize_images = true
|
||||
end
|
||||
|
||||
def presenter
|
||||
|
||||
@@ -45,7 +45,7 @@ class UserPolicy < ApplicationPolicy
|
||||
%i[
|
||||
comment_threshold default_image_size favorite_tags
|
||||
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
|
||||
style_usernames show_deleted_posts show_deleted_children
|
||||
disable_categorized_saved_searches disable_tagged_filenames
|
||||
|
||||
Reference in New Issue
Block a user