Scoping a finder to the current_user is useful in most instances, but does not account for a user being an administrator and having access to objects to which it is not directly associated.
Create a named scope within the model to restrict the selection to records owned by the user or any if the specified user is an administrator. The User model must implement a method called "is_admin?" that returns true if the User is considered an admin.
This way you can call:
my_widgets = Widget.accessible_by(user).find(:all, :conditions => ["created_at > ?", 1.day.ago.to_s(:db)])
class Widget
named_scope :accessible_by, lambda {|u|
conditions = nil
unless u.is_admin?
conditions = ["widgets.user_id = :user_id", {:user_id => u.id}]
end
return {:conditions => conditions}
}
end