From f29fa3271ad69c6976b9f77821ed815dd0acbdf3 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 3 Apr 2019 18:56:42 -0500 Subject: [PATCH 1/6] only show new _content_ link in header if a user can follow it --- app/controllers/content_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 9ac5107f..e4965e2c 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? From 05f8174463d5b8bf0d7a812f3e0628a6b31bff6c Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 3 Apr 2019 18:56:52 -0500 Subject: [PATCH 2/6] fix a couple tests --- .../subscriptions_controller_spec.rb | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) 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' } From d92e80cea3d7ab20dd7b1d652ee79e2517223b83 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 3 Apr 2019 19:06:11 -0500 Subject: [PATCH 3/6] let users know why they can't create additional pages --- app/views/content/list/_cards.html.erb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/views/content/list/_cards.html.erb b/app/views/content/list/_cards.html.erb index f2fc986f..835f18c5 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 %> subscription + is required to create additional + <%= content_type.name.downcase %> pages, but any page you've already created + is yours forever. +

+
+
+
<% end %> From 05487bf30a9bfccb13a5ac73bc70f190b8afdea0 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 3 Apr 2019 19:08:02 -0500 Subject: [PATCH 4/6] verbiage --- app/views/content/list/_cards.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/content/list/_cards.html.erb b/app/views/content/list/_cards.html.erb index 835f18c5..ff1d745a 100644 --- a/app/views/content/list/_cards.html.erb +++ b/app/views/content/list/_cards.html.erb @@ -92,15 +92,15 @@
-

+

<%= content_type.icon %>

An active - <%= link_to 'Notebook.ai Premium', subscription_path %> subscription + <%= 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 any page you've already created - is yours forever. + <%= content_type.name.downcase %> pages, but pages you've already created will always + be available here.

From 0f503b05e8acd514c49e575100310025e3c67088 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 3 Apr 2019 19:09:27 -0500 Subject: [PATCH 5/6] add back create new _content_ link in nav on content#show --- app/controllers/content_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index e4965e2c..797826c4 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -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 From 203ffb40d4adbc5693322747a25a132a219ec472 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 3 Apr 2019 19:26:15 -0500 Subject: [PATCH 6/6] fix billing plan changes for users with invalid usernames :| --- app/services/subscription_service.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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,