-
Notifications
You must be signed in to change notification settings - Fork 0
restricts access to activerecord data
License
struds/acts_as_restricted
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
ActsAsRestricted ================ Restrict read/write access to your active record classes via named scope so you can use your models exactly as normal but add a restricted method/filter: Message.restricted.find(:all) and all instantiated objects from the find should be tainted as restricted objects so you can also restrict writes to that data. Preamble ======== TODO ==== Need to add restricted writes back in on instantiated restricted objects, this was lost after a rewrite to move to named_scope since rails 2.1 Example ======= install plugin add the following line to your class: acts_as_restricted :read => true, :write => true the options instruct whether to restrict access to read or write, by default both are set to true. Also by default acts_as_restricted will restrict all access. you can set specific conditions for reading and writing in the class by optionally adding these functions: this example is from my project currently using the plugin and restricts read/write access to messages and received messages. acts_as_restricted :read => true, :write => true todo: restricted writes to be added back in.. def self.restricted_condition if current_user "sender_uid = #{current_user.id} or message_recipients.recipient_uid = #{current_user.id}" else ActsAsRestricted::SQL_NO_ACCESS # actually this is just "0" end end def self.restricted_join "LEFT OUTER JOIN message_recipients ON message_recipients.message_id = messages.id" end def self.restricted_select "messages.*" end Both default_condition and default_join allow you to add conditions or joins to finders with scope and keep all existing joins etc intact. the current_user function is also made available and grabs from the current thread:Thread.current['user'] the plugin allows you to limit data retrieved, you completely restrict, or return subsets of data. You can also control writes to data (including create) Examples ======== >> Thread.current['user'] = User.find_by_id(1) Copyright (c) 2008 [Stephen Strudwick], released under the MIT license
About
restricts access to activerecord data
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published