diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 26b6e102c..870d085e0 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -4,6 +4,10 @@ class CommentsController < ApplicationController respond_to :html, :xml, :json, :atom respond_to :js, only: [:new, :update, :destroy, :undelete] + before_action if: -> { request.format.html? && !Danbooru.config.comments_enabled?.to_s.truthy? } do + redirect_to root_path + end + rate_limit :create, rate: 1.0/1.minute, burst: 50 def index diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index f319b7610..b83b04957 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -3,7 +3,11 @@ class ForumTopicsController < ApplicationController respond_to :html, :xml, :json respond_to :atom, only: [:index, :show] + before_action :normalize_search, :only => :index + before_action if: -> { request.format.html? && !Danbooru.config.forum_enabled?.to_s.truthy? } do + redirect_to root_path + end rate_limit :create, rate: 1.0/1.minute, burst: 50 diff --git a/app/logical/autocomplete_service.rb b/app/logical/autocomplete_service.rb index af5918837..58c756f82 100644 --- a/app/logical/autocomplete_service.rb +++ b/app/logical/autocomplete_service.rb @@ -28,23 +28,27 @@ class AutocompleteService TAG_PREFIXES = TagCategory.mapping.keys.map { |prefix| prefix + ":" } - attr_reader :query, :type, :limit, :current_user + attr_reader :query, :type, :limit, :current_user, :enabled + alias_method :enabled?, :enabled # Perform completion for the given search type and query. # @param query [String] the string being completed # @param type [String] the type of completion being performed # @param current_user [User] the user we're performing completion for # @param limit [Integer] the max number of results to return - def initialize(query, type, current_user: User.anonymous, limit: 10) + def initialize(query, type, current_user: User.anonymous, limit: 10, enabled: Danbooru.config.autocomplete_enabled?.to_s.truthy?) @query = query.to_s @type = type.to_s.to_sym @current_user = current_user @limit = limit + @enabled = enabled end # Return the results of the completion. # @return [Array] the autocomplete results def autocomplete_results + return [] if !enabled? + case type when :tag_query autocomplete_tag_query diff --git a/app/logical/rate_limiter.rb b/app/logical/rate_limiter.rb index 47b6e52ba..086cd909c 100644 --- a/app/logical/rate_limiter.rb +++ b/app/logical/rate_limiter.rb @@ -16,7 +16,7 @@ class RateLimiter attr_reader :action, :keys, :cost, :rate, :burst, :enabled alias_method :enabled?, :enabled - def initialize(action, keys = ["*"], cost: 1, rate: 1, burst: 1, enabled: Danbooru.config.rate_limits_enabled?) + def initialize(action, keys = ["*"], cost: 1, rate: 1, burst: 1, enabled: Danbooru.config.rate_limits_enabled?.to_s.truthy?) @action = action @keys = keys @cost = cost diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index 64d3a2703..306f09bb2 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -87,13 +87,13 @@ <% end %> <%= nav_link_to("Posts", posts_path) %> - <%= nav_link_to("Comments", comments_path) %> + <%= nav_link_to("Comments", comments_path) if Danbooru.config.comments_enabled?.to_s.truthy? %> <%= nav_link_to("Notes", notes_path) %> <%= nav_link_to("Artists", artists_path) %> <%= nav_link_to("Tags", tags_path) %> <%= nav_link_to("Pools", gallery_pools_path) %> <%= nav_link_to("Wiki", wiki_page_path("help:home")) %> - <%= nav_link_to("Forum", forum_topics_path, :class => (CurrentUser.has_forum_been_updated? ? "forum-updated" : nil)) %> + <%= nav_link_to("Forum", forum_topics_path, class: ("forum-updated" if CurrentUser.has_forum_been_updated?)) if Danbooru.config.forum_enabled?.to_s.truthy? %> <% if CurrentUser.is_moderator? %> <%= nav_link_to("Reports", moderation_reports_path, :class => (ModerationReport.where(status: "pending").present? ? "reports-pending" : nil)) %> diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 1a9e1684c..20f59c30c 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -48,7 +48,9 @@
  • <%= link_to "Random", random_posts_path(tags: params[:tags]), id: "random-post", "data-shortcut": "r", rel: "nofollow" %>
  • <% if @post_set.post_query.has_single_tag? %>
  • <%= link_to "History", post_versions_path(search: { changed_tags: @post_set.post_query.tag_name }), rel: "nofollow" %>
  • -
  • <%= link_to "Discussions", forum_posts_path(search: { linked_to: @post_set.post_query.tag_name }), rel: "nofollow" %>
  • + <% if Danbooru.config.forum_enabled?.to_s.truthy? %> +
  • <%= link_to "Discussions", forum_posts_path(search: { linked_to: @post_set.post_query.tag_name }), rel: "nofollow" %>
  • + <% end %> <% end %>
  • <%= link_to "Count", posts_counts_path(tags: params[:tags]), rel: "nofollow" %>
  • diff --git a/app/views/posts/show.html+tooltip.erb b/app/views/posts/show.html+tooltip.erb index 820a14593..d076b57eb 100644 --- a/app/views/posts/show.html+tooltip.erb +++ b/app/views/posts/show.html+tooltip.erb @@ -11,7 +11,7 @@ <%= upvote_icon %> - <% if @post.last_commented_at.present? %> + <% if Danbooru.config.comments_enabled?.to_s.truthy? && @post.last_commented_at.present? %> <%= @post.comments.count %> <%= comments_icon(class: "fa-xs") %> diff --git a/app/views/posts/show.html.erb b/app/views/posts/show.html.erb index cf4530060..8b0b8099c 100644 --- a/app/views/posts/show.html.erb +++ b/app/views/posts/show.html.erb @@ -1,7 +1,9 @@ <% page_title @post.presenter.humanized_essential_tag_string %> <% meta_description "View this #{@post.image_width}x#{@post.image_height} #{number_to_human_size(@post.file_size)} image" %> <% canonical_url post_url(@post, host: Danbooru.config.hostname) %> -<% atom_feed_tag "Comments for post ##{@post.id}", comments_url(:atom, search: { post_id: @post.id }) %> +<% if Danbooru.config.comments_enabled?.to_s.truthy? %> + <% atom_feed_tag "Comments for post ##{@post.id}", comments_url(:atom, search: { post_id: @post.id }) %> +<% end %> <%= render "posts/partials/common/secondary_links" %> @@ -322,7 +324,9 @@ <% end %> -
  • Comments
  • + <% if Danbooru.config.comments_enabled?.to_s.truthy? %> +
  • Comments
  • + <% end %> <% if RecommenderService.available_for_post?(@post) %>
  • Recommended
  • @@ -339,9 +343,11 @@ <% end %> -
    - <%= render_comment_section(@post, current_user: CurrentUser.user) %> -
    + <% if Danbooru.config.comments_enabled?.to_s.truthy? %> +
    + <%= render_comment_section(@post, current_user: CurrentUser.user) %> +
    + <% end %>
    -
      -
    • Comments

    • -
    • <%= link_to_wiki "Help", "help:comments" %>
    • -
    • <%= link_to("Listing", comments_path) %>
    • -
    • <%= link_to("Search", search_comments_path) %>
    • -
    • <%= link_to("Votes", comment_votes_path) %>
    • -
    • <%= link_to("RSS", comments_path(:atom)) %>
    • -
    -
      -
    • Forum

    • -
    • <%= link_to_wiki "Help", "help:forum" %>
    • -
    • <%= link_to("Listing", forum_topics_path) %>
    • -
    • <%= link_to("Search", search_forum_posts_path) %>
    • -
    • <%= link_to("Votes", forum_post_votes_path) %>
    • -
    • <%= link_to("RSS", forum_topics_path(:atom)) %>
    • -
    + <% if Danbooru.config.comments_enabled?.to_s.truthy? %> +
      +
    • Comments

    • +
    • <%= link_to_wiki "Help", "help:comments" %>
    • +
    • <%= link_to("Listing", comments_path) %>
    • +
    • <%= link_to("Search", search_comments_path) %>
    • +
    • <%= link_to("Votes", comment_votes_path) %>
    • +
    • <%= link_to("RSS", comments_path(:atom)) %>
    • +
    + <% end %> + <% if Danbooru.config.forum_enabled?.to_s.truthy? %> +
      +
    • Forum

    • +
    • <%= link_to_wiki "Help", "help:forum" %>
    • +
    • <%= link_to("Listing", forum_topics_path) %>
    • +
    • <%= link_to("Search", search_forum_posts_path) %>
    • +
    • <%= link_to("Votes", forum_post_votes_path) %>
    • +
    • <%= link_to("RSS", forum_topics_path(:atom)) %>
    • +
    + <% end %>
    • Wiki

    • <%= link_to_wiki "Help", "help:wiki" %>
    • diff --git a/app/views/users/_statistics.html.erb b/app/views/users/_statistics.html.erb index fe5c813a2..7d9d0ff2a 100644 --- a/app/views/users/_statistics.html.erb +++ b/app/views/users/_statistics.html.erb @@ -208,20 +208,24 @@ <% end %> - - Forum Posts - <%= presenter.forum_post_count(self) %> - + <% if Danbooru.config.forum_enabled?.to_s.truthy? %> + + Forum Posts + <%= presenter.forum_post_count(self) %> + + <% end %> Approvals <%= presenter.approval_count(self) %> - - Comments - <%= presenter.comment_count(self) %> in <%= presenter.commented_posts_count(self) %> posts - + <% if Danbooru.config.comments_enabled?.to_s.truthy? %> + + Comments + <%= presenter.comment_count(self) %> in <%= presenter.commented_posts_count(self) %> posts + + <% end %> Appeals diff --git a/app/views/users/show.html+tooltip.erb b/app/views/users/show.html+tooltip.erb index 0102ff30a..e0d4e69c3 100644 --- a/app/views/users/show.html+tooltip.erb +++ b/app/views/users/show.html+tooltip.erb @@ -111,17 +111,21 @@
      Favorites
      <% end %> -
    • - <%= link_to comments_path(search: { creator_id: @user.id }), class: "link-plain" do %> -
      <%= humanized_number(@user.comment_count) %>
      -
      Comments
      - <% end %> -
    • -
    • - <%= link_to forum_posts_path(search: { creator_id: @user.id }), class: "link-plain" do %> -
      <%= humanized_number(@user.forum_post_count) %>
      -
      Forum Posts
      - <% end %> -
    • + <% if Danbooru.config.comments_enabled?.to_s.truthy? %> +
    • + <%= link_to comments_path(search: { creator_id: @user.id }), class: "link-plain" do %> +
      <%= humanized_number(@user.comment_count) %>
      +
      Comments
      + <% end %> +
    • + <% end %> + <% if Danbooru.config.forum_enabled?.to_s.truthy? %> +
    • + <%= link_to forum_posts_path(search: { creator_id: @user.id }), class: "link-plain" do %> +
      <%= humanized_number(@user.forum_post_count) %>
      +
      Forum Posts
      + <% end %> +
    • + <% end %>
    diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 46907e33c..062340224 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -12,5 +12,7 @@ -<% atom_feed_tag "Comments on #{@user.pretty_name}'s uploads", comments_url(:atom, search: { post_tags_match: "user:#{@user.name}" }) %> -<% atom_feed_tag "Comments on posts commented on by #{@user.pretty_name}", comments_url(:atom, search: { post_tags_match: "commenter:#{@user.name}" }) %> +<% if Danbooru.config.comments_enabled?.to_s.truthy? %> + <% atom_feed_tag "Comments on #{@user.pretty_name}'s uploads", comments_url(:atom, search: { post_tags_match: "user:#{@user.name}" }) %> + <% atom_feed_tag "Comments on posts commented on by #{@user.pretty_name}", comments_url(:atom, search: { post_tags_match: "commenter:#{@user.name}" }) %> +<% end %> diff --git a/app/views/wiki_pages/_sidebar.html.erb b/app/views/wiki_pages/_sidebar.html.erb index cc9af4c32..11c2035f0 100644 --- a/app/views/wiki_pages/_sidebar.html.erb +++ b/app/views/wiki_pages/_sidebar.html.erb @@ -10,7 +10,9 @@
  • <%= link_to "Tag History", post_versions_path(search: { changed_tags: @wiki_page.title }) %>
  • <% end %>
  • <%= link_to "Wiki History", wiki_page_versions_path(search: { wiki_page_id: @wiki_page.id }) %>
  • -
  • <%= link_to "Discussions", forum_posts_path(search: { linked_to: @wiki_page.title }) %>
  • + <% if Danbooru.config.forum_enabled?.to_s.truthy? %> +
  • <%= link_to "Discussions", forum_posts_path(search: { linked_to: @wiki_page.title }) %>
  • + <% end %>
  • <%= link_to "What Links Here", wiki_pages_path(search: { linked_to: @wiki_page.title }) %>
  • <% end %> diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index 47c7dc655..aa0e952a7 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -377,6 +377,21 @@ module Danbooru true end + # Whether to enable comments. + def comments_enabled? + true + end + + # Whether to enable the forum. + def forum_enabled? + true + end + + # Whether to enable autocomplete. + def autocomplete_enabled? + true + end + def stripe_secret_key end