mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-20 13:49:39 +02:00
fix: Don't show Billings on settings navbar when self-hosted (#1912)
* Do not show billing settings navbar item when self hosted * Do not show billing settings navbar item when self hosted * Add condition to settings helper * Let Stripe::AuthenticationError bubble up
This commit is contained in:
parent
9138bd2b76
commit
624faa10d0
6 changed files with 36 additions and 8 deletions
|
@ -1,4 +1,6 @@
|
||||||
class SubscriptionsController < ApplicationController
|
class SubscriptionsController < ApplicationController
|
||||||
|
before_action :redirect_to_root_if_self_hosted
|
||||||
|
|
||||||
def new
|
def new
|
||||||
if Current.family.stripe_customer_id.blank?
|
if Current.family.stripe_customer_id.blank?
|
||||||
customer = stripe_client.v1.customers.create(
|
customer = stripe_client.v1.customers.create(
|
||||||
|
@ -44,4 +46,8 @@ class SubscriptionsController < ApplicationController
|
||||||
def stripe_client
|
def stripe_client
|
||||||
@stripe_client ||= Stripe::StripeClient.new(ENV["STRIPE_SECRET_KEY"])
|
@stripe_client ||= Stripe::StripeClient.new(ENV["STRIPE_SECRET_KEY"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def redirect_to_root_if_self_hosted
|
||||||
|
redirect_to root_path, alert: I18n.t("subscriptions.self_hosted_alert") if self_hosted?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ module SettingsHelper
|
||||||
{ name: I18n.t("settings.settings_nav.preferences_label"), path: :settings_preferences_path },
|
{ name: I18n.t("settings.settings_nav.preferences_label"), path: :settings_preferences_path },
|
||||||
{ name: I18n.t("settings.settings_nav.security_label"), path: :settings_security_path },
|
{ name: I18n.t("settings.settings_nav.security_label"), path: :settings_security_path },
|
||||||
{ name: I18n.t("settings.settings_nav.self_hosting_label"), path: :settings_hosting_path, condition: :self_hosted? },
|
{ name: I18n.t("settings.settings_nav.self_hosting_label"), path: :settings_hosting_path, condition: :self_hosted? },
|
||||||
{ name: I18n.t("settings.settings_nav.billing_label"), path: :settings_billing_path },
|
{ name: I18n.t("settings.settings_nav.billing_label"), path: :settings_billing_path, condition: :not_self_hosted? },
|
||||||
{ name: I18n.t("settings.settings_nav.accounts_label"), path: :accounts_path },
|
{ name: I18n.t("settings.settings_nav.accounts_label"), path: :accounts_path },
|
||||||
{ name: I18n.t("settings.settings_nav.imports_label"), path: :imports_path },
|
{ name: I18n.t("settings.settings_nav.imports_label"), path: :imports_path },
|
||||||
{ name: I18n.t("settings.settings_nav.tags_label"), path: :tags_path },
|
{ name: I18n.t("settings.settings_nav.tags_label"), path: :tags_path },
|
||||||
|
@ -45,4 +45,9 @@ module SettingsHelper
|
||||||
concat(next_setting)
|
concat(next_setting)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def not_self_hosted?
|
||||||
|
!self_hosted?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,10 +32,11 @@
|
||||||
<%= render "settings/settings_nav_item", name: t(".self_hosting_label"), path: settings_hosting_path, icon: "database" %>
|
<%= render "settings/settings_nav_item", name: t(".self_hosting_label"), path: settings_hosting_path, icon: "database" %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% unless self_hosted? %>
|
||||||
<li>
|
<li>
|
||||||
<%= render "settings/settings_nav_item", name: t(".billing_label"), path: settings_billing_path, icon: "circle-dollar-sign" %>
|
<%= render "settings/settings_nav_item", name: t(".billing_label"), path: settings_billing_path, icon: "circle-dollar-sign" %>
|
||||||
</li>
|
</li>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<%= render "settings/settings_nav_item", name: t(".accounts_label"), path: accounts_path, icon: "layers" %>
|
<%= render "settings/settings_nav_item", name: t(".accounts_label"), path: accounts_path, icon: "layers" %>
|
||||||
|
|
3
config/locales/views/subscriptions/en.yml
Normal file
3
config/locales/views/subscriptions/en.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
en:
|
||||||
|
subscriptions:
|
||||||
|
self_hosted_alert: "Maybe+ is not available in self-hosted mode."
|
|
@ -1,7 +1,14 @@
|
||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
|
||||||
class SubscriptionsControllerTest < ActionDispatch::IntegrationTest
|
class SubscriptionsControllerTest < ActionDispatch::IntegrationTest
|
||||||
# test "the truth" do
|
setup do
|
||||||
# assert true
|
sign_in @user = users(:family_admin)
|
||||||
# end
|
end
|
||||||
|
|
||||||
|
test "redirects to settings if self hosting" do
|
||||||
|
Rails.application.config.app_mode.stubs(:self_hosted?).returns(true)
|
||||||
|
get subscription_path
|
||||||
|
assert_redirected_to root_path
|
||||||
|
assert_equal I18n.t("subscriptions.self_hosted_alert"), flash[:alert]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,6 +46,12 @@ class SettingsTest < ApplicationSystemTestCase
|
||||||
assert_selector 'span[data-clipboard-target="iconSuccess"]', visible: true, count: 1 # text copied and icon changed to checkmark
|
assert_selector 'span[data-clipboard-target="iconSuccess"]', visible: true, count: 1 # text copied and icon changed to checkmark
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "does not show billing link if self hosting" do
|
||||||
|
Rails.application.config.app_mode.stubs(:self_hosted?).returns(true)
|
||||||
|
open_settings_from_sidebar
|
||||||
|
assert_no_selector "li", text: I18n.t("settings.settings_nav.billing_label")
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def open_settings_from_sidebar
|
def open_settings_from_sidebar
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue