Skip to content

Commit d654041

Browse files
authored
Merge pull request #1961 from Shopify/remove-callback-controller-methods
[Breaking] Removes deprecated methods in callback controller
2 parents d313ec4 + 1fd18ec commit d654041

File tree

3 files changed

+4
-207
lines changed

3 files changed

+4
-207
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Unreleased
22
----------
3+
4+
- ⚠️ [Breaking] Removed deprecated `CallbackController` methods. `perform_after_authenticate_job`, `install_webhooks`, and `perform_post_authenticate_jobs` have been removed. [#1961](https://github.com/Shopify/shopify_app/pull/1961)
35
- ⚠️ [Breaking] Bumps minimum supported Ruby version to 3.1 [#1959](https://github.com/Shopify/shopify_app/pull/1959)
46
- Adds a `script_tag_manager` that will automatically create script tags when the app is installed. [1948](https://github.com/Shopify/shopify_app/pull/1948)
57

app/controllers/shopify_app/callback_controller.rb

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,8 @@ def callback
2323

2424
return respond_with_user_token_flow if start_user_token_flow?(api_session)
2525

26-
if ShopifyApp::VERSION < "23.0"
27-
# deprecated in 23.0
28-
if ShopifyApp.configuration.custom_post_authenticate_tasks.present?
29-
ShopifyApp.configuration.post_authenticate_tasks.perform(api_session)
30-
else
31-
perform_post_authenticate_jobs(api_session)
32-
end
33-
else
34-
ShopifyApp.configuration.post_authenticate_tasks.perform(api_session)
35-
end
26+
ShopifyApp.configuration.post_authenticate_tasks.perform(api_session)
27+
3628
redirect_to_app if check_billing(api_session)
3729
end
3830

@@ -145,45 +137,5 @@ def update_user_access_scopes?
145137
def user_access_scopes_strategy
146138
ShopifyApp.configuration.user_access_scopes_strategy
147139
end
148-
149-
def perform_post_authenticate_jobs(session)
150-
# Ensure we use the shop session to install webhooks
151-
session_for_shop = session.online? ? shop_session : session
152-
153-
install_webhooks(session_for_shop)
154-
install_scripttags(session_for_shop)
155-
perform_after_authenticate_job(session)
156-
end
157-
158-
def install_webhooks(session)
159-
return unless ShopifyApp.configuration.has_webhooks?
160-
161-
WebhooksManager.queue(session.shop, session.access_token)
162-
end
163-
164-
def install_scripttags(session)
165-
return unless ShopifyApp.configuration.has_script_tags?
166-
167-
ScriptTagsManager.queue(
168-
session.shop,
169-
session.access_token,
170-
ShopifyApp.configuration.script_tags,
171-
)
172-
end
173-
174-
def perform_after_authenticate_job(session)
175-
config = ShopifyApp.configuration.after_authenticate_job
176-
177-
return unless config && config[:job].present?
178-
179-
job = config[:job]
180-
job = job.constantize if job.is_a?(String)
181-
182-
if config[:inline] == true
183-
job.perform_now(shop_domain: session.shop)
184-
else
185-
job.perform_later(shop_domain: session.shop)
186-
end
187-
end
188140
end
189141
end

test/controllers/callback_controller_test.rb

Lines changed: 0 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -170,103 +170,6 @@ class CallbackControllerTest < ActionController::TestCase
170170
refute_equal cookies.encrypted[@stubbed_cookie.name], @stubbed_cookie.value
171171
end
172172

173-
test "#callback starts the WebhooksManager if webhooks are configured" do
174-
# Deprecated in 23.0, tests moved to PostAuthenticateTasksTest
175-
ShopifyApp.configure do |config|
176-
config.webhooks = [{ topic: "carts/update", address: "example-app.com/webhooks" }]
177-
end
178-
179-
ShopifyApp::WebhooksManager.expects(:queue).with(SHOP_DOMAIN, "token")
180-
181-
mock_oauth
182-
get :callback, params: @callback_params
183-
end
184-
185-
test "#callback doesn't run the WebhooksManager if no webhooks are configured" do
186-
# Deprecated in 23.0, tests moved to PostAuthenticateTasksTest
187-
ShopifyApp.configure do |config|
188-
config.webhooks = []
189-
end
190-
191-
ShopifyApp::WebhooksManager.expects(:queue).never
192-
193-
mock_oauth
194-
get :callback, params: @callback_params
195-
end
196-
197-
test "#callback calls #perform_after_authenticate_job and performs inline when inline is true" do
198-
# Deprecated in 23.0, tests moved to PostAuthenticateTasksTest
199-
ShopifyApp.configure do |config|
200-
config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: true }
201-
end
202-
203-
Shopify::AfterAuthenticateJob.expects(:perform_now).with(shop_domain: SHOP_DOMAIN)
204-
205-
mock_oauth
206-
get :callback, params: @callback_params
207-
end
208-
209-
test "#callback calls #perform_after_authenticate_job and performs asynchronous when inline isn't true" do
210-
# Deprecated in 23.0, tests moved to PostAuthenticateTasksTest
211-
ShopifyApp.configure do |config|
212-
config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: false }
213-
end
214-
215-
Shopify::AfterAuthenticateJob.expects(:perform_later).with(shop_domain: SHOP_DOMAIN)
216-
217-
mock_oauth
218-
get :callback, params: @callback_params
219-
end
220-
221-
test "#callback doesn't call #perform_after_authenticate_job if job is nil" do
222-
# Deprecated in 23.0, tests moved to PostAuthenticateTasksTest
223-
ShopifyApp.configure do |config|
224-
config.after_authenticate_job = { job: nil, inline: false }
225-
end
226-
227-
Shopify::AfterAuthenticateJob.expects(:perform_later).never
228-
229-
mock_oauth
230-
get :callback, params: @callback_params
231-
end
232-
233-
test "#callback calls #perform_after_authenticate_job and performs async if inline isn't present" do
234-
# Deprecated in 23.0, tests moved to PostAuthenticateTasksTest
235-
ShopifyApp.configure do |config|
236-
config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob }
237-
end
238-
239-
Shopify::AfterAuthenticateJob.expects(:perform_later).with(shop_domain: SHOP_DOMAIN)
240-
241-
mock_oauth
242-
get :callback, params: @callback_params
243-
end
244-
245-
test "#callback calls #perform_after_authenticate_job constantizes from a string to a class" do
246-
# Deprecated in 23.0, tests moved to PostAuthenticateTasksTest
247-
ShopifyApp.configure do |config|
248-
config.after_authenticate_job = { job: "Shopify::AfterAuthenticateJob", inline: false }
249-
end
250-
251-
Shopify::AfterAuthenticateJob.expects(:perform_later).with(shop_domain: SHOP_DOMAIN)
252-
253-
mock_oauth
254-
get :callback, params: @callback_params
255-
end
256-
257-
test "#callback calls #perform_after_authenticate_job raises if the string is not a valid job class" do
258-
# Deprecated in 23.0, tests moved to PostAuthenticateTasksTest
259-
ShopifyApp.configure do |config|
260-
config.after_authenticate_job = { job: "InvalidJobClassThatDoesNotExist", inline: false }
261-
end
262-
263-
mock_oauth
264-
265-
assert_raise NameError do
266-
get :callback, params: @callback_params
267-
end
268-
end
269-
270173
test "#callback redirects to the root_url with shop and host parameter for non-embedded" do
271174
ShopifyApp.configuration.embedded_app = false
272175
ShopifyAppConfigurer.setup_context # to reset the context, as there's no attr_writer for embedded
@@ -305,52 +208,6 @@ class CallbackControllerTest < ActionController::TestCase
305208
assert_redirected_to "https://#{@host}/admin/apps/key/return_to/path"
306209
end
307210

308-
test "#callback performs install_webhook job after authentication" do
309-
# Deprecated in 23.0, tests moved to PostAuthenticateTasksTest
310-
mock_oauth
311-
312-
ShopifyApp.configure do |config|
313-
config.webhooks = [{ topic: "carts/update", address: "example-app.com/webhooks" }]
314-
end
315-
316-
ShopifyApp::WebhooksManager.expects(:queue).with(SHOP_DOMAIN, "token")
317-
318-
get :callback, params: @callback_params
319-
assert_response 302
320-
end
321-
322-
test "#callback performs install_webhook job with an offline session after an online session OAuth" do
323-
# Deprecated in 23.0, tests moved to PostAuthenticateTasksTest
324-
ShopifyApp.configure do |config|
325-
config.webhooks = [{ topic: "carts/update", address: "example-app.com/webhooks" }]
326-
end
327-
ShopifyApp::SessionRepository.shop_storage.store(@stubbed_session)
328-
ShopifyApp::SessionRepository.user_storage = ShopifyApp::InMemoryUserSessionStore
329-
330-
mock_oauth(session: online_session)
331-
332-
ShopifyApp::WebhooksManager.expects(:queue).with(SHOP_DOMAIN, "token")
333-
334-
get :callback, params: @callback_params
335-
assert_response 302
336-
ensure
337-
ShopifyApp::SessionRepository.shop_storage.clear
338-
end
339-
340-
test "#callback performs after_authenticate job after authentication" do
341-
# Deprecated in 23.0, tests moved to PostAuthenticateTasksTest
342-
mock_oauth
343-
344-
ShopifyApp.configure do |config|
345-
config.after_authenticate_job = { job: Shopify::AfterAuthenticateJob, inline: true }
346-
end
347-
348-
Shopify::AfterAuthenticateJob.expects(:perform_now).with(shop_domain: SHOP_DOMAIN)
349-
350-
get :callback, params: @callback_params
351-
assert_response 302
352-
end
353-
354211
test "#callback calls post_authenticate_tasks if custom_post_authenticate_tasks is set" do
355212
mock_oauth
356213

@@ -377,20 +234,6 @@ class CallbackControllerTest < ActionController::TestCase
377234
assert_response 302
378235
end
379236

380-
test "#callback calls methods in callback controller if custom_post_authenticate_tasks is not set" do
381-
mock_oauth
382-
383-
ShopifyApp.configure do |_config|
384-
ShopifyApp.configuration.custom_post_authenticate_tasks = nil
385-
end
386-
387-
CallbackController.any_instance.expects(:install_webhooks)
388-
CallbackController.any_instance.expects(:perform_after_authenticate_job)
389-
390-
get :callback, params: @callback_params
391-
assert_response 302
392-
end
393-
394237
private
395238

396239
def mock_oauth(cookie: @stubbed_cookie, session: @stubbed_session)

0 commit comments

Comments
 (0)