-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: clean up code base to improve selfhosting (#49)
- Loading branch information
Showing
12 changed files
with
191 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
# These alerts are only used in the Fugu Cloud veresion (not imporatnt if you're self-hosting) | ||
module InactiveAlertable | ||
extend ActiveSupport::Concern | ||
|
||
private | ||
|
||
def show_not_active_flash | ||
return unless ENV["FUGU_CLOUD"] == "true" | ||
|
||
flash.now[:not_active] = user_canceled_flash if current_user.canceled? | ||
flash.now[:not_active] = user_inactive_flash if current_user.inactive? | ||
end | ||
|
||
# rubocop:disable Rails/OutputSafety | ||
def user_canceled_flash | ||
%( | ||
You have canceled your subscription and it will end soon. | ||
Make sure to <a href="#{users_settings_path}">renew</a> it | ||
if you want to keep using Fugu. | ||
).html_safe | ||
end | ||
|
||
def user_inactive_flash | ||
%( | ||
Hey there 👋 Make sure to <a href="#{users_settings_path}">subscribe</a> in | ||
order to track events. | ||
You can use your test API key to give Fugu a spin without a subscription. | ||
).html_safe | ||
end | ||
# rubocop:enable Rails/OutputSafety | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
# This validation is only run for the Fugu Cloud version (does not apply for self-hosting) | ||
module Inactivable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
validate :user_cannot_be_inactive, if: -> { ENV["FUGU_CLOUD"] == "true" } | ||
end | ||
|
||
private | ||
|
||
def user_cannot_be_inactive | ||
return unless api_key | ||
|
||
return unless !api_key.test && api_key.project.user.inactive? | ||
|
||
errors.add(:base, "You need an active subscription to capture events with your live API key") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<%# Only needed by Fugu Cloud %> | ||
|
||
<h2>Subscription</h2> | ||
<p class="mb-4"> | ||
<% if current_user.active? %> | ||
Your Fugu subscription is active and renews monthly.<br> | ||
<%= link_to "Cancel subscription or update payment method", stripe_customer_portal_url, | ||
data: { turbo: false } | ||
%> | ||
<% elsif current_user.canceled? %> | ||
Your Fugu subscription is canceled, but will remain active until <%= cancel_at %>.<br> | ||
<%= link_to "Renew subscription", stripe_customer_portal_url, | ||
data: { turbo: false } | ||
%> | ||
<% else %> | ||
You don't have an active subscription.<br> | ||
Fugu costs $9/month and includes 1 million events/month.<br> | ||
<%= link_to "Start your subscription now", stripe_checkout_session_url, | ||
data: { turbo: false } | ||
%> | ||
<% if current_user.stripe_customer_id.present? %> | ||
<br> | ||
<%= link_to "View past invoices", stripe_customer_portal_url, | ||
data: { turbo: false } | ||
%> | ||
<% end %> | ||
<% end %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<%# Only needed by Fugu Cloud %> | ||
|
||
<h2>Support</h2> | ||
<p class="mb-4"> | ||
Thanks for being an early Fugu user ❤️ | ||
Contact me if you have questions or need help: [email protected] or | ||
<a href="https://twitter.com/canolcer" targt="_blank">@canolcer</a>. | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,16 @@ | ||
<% content_for :main do %> | ||
<h1 class="text-xl mb-4 font-medium mb-8">Account settings</h1> | ||
<h1 class="text-xl font-medium mb-8">Account settings</h1> | ||
<%= render "partials/narrow_box" do %> | ||
<h2>Email</h2> | ||
<p class="mb-4"> | ||
<%= current_user.email %> | ||
</p> | ||
<h2>Subscription</h2> | ||
<p class="mb-4"> | ||
<% if current_user.active? %> | ||
Your Fugu subscription is active and renews monthly.<br> | ||
<%= link_to "Cancel subscription or update payment method", stripe_customer_portal_url, | ||
data: { turbo: false } | ||
%> | ||
<% elsif current_user.canceled? %> | ||
Your Fugu subscription is canceled, but will remain active until <%= @cancel_at %>.<br> | ||
<%= link_to "Renew subscription", stripe_customer_portal_url, | ||
data: { turbo: false } | ||
%> | ||
<% else %> | ||
You don't have an active subscription.<br> | ||
Fugu costs $9/month and includes 1 million events/month.<br> | ||
<%= link_to "Start your subscription now", stripe_checkout_session_url, | ||
data: { turbo: false } | ||
%> | ||
<% if current_user.stripe_customer_id.present? %> | ||
<br> | ||
<%= link_to "View past invoices", stripe_customer_portal_url, | ||
data: { turbo: false } | ||
%> | ||
<% end %> | ||
<% end %> | ||
</p> | ||
<h2>Support</h2> | ||
<p class="mb-4"> | ||
Thanks for being an early Fugu user ❤️ | ||
Contact me if you have questions or need help: [email protected] or | ||
<a href="https://twitter.com/canolcer" targt="_blank">@canolcer</a>. | ||
</p> | ||
|
||
<%# only needed by Fugu Cloud (not needed if you're self-hosting) %> | ||
<%= render partial: "subscription", locals: { cancel_at: @cancel_at } if ENV["FUGU_CLOUD"] == "true" %> | ||
<%# only needed by Fugu Cloud (not needed if you're self-hosting) %> | ||
<%= render partial: "support" if ENV["FUGU_CLOUD"] == "true" %> | ||
<%= button_to "Log out", | ||
destroy_user_session_path, | ||
method: :delete, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters