New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

account_scopper

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

account_scopper

  • 0.2.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= Account Scopper

Account Scopper aims to make conversion from a single account to multi-accounts application as easy as possible.

Simply set your current_account before each request and the scoping will be done on it's own.

== Install

If new to gemcutter first run

sudo gem install gemcutter sudo gemcutter tumble

Then run

sudo gem install account_scopper

If using rails, in your config/environment.rb

config.gem 'account_scopper'

== Usage

To convert your application, you will need to make few changes :

  1. Create an Account model and Accounts table
  2. Add account_id to your existing models (except Account of course)
  3. Define relationship between Account and other models
  4. Add the class variable "current_account" to the model Account
  5. Initialize Account.current_account before every request (eg: app/controllers/application.rb)

eg:

app/model/account.rb

class Account < ActiveRecord::Base cattr_accessor :current_account

has_many :users

end

app/model/user.rb

class User < ActiveRecord::Base
belongs_to :account end

app/controllers/application.rb

class ApplicationController < ActionController::Base before_filter :set_current_account # ...

private
  # Don't forget that @current_account should be properly setup to be an Account object
  # for this purpose you can use the plugin AccountLocation from David Heinemeier Hansson
  def set_current_account
    Account.current_account = @current_account
  end

end

== What it does

The plugin overwrite few methods from ActiveRecord::Base

To have a better understanding of what it does, the best way is still to look at the code itself and the tests.

== Helpers

As account_scopper scopes all database requests, validates_uniqueness_of will also scope to the current account.

In some cases, you may like to make sure that somethings remain unique to your whole system.

(eg: the user login or email if logging in from a common page for all accounts)

For this purpose, you can use validates_global_uniqueness_of. This validations will make sure your attribute is unique over all accounts.

== Warning

If using manually generated database requests like find_by_sql, ... you'll have to do your own scoping

== Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

== Copyright

Copyright (c) 2009 Sebastien Grosjean. See LICENSE for details.

FAQs

Package last updated on 17 Nov 2009

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc