-
Notifications
You must be signed in to change notification settings - Fork 699
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 after authenticate job option #432
Conversation
|
||
def init_after_authenticate_config | ||
initializer = load_initializer | ||
return if initializer.include?("config.webhooks") |
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.
why do you need to return if they have have webhooks configured?
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.
🤦♂️ typo
|
||
inject_into_file( | ||
'config/initializers/shopify_app.rb', | ||
" config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: false }\n", |
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 would generate this without the inline arg since most people should use it as a job
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.
oh I see - its not really a default argument the way I was thinking of it. Maybe it is better to have here since otherwise it would only live in documentation. What are your thoughts @Hammadk
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 agree that we should keep inline: false
around for documentation purposes
lib/shopify_app/sessions_concern.rb
Outdated
def perform_after_authenticate_job | ||
return unless ShopifyApp.configuration.after_authenticate_job | ||
|
||
job = ShopifyApp.configuration.after_authenticate_job[:job] |
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.
Is it possible for ShopifyApp.configuration.after_authenticate_job
to be truthy, without a job set in ShopifyApp.configuration.after_authenticate_job[:job]
?
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.
LGTM other than the minor comment
30e37a3
to
5b60e70
Compare
Yes, I switched it up to check for the presence of the Also removed my typo and added the error handler like I originally intended. Ready for another quick round of 👀 |
5b60e70
to
79bbb27
Compare
lib/shopify_app/sessions_concern.rb
Outdated
|
||
return unless config && config[:job].present? && config[:inline].present? | ||
|
||
if config[:inline] |
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.
We should add tests for this conditional.
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 was pondering on this for a bit. There doesn't seem to be anything testing the authentication flow of the app - installing script tags and webhooks got lucky because they are contained in their own class instead of a job firing from within the app itself and not the gem, therefore you're able to unit test vs. integration test.
I think the only way to properly tests this is to have an integration test which goes through the entire authentication flow, unless there's a simpler way that I'm missing here?
If that's the case I could attempt to address it in another PR before merging this and can put this on hold for a bit until I can get to it.
Open to other suggestions - is there a way I can test this without essentially writing an entire integration test for the auth flow?
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.
Have a look at the SessionControllerTests
. One way to do this is by testing the #callback
method.
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.
💡 ahhh that's what I was missing. TY.
44e3d7e
to
6b6152e
Compare
Nice call on the test 😉 totally missed that one. Should be good for review again! Todo before :
|
.byebug_history
Outdated
config[:inline].present? | ||
config[:job].present? | ||
config | ||
next |
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.
🔥
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.
🤦♂️
lib/shopify_app/sessions_concern.rb
Outdated
|
||
return unless config && config[:job].present? && config[:inline].in?([true, false]) | ||
|
||
if config[:inline] |
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.
Do we have a default value for config[:inline]
? If not, we won't get to this statement because most people won't set config[:inline]
. We should change this to:
return unless config && config[:job].present?
if config[:inline] == true
...
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.
By default we add inline: false when you generate the job, but I see your point. So should we just consider anything but true to mean you want to perform asynchronously ?
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.
Yeah, config[:inline] == true
is good because it's self documenting code. If someone thinking about running an inline job, reading this code would tell them that they need to set that value to true
.
|
||
mock_shopify_omniauth | ||
get :callback, params: { shop: 'shop' } | ||
end |
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.
Indentation is off here.
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.
Great work. This will make the Shopify app gem much more useful. Looking forward to the updates.
7cf036f
to
debcd11
Compare
This should be ready for review - comments are fixed up, README and Changelog added, version bumped a minor version. |
README.md
Outdated
@@ -23,6 +23,7 @@ Table of Contents | |||
* [Home Controller Generator](#home-controller-generator) | |||
* [App Proxy Controller Generator](#app-proxy-controller-generator) | |||
* [Controllers, Routes and Views](#controllers-routes-and-views) | |||
* [After Authenticate Job and Generator](#after-authenticate-job-an-generator) |
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 would probably drop Generator
from the section heading
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.
Also I think this should go after the Webhooks and ScriptTags manager sections
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.
Missed this one, updated!
README.md
Outdated
|
||
You can generate an after authenticate job by running `shopify_app:add_after_authenticate_job` which will add a line in `shopify_app.rb` giving the option | ||
to run a job of your choosing either inline or asynchronously after the shop has authenticated. By default the job will run asynchronously unless `inline: false` | ||
is specified. |
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 would write this more like this:
If your app needs to perform specific actions after it is installed ShopifyApp can queue or run a job of your choosing (note that we already provide support for automatically creating Webhooks and Scripttags). To configure the after authenticate job update your initializer as follows:
ShopifyApp.configure do |config|
config.add_after_authenticate_job = { job: Shopify::AfterAuthenticateJob }
end
If you need the job to run synchronously add the inline
flag:
ShopifyApp.configure do |config|
config.add_after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: true }
end
We've also provided a generator which creates a skeleton job and updates the initializer for you:
bin/rails g shopify_app:add_after_authenticate_job
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.
👍 Thanks for that, I'm awful with words.
debcd11
to
6f1197f
Compare
README is updated with gooder ( 😉 ) words! |
6f1197f
to
4da222e
Compare
CHANGELOG.md
Outdated
@@ -1,3 +1,7 @@ | |||
7.3.1 |
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'd make this 7.4 since we added a feature
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.
👍 bumped.
4da222e
to
3939188
Compare
🚢 |
What
Adds the ability to generate an after authenticate job which can perform async or inline once the shop has authenticated with the app.
Branch renamed from: #428 to better reflect the changes.
@Hammadk @kevinhughes27 ready for review again - made the config a hash accepting
job
andinline
.