Module: Trust::ActiveModel
- Extended by:
- ActiveSupport::Concern
- Included in:
- ActiveRecord::Base, Mongoid::Document
- Defined in:
- lib/trust/active_model.rb
Overview
Trust::ActiveModel extension
Extends ActiveRecord with the permits?
and ensure_permitted!
method on class and instances If using Mongoid same features are included there
Options:
-
:parent
- Specifies that the persmision should be tested in the context of a parent -
:by
- Specifies an actor to be used instead of the currently logged in user
Examples
# If current user is permitted to create customers, create it
if Customer.permits? :create
Customer.create attributes
end
# If current user is permitted to create accounts for the given customer, create it
if Account.permits? :create, @customer
Account.create attributes
end
# If the specified actor is permitted to create accounts for the given customer, create it
if Account.permits? :create, @customer, :by => @actor
Account.create attributes
end
# Raise an exception if user is not permitted to update the given customer, else save it
@customer.ensure_permitted! :update
@customer.save
# Raise an exception if the specified user is not permitted to update the given customer, else save it
@customer.ensure_permitted! :update, :by => @actor
@customer.save
Defined Under Namespace
Modules: ClassMethods