-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
234a17d
commit 25a850f
Showing
27 changed files
with
542 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
language: ruby | ||
rvm: | ||
- 2.0.0 | ||
- 2.5.3 | ||
services: | ||
- xvfb | ||
before_script: | ||
- "export DISPLAY=:99.0" | ||
- "sh -e /etc/init.d/xvfb start" | ||
- 'bundle exec rake test_app' | ||
script: 'bundle exec rspec spec' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
source 'http://rubygems.org' | ||
source 'https://rubygems.org' | ||
|
||
group :assets do | ||
gem 'therubyracer' | ||
git_source(:github) do |repo_name| | ||
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/') | ||
"https://github.com/#{repo_name}.git" | ||
end | ||
|
||
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-2-stable' | ||
gem 'spree_core', github: 'spree/spree', branch: 'master' | ||
gem 'spree_backend', github: 'spree/spree', branch: 'master' | ||
gem 'spree_frontend', github: 'spree/spree', branch: 'master' | ||
# Provides basic authentication functionality for testing parts of your engine | ||
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master' | ||
gem 'rails-controller-testing' | ||
|
||
gem 'sqlite3', '~> 1.4' | ||
|
||
gem 'rubocop', require: false | ||
gem 'rubocop-rspec', require: false | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module SpreeMultiTenant::BaseMailerDecorator | ||
if SpreeMultiTenant.configuration.use_tenanted_mailers | ||
def send_action(method_name, *args) | ||
tenant = Multitenant.current_tenant | ||
had_current_tenant = !tenant.nil? | ||
if !had_current_tenant && args.first # Attempt to get tenant from args.first | ||
if self.class == Spree::OrderMailer | ||
order = args.first.respond_to?(:id) ? args.first : Spree::Order.find(args.first) | ||
tenant = order.try(:tenant) | ||
elsif self.class == Spree::ReimbursementMailer | ||
reimbursement = args.first.respond_to?(:id) ? args.first : Spree::Reimbursement.find(args.first) | ||
tenant = reimbursement.try(:tenant) | ||
elsif self.class == Spree::ShipmentMailer | ||
shipment = args.first.respond_to?(:id) ? args.first : Spree::Shipment.find(args.first) | ||
tenant = shipment.try(:tenant) | ||
end | ||
end | ||
|
||
return super unless tenant | ||
|
||
# Add tenant views path | ||
path = "app/tenants/#{tenant.code}/views" | ||
prepend_view_path(path) | ||
|
||
if had_current_tenant | ||
super | ||
else | ||
# Execute ActiveRecord queries within the scope of the tenant | ||
SpreeMultiTenant.with_tenant tenant do | ||
super | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
mailer_classes = [ | ||
Spree::BaseMailer, | ||
] | ||
mailer_classes.each do |mailer_class| | ||
mailer_class.include(SpreeMultiTenant::BaseMailerDecorator) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,13 @@ | ||
class AddTenantToModels < ActiveRecord::Migration | ||
class AddTenantToModels < ActiveRecord::Migration[4.2] | ||
def change | ||
tables = [ | ||
"spree_addresses", | ||
"spree_adjustments", | ||
"spree_assets", | ||
"spree_calculators", | ||
"spree_configurations", | ||
"spree_countries", | ||
"spree_credit_cards", | ||
"spree_payment_methods", | ||
"spree_inventory_units", | ||
"spree_line_items", | ||
"spree_log_entries", | ||
"spree_option_types", | ||
"spree_option_values", | ||
"spree_orders", | ||
"spree_payments", | ||
"spree_preferences", | ||
"spree_product_option_types", | ||
"spree_product_properties", | ||
"spree_products", | ||
"spree_promotion_action_line_items", | ||
"spree_promotion_actions", | ||
"spree_promotion_rules", | ||
"spree_properties", | ||
"spree_prototypes", | ||
"spree_return_authorizations", | ||
"spree_roles", | ||
"spree_shipments", | ||
"spree_shipping_categories", | ||
"spree_shipping_methods", | ||
"spree_state_changes", | ||
"spree_states", | ||
"spree_tax_categories", | ||
"spree_tax_rates", | ||
"spree_taxonomies", | ||
"spree_taxons", | ||
"spree_tokenized_permissions", | ||
"spree_trackers", | ||
"spree_users", | ||
"spree_variants", | ||
"spree_zone_members", | ||
"spree_zones", | ||
] | ||
tables = SpreeMultiTenant.tenanted_models.map(&:table_name).uniq | ||
tables.each do |table| | ||
add_column table, :tenant_id, :integer | ||
add_column table, :tenant_id, :integer, default: 0 | ||
change_column table, :tenant_id, :integer, null: false | ||
change_column_default table, :tenant_id, nil | ||
add_index table, :tenant_id | ||
end | ||
SpreeMultiTenant.tenanted_models.each(&:reset_column_information) | ||
end | ||
end | ||
|
11 changes: 0 additions & 11 deletions
11
db/migrate/20120907152215_update_constraint_on_spree_preferences_key.rb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
db/migrate/20191126121901_update_unique_constraints_for_multitenant_on_spree_tables.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
class UpdateUniqueConstraintsForMultitenantOnSpreeTables < ActiveRecord::Migration[4.2] | ||
def change | ||
tables = { | ||
country: [{name: [:case_insensitive]}, {iso_name: [:case_insensitive]}, :iso, :iso3], | ||
customer_return: [:number], | ||
order: [:number], | ||
payment: [:number], | ||
preferences: [:key], | ||
product: [:slug], | ||
promotion: [{code: [:case_insensitive]}], | ||
refund_reason: [{name: [:case_insensitive]}], | ||
reimbursement: [:number], | ||
reimbursement_type: [{name: [:case_insensitive]}], | ||
return_authorization: [:number], | ||
return_authorization_reason: [{name: [:case_insensitive]}], | ||
role: [{name: [:case_insensitive]}], | ||
shipment: [:number], | ||
stock_transfer: [:number], | ||
store: [{code: [:case_insensitive]}], | ||
tag: [:name], | ||
user: [:email], | ||
} | ||
|
||
tables.each do |table, column_infos| | ||
table_class = "Spree::#{table.to_s.classify}".safe_constantize | ||
if table_class | ||
table_name = table_class.table_name | ||
|
||
column_infos.each do |column_info| | ||
column = column_info.is_a?(Symbol) ? column_info : column_info.keys.first | ||
column_options = column_info.is_a?(Symbol) ? [] : column_info.values.first | ||
is_case_insensitive = column_options.include?(:case_insensitive) && | ||
supports_expression_index? | ||
column_expression = is_case_insensitive ? "lower(#{column})" : column | ||
column_expression_for_index = is_case_insensitive ? "lower_#{column}" : column | ||
# When attempting to find the old index, might need to find by index_custom_name: | ||
index_custom_name = | ||
if table == :user # Special case | ||
'email_idx_unique' | ||
else # General case | ||
"index_#{table_name}_on_#{column_expression_for_index}" | ||
end | ||
|
||
if index_exists?(table_name, column, unique: true) | ||
remove_index table_name, column | ||
add_index table_name, column # change to NOT unique | ||
elsif index_name_exists?(table_name, index_custom_name) | ||
remove_index table_name, name: index_custom_name | ||
add_index table_name, column_expression # change to NOT unique | ||
end | ||
|
||
add_index table_name, | ||
"#{column_expression}, tenant_id", | ||
unique: true, | ||
name: index_custom_name + "_tenant" # Avoid "Index name is too long" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.