Permalink
Browse files

corrected role -> persona

  • Loading branch information...
1 parent d7ff191 commit 3630ec72682bbdc1871aaa3b1b75ad0a16a63ae6 @benwyrosdick benwyrosdick committed May 5, 2009
@@ -2,8 +2,9 @@ class AllowanceGenerator < Rails::Generator::Base
def manifest
record do |m|
m.migration_template "migrate/add_allowance.rb", "db/migrate",
- :migration_name => "AddAllowance#{args.map{|a| a.classify}.join('')}",
:migration_file_name => "add_allowance_#{args.map{|a| a.underscore}.join('_')}"
+
+ m.readme 'INSTALL'
end
end
end
@@ -0,0 +1,5 @@
+== Installation
+
+Finished adding the allowance(s). There are still a few things you have to do.
+
+ * rake db:migrate
@@ -4,15 +4,12 @@ def manifest
# Models
m.file "models/allowance.rb", "app/models/allowance.rb"
- m.file "models/role.rb", "app/models/role.rb"
+ m.file "models/persona.rb", "app/models/persona.rb"
+ m.file "models/user_persona.rb", "app/models/user_persona.rb"
- m.migration_template "migrate/create_fences.rb", "db/migrate"
+ m.migration_template "migrate/create_fences.rb", "db/migrate", :migration_file_name => 'create_fences'
m.readme "INSTALL"
end
end
-
- def file_name
- "create_fences"
- end
end
@@ -1,5 +1,7 @@
== Installation
Finished generating the basic user authorization system. There are still a few things you have to do.
-
- ./script/generate allowance ALLOWANCE [, ALLOWANCES]
+
+ * rake db:migrate
+ * add 'fencable' to your user model
+ * ./script/generate allowance ALLOWANCE [, ALLOWANCES]
@@ -8,24 +8,23 @@ def self.up
t.timestamps
end
- create_table :roles, :force => true do |t|
- t.string :name, :limit => 40
- t.string :authorizable_type
- t.integer :authorizable_id
+ create_table :personas do |t|
+ t.string :name
t.timestamps
end
- create_table :roles_users, :id => false, :force => true do |t|
- t.integer :role_id, :user_id
+ create_table :user_personas do |t|
+ t.integer :user_id
+ t.integer :persona_id
t.timestamps
end
end
def self.down
- drop_table :roles_users
- drop_table :roles
+ drop_table :user_personas
+ drop_table :personas
drop_table :allowances
end
end
@@ -0,0 +1,11 @@
+class Persona < ActiveRecord::Base
+ has_many :user_personas, :dependent => :delete_all
+ has_many :users, :through => :user_personas
+
+ has_one :allowance, :as => :allowable
+
+ validates_presence_of :name, :allowance
+ validates_uniqueness_of :name
+
+ attr_protected :allowance
+end
@@ -1,8 +0,0 @@
-# Defines named roles for users that may be applied to
-# objects in a polymorphic fashion. For example, you could create a role
-# "moderator" for an instance of a model (i.e., an object), a model class,
-# or without any specification at all.
-class Role < ActiveRecord::Base
- has_and_belongs_to_many :users
- belongs_to :authorizable, :polymorphic => true
-end
@@ -0,0 +1,4 @@
+class UserPersona < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :persona
+end
View
@@ -28,7 +28,7 @@ def allow(*args, &block)
module ControllerInstanceMethods
def allow(allowances, additional_condition)
- unless (allowances.include?(:all) or current_user.is_allowed_to?(allowances)) and additional_condition
+ unless (allowances.include?(:all) or (current_user and current_user.is_allowed_to?(allowances))) and additional_condition
respond_to do |format|
format.html do
flash[:notice] = "Permission denied."
@@ -45,7 +45,7 @@ def allow(allowances, additional_condition)
module ViewInstanceMethods
def allow(*allowances)
- if block_given? and current_user.is_allowed_to? allowances
+ if block_given? and current_user and current_user.is_allowed_to? allowances
yield
end
end

0 comments on commit 3630ec7

Please sign in to comment.