wireframe / multitenant

making cross tenant data leaks a thing of the past.
http://blog.codecrate.com/2011/03/multitenant-locking-down-your-app-and.html
MIT License
164 stars 36 forks source link

Build Status

Multitenant

When building multitenant applications, never let an unscoped Model.all accidentally leak data to an unintended audience.

Usage

class User < ActiveRecord::Base
  belongs_to :tenant
  belongs_to_multitenant

  validates :email, uniqueness: true                    # application-wide uniqueness
  validates :alias, uniqueness: { scope: :tenant_id }   # tenant-wide uniqueness
end

Multitenant.with_tenant current_tenant do
  # queries within this block are automatically
  # scoped to the current tenant
  User.all

  # new objects created within this block are automatically
  # assigned to the current tenant
  User.create :name => 'Bob'
end

Features

Contributing

Credits

Thanks to Lars Klevan for inspiring this project.

Copyright

Copyright (c) 2011 Ryan Sonnek. See LICENSE.txt for further details.