Skip to content

Commit

Permalink
FEATURE: allow authorisation call to determine final landing path (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
merefield authored Sep 22, 2023
1 parent 39566e6 commit f50c602
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
discourse_subscription_client (0.1.0.pre14)
discourse_subscription_client (0.1.0.pre15)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -231,6 +231,7 @@ GEM

PLATFORMS
arm64-darwin-21
arm64-darwin-22
x86_64-linux

DEPENDENCIES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def index
end

def authorize
session[:final_landing_path] = params[:final_landing_path]

request_id = DiscourseSubscriptionClient::Authorization.request_id(@supplier.id)
cookies[:user_api_request_id] = request_id
redirect_to DiscourseSubscriptionClient::Authorization.url(current_user, @supplier, request_id).to_s,
Expand All @@ -36,7 +38,11 @@ def authorize_callback

DiscourseSubscriptionClient::Subscriptions.update

redirect_to "/admin/plugins/subscription-client/subscriptions"
if !session[:final_landing_path].blank?
redirect_to session[:final_landing_path]
else
redirect_to "/admin/plugins"
end
end

def destroy
Expand Down
2 changes: 1 addition & 1 deletion lib/discourse_subscription_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module DiscourseSubscriptionClient
VERSION = "0.1.0.pre14"
VERSION = "0.1.0.pre15"
end
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
expect(@request.cookie_jar[:user_api_request_id].present?).to eq(true)
end

it "authorizes and stores requested landing page" do
get "/admin/plugins/subscription-client/suppliers/authorize", params: { supplier_id: supplier.id, final_landing_path: "/admin/wizards/wizard" }
expect(response.status).to eq(302)
expect(session[:final_landing_path]).to eq("/admin/wizards/wizard")
end

it "handles authorization callbacks" do
request_id = cookies[:user_api_request_id] = DiscourseSubscriptionClient::Authorization.request_id(supplier.id)
payload = generate_auth_payload(admin.id, request_id)
Expand All @@ -56,6 +62,16 @@
expect(subscription.subscribed).to eq(true)
end

it "handles authorization callbacks and redirects to prior requested landing path" do
session[:final_landing_path] = "/admin/wizards/wizard"
request_id = cookies[:user_api_request_id] = DiscourseSubscriptionClient::Authorization.request_id(supplier.id)
payload = generate_auth_payload(admin.id, request_id)
stub_subscription_request(200, resource, subscription_response)

get "/admin/plugins/subscription-client/suppliers/authorize/callback", params: { payload: payload }
expect(response).to redirect_to("/admin/wizards/wizard")
end

it "destroys authorizations" do
request_id = DiscourseSubscriptionClient::Authorization.request_id(supplier.id)
payload = generate_auth_payload(admin.id, request_id)
Expand Down

0 comments on commit f50c602

Please sign in to comment.