Skip to content
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

Detect controller concern clash #1560

Merged
merged 2 commits into from
Nov 15, 2022
Merged

Conversation

andyw8
Copy link
Contributor

@andyw8 andyw8 commented Oct 31, 2022

What this PR does

Closes https://github.com/Shopify/first-party-library-planning/issues/486

RequireKnownShop and LoginProtection both have a method current_shopify_domain but with different implementations. If both these concerns are included, it can result in unintentional behaviour, since one method will overwrite the other.

Reviewer's guide to testing

Things to focus on

Checklist

Before submitting the PR, please consider if any of the following are needed:

  • Update CHANGELOG.md if the changes would impact users
  • Update README.md, if appropriate.
  • Update any relevant pages in /docs, if necessary
  • For security fixes, the Disclosure Policy must be followed.

@andyw8 andyw8 force-pushed the andyw8/detect-controller-concern-clash branch 6 times, most recently from 5bbb403 to 422346c Compare November 1, 2022 15:11
@@ -1,5 +1,4 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
include ShopifyApp::LoginProtection
Copy link
Contributor Author

@andyw8 andyw8 Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(tests pass but need to do more digging here to see if this is valid)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this needs be removed, because the UnauthenticatedHomeController template inherits from ApplicationController and so would have both ShopifyApp::LoginProtection and ShopifyApp::RequireKnownShop.

cc @nelsonwittwer @teddyhwang

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds sane to me - we shouldn't be including LoginProtection globally unless we have a separate "unauthenticated" app controller.

@andyw8
Copy link
Contributor Author

andyw8 commented Nov 1, 2022

FYI @nelsonwittwer @klenotiw

@andyw8 andyw8 mentioned this pull request Nov 8, 2022
@andyw8 andyw8 force-pushed the andyw8/detect-controller-concern-clash branch 2 times, most recently from 87febfe to 480bf4b Compare November 8, 2022 21:59
@@ -1,6 +1,9 @@
# frozen_string_literal: true

class HomeController < ApplicationController
include ShopifyApp::EmbeddedApp
Copy link
Contributor Author

@andyw8 andyw8 Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andyw8 andyw8 force-pushed the andyw8/detect-controller-concern-clash branch 2 times, most recently from 557fee1 to 10b1f2b Compare November 8, 2022 22:11
CHANGELOG.md Outdated
@@ -2,6 +2,7 @@ Unreleased
----------
* Fixes a bug with `EnsureAuthenticatedLinks` causing deep links to not work [#1549](https://github.com/Shopify/shopify_app/pull/1549)
* Ensure online token is properly used when using `current_shopify_session` [#1566](https://github.com/Shopify/shopify_app/pull/1566)
* Detect the use of incompatible controller concerns [#1560](https://github.com/Shopify/shopify_app/pull/1560). Depending on how your app is structured, this may result in an error on startup even though the app was working correctly. However, it is helping exposing an existing flaw that may have caused issues in future.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this seeem clear?

Copy link
Contributor

@paulomarg paulomarg Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to me, but I wonder if we should just log a warning rather than blow up, so this doesn't become a breaking change. Could we switch it over to an error on a later major version?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does sound like it's a breaking change so we should follow our deprecation strategy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I'll try switch it over to a deprecation, e.g.:

We detected the use of incompatible concerns (RequireKnownShop and LoginProtection) in a controller, which may lead to unpredictable behavior. In a future release of this library this will raise an error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we easily log the controller name to make debugging it easier?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logs should already indicate the location, but I've added it just in case. Here's how it looks now:

DEPRECATION WARNING: We detected the use of incompatible concerns (RequireKnownShop and LoginProtection) in ProductsController,
which may lead to unpredictable behavior. In a future release of this library this will raise an error.
 (called from include at /Users/andyw8/src/github.com/Shopify/shopify_app/my_shopify_app_clash/app/controllers/products_controller.rb:5)

@andyw8 andyw8 force-pushed the andyw8/detect-controller-concern-clash branch from 10b1f2b to 9d7e60a Compare November 9, 2022 15:55
@andyw8 andyw8 marked this pull request as ready for review November 9, 2022 15:55
@andyw8 andyw8 requested review from paulomarg, teddyhwang and nelsonwittwer and removed request for teddyhwang November 9, 2022 15:55
@andyw8
Copy link
Contributor Author

andyw8 commented Nov 9, 2022

I tested on a newly generated app with a intentional conflict in the ProductsControllers:

class ProductsController < AuthenticatedController
  include ShopifyApp::RequireKnownShop
  # ...

With config.eager_load = true, as it would be in production, the app refuses to boot, as would be expected.

With the Rails default of config.eager_load = false, the browsers stalls on "Loading..." for the Products request, and the error is reported in the console.
(now that we are outputting a deprecation warning the above is no longer true).

@andyw8 andyw8 mentioned this pull request Nov 9, 2022
4 tasks
@andyw8 andyw8 force-pushed the andyw8/detect-controller-concern-clash branch from bcc75be to bd1f046 Compare November 15, 2022 14:50
@andyw8 andyw8 merged commit e297ef1 into main Nov 15, 2022
@andyw8 andyw8 deleted the andyw8/detect-controller-concern-clash branch November 15, 2022 14:50
fabriazza pushed a commit to fabriazza/shopify_app that referenced this pull request Feb 1, 2023
* Detect controller concern clash

* Deprecation warning instead of raising error

Co-authored-by: Andy Waite <andyw8@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants