<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;p&gt;copied from &lt;a href=&quot;http://code.google.com/p/rolerequirement/&quot;&gt;Google Code&lt;/a&gt;&lt;br /&gt;
h2. Summary&lt;/p&gt;
&lt;p&gt;RoleRequirement focuses on a simple approach to role-based authentication. You don&amp;#8217;t have to learn a new language in order to specify roles; instead, RoleRequirement leverages the power of !Ruby to strike a marvelous balance between simplicity and flexibility.&lt;/p&gt;
&lt;p&gt;Features:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;A user can have many roles or one role&lt;/li&gt;
	&lt;li&gt;Full test helpers to make it easy to test your controllers. (&lt;a href=&quot;http://code.google.com/p/rolerequirement/wiki/TestingRoleRequirement&quot;&gt;examples here&lt;/a&gt;)&lt;/li&gt;
	&lt;li&gt;Squeaky clean implementation &amp;#8211; don&amp;#8217;t repeat yourself!&lt;/li&gt;
	&lt;li&gt;Code generators: spend more time coding and less time wading through installation instructions.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Usage&lt;/h2&gt;
&lt;p&gt;Steps to using as easy as 1, 1.5, 2, 3!&lt;/p&gt;
&lt;h3&gt;1. Install restful_authentication and role_requirement&lt;/h3&gt;
&lt;p&gt;Install restful_authentication as usual, running your usual &amp;#8216;script/generate authenticated user sessions&amp;#8217;.&lt;/p&gt;
script/plugin install git://github.com/technoweenie/restful-authentication.git
script/generate authenticated user sessions
&lt;p&gt;To install role_requirement:&lt;/p&gt;
script/plugin install git://github.com/timcharper/role_requirement.git
&lt;h3&gt;2. Run the generator&lt;/h3&gt;
script/generate roles Role User
&lt;p&gt;(where User is the name of your user model, and Role is the name of the roles model to create.)&lt;/p&gt;
&lt;p&gt;Note: You&amp;#8217;ll need to run rake db:migrate to actually modify the database&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://code.google.com/p/rolerequirement/wiki/WhatTheGeneratorsDo&quot;&gt;click here for a list of what the generators do&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;3. Define your role requirements in your controllers&lt;/h3&gt;
&lt;p&gt;Only allow administrators to access Users here.&lt;/p&gt;
class Admin::Users &amp;lt; ApplicationController
require_role &amp;#8220;admin&amp;#8221;
&amp;#8230;
end
&lt;p&gt;Require contractor role for everything, and then require admin role to destroy, and only let contractors access listings they have access to:&lt;/p&gt;
class Admin::Listings &amp;lt; ApplicationController
require_role &amp;#8220;contractor&amp;#8221;
require_role &amp;#8220;admin&amp;#8221;, :for =&amp;gt; :destroy # don&amp;#8217;t allow contractors to destroy
&lt;ol&gt;
	&lt;li&gt;leverage ruby to prevent contractors from updating listings they don&amp;#8217;t have access to.&lt;br /&gt;
    require_role &amp;#8220;admin&amp;#8221;, :for =&amp;gt; :update, :unless =&amp;gt; &amp;quot;current_user.authorized_for_listing?(params[:id]) &amp;quot;&lt;br /&gt;
    &amp;#8230;&lt;br /&gt;
  end&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Other examples:&lt;/p&gt;
&lt;p&gt;allow everyone to access index, but only admin can access the rest&lt;/p&gt;
require_role &amp;#8220;admin&amp;#8221;, :for_all_except =&amp;gt; :index
&lt;p&gt;allow everyone to access show and index, but only admin can access the rest&lt;/p&gt;
require_role &amp;#8220;admin&amp;#8221;, :for_all_except =&amp;gt; [:index, :show]
&lt;p&gt;Help&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s how to get help&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Browse the Documentation&lt;/li&gt;
	&lt;li&gt;Install the plugin, generate the rdoc&amp;#8217;s, and browse from there.&lt;/li&gt;
	&lt;li&gt;post an issue to the issue tracker&lt;/li&gt;
	&lt;li&gt;Fire off a message to the mailing list&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Author&lt;/p&gt;
Tim C. Harper &amp;#8211; irb(main):001:0&amp;gt; ( &amp;#8216;tim_see_harperATgmail._see_om&amp;#8217;.gsub(&amp;#8216;&lt;em&gt;see&lt;/em&gt;&amp;#8217;, &amp;#8216;c&amp;#8217;).gsub(&amp;#8216;AT&amp;#8217;, &amp;#8216;@&amp;#8217;) )</body>
  <created-at type="datetime">2008-10-11T12:58:42-07:00</created-at>
  <id type="integer">66056</id>
  <permalink>usage</permalink>
  <repository-id type="integer">24558</repository-id>
  <title>Usage</title>
  <updated-at type="datetime">2008-10-11T13:36:51-07:00</updated-at>
  <user-id type="integer">25921</user-id>
</wiki>
