Skip to content

Commit

Permalink
Merge branch 'release/0.17.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvoon committed Jul 16, 2019
2 parents 4f30c12 + 78f0f04 commit 544c41e
Show file tree
Hide file tree
Showing 246 changed files with 2,968 additions and 1,154 deletions.
434 changes: 269 additions & 165 deletions .rubocop.yml

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# Change Log
All notable changes to this project will be documented in this file.

## 0.17.0 - 2019-07-16
### Added
- Timber logging for generated apps
- rubocop-performance and rubocop-rails plugins
- Support for AppSignal
- Generator for React applications

### Changed
- Switch from Minitest to RSpec as the testing library for generated apps
- Update rubocop.yml file
- Lock shopify_api version to avoid breaking changes
- Upgrade Rails to 5.2.2 to avoid gem vulnerabilities
- Run rubocop auto-corrections
- Use with_indifferent_access when reading Flow properties
- Renaming of methods and general refactoring

## 0.16.1 - 2019-01-01
### Added
- Support for Shopify Flow triggers and actions
Expand Down
6 changes: 1 addition & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('lib/**/*.rb')
end

APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
load 'rails/tasks/engine.rake'


load 'rails/tasks/statistics.rake'



Bundler::GemHelper.install_tasks

require 'rake/testtask'
Expand All @@ -33,5 +30,4 @@ Rake::TestTask.new(:test) do |t|
t.verbose = false
end


task default: :test
9 changes: 9 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ 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.16.1 to 0.17.1
Upgrade your app to Rails version 5.2.2.

Set your `shopify_api` version to 6.0:

```ruby
gem 'shopify_api', '~> 6.0'
```

## Upgrading from 0.16.0 to 0.16.1
Ensure new Shopify Flow database migrations are brought across and run:

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.16.1
0.17.0
9 changes: 5 additions & 4 deletions app/clients/disco_app/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@

class DiscoApp::ApiClient

SUBSCRIPTION_ENDPOINT = 'app_subscriptions.json'
SUBSCRIPTION_ENDPOINT = 'app_subscriptions.json'.freeze

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

def create_app_subscription
return unless @url.present?
return if @url.blank?

url = @url + SUBSCRIPTION_ENDPOINT
begin
response = RestClient::Request.execute(
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.new(e.message)
raise DiscoApiError, e.message
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/clients/disco_app/graphql_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def create_flow_trigger(title, resource_name, resource_url, properties)

# The double .to_json.to_json below looks odd but is required to properly escape the JSON hash
# when inserting it into the GraphQL mutation call.
response = execute(%Q(
response = execute(%(
mutation {
flowTriggerReceive(body: #{body.to_json.to_json}) {
userErrors {
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/disco_app/admin/app_settings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class DiscoApp::Admin::AppSettingsController < DiscoApp::Admin::ApplicationController

include DiscoApp::Admin::Concerns::AppSettingsController

end
1 change: 1 addition & 0 deletions app/controllers/disco_app/admin/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class DiscoApp::Admin::ApplicationController < ActionController::Base

include DiscoApp::Admin::Concerns::AuthenticatedController

private
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module DiscoApp::Admin::Concerns::AppSettingsController

extend ActiveSupport::Concern

def edit
Expand All @@ -7,7 +8,7 @@ def edit

def update
@app_settings = DiscoApp::AppSettings.instance
if @app_settings.update_attributes(app_settings_params)
if @app_settings.update(app_settings_params)
flash[:success] = 'Settings updated.'
redirect_to edit_admin_app_settings_path
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
module DiscoApp::Admin::Concerns::AuthenticatedController

extend ActiveSupport::Concern

included do

protect_from_forgery with: :exception
before_action :authenticate_administrator
layout 'admin'

end

private

def authenticate_administrator
authenticate_or_request_with_http_basic do |username, password|
(not username.blank?) && (not password.blank?) && username == ENV['ADMIN_APP_USERNAME'] && password == ENV['ADMIN_APP_PASSWORD']
username.present? &&
password.present? &&
username == ENV['ADMIN_APP_USERNAME'] &&
password == ENV['ADMIN_APP_PASSWORD']
end
end

Expand Down
5 changes: 3 additions & 2 deletions app/controllers/disco_app/admin/concerns/plans_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module DiscoApp::Admin::Concerns::PlansController

extend ActiveSupport::Concern

included do
Expand Down Expand Up @@ -26,7 +27,7 @@ def edit
end

def update
if @plan.update_attributes(plan_params)
if @plan.update(plan_params)
redirect_to edit_admin_plan_path(@plan)
else
render 'edit'
Expand All @@ -47,7 +48,7 @@ def find_plan
def plan_params
params.require(:plan).permit(
:name, :status, :plan_type, :trial_period_days, :amount,
:plan_codes_attributes => [:id, :_destroy, :code, :trial_period_days, :amount]
plan_codes_attributes: %i[id _destroy code trial_period_days amount]
)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module DiscoApp::Admin::Concerns::ShopsController

extend ActiveSupport::Concern

def index
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module DiscoApp::Admin::Concerns::SourcesController

extend ActiveSupport::Concern

included do
Expand Down Expand Up @@ -26,7 +27,7 @@ def edit
end

def update
if @source.update_attributes(source_params)
if @source.update(source_params)
redirect_to edit_admin_plan_path(@source)
else
render 'edit'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module DiscoApp::Admin::Concerns::SubscriptionsController

extend ActiveSupport::Concern

included do
Expand All @@ -9,7 +10,7 @@ def edit
end

def update
if @subscription.update_attributes(subscription_params)
if @subscription.update(subscription_params)
redirect_to edit_admin_shop_subscription_path(@subscription.shop, @subscription)
else
render 'edit'
Expand All @@ -19,7 +20,7 @@ def update
private

def find_subscription
@subscription = DiscoApp::Subscription.find_by_id(params[:id])
@subscription = DiscoApp::Subscription.find_by(id: params[:id])
end

def subscription_params
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/disco_app/admin/plans_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class DiscoApp::Admin::PlansController < DiscoApp::Admin::ApplicationController

include DiscoApp::Admin::Concerns::PlansController

end
2 changes: 2 additions & 0 deletions app/controllers/disco_app/admin/resources/shops_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class DiscoApp::Admin::Resources::ShopsController < JSONAPI::ResourceController

include DiscoApp::Admin::Concerns::AuthenticatedController

end
2 changes: 2 additions & 0 deletions app/controllers/disco_app/admin/shops_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class DiscoApp::Admin::ShopsController < DiscoApp::Admin::ApplicationController

include DiscoApp::Admin::Concerns::ShopsController

end
2 changes: 2 additions & 0 deletions app/controllers/disco_app/admin/sources_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class DiscoApp::Admin::SourcesController < DiscoApp::Admin::ApplicationController

include DiscoApp::Admin::Concerns::SourcesController

end
2 changes: 2 additions & 0 deletions app/controllers/disco_app/admin/subscriptions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class DiscoApp::Admin::SubscriptionsController < DiscoApp::Admin::ApplicationController

include DiscoApp::Admin::Concerns::SubscriptionsController

end
13 changes: 6 additions & 7 deletions app/controllers/disco_app/charges_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class DiscoApp::ChargesController < ApplicationController

include DiscoApp::Concerns::AuthenticatedController

skip_before_action :check_active_charge
Expand All @@ -13,7 +14,7 @@ def new
# subscription. If successful, redirect to the (external) charge confirmation
# URL. If it fails, redirect back to the new charge page.
def create
if(charge = DiscoApp::ChargesService.create(@shop, @subscription)).nil?
if (charge = DiscoApp::ChargesService.create(@shop, @subscription)).nil?
redirect_to action: :new
else
redirect_to charge.confirmation_url
Expand All @@ -25,8 +26,8 @@ def create
# charge wasn't accepted, the flow will start again.
def activate
# First attempt to find a matching charge.
if(charge = @subscription.charges.find_by(id: params[:id], shopify_id: params[:charge_id])).nil?
redirect_to action: :new and return
if (charge = @subscription.charges.find_by(id: params[:id], shopify_id: params[:charge_id])).nil?
redirect_to(action: :new) && return
end
if DiscoApp::ChargesService.activate(@shop, charge)
redirect_to main_app.root_url
Expand All @@ -38,10 +39,8 @@ def activate
private

def find_subscription
@subscription = @shop.subscriptions.find_by_id!(params[:subscription_id])
unless @subscription.requires_active_charge? and not @subscription.active_charge?
redirect_to main_app.root_url
end
@subscription = @shop.subscriptions.find_by!(id: params[:subscription_id])
redirect_to main_app.root_url unless @subscription.requires_active_charge? && !@subscription.active_charge?
end

end
12 changes: 6 additions & 6 deletions app/controllers/disco_app/concerns/app_proxy_controller.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
module DiscoApp::Concerns::AppProxyController

extend ActiveSupport::Concern

included do
before_action :verify_proxy_signature
before_action :shopify_shop
after_action :add_liquid_header

rescue_from ActiveRecord::RecordNotFound do |exception|
rescue_from ActiveRecord::RecordNotFound do |_exception|
render_error 404
end
end

private

def verify_proxy_signature
unless proxy_signature_is_valid?
head :unauthorized
end
head :unauthorized unless proxy_signature_is_valid?
end

def proxy_signature_is_valid?
return true if (Rails.env.development? || Rails.env.test?) and DiscoApp.configuration.skip_proxy_verification?
return true if (Rails.env.development? || Rails.env.test?) && DiscoApp.configuration.skip_proxy_verification?

DiscoApp::ProxyService.proxy_signature_is_valid?(request.query_string, ShopifyApp.configuration.secret)
end

def shopify_shop
@shop = DiscoApp::Shop.find_by_shopify_domain!(params[:shop])
@shop = DiscoApp::Shop.find_by!(shopify_domain: params[:shop])
end

def add_liquid_header
Expand Down
Loading

0 comments on commit 544c41e

Please sign in to comment.