[Setup] Ignore limits when seeding

This makes the environment config understand booleans. If something
ends with "?" it tries to interpret it as a boolean. A bunch of
existing configs where changed to reflect this change.
This commit is contained in:
Earlopain 2021-11-14 22:16:36 +01:00
parent ce871e412c
commit 061176e095
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
26 changed files with 62 additions and 55 deletions

View File

@ -13,7 +13,7 @@
3. `cd` into the repo.
4. Run the following commands:
```
docker-compose run e621 /app/bin/setup
docker-compose run -e DANBOORU_DISABLE_THROTTLES=true e621 /app/bin/setup
docker-compose up
```
After running the commands once only `docker-compose up` is needed to bring up the containers.
@ -62,5 +62,5 @@ IQDB integration is delegated to the [IQDBS service](https://github.com/zwagoth/
### Cropped Thumbnails
There's optional support for cropped thumbnails. This relies on installing
`libvips-8.6` or higher and setting `Danbooru.config.enable_image_cropping`
`libvips-8.6` or higher and setting `Danbooru.config.enable_image_cropping?`
to true.

View File

@ -189,7 +189,7 @@ class ApplicationController < ActionController::Base
def reset_current_user
CurrentUser.user = nil
CurrentUser.ip_addr = nil
CurrentUser.safe_mode = Danbooru.config.safe_mode
CurrentUser.safe_mode = Danbooru.config.safe_mode?
CurrentUser.root_url = root_url.chomp("/")
end
@ -235,7 +235,7 @@ class ApplicationController < ActionController::Base
end
def enforce_readonly
return unless Danbooru.config.readonly_mode
return unless Danbooru.config.readonly_mode?
raise ReadOnlyException.new "The site is in readonly mode" unless allowed_readonly_actions.include? action_name
end

View File

@ -27,7 +27,7 @@ class DmailsController < ApplicationController
def show
@dmail = Dmail.find(params[:id])
check_privilege(@dmail)
@dmail.mark_as_read! unless Danbooru.config.readonly_mode
@dmail.mark_as_read! unless Danbooru.config.readonly_mode?
respond_with(@dmail)
end

View File

@ -37,7 +37,7 @@ class ForumTopicsController < ApplicationController
end
def show
if request.format == Mime::Type.lookup("text/html") && !Danbooru.config.readonly_mode
if request.format == Mime::Type.lookup("text/html") && !Danbooru.config.readonly_mode?
@forum_topic.mark_as_read!(CurrentUser.user)
end
@forum_posts = ForumPost.includes(topic: [:category]).search(:topic_id => @forum_topic.id).reorder("forum_posts.id").paginate(params[:page])

View File

@ -30,7 +30,7 @@ class StaticController < ApplicationController
end
def disable_mobile_mode
if CurrentUser.is_member? && !Danbooru.config.readonly_mode
if CurrentUser.is_member? && !Danbooru.config.readonly_mode?
user = CurrentUser.user
user.disable_responsive_mode = !user.disable_responsive_mode
user.save

View File

@ -50,7 +50,7 @@ class PostsDecorator < ApplicationDecorator
end
def cropped_url(options)
cropped_url = if Danbooru.config.enable_image_cropping && options[:show_cropped] && object.has_cropped? && !CurrentUser.user.disable_cropped_thumbnails?
cropped_url = if Danbooru.config.enable_image_cropping? && options[:show_cropped] && object.has_cropped? && !CurrentUser.user.disable_cropped_thumbnails?
object.crop_file_url
else
object.preview_file_url
@ -130,7 +130,7 @@ class PostsDecorator < ApplicationDecorator
end
tooltip += "\n\n#{post.tag_string}"
cropped_url = if Danbooru.config.enable_image_cropping && options[:show_cropped] && post.has_cropped? && !CurrentUser.user.disable_cropped_thumbnails?
cropped_url = if Danbooru.config.enable_image_cropping? && options[:show_cropped] && post.has_cropped? && !CurrentUser.user.disable_cropped_thumbnails?
post.crop_file_url
else
post.preview_file_url

View File

@ -45,7 +45,7 @@ module DanbooruImageResizer
end
def crop_ruby(file, width, height, resize_quality)
return nil unless Danbooru.config.enable_image_cropping
return nil unless Danbooru.config.enable_image_cropping?
output_file = Tempfile.new
begin
@ -83,7 +83,7 @@ module DanbooruImageResizer
end
def crop_shell(file, width, height, quality)
return nil unless Danbooru.config.enable_image_cropping
return nil unless Danbooru.config.enable_image_cropping?
output_file = Tempfile.new(["crop", ".jpg"])

View File

@ -2,7 +2,7 @@ module Maintenance
module_function
def daily
return if Danbooru.config.readonly_mode
return if Danbooru.config.readonly_mode?
ignoring_exceptions { PostPruner.new.prune! }
ignoring_exceptions { Upload.where('created_at < ?', 1.week.ago).delete_all }
@ -20,7 +20,7 @@ module Maintenance
end
def weekly
return if Danbooru.config.readonly_mode
return if Danbooru.config.readonly_mode?
#ignoring_exceptions { ApproverPruner.prune! }
#ignoring_exceptions { TagRelationshipRetirementService.find_and_retire! }

View File

@ -65,7 +65,7 @@ class PixivUgoiraConverter
end
def self.generate_crop(ugoira_file)
return nil unless Danbooru.config.enable_image_cropping
return nil unless Danbooru.config.enable_image_cropping?
file = Tempfile.new(["ugoira-crop", ".zip"], binmode: true)
zipfile = Zip::File.new(ugoira_file.path)

View File

@ -23,7 +23,7 @@ class SessionLoader
load_remember_token
end
CurrentUser.user.unban! if CurrentUser.user.ban_expired? && !Danbooru.config.readonly_mode
CurrentUser.user.unban! if CurrentUser.user.ban_expired? && !Danbooru.config.readonly_mode?
if CurrentUser.user.is_blocked?
recent_ban = CurrentUser.user.recent_ban
ban_message = "Account is banned: forever"
@ -33,8 +33,8 @@ class SessionLoader
raise AuthenticationFailure.new(ban_message)
end
set_statement_timeout
update_last_logged_in_at unless Danbooru.config.readonly_mode
update_last_ip_addr unless Danbooru.config.readonly_mode
update_last_logged_in_at unless Danbooru.config.readonly_mode?
update_last_ip_addr unless Danbooru.config.readonly_mode?
set_time_zone
set_safe_mode
refresh_old_remember_token
@ -121,7 +121,7 @@ private
end
def set_safe_mode
safe_mode = Danbooru.config.safe_mode || params[:safe_mode].to_s.truthy? || CurrentUser.user.enable_safe_mode?
safe_mode = Danbooru.config.safe_mode? || params[:safe_mode].to_s.truthy? || CurrentUser.user.enable_safe_mode?
CurrentUser.safe_mode = safe_mode
end
end

View File

@ -160,7 +160,7 @@ class UploadService
end
def automatic_tags(upload, file)
return "" unless Danbooru.config.enable_dimension_autotagging
return "" unless Danbooru.config.enable_dimension_autotagging?
tags = []
tags += ["animated_gif", "animated"] if is_animated_gif?(upload, file)

View File

@ -251,7 +251,7 @@ class Dmail < ApplicationRecord
end
def mark_as_read!
return if Danbooru.config.readonly_mode
return if Danbooru.config.readonly_mode?
update_column(:is_read, true)
owner.dmails.unread.count.tap do |unread_count|

View File

@ -113,7 +113,7 @@ class ForumTopic < ApplicationRecord
end
def mark_as_read!(user = CurrentUser.user)
return if user.is_anonymous? || Danbooru.config.readonly_mode
return if user.is_anonymous? || Danbooru.config.readonly_mode?
match = ForumTopicVisit.where(:user_id => user.id, :forum_topic_id => id).first
if match

View File

@ -924,7 +924,7 @@ class Post < ApplicationRecord
end
def add_automatic_tags(tags)
return tags if !Danbooru.config.enable_dimension_autotagging
return tags if !Danbooru.config.enable_dimension_autotagging?
tags -= %w(thumbnail low_res hi_res absurd_res superabsurd_res huge_filesize flash webm mp4 wide_image long_image ugoira)
@ -1329,7 +1329,7 @@ class Post < ApplicationRecord
# optimize some cases. these are just estimates but at these
# quantities being off by a few hundred doesn't matter much
if Danbooru.config.estimate_post_counts
if Danbooru.config.estimate_post_counts?
if tags == ""
return (Post.maximum(:id) * (2200402.0 / 2232212)).floor
@ -2118,7 +2118,7 @@ class Post < ApplicationRecord
has_bit_flags BOOLEAN_ATTRIBUTES
def safeblocked?
return true if Danbooru.config.safe_mode && rating != "s"
return true if Danbooru.config.safe_mode? && rating != "s"
CurrentUser.safe_mode? && (rating != "s" || has_tag?("toddlercon|rape|bestiality|beastiality|lolita|loli|shota|pussy|penis|genitals"))
end

View File

@ -457,12 +457,12 @@ class User < ApplicationRecord
extend Memoist
def younger_than(duration)
return false if Danbooru.config.disable_age_checks
return false if Danbooru.config.disable_age_checks?
created_at > duration.ago
end
def older_than(duration)
return true if Danbooru.config.disable_age_checks
return true if Danbooru.config.disable_age_checks?
created_at < duration.ago
end
@ -470,7 +470,7 @@ class User < ApplicationRecord
define_method("#{name}_limit".to_sym, limiter)
define_method("can_#{name}_with_reason".to_sym) do
return true if Danbooru.config.disable_throttles
return true if Danbooru.config.disable_throttles?
return send(checker) if checker && send(checker)
return :REJ_NEWBIE if newbie_duration && younger_than(newbie_duration)
return :REJ_LIMITED if send("#{name}_limit") <= 0
@ -546,15 +546,15 @@ class User < ApplicationRecord
end
def can_upload_with_reason
if hourly_upload_limit <= 0 && !Danbooru.config.disable_throttles
if hourly_upload_limit <= 0 && !Danbooru.config.disable_throttles?
:REJ_UPLOAD_HOURLY
elsif can_upload_free? || is_admin?
true
elsif younger_than(7.days)
:REJ_UPLOAD_NEWBIE
elsif !is_privileged? && post_edit_limit <= 0 && !Danbooru.config.disable_throttles
elsif !is_privileged? && post_edit_limit <= 0 && !Danbooru.config.disable_throttles?
:REJ_UPLOAD_EDIT
elsif upload_limit <= 0 && !Danbooru.config.disable_throttles
elsif upload_limit <= 0 && !Danbooru.config.disable_throttles?
:REJ_UPLOAD_LIMIT
else
true

View File

@ -44,7 +44,7 @@ class PostPresenter < Presenter
locals[:tooltip] = "Rating: #{post.rating}\nID: #{post.id}\nDate: #{post.created_at}\nStatus: #{post.status}\nScore: #{post.score}\n\n#{post.tag_string}"
locals[:cropped_url] = if Danbooru.config.enable_image_cropping && options[:show_cropped] && post.has_cropped? && !CurrentUser.user.disable_cropped_thumbnails?
locals[:cropped_url] = if Danbooru.config.enable_image_cropping? && options[:show_cropped] && post.has_cropped? && !CurrentUser.user.disable_cropped_thumbnails?
post.crop_file_url
else
post.preview_file_url

View File

@ -6,7 +6,7 @@
<%= render "posts/partials/common/inline_blacklist" %>
<div id="posts" class="user-disable-cropped-<%= Danbooru.config.enable_image_cropping && CurrentUser.user.disable_cropped_thumbnails? %>">
<div id="posts" class="user-disable-cropped-<%= Danbooru.config.enable_image_cropping? && CurrentUser.user.disable_cropped_thumbnails? %>">
<div id="posts-container">
<%= @post_set.presenter.post_previews_html(self, show_cropped: true) %>
</div>

View File

@ -89,7 +89,7 @@
</head>
<%= tag.body **body_attributes(CurrentUser.user) do %>
<%= render "layouts/theme_include" %>
<% if Danbooru.config.beta_notice %>
<% if Danbooru.config.beta_notice? %>
<div id="news-updates">
<ul>
<li>
@ -114,7 +114,7 @@
</header>
<div id="page">
<% if Danbooru.config.readonly_mode %>
<% if Danbooru.config.readonly_mode? %>
<div id="readonly-notice">
<h1>The site is currently in readonly mode. </h1>
</div>

View File

@ -14,7 +14,7 @@
<%= render "posts/partials/common/inline_blacklist" %>
<div id="posts" class="user-disable-cropped-<%= Danbooru.config.enable_image_cropping && CurrentUser.user.disable_cropped_thumbnails? %>">
<div id="posts" class="user-disable-cropped-<%= Danbooru.config.enable_image_cropping? && CurrentUser.user.disable_cropped_thumbnails? %>">
<div id="posts-container">
<%= @post_set.presenter.post_previews_html(self) %>
</div>

View File

@ -1,4 +1,4 @@
<div id="posts" class="user-disable-cropped-<%= Danbooru.config.enable_image_cropping && CurrentUser.user.disable_cropped_thumbnails? %>">
<div id="posts" class="user-disable-cropped-<%= Danbooru.config.enable_image_cropping? && CurrentUser.user.disable_cropped_thumbnails? %>">
<div id="posts-container">
<% if @posts.empty? %>
<%= render "posts/blank" %>

View File

@ -1,7 +1,7 @@
<div class="recommended-posts">
<p><em>You might also like:</em></p>
<section class="user-disable-cropped-<%= Danbooru.config.enable_image_cropping && CurrentUser.user.disable_cropped_thumbnails? %>">
<section class="user-disable-cropped-<%= Danbooru.config.enable_image_cropping? && CurrentUser.user.disable_cropped_thumbnails? %>">
<%= PostSets::Recommended.new(post).presenter.post_previews_html(self) %>
</section>
</div>

View File

@ -1,3 +1,3 @@
<section class="recommended-posts user-disable-cropped-<%= Danbooru.config.enable_image_cropping && CurrentUser.user.disable_cropped_thumbnails? %>">
<section class="recommended-posts user-disable-cropped-<%= Danbooru.config.enable_image_cropping? && CurrentUser.user.disable_cropped_thumbnails? %>">
<%= PostSets::Recommended.new(@posts).presenter.post_previews_html(self) %>
</section>

View File

@ -25,7 +25,7 @@ module Danbooru
end
# Force rating:s on this version of the site.
def safe_mode
def safe_mode?
false
end
@ -173,15 +173,15 @@ fart'
40
end
def disable_throttles
def disable_throttles?
false
end
def disable_age_checks
def disable_age_checks?
false
end
def disable_cache_store
def disable_cache_store?
false
end
@ -319,7 +319,7 @@ fart'
750
end
def beta_notice
def beta_notice?
false
end
@ -676,11 +676,11 @@ fart'
},
]
end
def flag_reason_48hours
"If you are the artist, and want this image to be taken down [b]permanently[/b], file a \"takedown\":/static/takedown instead.\nTo replace the image with a \"fixed\" version, upload that image first, and then use the \"Duplicate or inferior version\" reason above.\nFor accidentally released paysite or private content, use the \"Paysite, commercial, or private content\" reason above."
end
def deletion_reasons
[
"Inferior version/duplicate of post #%PARENT_ID%",
@ -821,7 +821,7 @@ fart'
nil
end
def enable_dimension_autotagging
def enable_dimension_autotagging?
true
end
@ -905,7 +905,7 @@ fart'
end
# enable some (donmai-specific) optimizations for post counts
def estimate_post_counts
def estimate_post_counts?
false
end
@ -941,7 +941,7 @@ fart'
def recaptcha_secret_key
end
def enable_image_cropping
def enable_image_cropping?
true
end
@ -1002,7 +1002,7 @@ fart'
end
def metrika_enabled?
false
false
end
# Additional video samples will be generated in these dimensions if it makes sense to do so
@ -1015,8 +1015,8 @@ fart'
[]
end
def readonly_mode
return false
def readonly_mode?
false
end
end
@ -1025,11 +1025,18 @@ fart'
@custom_configuration ||= CustomConfiguration.new
end
def env_to_boolean(method, var)
is_boolean = method.to_s.end_with? "?"
return true if is_boolean && var.truthy?
return false if is_boolean && var.falsy?
var
end
def method_missing(method, *args)
var = ENV["DANBOORU_#{method.to_s.upcase.chomp("?")}"]
if var.present?
var
env_to_boolean(method, var)
else
custom_configuration.send(method, *args)
end

View File

@ -1,7 +1,7 @@
def get_cache_store
if Rails.env.test?
[:memory_store, { size: 32.megabytes }]
elsif Danbooru.config.disable_cache_store
elsif Danbooru.config.disable_cache_store?
:null_store
else
[:mem_cache_store, Danbooru.config.memcached_servers, { namespace: Danbooru.config.safe_app_name }]

View File

@ -79,7 +79,7 @@ class ActiveSupport::TestCase
mock_missed_search_service!
WebMock.allow_net_connect!
Danbooru.config.stubs(:enable_sock_puppet_validation?).returns(false)
Danbooru.config.stubs(:disable_throttles).returns(true)
Danbooru.config.stubs(:disable_throttles?).returns(true)
FileUtils.mkdir_p("#{Rails.root}/tmp/test-storage2")
storage_manager = StorageManager::Local.new(base_dir: "#{Rails.root}/tmp/test-storage2")

View File

@ -4,7 +4,7 @@ class UserTest < ActiveSupport::TestCase
context "A user" do
setup do
# stubbed to true in test_helper.rb
Danbooru.config.stubs(:disable_throttles).returns(false)
Danbooru.config.stubs(:disable_throttles?).returns(false)
@user = FactoryBot.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"