-
Notifications
You must be signed in to change notification settings - Fork 698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GDPR and Uninstall Jobs to Generator #1597
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
af0b2a9
add uninstall job to generator
klenotiw c772229
uninstalled webhook added to config
klenotiw 04a9be8
update uninstalled webhook and add gdpr jobs
klenotiw aa750d6
docs about gdpr webhooks
klenotiw 0da864d
add tests
klenotiw 62fb6c3
changelog
klenotiw 2458306
raise error on shop not being found
klenotiw f8196b5
add gdpr webhook registrations
klenotiw 683b9f4
use record not found error
klenotiw 1a293c3
fix gdpr names
klenotiw 67de851
fix tests
klenotiw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
lib/generators/shopify_app/add_app_uninstalled_job/add_app_uninstalled_job_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails/generators/base" | ||
|
||
module ShopifyApp | ||
module Generators | ||
class AddAppUninstalledJobGenerator < Rails::Generators::Base | ||
source_root File.expand_path("../templates", __FILE__) | ||
|
||
def create_job | ||
template("app_uninstalled_job.rb", "app/jobs/app_uninstalled_job.rb") | ||
end | ||
end | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
lib/generators/shopify_app/add_app_uninstalled_job/templates/app_uninstalled_job.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class AppUninstalledJob < ActiveJob::Base | ||
extend ShopifyAPI::Webhooks::Handler | ||
|
||
class << self | ||
def handle(topic:, shop:, body:) | ||
perform_later(topic: topic, shop_domain: shop, webhook: body) | ||
end | ||
end | ||
|
||
def perform(topic:, shop_domain:, webhook:) | ||
shop = Shop.find_by(shopify_domain: shop_domain) | ||
|
||
if shop.nil? | ||
logger.error("#{self.class} failed: cannot find shop with domain '#{shop_domain}'") | ||
|
||
raise ActiveRecord::RecordNotFound, "Shop Not Found" | ||
end | ||
|
||
logger.info("#{self.class} started for shop '#{shop_domain}'") | ||
shop.destroy | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
lib/generators/shopify_app/add_gdpr_jobs/add_gdpr_jobs_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails/generators/base" | ||
|
||
module ShopifyApp | ||
module Generators | ||
class AddGdprJobsGenerator < Rails::Generators::Base | ||
source_root File.expand_path("../templates", __FILE__) | ||
|
||
def add_customer_data_request_job | ||
template("customers_data_request_job.rb", "app/jobs/customers_data_request_job.rb") | ||
end | ||
|
||
def add_shop_redact_job | ||
template("shop_redact_job.rb", "app/jobs/shop_redact_job.rb") | ||
end | ||
|
||
def add_customer_redact_job | ||
template("customers_redact_job.rb", "app/jobs/customers_redact_job.rb") | ||
end | ||
end | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
lib/generators/shopify_app/add_gdpr_jobs/templates/customers_data_request_job.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class CustomersDataRequestJob < ActiveJob::Base | ||
extend ShopifyAPI::Webhooks::Handler | ||
|
||
class << self | ||
def handle(topic:, shop:, body:) | ||
perform_later(topic: topic, shop_domain: shop, webhook: body) | ||
end | ||
end | ||
|
||
def perform(topic:, shop_domain:, webhook:) | ||
shop = Shop.find_by(shopify_domain: shop_domain) | ||
|
||
if shop.nil? | ||
logger.error("#{self.class} failed: cannot find shop with domain '#{shop_domain}'") | ||
|
||
raise ActiveRecord::RecordNotFound, "Shop Not Found" | ||
end | ||
|
||
shop.with_shopify_session do | ||
end | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
lib/generators/shopify_app/add_gdpr_jobs/templates/customers_redact_job.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class CustomersRedactJob < ActiveJob::Base | ||
extend ShopifyAPI::Webhooks::Handler | ||
|
||
class << self | ||
def handle(topic:, shop:, body:) | ||
perform_later(topic: topic, shop_domain: shop, webhook: body) | ||
end | ||
end | ||
|
||
def perform(topic:, shop_domain:, webhook:) | ||
shop = Shop.find_by(shopify_domain: shop_domain) | ||
|
||
if shop.nil? | ||
logger.error("#{self.class} failed: cannot find shop with domain '#{shop_domain}'") | ||
|
||
raise ActiveRecord::RecordNotFound, "Shop Not Found" | ||
end | ||
|
||
shop.with_shopify_session do | ||
end | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
lib/generators/shopify_app/add_gdpr_jobs/templates/shop_redact_job.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class ShopRedactJob < ActiveJob::Base | ||
extend ShopifyAPI::Webhooks::Handler | ||
|
||
class << self | ||
def handle(topic:, shop:, body:) | ||
perform_later(topic: topic, shop_domain: shop, webhook: body) | ||
end | ||
end | ||
|
||
def perform(topic:, shop_domain:, webhook:) | ||
shop = Shop.find_by(shopify_domain: shop_domain) | ||
|
||
if shop.nil? | ||
logger.error("#{self.class} failed: cannot find shop with domain '#{shop_domain}'") | ||
|
||
raise ActiveRecord::RecordNotFound, "Shop Not Found" | ||
end | ||
|
||
shop.with_shopify_session do | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "generators/shopify_app/add_app_uninstalled_job/add_app_uninstalled_job_generator" | ||
|
||
class AddAppUninstalledJobGeneratorTest < Rails::Generators::TestCase | ||
tests ShopifyApp::Generators::AddAppUninstalledJobGenerator | ||
destination File.expand_path("../tmp", File.dirname(__FILE__)) | ||
|
||
setup do | ||
ShopifyApp.configure do |config| | ||
config.embedded_app = true | ||
end | ||
|
||
prepare_destination | ||
provide_existing_application_file | ||
provide_existing_routes_file | ||
provide_existing_application_controller | ||
end | ||
|
||
test "creates app uninstalled job file" do | ||
run_generator | ||
|
||
assert_file "app/jobs/app_uninstalled_job.rb" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "generators/shopify_app/add_gdpr_jobs/add_gdpr_jobs_generator" | ||
|
||
class AddGdprJobsGeneratorJobTest < Rails::Generators::TestCase | ||
tests ShopifyApp::Generators::AddGdprJobsGenerator | ||
destination File.expand_path("../tmp", File.dirname(__FILE__)) | ||
|
||
setup do | ||
ShopifyApp.configure do |config| | ||
config.embedded_app = true | ||
end | ||
|
||
prepare_destination | ||
provide_existing_application_file | ||
provide_existing_routes_file | ||
provide_existing_application_controller | ||
end | ||
|
||
test "creates app uninstalled job file" do | ||
run_generator | ||
|
||
klenotiw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert_file "app/jobs/customers_data_request_job.rb" | ||
assert_file "app/jobs/shop_redact_job.rb" | ||
assert_file "app/jobs/customers_redact_job.rb" | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should be raising an error and failing jobs if we can't find their shop domain 🤔
Sidekiq and Active Job have cool tooling for jobs that fail. If devs aren't watching logs, they might be missing out on key information that jobs are failing.
Raising an error will be available with exception handing software (bugsnag, airbake, rollbar, etc) as well as job monitoring dashboards like sidekiq's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern seems to be in other jobs as well. I'd recommend logging in addition to failing the job. Failing a job means the job raised an exception during its run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize you are probably boosting these from templates, but this is a good opportunity for improvement 😄 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I just added a raise
StandardError
I thought I remember you saying to raiseNotFound
error? I couldn't find it anywhere maybe you said a different error, my bad for forgetting.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://api.rubyonrails.org/classes/ActiveRecord/RecordNotFound.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, you could use find_by! instead of find_by whiches raise an active record not found error automagically by the power of rails. We'd lose the logging with that approach though