* Create "blank" EmailSubscriptionTag * Refactor liquid_tags_used with spec * Create /user_subscriptions#create - Update liquid tag name to UserSubscriptionTag * Add rate limiting and specs * Add counter_culture for user_subscriptions * Update /async_info/base_data - Alphabetize user_data - Add email - Add subscription_source_article_ids - Cache subscription_source_article_ids on User model * Add stale email check and specs * Change user_email to subscriber_email for clarity * Restrict UserSubscriptionTag * Rename RESTRICTED_TAGS to RESTRICTED_LIQUID_TAGS * Make TODO comment more clear * Refactor error responses and update specs * Update type to source_type in error message * Use constantize over safe_constantize * Add check for active source * Refactor checking of current_user's subscriptions - Remove data from async_info - Create a new service to fetch/cache a user's existing subscriptions * Restrict email in base_data to admin roles * Oops! Rename liquid tag file * Change error back to result...oops! * It's not goodbye, it's see you later. RIP email :/ * Add current_email to /user_subscriptions/base_data * Revert adding current_email * Undo async_info_controller changes/fix conflict * Move params to constant * Refactor SubscriptionCacheChecker * Remove duplicate status code in JSON response * Remove duplicate status code for #subscribed * Use response.parsed_body * Remove user guard in SubscriptionCacheChecker
155 lines
3.7 KiB
Ruby
155 lines
3.7 KiB
Ruby
class Internal::ConfigsController < Internal::ApplicationController
|
|
layout "internal"
|
|
|
|
before_action :extra_authorization_and_confirmation, only: [:create]
|
|
|
|
def show
|
|
@logo_svg = SiteConfig.logo_svg.html_safe # rubocop:disable Rails/OutputSafety
|
|
end
|
|
|
|
def create
|
|
clean_up_params
|
|
|
|
config_params.each do |key, value|
|
|
if value.is_a?(Array)
|
|
SiteConfig.public_send("#{key}=", value.reject(&:blank?)) unless value.empty?
|
|
elsif value.respond_to?(:to_h)
|
|
SiteConfig.public_send("#{key}=", value.to_h) unless value.empty?
|
|
else
|
|
SiteConfig.public_send("#{key}=", value.strip) unless value.nil?
|
|
end
|
|
end
|
|
|
|
bust_relevant_caches
|
|
redirect_to internal_config_path, notice: "Site configuration was successfully updated."
|
|
end
|
|
|
|
private
|
|
|
|
def config_params
|
|
allowed_params = %i[
|
|
ga_view_id ga_fetch_rate
|
|
periodic_email_digest_max
|
|
periodic_email_digest_min
|
|
sidebar_tags
|
|
twitter_hashtag
|
|
shop_url
|
|
payment_pointer
|
|
health_check_token
|
|
]
|
|
|
|
allowed_params = allowed_params |
|
|
campaign_params |
|
|
community_params |
|
|
newsletter_params |
|
|
rate_limit_params |
|
|
mascot_params |
|
|
image_params |
|
|
onboarding_params |
|
|
job_params
|
|
|
|
params[:site_config][:email_addresses][:default] = ApplicationConfig["DEFAULT_EMAIL"] if params[:site_config][:email_addresses].present?
|
|
params.require(:site_config).permit(
|
|
allowed_params,
|
|
authentication_providers: [],
|
|
social_media_handles: SiteConfig.social_media_handles.keys,
|
|
email_addresses: SiteConfig.email_addresses.keys,
|
|
meta_keywords: SiteConfig.meta_keywords.keys,
|
|
)
|
|
end
|
|
|
|
def extra_authorization_and_confirmation
|
|
not_authorized unless current_user.has_role?(:single_resource_admin, Config) # Special additional permission
|
|
not_authorized if params[:confirmation] != "My username is @#{current_user.username} and this action is 100% safe and appropriate."
|
|
end
|
|
|
|
def clean_up_params
|
|
config = params[:site_config]
|
|
%i[sidebar_tags suggested_tags suggested_users].each do |param|
|
|
config[param] = config[param].downcase.delete(" ") if config[param]
|
|
end
|
|
end
|
|
|
|
def bust_relevant_caches
|
|
# Needs to change when suggested_tags is edited.
|
|
CacheBuster.bust("/tags/onboarding")
|
|
end
|
|
|
|
def campaign_params
|
|
%i[
|
|
campaign_featured_tags
|
|
campaign_hero_html_variant_name
|
|
campaign_sidebar_enabled
|
|
campaign_sidebar_image
|
|
campaign_url
|
|
campaign_articles_require_approval
|
|
]
|
|
end
|
|
|
|
def community_params
|
|
%i[
|
|
community_description
|
|
community_member_description
|
|
community_member_label
|
|
community_action
|
|
tagline
|
|
]
|
|
end
|
|
|
|
def newsletter_params
|
|
%i[
|
|
mailchimp_community_moderators_id
|
|
mailchimp_newsletter_id
|
|
mailchimp_sustaining_members_id
|
|
mailchimp_tag_moderators_id
|
|
]
|
|
end
|
|
|
|
def rate_limit_params
|
|
%i[
|
|
rate_limit_comment_creation
|
|
rate_limit_email_recipient
|
|
rate_limit_follow_count_daily
|
|
rate_limit_image_upload
|
|
rate_limit_published_article_creation
|
|
rate_limit_organization_creation
|
|
rate_limit_user_subscription_creation
|
|
]
|
|
end
|
|
|
|
def mascot_params
|
|
%i[
|
|
mascot_image_description
|
|
mascot_image_url
|
|
mascot_footer_image_url
|
|
mascot_user_id
|
|
]
|
|
end
|
|
|
|
def image_params
|
|
%i[
|
|
favicon_url
|
|
logo_png
|
|
logo_svg
|
|
main_social_image
|
|
primary_sticker_image_url
|
|
]
|
|
end
|
|
|
|
def onboarding_params
|
|
%i[
|
|
onboarding_logo_image
|
|
onboarding_background_image
|
|
onboarding_taskcard_image
|
|
suggested_tags
|
|
suggested_users
|
|
]
|
|
end
|
|
|
|
def job_params
|
|
%i[
|
|
jobs_url
|
|
display_jobs_banner
|
|
]
|
|
end
|
|
end
|