27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

This chapter covers<br />

� Expanding with a more advanced system<br />

� Setting permissions to control user actions<br />

� Implementing a seed of data for the app<br />

More authorization<br />

At the end of chapter 7, you learned a basic form of authorization based on a boolean<br />

field on the users table called admin. If this field is set to true, identifying<br />

admin users, those users can access the CRUD functions of the Project resource as<br />

well as an admin namespace where they can perform CRUD on the User resource.<br />

In this chapter, we expand on authorization options by implementing a broader<br />

authorization system using a Permission model. The records for this model’s table<br />

define the actions specified users can take on objects from your system, such as<br />

projects. Each record tracks the user who has a specific permission, the object to<br />

which the permission applies, and the type of permission granted.<br />

The authorization implemented in this chapter is whitelist authorization. Under<br />

whitelist authorization, all users are denied access to everything by default, and you<br />

must specify what the user can do. The opposite is blacklist authorization, under<br />

which all users are allowed access to everything by default and you must block what<br />

they may not access. You use whitelist authorization for your application because<br />

164

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!