diff --git a/app/models/machine_learning.rb b/app/models/machine_learning.rb index 0b680e212..a9504c0a4 100644 --- a/app/models/machine_learning.rb +++ b/app/models/machine_learning.rb @@ -89,15 +89,7 @@ class MachineLearning end def tenant_data_folder - File.join(tenant_subfolder, "machine_learning", "data").delete_prefix("/") - end - - def tenant_subfolder - if Tenant.default? - "" - else - File.join("tenants", Tenant.current_schema) - end + Tenant.path_with_subfolder("machine_learning/data") end def data_output_files diff --git a/app/models/tenant.rb b/app/models/tenant.rb index dbe00b335..45d9e2373 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -71,6 +71,18 @@ class Tenant < ApplicationRecord end end + def self.subfolder_path + if default? + "" + else + File.join("tenants", current_schema) + end + end + + def self.path_with_subfolder(filename_or_folder) + File.join(subfolder_path, filename_or_folder).delete_prefix("/") + end + def self.default? current_schema == "public" end diff --git a/app/views/robots/index.text.erb b/app/views/robots/index.text.erb index 8a432d78d..29c1e6ce3 100644 --- a/app/views/robots/index.text.erb +++ b/app/views/robots/index.text.erb @@ -14,8 +14,4 @@ Disallow: /*?*locale-switcher Disallow: /*?*filter Disallow: user_id -<% if Tenant.default? %> -Sitemap: <%= "#{root_url}sitemap.xml" %> -<% else %> -Sitemap: <%= "#{root_url}tenants/#{Tenant.current_schema}/sitemap.xml" %> -<% end %> +Sitemap: <%= "#{root_url}#{Tenant.path_with_subfolder("sitemap.xml")}" %> diff --git a/config/sitemap.rb b/config/sitemap.rb index 31f973f2b..ecf4378f3 100644 --- a/config/sitemap.rb +++ b/config/sitemap.rb @@ -10,12 +10,7 @@ SitemapGenerator::Sitemap.verbose = false if Rails.env.test? Tenant.run_on_each do SitemapGenerator::Sitemap.default_host = root_url(Tenant.current_url_options) - - if Tenant.default? - SitemapGenerator::Sitemap.sitemaps_path = nil - else - SitemapGenerator::Sitemap.sitemaps_path = "tenants/#{Tenant.current_schema}" - end + SitemapGenerator::Sitemap.sitemaps_path = Tenant.subfolder_path SitemapGenerator::Sitemap.create do add help_path diff --git a/lib/active_storage/service/tenant_disk_service.rb b/lib/active_storage/service/tenant_disk_service.rb index 63414f295..836983d03 100644 --- a/lib/active_storage/service/tenant_disk_service.rb +++ b/lib/active_storage/service/tenant_disk_service.rb @@ -6,7 +6,7 @@ module ActiveStorage if Tenant.default? super else - super.sub(root, File.join(root, "tenants", Tenant.current_schema)) + super.sub(root, File.join(root, Tenant.subfolder_path)) end end end diff --git a/spec/models/attachable_spec.rb b/spec/models/attachable_spec.rb index 32b208bc8..2cb13825b 100644 --- a/spec/models/attachable_spec.rb +++ b/spec/models/attachable_spec.rb @@ -5,6 +5,7 @@ describe Attachable do file_path = build(:image).file_path expect(file_path).to include "storage/" + expect(file_path).not_to include "storage//" expect(file_path).not_to include "tenants" end