diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 9ac5107f..797826c4 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -523,7 +523,7 @@ class ContentController < ApplicationController @navbar_actions << { label: "New #{content_type.name.downcase}", href: main_app.new_polymorphic_path(content_type) - } + } if current_user.can_create?(content_type) discussions_link = ForumsLinkbuilderService.worldbuilding_url(content_type) if discussions_link.present? @@ -551,11 +551,11 @@ class ContentController < ApplicationController href: main_app.polymorphic_path(content_type) } end - # - # @navbar_actions << { - # label: "New #{content_type.name.downcase}", - # href: main_app.new_polymorphic_path(content_type) - # } + + @navbar_actions << { + label: "New #{content_type.name.downcase}", + href: main_app.new_polymorphic_path(content_type) + } end end diff --git a/app/services/subscription_service.rb b/app/services/subscription_service.rb index 75282b56..de365cac 100644 --- a/app/services/subscription_service.rb +++ b/app/services/subscription_service.rb @@ -13,7 +13,9 @@ class SubscriptionService < Service # Add any one-time referral bonuses add_any_referral_bonuses(user, plan_id) - user.update(selected_billing_plan_id: related_plan.id) + # We intentionally skip callbacks on this to ensure the billing plan changes even on invalid users + user.update_column(:selected_billing_plan_id, related_plan.id) + user.subscriptions.create( billing_plan: related_plan, start_date: DateTime.now, diff --git a/app/views/content/list/_cards.html.erb b/app/views/content/list/_cards.html.erb index f2fc986f..ff1d745a 100644 --- a/app/views/content/list/_cards.html.erb +++ b/app/views/content/list/_cards.html.erb @@ -88,5 +88,22 @@ <% end %> + <% else %> +
+
+
+

+ <%= content_type.icon %> +

+

+ An active + <%= link_to 'Notebook.ai Premium', subscription_path, class: 'blue-text text-darken-2' %> subscription + is required to create additional + <%= content_type.name.downcase %> pages, but pages you've already created will always + be available here. +

+
+
+
<% end %> diff --git a/spec/controllers/subscriptions_controller_spec.rb b/spec/controllers/subscriptions_controller_spec.rb index de9a7476..cbc7f59f 100644 --- a/spec/controllers/subscriptions_controller_spec.rb +++ b/spec/controllers/subscriptions_controller_spec.rb @@ -48,6 +48,36 @@ RSpec.describe SubscriptionsController, type: :controller do @user.update(stripe_customer_id: 'stripe-id') sign_in @user + @free_plan = BillingPlan.create( + name: 'Starter', + stripe_plan_id: 'starter', + monthly_cents: 0, # $0.00/mo + available: true, + + # Content creation and other permissions: + universe_limit: 5, + allows_core_content: true, + allows_extended_content: false, + allows_collective_content: false, + allows_collaboration: false, + bonus_bandwidth_kb: 123155 + ) + + @beta_plan = BillingPlan.create( + name: 'Early Adopters', + stripe_plan_id: 'early-adopters', + monthly_cents: 0, # $0.00/mo + available: true, + + # Content creation and other permissions: + universe_limit: 5, + allows_core_content: true, + allows_extended_content: false, + allows_collective_content: false, + allows_collaboration: false, + bonus_bandwidth_kb: 123155 + ) + @premium_plan = BillingPlan.create( name: 'Premium', stripe_plan_id: 'premium', @@ -73,21 +103,6 @@ RSpec.describe SubscriptionsController, type: :controller do allows_collaboration: true, bonus_bandwidth_kb: 123155 ) - - @free_plan = BillingPlan.create( - name: 'Starter', - stripe_plan_id: 'starter', - monthly_cents: 0, # $0.00/mo - available: true, - - # Content creation and other permissions: - universe_limit: 5, - allows_core_content: true, - allows_extended_content: false, - allows_collective_content: false, - allows_collaboration: false, - bonus_bandwidth_kb: 123155 - ) end describe "User with no plan (fallback to Starter) tries to upgrade" do @@ -101,7 +116,6 @@ RSpec.describe SubscriptionsController, type: :controller do describe "User on Starter" do before do # Create a Starter subscription for the user - @user.active_subscriptions.create(billing_plan: @free_plan, start_date: Time.now - 5.days, end_date: Time.now + 5.days) @user.update(selected_billing_plan_id: @free_plan.id) end @@ -169,12 +183,10 @@ RSpec.describe SubscriptionsController, type: :controller do describe "User on Premium" do before do # Create a premium subscription for the user - @user.active_subscriptions.create(billing_plan: @premium_plan, start_date: Time.now - 5.days, end_date: Time.now + 5.days) - expect(@user.active_subscriptions.map(&:billing_plan_id)).to eq([@premium_plan.id]) + @user.update(selected_billing_plan_id: BillingPlan.find_by(stripe_plan_id: 'premium').id) end it "allows downgrading to Starter" do - # Downgrade to Starter post :change, params: { stripe_plan_id: 'starter' }