diff --git a/app/models/tenant.rb b/app/models/tenant.rb index b1221dd54f15..4451fd6124ac 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -90,8 +90,16 @@ def all_subprojects self.class.descendants_of(self).where(:divisible => false) end + def regional_tenants + self.class.regional_tenants(self) + end + + def self.regional_tenants(tenant) + where(arel_table.grouping(arel_attribute(:name).eq(tenant.name))) + end + def accessible_tenant_ids(strategy = nil) - (strategy ? send(strategy) : []).append(id) + (strategy ? regional_tenants.map(&strategy.to_sym).flatten : []) + regional_tenants.ids end def name