2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-08-12 04:59:00 +08:00
|
|
|
class AboutController < ApplicationController
|
2018-02-01 12:17:59 +08:00
|
|
|
requires_login only: [:live_post_counts]
|
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
skip_before_action :check_xhr, only: [:index]
|
2014-08-12 04:59:00 +08:00
|
|
|
|
|
|
|
def index
|
2017-03-08 15:42:24 +08:00
|
|
|
return redirect_to path("/login") if SiteSetting.login_required? && current_user.nil?
|
2016-03-08 04:28:02 +08:00
|
|
|
|
2019-07-31 21:46:58 +08:00
|
|
|
@about = About.new(current_user)
|
2018-11-28 00:19:59 +08:00
|
|
|
@title = "#{I18n.t("js.about.simple_title")} - #{SiteSetting.title}"
|
2016-03-08 04:28:02 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { render :index }
|
2020-05-23 12:56:13 +08:00
|
|
|
format.json { render_json_dump(AboutSerializer.new(@about, scope: guardian)) }
|
2016-03-08 04:28:02 +08:00
|
|
|
end
|
2014-08-12 04:59:00 +08:00
|
|
|
end
|
2015-08-28 05:28:33 +08:00
|
|
|
|
|
|
|
def live_post_counts
|
|
|
|
unless current_user.staff?
|
|
|
|
RateLimiter.new(current_user, "live_post_counts", 1, 10.minutes).performed!
|
2023-01-09 20:20:10 +08:00
|
|
|
end
|
2015-08-28 05:28:33 +08:00
|
|
|
category_topic_ids = Category.pluck(:topic_id).compact!
|
|
|
|
public_topics =
|
|
|
|
Topic.listable_topics.visible.secured(Guardian.new(nil)).where.not(id: category_topic_ids)
|
|
|
|
stats = { public_topic_count: public_topics.count }
|
|
|
|
stats[:public_post_count] = public_topics.sum(:posts_count) - stats[:public_topic_count]
|
|
|
|
render json: stats
|
|
|
|
end
|
2014-08-12 04:59:00 +08:00
|
|
|
end
|