Add config options to disable comments and the forum.
Add options to disable comments, the forum, and autocomplete. This is for personal boorus and potentially for safe mode. Note that disabling the forum may cause difficulties with creating and approving BURs. Disabling comments and the forum merely hides them from most areas, rather than completely removing them.
This commit is contained in:
@@ -4,6 +4,10 @@ class CommentsController < ApplicationController
|
|||||||
respond_to :html, :xml, :json, :atom
|
respond_to :html, :xml, :json, :atom
|
||||||
respond_to :js, only: [:new, :update, :destroy, :undelete]
|
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
|
rate_limit :create, rate: 1.0/1.minute, burst: 50
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|||||||
@@ -3,7 +3,11 @@
|
|||||||
class ForumTopicsController < ApplicationController
|
class ForumTopicsController < ApplicationController
|
||||||
respond_to :html, :xml, :json
|
respond_to :html, :xml, :json
|
||||||
respond_to :atom, only: [:index, :show]
|
respond_to :atom, only: [:index, :show]
|
||||||
|
|
||||||
before_action :normalize_search, :only => :index
|
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
|
rate_limit :create, rate: 1.0/1.minute, burst: 50
|
||||||
|
|
||||||
|
|||||||
@@ -28,23 +28,27 @@ class AutocompleteService
|
|||||||
|
|
||||||
TAG_PREFIXES = TagCategory.mapping.keys.map { |prefix| prefix + ":" }
|
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.
|
# Perform completion for the given search type and query.
|
||||||
# @param query [String] the string being completed
|
# @param query [String] the string being completed
|
||||||
# @param type [String] the type of completion being performed
|
# @param type [String] the type of completion being performed
|
||||||
# @param current_user [User] the user we're performing completion for
|
# @param current_user [User] the user we're performing completion for
|
||||||
# @param limit [Integer] the max number of results to return
|
# @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
|
@query = query.to_s
|
||||||
@type = type.to_s.to_sym
|
@type = type.to_s.to_sym
|
||||||
@current_user = current_user
|
@current_user = current_user
|
||||||
@limit = limit
|
@limit = limit
|
||||||
|
@enabled = enabled
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the results of the completion.
|
# Return the results of the completion.
|
||||||
# @return [Array<Hash>] the autocomplete results
|
# @return [Array<Hash>] the autocomplete results
|
||||||
def autocomplete_results
|
def autocomplete_results
|
||||||
|
return [] if !enabled?
|
||||||
|
|
||||||
case type
|
case type
|
||||||
when :tag_query
|
when :tag_query
|
||||||
autocomplete_tag_query
|
autocomplete_tag_query
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class RateLimiter
|
|||||||
attr_reader :action, :keys, :cost, :rate, :burst, :enabled
|
attr_reader :action, :keys, :cost, :rate, :burst, :enabled
|
||||||
alias_method :enabled?, :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
|
@action = action
|
||||||
@keys = keys
|
@keys = keys
|
||||||
@cost = cost
|
@cost = cost
|
||||||
|
|||||||
@@ -87,13 +87,13 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= nav_link_to("Posts", posts_path) %>
|
<%= 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("Notes", notes_path) %>
|
||||||
<%= nav_link_to("Artists", artists_path) %>
|
<%= nav_link_to("Artists", artists_path) %>
|
||||||
<%= nav_link_to("Tags", tags_path) %>
|
<%= nav_link_to("Tags", tags_path) %>
|
||||||
<%= nav_link_to("Pools", gallery_pools_path) %>
|
<%= nav_link_to("Pools", gallery_pools_path) %>
|
||||||
<%= nav_link_to("Wiki", wiki_page_path("help:home")) %>
|
<%= 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? %>
|
<% if CurrentUser.is_moderator? %>
|
||||||
<%= nav_link_to("Reports", moderation_reports_path, :class => (ModerationReport.where(status: "pending").present? ? "reports-pending" : nil)) %>
|
<%= nav_link_to("Reports", moderation_reports_path, :class => (ModerationReport.where(status: "pending").present? ? "reports-pending" : nil)) %>
|
||||||
|
|||||||
@@ -48,7 +48,9 @@
|
|||||||
<li><%= link_to "Random", random_posts_path(tags: params[:tags]), id: "random-post", "data-shortcut": "r", rel: "nofollow" %></li>
|
<li><%= link_to "Random", random_posts_path(tags: params[:tags]), id: "random-post", "data-shortcut": "r", rel: "nofollow" %></li>
|
||||||
<% if @post_set.post_query.has_single_tag? %>
|
<% if @post_set.post_query.has_single_tag? %>
|
||||||
<li><%= link_to "History", post_versions_path(search: { changed_tags: @post_set.post_query.tag_name }), rel: "nofollow" %></li>
|
<li><%= link_to "History", post_versions_path(search: { changed_tags: @post_set.post_query.tag_name }), rel: "nofollow" %></li>
|
||||||
<li><%= link_to "Discussions", forum_posts_path(search: { linked_to: @post_set.post_query.tag_name }), rel: "nofollow" %></li>
|
<% if Danbooru.config.forum_enabled?.to_s.truthy? %>
|
||||||
|
<li><%= link_to "Discussions", forum_posts_path(search: { linked_to: @post_set.post_query.tag_name }), rel: "nofollow" %></li>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<li><%= link_to "Count", posts_counts_path(tags: params[:tags]), rel: "nofollow" %></li>
|
<li><%= link_to "Count", posts_counts_path(tags: params[:tags]), rel: "nofollow" %></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<%= upvote_icon %>
|
<%= upvote_icon %>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<% if @post.last_commented_at.present? %>
|
<% if Danbooru.config.comments_enabled?.to_s.truthy? && @post.last_commented_at.present? %>
|
||||||
<span class="post-tooltip-comments post-tooltip-info">
|
<span class="post-tooltip-comments post-tooltip-info">
|
||||||
<span><%= @post.comments.count %></span>
|
<span><%= @post.comments.count %></span>
|
||||||
<%= comments_icon(class: "fa-xs") %>
|
<%= comments_icon(class: "fa-xs") %>
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
<% page_title @post.presenter.humanized_essential_tag_string %>
|
<% 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" %>
|
<% 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) %>
|
<% 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" %>
|
<%= render "posts/partials/common/secondary_links" %>
|
||||||
|
|
||||||
@@ -322,7 +324,9 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<menu id="post-sections" class="mb-4">
|
<menu id="post-sections" class="mb-4">
|
||||||
<li class="active"><a href="#comments">Comments</a></li>
|
<% if Danbooru.config.comments_enabled?.to_s.truthy? %>
|
||||||
|
<li class="active"><a href="#comments">Comments</a></li>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<% if RecommenderService.available_for_post?(@post) %>
|
<% if RecommenderService.available_for_post?(@post) %>
|
||||||
<li><a href="#recommended">Recommended</a></li>
|
<li><a href="#recommended">Recommended</a></li>
|
||||||
@@ -339,9 +343,11 @@
|
|||||||
</section>
|
</section>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<section id="comments">
|
<% if Danbooru.config.comments_enabled?.to_s.truthy? %>
|
||||||
<%= render_comment_section(@post, current_user: CurrentUser.user) %>
|
<section id="comments">
|
||||||
</section>
|
<%= render_comment_section(@post, current_user: CurrentUser.user) %>
|
||||||
|
</section>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<section id="notes" style="display: none;">
|
<section id="notes" style="display: none;">
|
||||||
<% if @post.has_notes? %>
|
<% if @post.has_notes? %>
|
||||||
|
|||||||
@@ -77,22 +77,26 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
<section class="flex-auto space-y-4">
|
<section class="flex-auto space-y-4">
|
||||||
<ul>
|
<% if Danbooru.config.comments_enabled?.to_s.truthy? %>
|
||||||
<li><h2>Comments</h2></li>
|
<ul>
|
||||||
<li><%= link_to_wiki "Help", "help:comments" %></li>
|
<li><h2>Comments</h2></li>
|
||||||
<li><%= link_to("Listing", comments_path) %></li>
|
<li><%= link_to_wiki "Help", "help:comments" %></li>
|
||||||
<li><%= link_to("Search", search_comments_path) %></li>
|
<li><%= link_to("Listing", comments_path) %></li>
|
||||||
<li><%= link_to("Votes", comment_votes_path) %></li>
|
<li><%= link_to("Search", search_comments_path) %></li>
|
||||||
<li><%= link_to("RSS", comments_path(:atom)) %></li>
|
<li><%= link_to("Votes", comment_votes_path) %></li>
|
||||||
</ul>
|
<li><%= link_to("RSS", comments_path(:atom)) %></li>
|
||||||
<ul>
|
</ul>
|
||||||
<li><h2>Forum</h2></li>
|
<% end %>
|
||||||
<li><%= link_to_wiki "Help", "help:forum" %></li>
|
<% if Danbooru.config.forum_enabled?.to_s.truthy? %>
|
||||||
<li><%= link_to("Listing", forum_topics_path) %></li>
|
<ul>
|
||||||
<li><%= link_to("Search", search_forum_posts_path) %></li>
|
<li><h2>Forum</h2></li>
|
||||||
<li><%= link_to("Votes", forum_post_votes_path) %></li>
|
<li><%= link_to_wiki "Help", "help:forum" %></li>
|
||||||
<li><%= link_to("RSS", forum_topics_path(:atom)) %></li>
|
<li><%= link_to("Listing", forum_topics_path) %></li>
|
||||||
</ul>
|
<li><%= link_to("Search", search_forum_posts_path) %></li>
|
||||||
|
<li><%= link_to("Votes", forum_post_votes_path) %></li>
|
||||||
|
<li><%= link_to("RSS", forum_topics_path(:atom)) %></li>
|
||||||
|
</ul>
|
||||||
|
<% end %>
|
||||||
<ul>
|
<ul>
|
||||||
<li><h2>Wiki</h2></li>
|
<li><h2>Wiki</h2></li>
|
||||||
<li><%= link_to_wiki "Help", "help:wiki" %></li>
|
<li><%= link_to_wiki "Help", "help:wiki" %></li>
|
||||||
|
|||||||
@@ -208,20 +208,24 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<tr>
|
<% if Danbooru.config.forum_enabled?.to_s.truthy? %>
|
||||||
<th>Forum Posts</th>
|
<tr>
|
||||||
<td><%= presenter.forum_post_count(self) %></td>
|
<th>Forum Posts</th>
|
||||||
</tr>
|
<td><%= presenter.forum_post_count(self) %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>Approvals</th>
|
<th>Approvals</th>
|
||||||
<td><%= presenter.approval_count(self) %></td>
|
<td><%= presenter.approval_count(self) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<% if Danbooru.config.comments_enabled?.to_s.truthy? %>
|
||||||
<th>Comments</th>
|
<tr>
|
||||||
<td><%= presenter.comment_count(self) %> in <%= presenter.commented_posts_count(self) %> posts</td>
|
<th>Comments</th>
|
||||||
</tr>
|
<td><%= presenter.comment_count(self) %> in <%= presenter.commented_posts_count(self) %> posts</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>Appeals</th>
|
<th>Appeals</th>
|
||||||
|
|||||||
@@ -111,17 +111,21 @@
|
|||||||
<div class="user-tooltip-stat-name">Favorites</div>
|
<div class="user-tooltip-stat-name">Favorites</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
<li class="user-tooltip-stat-item">
|
<% if Danbooru.config.comments_enabled?.to_s.truthy? %>
|
||||||
<%= link_to comments_path(search: { creator_id: @user.id }), class: "link-plain" do %>
|
<li class="user-tooltip-stat-item">
|
||||||
<div class="user-tooltip-stat-value"><%= humanized_number(@user.comment_count) %></div>
|
<%= link_to comments_path(search: { creator_id: @user.id }), class: "link-plain" do %>
|
||||||
<div class="user-tooltip-stat-name">Comments</div>
|
<div class="user-tooltip-stat-value"><%= humanized_number(@user.comment_count) %></div>
|
||||||
<% end %>
|
<div class="user-tooltip-stat-name">Comments</div>
|
||||||
</li>
|
<% end %>
|
||||||
<li class="user-tooltip-stat-item">
|
</li>
|
||||||
<%= link_to forum_posts_path(search: { creator_id: @user.id }), class: "link-plain" do %>
|
<% end %>
|
||||||
<div class="user-tooltip-stat-value"><%= humanized_number(@user.forum_post_count) %></div>
|
<% if Danbooru.config.forum_enabled?.to_s.truthy? %>
|
||||||
<div class="user-tooltip-stat-name">Forum Posts</div>
|
<li class="user-tooltip-stat-item">
|
||||||
<% end %>
|
<%= link_to forum_posts_path(search: { creator_id: @user.id }), class: "link-plain" do %>
|
||||||
</li>
|
<div class="user-tooltip-stat-value"><%= humanized_number(@user.forum_post_count) %></div>
|
||||||
|
<div class="user-tooltip-stat-name">Forum Posts</div>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -12,5 +12,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% atom_feed_tag "Comments on #{@user.pretty_name}'s uploads", comments_url(:atom, search: { post_tags_match: "user:#{@user.name}" }) %>
|
<% if Danbooru.config.comments_enabled?.to_s.truthy? %>
|
||||||
<% atom_feed_tag "Comments on posts commented on by #{@user.pretty_name}", comments_url(:atom, search: { post_tags_match: "commenter:#{@user.name}" }) %>
|
<% 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 %>
|
||||||
|
|||||||
@@ -10,7 +10,9 @@
|
|||||||
<li><%= link_to "Tag History", post_versions_path(search: { changed_tags: @wiki_page.title }) %></li>
|
<li><%= link_to "Tag History", post_versions_path(search: { changed_tags: @wiki_page.title }) %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<li><%= link_to "Wiki History", wiki_page_versions_path(search: { wiki_page_id: @wiki_page.id }) %></li>
|
<li><%= link_to "Wiki History", wiki_page_versions_path(search: { wiki_page_id: @wiki_page.id }) %></li>
|
||||||
<li><%= link_to "Discussions", forum_posts_path(search: { linked_to: @wiki_page.title }) %></li>
|
<% if Danbooru.config.forum_enabled?.to_s.truthy? %>
|
||||||
|
<li><%= link_to "Discussions", forum_posts_path(search: { linked_to: @wiki_page.title }) %></li>
|
||||||
|
<% end %>
|
||||||
<li><%= link_to "What Links Here", wiki_pages_path(search: { linked_to: @wiki_page.title }) %></li>
|
<li><%= link_to "What Links Here", wiki_pages_path(search: { linked_to: @wiki_page.title }) %></li>
|
||||||
</ul>
|
</ul>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -377,6 +377,21 @@ module Danbooru
|
|||||||
true
|
true
|
||||||
end
|
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
|
def stripe_secret_key
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user