Skip to content

Commit

Permalink
feat: support non root context (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque authored May 22, 2020
1 parent 0954ac0 commit dc48049
Show file tree
Hide file tree
Showing 27 changed files with 125 additions and 100 deletions.
4 changes: 2 additions & 2 deletions lib/pact_broker/api/pact_broker_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ def group_url(pacticipant_name, base_url = '')
"#{base_url}/groups/#{pacticipant_name}"
end

def hal_browser_url target_url
"/hal-browser/browser.html#" + target_url
def hal_browser_url target_url, base_url = ''
"#{base_url}/hal-browser/browser.html#" + target_url
end

def url_encode param
Expand Down
28 changes: 14 additions & 14 deletions lib/pact_broker/api/renderers/html_pact_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ def call

def head
"<title>#{title}</title>
<link rel='stylesheet' type='text/css' href='/stylesheets/github.css'>
<link rel='stylesheet' type='text/css' href='/stylesheets/pact.css'>
<link rel='stylesheet' type='text/css' href='/stylesheets/github-json.css'>
<link rel='stylesheet' type='text/css' href='/css/bootstrap.min.css'>
<link rel='stylesheet' type='text/css' href='/stylesheets/material-menu.css'>
<link rel='stylesheet' type='text/css' href='/stylesheets/jquery-confirm.min.css'>
<script src='/javascripts/highlight.pack.js'></script>
<script src='/javascripts/jquery-3.3.1.min.js'></script>
<script src='/js/bootstrap.min.js'></script>
<script src='/javascripts/material-menu.js'></script>
<script src='/javascripts/pact.js'></script>
<script src='/javascripts/jquery-confirm.min.js'></script>
<link rel='stylesheet' type='text/css' href='#{base_url}/stylesheets/github.css'>
<link rel='stylesheet' type='text/css' href='#{base_url}/stylesheets/pact.css'>
<link rel='stylesheet' type='text/css' href='#{base_url}/stylesheets/github-json.css'>
<link rel='stylesheet' type='text/css' href='#{base_url}/css/bootstrap.min.css'>
<link rel='stylesheet' type='text/css' href='#{base_url}/stylesheets/material-menu.css'>
<link rel='stylesheet' type='text/css' href='#{base_url}/stylesheets/jquery-confirm.min.css'>
<script src='#{base_url}/javascripts/highlight.pack.js'></script>
<script src='#{base_url}/javascripts/jquery-3.3.1.min.js'></script>
<script src='#{base_url}/js/bootstrap.min.js'></script>
<script src='#{base_url}/javascripts/material-menu.js'></script>
<script src='#{base_url}/javascripts/pact.js'></script>
<script src='#{base_url}/javascripts/jquery-confirm.min.js'></script>
<script>hljs.initHighlightingOnLoad();</script>"
end

Expand All @@ -72,7 +72,7 @@ def pact_metadata
<a href=\"#{matrix_url}\">View Matrix</a>
</li>
<li>
<a href=\"/\">Home</a>
<a href=\"#{base_url}\">Home</a>
</li>
<li>
<span data-consumer-name=\"#{@pact.consumer.name}\"
Expand Down Expand Up @@ -129,7 +129,7 @@ def published_date_in_words
end

def json_url
PactBroker::Api::PactBrokerUrls.hal_browser_url pact_url
PactBroker::Api::PactBrokerUrls.hal_browser_url pact_url, base_url
end

def pact_url
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/api/resources/pact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def pact_params

def set_post_deletion_response
latest_pact = pact_service.find_latest_pact(pact_params)
response_body = { "_links" => {} }
response_body = { "_links" => { index: { href: base_url } } }
if latest_pact
response_body["_links"]["pb:latest-pact-version"] = {
href: latest_pact_url(base_url, latest_pact),
Expand Down
8 changes: 7 additions & 1 deletion lib/pact_broker/doc/controllers/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def resource_exists? rel_name, context = nil
get ":rel_name" do
rel_name = params[:rel_name]
context = params[:context]
view_params = {:layout_engine => :haml, layout: :'layouts/main'}
view_params = {:layout_engine => :haml, layout: :'layouts/main', locals: { base_url: base_url }}
if resource_exists? rel_name, context
markdown view_name_for(rel_name, context).to_sym, view_params, {}
elsif resource_exists? rel_name
Expand All @@ -42,6 +42,12 @@ def resource_exists? rel_name, context = nil
markdown :not_found, view_params, {}
end
end

private

def base_url
PactBroker.configuration.base_url || request.base_url
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/doc/views/layouts/main.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%html
%head
%link{rel: 'stylesheet', href: '/css/bootstrap.min.css'}
%link{rel: 'stylesheet', href: "#{base_url}/css/bootstrap.min.css"}
%body{style: 'margin:20px'}
= yield
1 change: 1 addition & 0 deletions lib/pact_broker/ui/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def initialize
end

map "/" do
use PathInfoFixer
run PactBroker::UI::Controllers::Index
end
}
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/ui/controllers/clusters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def initialize pacticipants, relationships
end

get "/" do
view_model = ViewDomain::IndexItems.new(pacticipant_service.find_index_items)
haml 'clusters/show', locals: {relationships: view_model}
view_model = ViewDomain::IndexItems.new(pacticipant_service.find_index_items, base_url: base_url)
haml 'clusters/show', locals: {relationships: view_model, base_url: base_url}
end

end
Expand Down
5 changes: 3 additions & 2 deletions lib/pact_broker/ui/controllers/groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class Groups < Base
pacticipant = pacticipant_service.find_pacticipant_by_name(params[:name])
erb :'groups/show.html', {
locals: {
csv_path: "/groups/#{params[:name]}.csv",
csv_path: "#{base_url}/groups/#{params[:name]}.csv",
pacticipant_name: params[:name],
repository_url: pacticipant&.repository_url
repository_url: pacticipant&.repository_url,
base_url: base_url
}
}, {
layout: 'layouts/main'
Expand Down
5 changes: 3 additions & 2 deletions lib/pact_broker/ui/controllers/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Index < Base

# TODO remove this code when verified
options[:optimised] = true unless params[:optimised] == 'false'
index_items = ViewDomain::IndexItems.new(index_service.find_index_items(options))
index_items = ViewDomain::IndexItems.new(index_service.find_index_items(options), base_url: base_url)

page = tags ? :'index/show-with-tags' : :'index/show'
locals = {
Expand All @@ -34,7 +34,8 @@ class Index < Base
page_number: page_number,
page_size: page_size,
pagination_record_count: index_items.pagination_record_count,
current_page_size: index_items.size
current_page_size: index_items.size,
base_url: base_url
}

haml page, {locals: locals, layout: :'layouts/main'}
Expand Down
8 changes: 5 additions & 3 deletions lib/pact_broker/ui/controllers/matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class Matrix < Base
lines: [],
title: "The Matrix",
selectors: create_selector_objects(selectors),
options: create_options_model(options)
options: create_options_model(options),
base_url: base_url
}
begin
if params[:q]
Expand All @@ -48,15 +49,16 @@ class Matrix < Base
selectors = [ PactBroker::Matrix::UnresolvedSelector.new(pacticipant_name: params[:consumer_name]), PactBroker::Matrix::UnresolvedSelector.new(pacticipant_name: params[:provider_name]) ]
options = {latestby: 'cvpv', limit: 100}
lines = matrix_service.find(selectors, options)
lines = PactBroker::UI::ViewDomain::MatrixLines.new(lines)
lines = PactBroker::UI::ViewDomain::MatrixLines.new(lines, base_url: base_url)
locals = {
lines: lines,
title: "The Matrix",
consumer_name: params[:consumer_name],
provider_name: params[:provider_name],
selectors: create_selector_objects(selectors),
options: create_options_model(options),
badge_url: nil
badge_url: nil,
base_url: base_url
}
haml :'matrix/show', {locals: locals, layout: :'layouts/main'}
end
Expand Down
8 changes: 4 additions & 4 deletions lib/pact_broker/ui/helpers/url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ module URLHelper

extend self

def group_url pacticipant_name
"/groups/#{ERB::Util.url_encode(pacticipant_name)}"
def group_url pacticipant_name, base_url = ''
"#{base_url}/groups/#{ERB::Util.url_encode(pacticipant_name)}"
end

def matrix_url consumer_name, provider_name
"/matrix/provider/#{ERB::Util.url_encode(provider_name)}/consumer/#{ERB::Util.url_encode(consumer_name)}"
def matrix_url consumer_name, provider_name, base_url = ''
"#{base_url}/matrix/provider/#{ERB::Util.url_encode(provider_name)}/consumer/#{ERB::Util.url_encode(consumer_name)}"
end
end
end
Expand Down
27 changes: 16 additions & 11 deletions lib/pact_broker/ui/view_models/index_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class IndexItem

include PactBroker::Api::PactBrokerUrls

def initialize relationship
def initialize relationship, options = {}
@relationship = relationship
@options = options
end

def consumer_name
Expand Down Expand Up @@ -48,35 +49,35 @@ def provider_version_latest_tag_names
end

def consumer_group_url
Helpers::URLHelper.group_url consumer_name
Helpers::URLHelper.group_url(consumer_name, base_url)
end

def provider_group_url
Helpers::URLHelper.group_url provider_name
Helpers::URLHelper.group_url(provider_name, base_url)
end

def latest_pact_url
"#{pactigration_base_url('', @relationship)}/latest"
"#{pactigration_base_url(base_url, @relationship)}/latest"
end

def pact_url
PactBroker::Api::PactBrokerUrls.pact_url('', @relationship)
PactBroker::Api::PactBrokerUrls.pact_url(base_url, @relationship)
end

def pact_matrix_url
Helpers::URLHelper.matrix_url consumer_name, provider_name
Helpers::URLHelper.matrix_url(consumer_name, provider_name, base_url)
end

def any_webhooks?
@relationship.any_webhooks?
end

def pact_versions_url
PactBroker::Api::PactBrokerUrls.pact_versions_url(consumer_name, provider_name)
PactBroker::Api::PactBrokerUrls.pact_versions_url(consumer_name, provider_name, base_url)
end

def integration_url
PactBroker::Api::PactBrokerUrls.integration_url(consumer_name, provider_name)
PactBroker::Api::PactBrokerUrls.integration_url(consumer_name, provider_name, base_url)
end

def webhook_label
Expand Down Expand Up @@ -114,11 +115,11 @@ def webhook_last_execution_date
def webhook_url
url = case @relationship.webhook_status
when :none
PactBroker::Api::PactBrokerUrls.webhooks_for_consumer_and_provider_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider
PactBroker::Api::PactBrokerUrls.webhooks_for_consumer_and_provider_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider, base_url
else
PactBroker::Api::PactBrokerUrls.webhooks_status_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider
PactBroker::Api::PactBrokerUrls.webhooks_status_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider, base_url
end
"/hal-browser/browser.html##{url}"
PactBroker::Api::PactBrokerUrls.hal_browser_url(url, base_url)
end

def last_verified_date
Expand Down Expand Up @@ -181,6 +182,10 @@ def short_version_number version_number
version_number
end
end

def base_url
@options[:base_url]
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/ui/view_models/index_items.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class IndexItems

attr_reader :pagination_record_count

def initialize index_items
def initialize index_items, options = {}
# Why are we sorting twice!?
@index_items = index_items.collect{ |index_item| IndexItem.new(index_item) }.sort
@index_items = index_items.collect{ |index_item| IndexItem.new(index_item, options) }.sort
# until the feature flag is turned on
@pagination_record_count = index_items.size
@pagination_record_count = index_items.pagination_record_count if index_items.respond_to?(:pagination_record_count)
Expand Down
19 changes: 12 additions & 7 deletions lib/pact_broker/ui/view_models/matrix_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ class MatrixLine
include PactBroker::Api::PactBrokerUrls
include PactBroker::Messages

def initialize line
def initialize line, options = {}
@line = line
@options = options
@overwritten = false # true if the pact was revised and this revision is no longer the latest
end

Expand All @@ -22,15 +23,15 @@ def provider_name
end

def provider_name_url
hal_browser_url(pacticipant_url_from_params(pacticipant_name: provider_name))
hal_browser_url(pacticipant_url_from_params({ pacticipant_name: provider_name }, base_url), base_url)
end

def consumer_name
@line.consumer_name
end

def consumer_name_url
hal_browser_url(pacticipant_url_from_params(pacticipant_name: consumer_name))
hal_browser_url(pacticipant_url_from_params({ pacticipant_name: consumer_name }, base_url), base_url)
end

def pact_version_sha
Expand Down Expand Up @@ -68,7 +69,7 @@ def display_consumer_version_number

def consumer_version_number_url
params = { pacticipant_name: consumer_name, version_number: consumer_version_number }
hal_browser_url(version_url_from_params(params))
hal_browser_url(version_url_from_params(params, base_url), base_url)
end

def consumer_version_order
Expand All @@ -85,7 +86,7 @@ def display_provider_version_number

def provider_version_number_url
params = { pacticipant_name: provider_name, version_number: provider_version_number }
hal_browser_url(version_url_from_params(params))
hal_browser_url(version_url_from_params(params, base_url), base_url)
end

def provider_version_order
Expand Down Expand Up @@ -142,15 +143,15 @@ def verification_status
end

def verification_status_url
hal_browser_url(verification_url(self))
hal_browser_url(verification_url(self, base_url), base_url)
end

def pact_publication_date
relative_date(@line.pact_created_at)
end

def pact_publication_date_url
pact_url('', @line)
pact_url(base_url, @line)
end

def relative_date date
Expand Down Expand Up @@ -182,6 +183,10 @@ def pre_verified_message
message("messages.matrix.pre_verified")
end
end

def base_url
@options[:base_url]
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/ui/view_models/matrix_lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module UI
module ViewDomain
class MatrixLines < Array

def initialize rows
def initialize rows, options = {}
lines = rows.collect do | row |
PactBroker::UI::ViewDomain::MatrixLine.new(row)
PactBroker::UI::ViewDomain::MatrixLine.new(row, options)
end
super(lines.sort)
end
Expand Down
6 changes: 3 additions & 3 deletions lib/pact_broker/ui/views/groups/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<head>
<meta charset="utf-8">
<title>Network Graph</title>
<link rel='shortcut icon' href='/favicon.ico' type='image/x-icon'/>
<link rel='shortcut icon' href='<%= base_url %>/favicon.ico' type='image/x-icon'/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="Duncan Alexander">
<script type="text/javascript" src="/javascripts/d3.v3.js.pagespeed.ce.dFNRrGTALe.js"></script>
<script type="text/javascript" src="<%= base_url %>/javascripts/d3.v3.js.pagespeed.ce.dFNRrGTALe.js"></script>
<style>
body{
font-family:"Helvetica Neue",Arial,sans-serif;
Expand Down Expand Up @@ -105,7 +105,7 @@ var relationshipPath = function(relationship, nodeLocations, pacticipants) {

var latestPactUrl = function (consumerName, providerName) {
//TODO send this with the relationship data
return '/pacts/provider/' + providerName + '/consumer/' + consumerName + '/latest';
return '<%= base_url %>/pacts/provider/' + providerName + '/consumer/' + consumerName + '/latest';
};

var relationshipData = function(pacticipant, relationships) {
Expand Down
Loading

0 comments on commit dc48049

Please sign in to comment.