Sha256: 53466917c2d5b4e77619e002ac11d370f73b565272bdae73be2d118fe458746c

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module ShopifyApp
  module AccessScopes
    class UserStrategy
      class InvalidInput < StandardError; end

      class << self
        def update_access_scopes?(user_id: nil, shopify_user_id: nil)
          return update_access_scopes_for_user_id?(user_id) if user_id
          return update_access_scopes_for_shopify_user_id?(shopify_user_id) if shopify_user_id

          raise(InvalidInput, "#update_access_scopes? requires user_id or shopify_user_id parameter inputs")
        end

        private

        def update_access_scopes_for_user_id?(user_id)
          user_access_scopes = user_access_scopes_by_user_id(user_id)
          configuration_access_scopes != user_access_scopes
        end

        def update_access_scopes_for_shopify_user_id?(shopify_user_id)
          user_access_scopes = user_access_scopes_by_shopify_user_id(shopify_user_id)
          configuration_access_scopes != user_access_scopes
        end

        def user_access_scopes_by_user_id(user_id)
          ShopifyApp::SessionRepository.retrieve_user_session(user_id)&.scope
        end

        def user_access_scopes_by_shopify_user_id(shopify_user_id)
          ShopifyApp::SessionRepository.retrieve_user_session_by_shopify_user_id(shopify_user_id)&.scope
        end

        def configuration_access_scopes
          ShopifyAPI::Auth::AuthScopes.new(ShopifyApp.configuration.user_access_scopes)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shopify_app-20.1.1 lib/shopify_app/access_scopes/user_strategy.rb
shopify_app-20.1.0 lib/shopify_app/access_scopes/user_strategy.rb