Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

fix: Don't show Billings on settings navbar when self-hosted (#1912)

Tony Vincent624faa10d0fe
diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb
index e2c19535..64552508 100644
--- a/app/controllers/subscriptions_controller.rb
+++ b/app/controllers/subscriptions_controller.rb
@@ -1,4 +1,6 @@
class SubscriptionsController < ApplicationController
+ before_action :redirect_to_root_if_self_hosted
+
def new
if Current.family.stripe_customer_id.blank?
customer = stripe_client.v1.customers.create(
@@ -44,4 +46,8 @@ class SubscriptionsController < ApplicationController
def stripe_client
@stripe_client ||= Stripe::StripeClient.new(ENV["STRIPE_SECRET_KEY"])
end
+
+ def redirect_to_root_if_self_hosted
+ redirect_to root_path, alert: I18n.t("subscriptions.self_hosted_alert") if self_hosted?
+ end
end
diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb
index 0eaecd85..e15414a5 100644
--- a/app/helpers/settings_helper.rb
+++ b/app/helpers/settings_helper.rb
@@ -4,7 +4,7 @@ module SettingsHelper
{ 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.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.imports_label"), path: :imports_path },
{ name: I18n.t("settings.settings_nav.tags_label"), path: :tags_path },
@@ -45,4 +45,9 @@ module SettingsHelper
concat(next_setting)
end
end
+
+ private
+ def not_self_hosted?
+ !self_hosted?
+ end
end
diff --git a/app/views/settings/_settings_nav.html.erb b/app/views/settings/_settings_nav.html.erb
index 1934d921..632e774c 100644
--- a/app/views/settings/_settings_nav.html.erb
+++ b/app/views/settings/_settings_nav.html.erb
@@ -32,10 +32,11 @@
<%= render "settings/settings_nav_item", name: t(".self_hosting_label"), path: settings_hosting_path, icon: "database" %>
</li>
<% end %>
-
- <li>
- <%= render "settings/settings_nav_item", name: t(".billing_label"), path: settings_billing_path, icon: "circle-dollar-sign" %>
- </li>
+ <% unless self_hosted? %>
+ <li>
+ <%= render "settings/settings_nav_item", name: t(".billing_label"), path: settings_billing_path, icon: "circle-dollar-sign" %>
+ </li>
+ <% end %>
<li>
<%= render "settings/settings_nav_item", name: t(".accounts_label"), path: accounts_path, icon: "layers" %>
diff --git a/config/locales/views/subscriptions/en.yml b/config/locales/views/subscriptions/en.yml
new file mode 100644
index 00000000..72ab67a9
--- /dev/null
+++ b/config/locales/views/subscriptions/en.yml
@@ -0,0 +1,3 @@
+en:
+ subscriptions:
+ self_hosted_alert: "Maybe+ is not available in self-hosted mode."
diff --git a/test/controllers/subscriptions_controller_test.rb b/test/controllers/subscriptions_controller_test.rb
index 3fda28d4..fe1b38d7 100644
--- a/test/controllers/subscriptions_controller_test.rb
+++ b/test/controllers/subscriptions_controller_test.rb
@@ -1,7 +1,14 @@
require "test_helper"
class SubscriptionsControllerTest < ActionDispatch::IntegrationTest
- # test "the truth" do
- # assert true
- # end
+ setup do
+ sign_in @user = users(:family_admin)
+ 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
diff --git a/test/system/settings_test.rb b/test/system/settings_test.rb
index 32f2b8c8..9d0338b0 100644
--- a/test/system/settings_test.rb
+++ b/test/system/settings_test.rb
@@ -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
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
def open_settings_from_sidebar