From b4c64c8e6ded3f4516a82678ad9010d294ce2caf Mon Sep 17 00:00:00 2001 From: Kartones Date: Tue, 31 Mar 2015 16:20:27 +0200 Subject: [PATCH] #1693 Improvements based on CR --- app/controllers/admin/pages_controller.rb | 6 +++--- .../admin/visualizations_controller.rb | 16 +++++++++++++--- config/initializers/carto_db.rb | 13 ------------- spec/lib/initializers/carto_db_spec.rb | 14 ++++++++++++++ .../api/json/oembed_controller_spec.rb | 14 ++++++++++++++ 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index 238d37b8d1f9..fa0f72abd0ce 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -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] @@ -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) diff --git a/app/controllers/admin/visualizations_controller.rb b/app/controllers/admin/visualizations_controller.rb index 7ca51994d6a1..81b3e7f135f8 100644 --- a/app/controllers/admin/visualizations_controller.rb +++ b/app/controllers/admin/visualizations_controller.rb @@ -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 @@ -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" diff --git a/config/initializers/carto_db.rb b/config/initializers/carto_db.rb index aec13f5cc6c5..0c0c46967c31 100644 --- a/config/initializers/carto_db.rb +++ b/config/initializers/carto_db.rb @@ -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 diff --git a/spec/lib/initializers/carto_db_spec.rb b/spec/lib/initializers/carto_db_spec.rb index d40b8b60a7ce..8aee3c0cd181 100644 --- a/spec/lib/initializers/carto_db_spec.rb +++ b/spec/lib/initializers/carto_db_spec.rb @@ -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 diff --git a/spec/unit/controllers/api/json/oembed_controller_spec.rb b/spec/unit/controllers/api/json/oembed_controller_spec.rb index e5d238458904..4905c0b6dac1 100644 --- a/spec/unit/controllers/api/json/oembed_controller_spec.rb +++ b/spec/unit/controllers/api/json/oembed_controller_spec.rb @@ -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