From 7fe64862c830bb091d367fcee12f16c5bef550d8 Mon Sep 17 00:00:00 2001 From: JOSE HERIBERTO Date: Wed, 22 Jun 2016 10:42:24 -0500 Subject: [PATCH] Allows tenant changes to resources by setting option. In case you want to ignore tenant changes to specific models you just need to use the option: ``` ignore_tenant_changes: true ``` For example: ``` acts_as_tenant :tenant, ignore_tenant_changes: true ``` --- lib/acts_as_tenant/model_extensions.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/acts_as_tenant/model_extensions.rb b/lib/acts_as_tenant/model_extensions.rb index 1ab36ca..984a74c 100644 --- a/lib/acts_as_tenant/model_extensions.rb +++ b/lib/acts_as_tenant/model_extensions.rb @@ -129,13 +129,15 @@ def acts_as_tenant(tenant = :account, options = {}) to_include = Module.new do define_method "#{fkey}=" do |integer| write_attribute("#{fkey}", integer) - raise ActsAsTenant::Errors::TenantIsImmutable if send("#{fkey}_changed?") && persisted? && !send("#{fkey}_was").nil? + # if the ignore_tenant_changes option is present and true we'll avoid the exception because maybe an admin is making the update + raise ActsAsTenant::Errors::TenantIsImmutable if send("#{fkey}_changed?") && persisted? && !send("#{fkey}_was").nil? && !options[:ignore_tenant_changes] integer end define_method "#{ActsAsTenant.tenant_klass.to_s}=" do |model| super(model) - raise ActsAsTenant::Errors::TenantIsImmutable if send("#{fkey}_changed?") && persisted? && !send("#{fkey}_was").nil? + # if the ignore_tenant_changes option is present and true we'll avoid the exception because maybe an admin is making the update + raise ActsAsTenant::Errors::TenantIsImmutable if send("#{fkey}_changed?") && persisted? && !send("#{fkey}_was").nil? && !options[:ignore_tenant_changes] model end