Skip to content

How to use permissions

Sameer Rahmani edited this page Jun 13, 2014 · 4 revisions

In this article you will learn how to use Faalis permissions. The Faalis permissions are really simple and most of the time you don't need to be worry about them.

Faalis Permissions

Faalis contains a full fledged users permission system using cancan gem. Faalis adds read, update, create, destroy permissions to objects you choose and authorize users access to that object by cancan gem. Of course you can edit these default permissions of add others too.

Faalis subsystems are aware of permissions and authorize user access to any object you specified.

Faalis implemented a Rails concern which adds supports for permissions to a model or any class which you want to use permissions for it. For example:

class Person < ActiveRecord::Base
  include Faalis::Permissions
  # rest of your model
end

Note: It previous versions of Faalis <= 0.26.3, Faalis::Permissions automatically included in any ActiveRecord::Base. But since it wasn't a good idea we fixed it.

Now take a look at a Mongoid example:

class Person
  include Mongoid::Document
  include Faalis::Permissions
end

As you can see we just added Faalis::Permissions to a simple class.

User & Group

Faalis::User is the user model which has a many to many relation with Faalis::Group (Note: If your using Mongoid or any other non-relational mappers, then you should know that Faalis::User embeds many Faalis::Group)

Each Faalis::Group has many (embeds many) permissions and Faalis authorize user access by groups which user is member of.

Change permissions

TODO

Objects permissions

In your application you may come to a situation which you need to apply permissions on an object, a non-model object (For example if you need to add a non-model dashboard module to dashboard). In this case you just need to include Faalis::Permissions in your class and add your class to models_with_permission variable in config/initializers/faalis.rb like:

config.models_with_permission = ["Faalis::Permissions::Auth",
                                 "Permissions::Others",
                                 "Permissions::Places"]