From 8239a1b5514682a0ff580d31e8c1a7af334c2ebd Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 17 May 2022 01:19:20 -0500 Subject: [PATCH] upgrades: fix Danbooru.config.user_upgrades_enabled? setting * Fix it so that if upgrades are disabled, only the payment button is disabled instead of the whole page. * Fix it so that disabling upgrades with DANBOORU_USER_UPGRADES_ENABLED="false" works. --- app/models/user_upgrade.rb | 2 +- app/policies/user_upgrade_policy.rb | 2 +- app/views/user_upgrades/new.html.erb | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/user_upgrade.rb b/app/models/user_upgrade.rb index 61d102b30..95fca14ca 100644 --- a/app/models/user_upgrade.rb +++ b/app/models/user_upgrade.rb @@ -28,7 +28,7 @@ class UserUpgrade < ApplicationRecord scope :self_upgrade, -> { where("recipient_id = purchaser_id") } def self.enabled? - Danbooru.config.user_upgrades_enabled? + Danbooru.config.user_upgrades_enabled?.to_s.truthy? end def self.gold_price diff --git a/app/policies/user_upgrade_policy.rb b/app/policies/user_upgrade_policy.rb index 641af6045..cded7874f 100644 --- a/app/policies/user_upgrade_policy.rb +++ b/app/policies/user_upgrade_policy.rb @@ -6,7 +6,7 @@ class UserUpgradePolicy < ApplicationPolicy end def new? - UserUpgrade.enabled? + true end def show? diff --git a/app/views/user_upgrades/new.html.erb b/app/views/user_upgrades/new.html.erb index 162dd4952..45c6c4d12 100644 --- a/app/views/user_upgrades/new.html.erb +++ b/app/views/user_upgrades/new.html.erb @@ -107,7 +107,9 @@ <% end %> - <% if @user_upgrade.purchaser.is_anonymous? %> + <% if !UserUpgrade.enabled? %> + <%= button_to "Get #{Danbooru.config.canonical_app_name} Gold", user_upgrades_path(user_id: @recipient.id), class: "button-primary", disabled: true %> + <% elsif @user_upgrade.purchaser.is_anonymous? %> <%= link_to "Get #{Danbooru.config.canonical_app_name} Gold", new_user_path(url: new_user_upgrade_path), class: "button-primary" %> <% elsif @user_upgrade.recipient.level <= User::Levels::MEMBER %> <%= button_to "Get #{Danbooru.config.canonical_app_name} Gold", user_upgrades_path(user_id: @recipient.id, upgrade_type: "gold", country: params[:country], promo: params[:promo], payment_processor: "authorize_net"), class: "button-primary", remote: true, disable_with: "Redirecting..." %>