Skip to content

Commit

Permalink
Paywall2 (#147)
Browse files Browse the repository at this point in the history
* Upgrading Stripe to 10.11.0

* Upgrading a few gems

* Upgrading chart.js

* Making sure paid features are protected and directing user's to the plan page when their organization has no subscription.
  • Loading branch information
spaquet committed Mar 6, 2024
1 parent bd68dcb commit f4bfa36
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ gem 'meta-tags', '~> 2.20.0'
gem 'sendgrid-actionmailer', '~> 3.2.0'

# Monitoring - Honeybadger []
gem 'honeybadger', '~> 5.5.0'
gem 'honeybadger', '~> 5.6.0'

# Use Sass to process CSS
# gem "sassc-rails"
Expand Down Expand Up @@ -155,7 +155,7 @@ gem 'ruby-openai', '~> 6.3.0'
gem 'pg_search', '~> 2.3.6'

# Stripe (payment, subscription processing) [https://github.com/stripe/stripe-ruby]
gem 'stripe', '~> 10.10.0'
gem 'stripe', '~> 10.11.0'

# To enable retry in Faraday v2.0+
gem 'faraday-retry', '~> 2.2.0'
Expand Down
39 changes: 19 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ GEM
ffi-compiler (~> 1.0)
ast (2.4.2)
aws-eventstream (1.3.0)
aws-partitions (1.894.0)
aws-partitions (1.895.0)
aws-sdk-core (3.191.3)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
Expand Down Expand Up @@ -173,7 +173,7 @@ GEM
caxlsx_rails (0.6.3)
actionpack (>= 3.1)
caxlsx (>= 3.0)
chartkick (5.0.5)
chartkick (5.0.6)
chronic (0.10.2)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
Expand All @@ -191,8 +191,7 @@ GEM
domain_name (0.6.20240107)
down (5.4.1)
addressable (~> 2.8)
drb (2.2.0)
ruby2_keywords
drb (2.2.1)
erubi (1.12.0)
event_stream_parser (1.0.0)
faraday (2.9.0)
Expand All @@ -213,7 +212,7 @@ GEM
activesupport (>= 6.1)
hashie (5.0.0)
hiredis (0.6.3)
honeybadger (5.5.1)
honeybadger (5.6.0)
htmlentities (4.3.4)
http (5.2.0)
addressable (~> 2.8)
Expand All @@ -224,8 +223,9 @@ GEM
http-cookie (1.0.5)
domain_name (~> 0.5)
http-form_data (2.3.0)
i18n (1.14.1)
i18n (1.14.3)
concurrent-ruby (~> 1.0)
racc (~> 1.7)
image_processing (1.12.2)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
Expand All @@ -242,7 +242,7 @@ GEM
jsbundling-rails (1.3.0)
railties (>= 6.0.0)
json (2.7.1)
jwt (2.8.0)
jwt (2.8.1)
base64
language_server-protocol (3.17.0.3)
llhttp-ffi (0.5.0)
Expand All @@ -256,7 +256,7 @@ GEM
net-imap
net-pop
net-smtp
marcel (1.0.2)
marcel (1.0.4)
matrix (0.4.2)
merit (4.0.3)
ambry (~> 1.0.0)
Expand Down Expand Up @@ -327,15 +327,15 @@ GEM
omniauth (~> 2.0)
online_migrations (0.14.1)
activerecord (>= 6.1)
pagy (7.0.6)
pagy (7.0.9)
paper_trail (15.1.0)
activerecord (>= 6.1)
request_store (~> 1.4)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
pg (1.5.5)
pg (1.5.6)
pg_search (2.3.6)
activerecord (>= 5.2)
activesupport (>= 5.2)
Expand Down Expand Up @@ -393,7 +393,7 @@ GEM
psych (>= 4.0.0)
redis (5.1.0)
redis-client (>= 0.17.0)
redis-client (0.20.0)
redis-client (0.21.0)
connection_pool
regexp_parser (2.9.0)
reline (0.4.3)
Expand All @@ -404,7 +404,7 @@ GEM
nokogiri
rexml (3.2.6)
rolify (6.0.1)
rubocop (1.60.2)
rubocop (1.61.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand All @@ -415,21 +415,20 @@ GEM
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-rails (2.23.1)
rubocop-ast (1.31.1)
parser (>= 3.3.0.4)
rubocop-rails (2.24.0)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-openai (6.3.1)
event_stream_parser (>= 0.3.0, < 2.0.0)
faraday (>= 1)
faraday-multipart (>= 1)
ruby-progressbar (1.13.0)
ruby-vips (2.2.1)
ffi (~> 1.12)
ruby2_keywords (0.0.5)
ruby_http_client (3.5.5)
rubyzip (2.3.2)
safely_block (0.4.0)
Expand Down Expand Up @@ -478,7 +477,7 @@ GEM
stimulus-rails (1.3.3)
railties (>= 6.0.0)
stringio (3.1.0)
stripe (10.10.0)
stripe (10.11.0)
thor (1.3.1)
timeout (0.4.1)
turbo-rails (2.0.4)
Expand Down Expand Up @@ -551,7 +550,7 @@ DEPENDENCIES
faraday-retry (~> 2.2.0)
groupdate
hiredis (~> 0.6.3)
honeybadger (~> 5.5.0)
honeybadger (~> 5.6.0)
image_processing (~> 1.2)
invisible_captcha (~> 2.2.0)
jbuilder
Expand Down Expand Up @@ -586,7 +585,7 @@ DEPENDENCIES
simplecov
sprockets-rails
stimulus-rails (~> 1.3.3)
stripe (~> 10.10.0)
stripe (~> 10.11.0)
turbo-rails (~> 2.0.0)
tzinfo-data
validate_url
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/connectors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
class ConnectorsController < ApplicationController
before_action :authenticate_user!
before_action :redirect_if_unauthenticated
# before_action :authorize_connector_access, only: %i[index show create]

def index; end
end
10 changes: 10 additions & 0 deletions app/controllers/imports_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ImportsController < ApplicationController
before_action :authenticate_user!
before_action :redirect_if_unauthenticated
before_action :authorize_import_access, only: %i[index show create]

def index
@import_results = current_user.import_results.order(created_at: :desc).limit(5)
Expand All @@ -19,4 +20,13 @@ def create
ProcessExcelImportJob.perform_async(current_user.id)
redirect_to(imports_path, notice: 'File is being processed. Check back later for the results.')
end

private

def authorize_import_access
organization = current_user.organization
return if ImportPolicy.new(current_user, organization).allowed?

redirect_to(subscriptions_path, alert: 'You need an active subscription to access this feature.')
end
end
8 changes: 8 additions & 0 deletions app/controllers/ssos_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class SsosController < ApplicationController
before_action :authenticate_user!
before_action :redirect_if_unauthenticated
before_action :authorize_sso_access, only: %i[update show edit]
before_action :set_organization

layout 'settings'
Expand All @@ -26,4 +27,11 @@ def set_organization
@organization = Organization.find(params[:organization_id])
@organization.name = nil if @organization.name === '__default__'
end

def authorize_sso_access
organization = current_user.organization
return if SsoPolicy.new(current_user, organization).allowed?

redirect_to(subscriptions_path, alert: 'You need an active subscription to access this feature.')
end
end
16 changes: 16 additions & 0 deletions app/policies/import_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# app/policies/import_policy.rb

class ImportPolicy
attr_reader :user, :organization

def initialize(user, organization)
@user = user
@organization = organization
end

def allowed?
user.organization.active_subscription? && user.has_role?(:allowed_role, organization)
end
end
16 changes: 16 additions & 0 deletions app/policies/sso_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# app/policies/sso_policy.rb

class SsoPolicy
attr_reader :user, :organization

def initialize(user, organization)
@user = user
@organization = organization
end

def allowed?
user.organization.active_subscription? && user.has_role?(:allowed_role, organization)
end
end
33 changes: 33 additions & 0 deletions app/views/connectors/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
<!-- app/views/connectors/index.html.erb -->
<%# Adding a blur when the user's organization has no valid subscription %>
<% if !current_user.organization&.active_subscription? %>
<div class="overlay fixed inset-0 bg-black bg-opacity-50 z-40 flex items-center justify-center">
<div class="mx-auto p-4 text-center bg-white border border-gray-200 rounded-lg shadow sm:p-8 dark:bg-gray-800 dark:border-gray-700">
<h5 class="mb-2 text-3xl font-bold text-gray-900 dark:text-white">Unlock Insights</h5>
<p class="mb-5 text-base text-gray-500 sm:text-lg dark:text-gray-400">Choose your plan to connect ThePew to different connectors and gain actionable knowledge.</p>
<div class="items-center justify-center space-y-4 sm:flex sm:space-y-0 sm:space-x-4 rtl:space-x-reverse">
<%= link_to subscriptions_path, class: "w-full sm:w-auto bg-gray-800 hover:bg-gray-700 focus:ring-4 focus:outline-none focus:ring-gray-300 text-white rounded-lg inline-flex items-center justify-center px-4 py-2.5 dark:bg-gray-700 dark:hover:bg-gray-600 dark:focus:ring-gray-700" do %>
<svg data-slot="icon" class="me-3 w-7 h-7" aria-hidden="true" focusable="false" data-prefix="fab" data-icon="open lock" role="img" fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<path d="M18 1.5c2.9 0 5.25 2.35 5.25 5.25v3.75a.75.75 0 0 1-1.5 0V6.75a3.75 3.75 0 1 0-7.5 0v3a3 3 0 0 1 3 3v6.75a3 3 0 0 1-3 3H3.75a3 3 0 0 1-3-3v-6.75a3 3 0 0 1 3-3h9v-3c0-2.9 2.35-5.25 5.25-5.25Z"></path>
</svg>
<div class="text-left rtl:text-right">
<div class="mb-1 text-xs">Unlock Insights</div>
<div class="-mt-1 font-sans text-sm font-semibold">Select a Plan</div>
</div>
<% end %>
</div>
</div>
</div>
<% end %>
<%# The page content%>
<%= turbo_frame_tag "settings_main" do %>
<h1 class="inline-block mb-2 font-extrabold text-3xl tracking-tight text-slate-800 dark:text-white">
Connectors
Expand Down Expand Up @@ -104,3 +125,15 @@
</div>
</div>
<% end %>
<script>
// No need for DOMContentLoaded since this script can be at the bottom
document.body.classList.add('prevent-scroll'); // Optionally prevent scrolling when overlay is active
</script>
<style>
.blur {
filter: blur(8px);
}
.prevent-scroll {
overflow: hidden;
}
</style>
2 changes: 1 addition & 1 deletion config/credentials/development.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
KH3uL0Ep3+qQ47NXoxR/Jc23axwCiWe38lvX8T+mzPYnCSTlS0RlwpFKLEx9KeVSB7bSU42OAmxb77pJvhPSwZkzA5rAxyrlV4kqnEqj/oTdCg4cL7yVdqHCTrrUjbZqjiTEL7KfKtfmQ3+YOw0zOfLSq8wWjWJdPTL3w7VbdGwMoYGOC4W/4SWwctEojTpedEhV4kn6usoZZMSpqI/ravecLL5j8P5RTr5i/x3kStlDwHdVmT58ciy/zIWphBLd7nf+RoWYN/jmJ4aGXw5/eOSFlWjap/lV2DWUUxflsPR/YEn3F0fb6K18gawiNkSMIMYJLY1nsROFXrXGOCDOt1HZLEMSqjZbD9RcEn2Tt/NAwjDRmcwUGK4r2G2r9EmnjsZsdSieP4bi1UB/B1F7GYIHJTyUQLaAtw35BAMUZerqTfo5Oodi6dxTSHN1gWCveQk5GQ0rqzl4ds5hvIBW2tgNCjBi66tfavY8KnV5ooALzdD3dYt6pn1d9fg6U5w1RssNLnhPiN+bZ7/HkfbiCWAI+cHedZ+ZfhzIokYkY0D7lCzODm2EWwdo4x+xKc1jlAaMFVvJXP5gbv5oU4z4T997bnN1FI+NsUI0uXxxVL0j1e7Z2yWtHPMGNnHcQs7LhxmNktNL9Y3c8bxtPPDk0Vygww7HTbFaP9Ju/S5L9ErQx5QCLrqmPSgFIgc8ga6enhgr7ItT2xVoep/lpjt9PDncUvv5XOMwudIxEOZtX6phqdJir2FT2owQA2nPf0m7M15e+kLtFoRTUhD1UNU3VMTYPSoGNrndODTXHvJdoFS1Sd2hBeEOaDompykNfj8d5fnfp+W2RxulJNrSD00xTQj6HUTDiMITc5BcXxBN03w8EA9skjZomeKM6uegK8NZOz2QBA==--+zjZQWcY4JVV19cz--lUJX8V1+jAdy419R8TWweA==
yrunTEpFCu82S2dW2d8PepmD+A18HXeeymeXwN80zBAtruXCyUGCAI3aMEAZRnneUzY2yCN/t5ifntHN06WWq2kUCzM0yHoLN/V/mWBNPpxAfh17dgiRrhLdKhJMNpVW637oPlRzCFQt+7t6io5x5zD7jKdUYAzn182/gYoucYBaGfGDfYj+wOt92D8cZq6HWP7DNaqaSzTity8G56CDJKcPCxv2dW4pebBui7QmtqIcYGp6qZdAp8r1fa8sPu/8ltCbKsqOI+sSv4YAad57TR088F+SO0C/A8Rc3Fj0FpTQh1EckMc92LPulD+94oArzRepblQli1KXiZbG6Io8ODAkKsNCmYSIT4R60qaMfcTitmAcf3ZLYezlbzCVQwP3hVJce/0/RxPynQm/Xfu7yi0Yv9No4yMX4aCy1BmmRaj7rwpZ+o3PP32PJxfSUOZe0sqcRfJFBvZlLDh8zrAnDTtTHu9dD1c1lr7v1y4JKh5adcXRKm/tsQHvMViKEzyLCjAqsiF+371KSBjny7O7YxIjzG7iuAyV/9+UCQuHJCBVMwqfATa0Yr5ZkjoVVNGH/foUo1pkaWMq3kl//VHH8BgQgkVRaTnAIAXKnMLnbr7APBKWCstOh3XMoDrrX1zaQkYUv5b8/44J76OFE5HmXed7xW2BZy4Si39HHSBEdOn4TQhMUdJ5S2fhH5xAuv85jpFTXldQG4d2Q4tvLoh7T5Ft/nBqIAxaKL0ZLvaDjRAsB2PnWeDIBqMMWbhlWlJ14ZYmk47zRD9R9rtAKAzUchFdCN1gnFhh1l+yXHX91bmsPQg5jzaNjN3nGq9hrJfXvB1dqs6rblE0hMqnXh56DJ9eSPzsosCZAbpBJgBX/TnjhpT37/n8SnnB0+QfrFKUR0UqFQ==--up3di3KuVXXLkU0n--jvrAxVyumqvlr+lX4GVozw==
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@rails/request.js": "0.0.9",
"@tailwindcss/typography": "0.5.10",
"autoprefixer": "10.4.17",
"chart.js": "4.4.1",
"chart.js": "4.4.2",
"chartjs-plugin-datalabels": "2.2.0",
"chartkick": "5.0.1",
"esbuild": "0.20.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,10 @@ chart.js@4:
dependencies:
"@kurkle/color" "^0.3.0"

chart.js@4.4.1:
version "4.4.1"
resolved "https://registry.yarnpkg.com/chart.js/-/chart.js-4.4.1.tgz#ac5dc0e69a7758909158a96fe80ce43b3bb96a9f"
integrity sha512-C74QN1bxwV1v2PEujhmKjOZ7iUM4w6BWs23Md/6aOZZSlwMzeCIDGuZay++rBgChYru7/+QFeoQW0fQoP534Dg==
chart.js@4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/chart.js/-/chart.js-4.4.2.tgz#95962fa6430828ed325a480cc2d5f2b4e385ac31"
integrity sha512-6GD7iKwFpP5kbSD4MeRRRlTnQvxfQREy36uEtm1hzHzcOqwWx0YEHuspuoNlslu+nciLIB7fjjsHkUv/FzFcOg==
dependencies:
"@kurkle/color" "^0.3.0"

Expand Down

0 comments on commit f4bfa36

Please sign in to comment.