Skip to content

Commit

Permalink
#1693 Improvements based on CR
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartones committed Mar 31, 2015
1 parent c2eb230 commit b4c64c8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
6 changes: 3 additions & 3 deletions app/controllers/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class Admin::PagesController < ApplicationController
NEW_DATASETS_PER_PAGE = 20
MAPS_PER_PAGE = 9
USER_TAGS_LIMIT = 100
PAGE_NUMBER_PLACEHOLDER = '-666'
PAGE_NUMBER_PLACEHOLDER = 'PAGENUMBERPLACEHOLDER'

ssl_required :common_data, :public, :datasets

before_filter :login_required, :except => [:public, :datasets, :sitemap, :index]
before_filter :belongs_to_organization
before_filter :ensure_organization_correct
skip_before_filter :browser_is_html5_compliant?, only: [:public, :datasets]
skip_before_filter :ensure_user_organization_valid, only: [:public]

Expand Down Expand Up @@ -406,7 +406,7 @@ def tag_or_nil
params[:tag]
end

def belongs_to_organization
def ensure_organization_correct
return if CartoDB.subdomainless_urls?

user_or_org_domain = CartoDB.subdomain_from_request(request)
Expand Down
16 changes: 13 additions & 3 deletions app/controllers/admin/visualizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ def public_table

# Legacy redirect, now all public pages also with org. name
if eligible_for_redirect?(@visualization.user)
redirect_to CartoDB.url(self, 'public_table', { id: "#{params[:id]}", redirected:true }, @visualization.user) and return
redirect_to CartoDB.url(self,
'public_table',
{ id: "#{params[:id]}", redirected:true },
@visualization.user
) and return
end

@vizjson = @visualization.to_vizjson
Expand Down Expand Up @@ -192,8 +196,14 @@ def public_map

# Legacy redirect, now all public pages also with org. name
if eligible_for_redirect?(@visualization.user)
redirect to CartoDB.url(self, 'public_visualizations_public_map', {
id: "#{@visualization.user.organization.name}.#{params[:id]}", redirected:true }, @visualization.user) and return
redirect to CartoDB.url(self,
'public_visualizations_public_map',
{
id: "#{@visualization.user.organization.name}.#{params[:id]}",
redirected:true
},
@visualization.user
) and return
end

response.headers['X-Cache-Channel'] = "#{@visualization.varnish_key}:vizjson"
Expand Down
13 changes: 0 additions & 13 deletions config/initializers/carto_db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,6 @@ def self.base_url(subdomain, org_username=nil, protocol_override=nil)
base_url
end

# NOTE: Not intended for usage outside testing (where is needed to clean state between tests)
def self.clear_internal_cache
remove_class_variable(:@@request_host) if defined?(@@request_host)
remove_class_variable(:@@hostname) if defined?(@@hostname)
remove_class_variable(:@@http_port) if defined?(@@http_port)
remove_class_variable(:@@https_port) if defined?(@@http_ports)
remove_class_variable(:@@session_domain) if defined?(@@session_domain)
remove_class_variable(:@@domain) if defined?(@@domain)
remove_class_variable(:@@subdomainless_urls) if defined?(@@subdomainless_urls)
remove_class_variable(:@@account_host) if defined?(@@account_host)
remove_class_variable(:@@account_path) if defined?(@@account_path)
end

# Note: use ||= only for fields who always have a non-nil, non-false value
# else, rely on defined? and pure assignment to allow nils and values caching the value

Expand Down
14 changes: 14 additions & 0 deletions spec/lib/initializers/carto_db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
require_relative '../../spec_helper'
require_relative '../../../spec/doubles/request'

module CartoDB
def self.clear_internal_cache
remove_class_variable(:@@request_host) if defined?(@@request_host)
remove_class_variable(:@@hostname) if defined?(@@hostname)
remove_class_variable(:@@http_port) if defined?(@@http_port)
remove_class_variable(:@@https_port) if defined?(@@http_ports)
remove_class_variable(:@@session_domain) if defined?(@@session_domain)
remove_class_variable(:@@domain) if defined?(@@domain)
remove_class_variable(:@@subdomainless_urls) if defined?(@@subdomainless_urls)
remove_class_variable(:@@account_host) if defined?(@@account_host)
remove_class_variable(:@@account_path) if defined?(@@account_path)
end
end

describe CartoDB do
after(:each) do
CartoDB.clear_internal_cache
Expand Down
14 changes: 14 additions & 0 deletions spec/unit/controllers/api/json/oembed_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

require_relative '../../../../spec_helper'

module CartoDB
def self.clear_internal_cache
remove_class_variable(:@@request_host) if defined?(@@request_host)
remove_class_variable(:@@hostname) if defined?(@@hostname)
remove_class_variable(:@@http_port) if defined?(@@http_port)
remove_class_variable(:@@https_port) if defined?(@@http_ports)
remove_class_variable(:@@session_domain) if defined?(@@session_domain)
remove_class_variable(:@@domain) if defined?(@@domain)
remove_class_variable(:@@subdomainless_urls) if defined?(@@subdomainless_urls)
remove_class_variable(:@@account_host) if defined?(@@account_host)
remove_class_variable(:@@account_path) if defined?(@@account_path)
end
end

describe Api::Json::OembedController do

after(:each) do
Expand Down

0 comments on commit b4c64c8

Please sign in to comment.