Skip to content

Commit

Permalink
Merge pull request #812 from xiuzhong/feature/MARLIN-748
Browse files Browse the repository at this point in the history
[MARLIN-748] add deeplink endpoint to pages controller
  • Loading branch information
adamaziz15 committed Jun 5, 2019
2 parents 65e29d5 + 528d530 commit 3143574
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions api/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MnoEnterprise::Engine.routes.draw do
# Generic routes
get '/launch/:id', to: 'pages#launch', constraints: {id: /[\w\-\.:]+/}
get '/deeplink/:organization_id/:entity_type/:entity_id', to: 'pages#deeplink', constraints: {organization_id: /[\w\-\.]+/, entity_id: /[\w\-]+/}
get '/loading/:id', to: 'pages#loading', constraints: {id: /[\w\-\.]+/}
get '/app_access_unauthorized', to: 'pages#app_access_unauthorized'
get '/billing_details_required', to: 'pages#billing_details_required'
Expand Down
11 changes: 9 additions & 2 deletions api/lib/mno_enterprise/concerns/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module MnoEnterprise::Concerns::Controllers::PagesController
# 'included do' causes the included code to be evaluated in the
# context where it is included rather than being executed in the module's context
included do
before_filter :authenticate_user!, only: [:launch]
before_filter :redirect_to_lounge_if_unconfirmed, only: [:launch]
before_filter :authenticate_user!, only: [:launch, :deeplink]
before_filter :redirect_to_lounge_if_unconfirmed, only: [:launch, :deeplink]
helper_method :main_logo_white_bg_path # To use in the provision view
end

Expand All @@ -30,6 +30,13 @@ def launch
redirect_to MnoEnterprise.router.launch_url(params[:id], {wtk: MnoEnterprise.jwt(user_id: current_user.uid)}.reverse_merge(request.query_parameters))
end

# GET /deeplink/:organization_id/:entity_type/:entity_id?params
# Redirect to Mno Enterprise entity deeplink
# Deeplink an entity (from dashboard) should redirect to this action
def deeplink
redirect_to MnoEnterprise.router.deeplink_url(params[:organization_id], params[:entity_type], params[:entity_id], {wtk: MnoEnterprise.jwt(user_id: current_user.uid)}.reverse_merge(request.query_parameters))
end

# GET /loading/:id
# Loading lounge - wait for an app to be online
def loading
Expand Down
15 changes: 15 additions & 0 deletions api/spec/controllers/mno_enterprise/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ module MnoEnterprise
end
end

describe 'GET #deeplink with parameters' do
let(:organization) { build(:organization) }
let(:entity_type) { 'invoices' }
let(:entity_id) { SecureRandom.uuid }
before { sign_in user }
subject { get :deeplink, organization_id: organization.uid, entity_type: entity_type, entity_id: entity_id, specific_parameters: 'specific:parameters_value' }

it_behaves_like "a navigatable protected user action"

it 'redirects to the mno enterprise deeplink page with a web token and extra params' do
subject
expect(response).to redirect_to(MnoEnterprise.router.deeplink_url(organization.uid, entity_type, entity_id, wtk: MnoEnterprise.jwt({user_id: user.uid}), specific_parameters: 'specific:parameters_value'))
end
end

describe 'GET #loading' do
subject { get :loading, id: app_instance.uid }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ module MnoEnterprise
expect(get("/launch/bla.mcube.co")).to route_to("mno_enterprise/pages#launch", id: 'bla.mcube.co')
end

it "routes to #launch" do
it "routes to #deeplink" do
expect(get("/deeplink/org-1f47/invoices/3456-we43")).to route_to("mno_enterprise/pages#deeplink", organization_id: 'org-1f47', entity_type: 'invoices', entity_id: '3456-we43')
end

it "routes to #loading" do
expect(get("/loading/cld-1f47d5s4")).to route_to("mno_enterprise/pages#loading", id: 'cld-1f47d5s4')
expect(get("/loading/bla.mcube.co")).to route_to("mno_enterprise/pages#loading", id: 'bla.mcube.co')
end
Expand Down
4 changes: 4 additions & 0 deletions core/lib/mno_enterprise/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def launch_url(id,opts = {})
host_url("/launch/#{id}",opts)
end

def deeplink_url(organization_id,entity_type,entity_id,opts = {})
host_url("/deeplink/#{organization_id}/#{entity_type}/#{entity_id}", opts)
end

def authorize_oauth_url(id,opts = {})
host_url("/oauth/#{id}/authorize",opts)
end
Expand Down
9 changes: 9 additions & 0 deletions core/spec/mno_enterprise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
it { expect(MnoEnterprise.router.launch_url(id)).to eq(url) }
end

describe 'deeplink_url' do
let(:organization_id) { 'org=12s2' }
let(:entity_type) { 'invoices' }
let(:entity_id) { '123245da-2sah4as-344wq' }

let(:url) { "#{root_path}/deeplink/#{organization_id}/#{entity_type}/#{entity_id}" }
it { expect(MnoEnterprise.router.deeplink_url(organization_id, entity_type, entity_id)).to eq(url) }
end

describe 'authorize_oauth_url' do
let(:url) { "#{root_path}/oauth/#{id}/authorize" }
it { expect(MnoEnterprise.router.authorize_oauth_url(id)).to eq(url) }
Expand Down

0 comments on commit 3143574

Please sign in to comment.