Make publishing of BTCPay wallet balances optional
This commit is contained in:
parent
91d3b977e9
commit
69fffb29d8
@ -1,4 +1,5 @@
|
|||||||
class Api::BtcpayController < Api::BaseController
|
class Api::BtcpayController < Api::BaseController
|
||||||
|
before_action :require_feature_enabled
|
||||||
|
|
||||||
def onchain_btc_balance
|
def onchain_btc_balance
|
||||||
balance = BtcpayManager::FetchOnchainWalletBalance.call
|
balance = BtcpayManager::FetchOnchainWalletBalance.call
|
||||||
@ -18,4 +19,11 @@ class Api::BtcpayController < Api::BaseController
|
|||||||
status: 500
|
status: 500
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def require_feature_enabled
|
||||||
|
unless Setting.btcpay_publish_wallet_balances
|
||||||
|
http_status :not_found and return
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -54,6 +54,8 @@ class Setting < RailsSettings::Base
|
|||||||
field :btcpay_auth_token, type: :string,
|
field :btcpay_auth_token, type: :string,
|
||||||
default: ENV["BTCPAY_AUTH_TOKEN"].presence
|
default: ENV["BTCPAY_AUTH_TOKEN"].presence
|
||||||
|
|
||||||
|
field :btcpay_publish_wallet_balances, type: :boolean, default: true
|
||||||
|
|
||||||
#
|
#
|
||||||
# Discourse
|
# Discourse
|
||||||
#
|
#
|
||||||
|
@ -21,5 +21,17 @@
|
|||||||
type: :password,
|
type: :password,
|
||||||
title: "Auth Token"
|
title: "Auth Token"
|
||||||
) %>
|
) %>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<h3>REST API</h3>
|
||||||
|
<ul role="list">
|
||||||
|
<%= render FormElements::FieldsetToggleComponent.new(
|
||||||
|
form: f,
|
||||||
|
attribute: :btcpay_publish_wallet_balances,
|
||||||
|
enabled: Setting.btcpay_publish_wallet_balances?,
|
||||||
|
title: "Publish wallet balances",
|
||||||
|
description: "Publish the store's on-chain and Lightning wallet balances"
|
||||||
|
) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -39,6 +39,18 @@ RSpec.describe "/api/btcpay", type: :request do
|
|||||||
expect(res["error"]).not_to be_nil
|
expect(res["error"]).not_to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "feature disabled" do
|
||||||
|
before do
|
||||||
|
Setting.btcpay_publish_wallet_balances = false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns a 404 status" do
|
||||||
|
get api_btcpay_onchain_btc_balance_path
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:not_found)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /lightning_btc_balance" do
|
describe "GET /lightning_btc_balance" do
|
||||||
@ -75,5 +87,17 @@ RSpec.describe "/api/btcpay", type: :request do
|
|||||||
expect(res["error"]).not_to be_nil
|
expect(res["error"]).not_to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "feature disabled" do
|
||||||
|
before do
|
||||||
|
Setting.btcpay_publish_wallet_balances = false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns a 404 status" do
|
||||||
|
get api_btcpay_lightning_btc_balance_path
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:not_found)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user