You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.4 KiB

  1. # frozen_string_literal: true
  2. class AboutController < ApplicationController
  3. include RegistrationSpamConcern
  4. layout 'public'
  5. # before_action :require_open_federation!, only: [:show, :more]
  6. before_action :set_body_classes, only: :show
  7. before_action :set_instance_presenter
  8. before_action :set_expires_in, only: [:more, :terms]
  9. before_action :set_registration_form_time, only: :show
  10. before_action :authenticate_user!, only: [:jump, :my_data]
  11. skip_before_action :require_functional!, only: [:more, :terms]
  12. def show; end
  13. def more
  14. flash.now[:notice] = I18n.t('about.instance_actor_flash') if params[:instance_actor]
  15. toc_generator = TOCGenerator.new(@instance_presenter.site_extended_description)
  16. @rules = Rule.ordered
  17. @contents = toc_generator.html
  18. @table_of_contents = toc_generator.toc
  19. @blocks = DomainBlock.with_user_facing_limitations.by_severity if display_blocks?
  20. end
  21. def terms; end
  22. def jump
  23. @jump_url = "https://#{request.fullpath[6..-1]}"
  24. end
  25. def my_data
  26. @uid = params[:user_id]
  27. if @uid and current_account.user.admin
  28. @account = Account.find(@uid)
  29. else
  30. @account = current_account
  31. end
  32. year = params[:year].to_i
  33. year = nil unless year > 2000
  34. @year_text = year or ''
  35. y = year ? "statuses.created_at >= '#{year}-1-1' and statuses.created_at < '#{year+1}-1-1'" : nil
  36. y2 = year ? "s2.created_at >= '#{year}-1-1' and s2.created_at < '#{year+1}-1-1'" : nil
  37. yf = year ? "favourites.created_at >='#{year}-1-1' and favourites.created_at < '#{year+1}-1-1'" : nil
  38. def raw_to_list(r)
  39. r.map{|k,v| {:account => Account.find(k), :num => v.to_s}}
  40. end
  41. @total = @account.statuses.where(y).count
  42. @most_times = @account.statuses.where(y).group('cast (created_at as date)').reorder('count_id desc').limit(1).count(:id).map{ |k,v| {:date => k.to_s, :num => v.to_s}}
  43. @most_fav = @account.statuses.where(y).joins(:status_stat).reorder('status_stats.favourites_count desc').first
  44. @like_me_most = raw_to_list(@account.statuses.where(yf).joins(:favourites).group('favourites.account_id').reorder('count_id desc').limit(5).count(:id))
  45. @i_like_most = raw_to_list(@account.favourites.where(yf).joins(:status).group('statuses.account_id').reorder('count_id desc').limit(5).count(:id))
  46. @communi_most = raw_to_list(@account.statuses.where(y).where(y2).joins('join statuses as s2 on statuses.account_id != s2.account_id and (statuses.in_reply_to_id = s2.id or s2.in_reply_to_id = statuses.id)').group('s2.account_id').reorder('count_id desc').limit(5).count(:id))
  47. end
  48. helper_method :display_blocks?
  49. helper_method :display_blocks_rationale?
  50. helper_method :public_fetch_mode?
  51. helper_method :new_user
  52. private
  53. def require_open_federation!
  54. not_found if whitelist_mode?
  55. end
  56. def display_blocks?
  57. Setting.show_domain_blocks == 'all' || (Setting.show_domain_blocks == 'users' && user_signed_in?)
  58. end
  59. def display_blocks_rationale?
  60. Setting.show_domain_blocks_rationale == 'all' || (Setting.show_domain_blocks_rationale == 'users' && user_signed_in?)
  61. end
  62. def new_user
  63. User.new.tap do |user|
  64. user.build_account
  65. user.build_invite_request
  66. end
  67. end
  68. def set_instance_presenter
  69. @instance_presenter = InstancePresenter.new
  70. end
  71. def set_body_classes
  72. @hide_navbar = true
  73. end
  74. def set_expires_in
  75. expires_in 0, public: true
  76. end
  77. end