Skip to content

Commit

Permalink
Merge branch 'release/0.18.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pillep committed Apr 15, 2020
2 parents 931ddbf + f38e6c7 commit 0e0b967
Show file tree
Hide file tree
Showing 53 changed files with 7,882 additions and 275 deletions.
206 changes: 115 additions & 91 deletions .rubocop.yml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 2.6.5
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Change Log
All notable changes to this project will be documented in this file.

## 0.18.0 - 2020-04-15
### Changed
- Upgraded to Rails 6
- Upgraded to Ruby 2.6.5
- Upgraded to shopify_api 9
- Upgraded to shopify_app 12
- Upgraded to sidekiq 6
- Replaced .ruby-version with .tool-versions
- Updated Timber initialiser
- Updated README

## 0.17.0 - 2019-07-16
### Added
- Timber logging for generated apps
Expand Down
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ gem 'timecop', '~> 0.8.0', group: [:development, :test]

# To continue using assigns and assert_template in Rails 5
gem 'rails-controller-testing', group: [:development, :test]

gem 'rb-readline', group: :development

gem 'webpacker'
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@ detailed below.

### 1. Setting up
First make sure you've got all of the tools you need for Shopify and Rails
development. You should read through the [Getting Started] board in Guru and
development. You should read through the [Getting Started] board in Notion and
make sure you've followed all setup instructions there, specifically the cards
on [Development Setup] and [Development Configuration]. The key things to note
are:

- You should have set up a Shopify Partner account to allow you to create
development stores and applications;
- [rbenv][] is recommended for Ruby version management;
- [asdf][] is recommended for Ruby version management;
- You should have the latest version of Ruby 2.5 installed locally, along with
the `rails` and `bundler` gems (make sure you have the version of Rails you'd
like to use installed - use `gem install rails -v VERSION` for this);
- You should have [ngrok] installed for HTTP tunnelling;
- You should have followed the instructions in the Development Configuration Guru
- You should have followed the instructions in the Development Configuration Notion
card for configuring Bundler with credentials to access Disco's private Gemfury server.
- You should have followed the instructions in the Development Configuration
Guru card to have generated a personal access token on Github and added it to
Notion page to have generated a personal access token on Github and added it to
your development configuration.

[Getting Started]: https://app.getguru.com/#/boards/30ff224a-3c2c-4d46-a6f0-f4dc3ced8fe1
[Development Setup]: https://app.getguru.com/#/facts/b3677c35-6e1f-4b7b-954b-4f9f990adeff
[Development Configuration]: https://app.getguru.com/#/facts/63da8b91-ec7f-4b75-ba19-8aa3e30ce777
[rbenv]: https://github.com/sstephenson/rbenv
[Development Setup]: https://www.notion.so/discolabs/Development-Setup-97199ecca84343c18f29efec6fd841ab
[Development Configuration]: https://www.notion.so/discolabs/Development-Configuration-9ac4e3d77da7454480d750bde3323a0a
[asdf]: https://github.com/asdf-vm/asdf
[ngrok]: https://ngrok.com

### 2. Creating the Rails app
Expand Down Expand Up @@ -101,7 +100,7 @@ With the above set up, you can now run the following from the command line to
create a new app:

```
bundle exec rake generate:partner_app
rails generate:partner_app
```

The `.env.local` will be automatically populated with values for
Expand Down Expand Up @@ -148,7 +147,7 @@ DiscoApp::Plan.find_or_create_by(
)
```

Run `bundle exec rake db:seed` and you're done!
Run `rails db:seed` and you're done!


### 4. Putting it all together
Expand Down Expand Up @@ -266,6 +265,7 @@ SETUP_PROC = lambda do |env|
env['omniauth.strategy'].options[:per_user_permissions] = true
params = Rack::Utils.parse_query(env['QUERY_STRING'])
env['omniauth.strategy'].options[:client_options][:site] = "https://#{params['shop']}"
env['omniauth.strategy'].options[:old_client_secret] = ShopifyApp.configuration.old_secret
end
Rails.application.config.middleware.use OmniAuth::Builder do
Expand Down Expand Up @@ -324,7 +324,7 @@ owners, you should ensure it creates a Plan with an `amount` value of zero, and
that all stores are subscribed to that plan during `DiscoApp::AppInstalledJob`.

The default set of plans for your app should be placed into the `db/seeds.rb`
file. Make sure you run `bundle exec rake db:seed` after resetting your database
file. Make sure you run `rails db:seed` after resetting your database
to ensure the plans are correctly set up.

Whenever a store's subscription level is changed,
Expand Down Expand Up @@ -967,9 +967,9 @@ steps you should take:
release of the gem (check the [release list][] to find the latest available
version).
- Run `bundle update`. You may have to resolve some gem dependencies.
- Run `bundle exec rake disco_app:install:migrations` to copy over any new
- Run `rails disco_app:install:migrations` to copy over any new
migrations from the gem into your application, ready to be run with a
`bundle exec rake db:migrate`.
`rails db:migrate`.
- Carefully read through `CHANGELOG.md`, `UPGRADING.md`, and the commit history
for `disco_app` between the previous version of the gem you were using and the
new one. You may have to make some changes to your application code to adapt
Expand Down Expand Up @@ -1045,7 +1045,7 @@ to update the relevant section of this README as well.
## Releasing
To create a new release of the application:

1. In general, follow the instructions for [releasing an app to production with git flow](https://app.getguru.com/card/7idyndGi/Releasing-an-app-to-production-with-git-flow).
1. In general, follow the instructions for [releasing an app to production with git flow](https://www.notion.so/discolabs/Releasing-an-app-to-production-with-git-flow-293c447447f74842968b8fa3b284e9a0).
2. During **Step 3** of the release process, in addition to bumping the version number in the `VERSION` file, you should:
1. Also update the version number in `version.rb` to match `VERSION`;
2. Ensure the `CHANGELOG` is up to date by reviewing all commits since the last release;
Expand Down
16 changes: 16 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ This file contains more detailed instructions on what's required when updating
an application between one release version of the gem to the next. It's intended
as more in-depth accompaniment to the notes in `CHANGELOG.md` for each version.

## Upgrading from 0.17.0 to 0.18.0
Upgrade to Rails 6 ([guide](https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-5-2-to-rails-6-0)).

Upgrade to Ruby 2.6.5.

Upgrade the following gems:
```
gem 'shopify_api', '~> 9.0'
gem 'shopify_app', '~> 12.0.7'
gem 'sidekiq', '~> 6.0'
```

Additionally, you might have to upgrade `react-rails`, `uglifier`, `vcr` and `webmock` gems.

Add `SHOPIFY_APP_API_VERSION` env variable.

## Upgrading from 0.16.1 to 0.17.1
Upgrade your app to Rails version 5.2.2.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.17.0
0.18.0
45 changes: 25 additions & 20 deletions app/clients/disco_app/api_client.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
require 'rest-client'

class DiscoApp::ApiClient
module DiscoApp

SUBSCRIPTION_ENDPOINT = 'app_subscriptions.json'.freeze
class DiscoApiError < StandardError; end

def initialize(shop, url)
@shop = shop
@url = url
end
class ApiClient

SUBSCRIPTION_ENDPOINT = 'app_subscriptions.json'.freeze

def create_app_subscription
return if @url.blank?

url = @url + SUBSCRIPTION_ENDPOINT
begin
RestClient::Request.execute(
method: :post,
headers: { content_type: :json },
url: url,
payload: { shop: @shop, subscription: @shop.current_subscription }.to_json
)
rescue RestClient::BadRequest, RestClient::ResourceNotFound => e
raise DiscoApiError, e.message
def initialize(shop, url)
@shop = shop
@url = url
end
end

def create_app_subscription
return if @url.blank?

url = @url + SUBSCRIPTION_ENDPOINT
begin
RestClient::Request.execute(
method: :post,
headers: { content_type: :json },
url: url,
payload: { shop: @shop, subscription: @shop.current_subscription }.to_json
)
rescue RestClient::BadRequest, RestClient::ResourceNotFound => e
raise DiscoApiError, e.message
end
end

end
end
2 changes: 0 additions & 2 deletions app/clients/disco_app/disco_api_error.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module DiscoApp::Concerns::AuthenticatedController
included do
before_action :auto_login
before_action :check_shop_whitelist
before_action :login_again_if_different_shop
before_action :login_again_if_different_user_or_shop
before_action :shopify_shop
before_action :check_installed
before_action :check_current_subscription
Expand All @@ -29,7 +29,7 @@ def auto_login

def shopify_shop
if shop_session
@shop = DiscoApp::Shop.find_by!(shopify_domain: @shop_session.url)
@shop = DiscoApp::Shop.find_by!(shopify_domain: @shop_session.domain)
else
redirect_to_login
end
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class SessionsController < ActionController::Base

include ShopifyApp::SessionsConcern
class SessionsController < ShopifyApp::SessionsController

def referral
cookies[DiscoApp::SOURCE_COOKIE_KEY] = params[:source] if params[:source].present?
Expand All @@ -22,7 +20,7 @@ def authenticate
if Rails.env.development? && DiscoApp.configuration.skip_oauth?
shop = DiscoApp::Shop.find_by!(shopify_domain: sanitized_shop_name)

sess = ShopifyAPI::Session.new(shop.shopify_domain, shop.shopify_token)
sess = ShopifyAPI::Session.new(domain: shop.shopify_domain, token: shop.shopify_token, api_version: shop.api_version)
session[:shopify] = ShopifyApp::SessionRepository.store(sess)
session[:shopify_domain] = sanitized_shop_name

Expand Down
4 changes: 1 addition & 3 deletions app/models/disco_app/concerns/renders_assets.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
require 'render_anywhere'
require 'uglifier'

module DiscoApp::Concerns::RendersAssets

extend ActiveSupport::Concern

included do
include RenderAnywhere
after_commit :queue_render_asset_group_job
end

Expand Down Expand Up @@ -138,7 +136,7 @@ def should_be_minified?(asset, options)
end

def render_asset_renderer
@render_asset_renderer ||= self.class.const_get('RenderingController').new
@render_asset_renderer ||= self.class.const_get('ApplicationController').new
end

# Render any script tags defined by the :script_tags options that we have
Expand Down
9 changes: 7 additions & 2 deletions app/models/disco_app/concerns/shop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module DiscoApp::Concerns::Shop
extend ActiveSupport::Concern

included do
include ShopifyApp::Shop
include ShopifyApp::SessionStorage
include ActionView::Helpers::DateHelper

# Define relationships to plans and subscriptions.
Expand Down Expand Up @@ -75,7 +75,7 @@ def protocol

# Return the absolute URL to the shop's admin.
def admin_url
"https://#{shopify_domain}/admin"
"https://#{shopify_domain}/admin/api/#{api_version}"
end

def installed_duration
Expand Down Expand Up @@ -107,6 +107,11 @@ def disco_api_client
def data
read_attribute(:data).with_indifferent_access
end

def api_version
ShopifyApp.configuration.api_version
end

end

end
4 changes: 2 additions & 2 deletions app/models/disco_app/session_storage.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module DiscoApp
class SessionStorage

def self.store(session)
def self.store(session, *args)
shop = Shop.find_or_initialize_by(shopify_domain: session.url)
shop.shopify_token = session.token
shop.save!
Expand All @@ -12,7 +12,7 @@ def self.retrieve(id)
return unless id

shop = Shop.find(id)
ShopifyAPI::Session.new(shop.shopify_domain, shop.shopify_token)
ShopifyAPI::Session.new(domain: shop.shopify_domain, token: shop.shopify_token, api_version: shop.api_version)
rescue ActiveRecord::RecordNotFound
nil
end
Expand Down
3 changes: 1 addition & 2 deletions app/views/layouts/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<head>
<title><%= yield(:title) %></title>
<%= stylesheet_link_tag 'disco_app/admin', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= csrf_meta_tags %>
</head>
<body class="next-ui">
Expand Down
3 changes: 1 addition & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title><%= yield(:title) %></title>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>

<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= csrf_meta_tags %>

<%= yield :extra_head %>
Expand All @@ -13,6 +13,5 @@

<%= yield %>

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
</body>
</html>
6 changes: 2 additions & 4 deletions app/views/layouts/embedded_app.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
// Initialise the Shopify App.
ShopifyApp.init({
"apiKey": "<%= ShopifyApp.configuration.api_key %>",
"shopOrigin": "<%= "https://#{ @shop_session.url }" if @shop_session %>",
"shopOrigin": "<%= "https://#{ @shop_session.domain }" if @shop_session %>",
"debug": <%= Rails.env.development? ? 'true' : 'false' %>
});
</script>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>

<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload', 'data-turbolinks-eval': false %>
<%= csrf_meta_tags %>

<%= yield :extra_head %>
Expand Down Expand Up @@ -43,8 +43,6 @@
</script>
<% end %>

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true, 'data-turbolinks-eval' => false %>

<%= render 'disco_app/shared/icons' %>
</body>
</html>
5 changes: 2 additions & 3 deletions app/views/layouts/embedded_app_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
// Initialise the Shopify App.
ShopifyApp.init({
"apiKey": "<%= ShopifyApp.configuration.api_key %>",
"shopOrigin": "<%= "https://#{ @shop_session.url }" if @shop_session %>",
"shopOrigin": "<%= "https://#{ @shop_session.domain }" if @shop_session %>",
"debug": <%= Rails.env.development? ? 'true' : 'false' %>,
"forceRedirect": false
});
</script>

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>

<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= csrf_meta_tags %>

<%= yield :extra_head %>
Expand Down
6 changes: 2 additions & 4 deletions app/views/shopify_app/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<head>
<title>Install <%= DiscoApp.configuration.app_name %></title>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= csrf_meta_tags %>

<%= yield :extra_head %>
Expand Down Expand Up @@ -36,7 +36,5 @@
</section>
</div>
<% end %>

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
</body>
</html>
Loading

0 comments on commit 0e0b967

Please sign in to comment.