Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

expanded README.rdoc

  • Loading branch information...
commit 1b04f3d54520dd65385e9a1badb6141da564b9ef 1 parent dc77c27
makandra authored
View
3  .gitignore
@@ -0,0 +1,3 @@
+doc
+pkg
+*.gem
View
32 README
@@ -1,32 +0,0 @@
-Aegis
-=====
-
-
-Example
-=======
-
-class Permissions < Aegis::Permissions
-
- role :moderator
- role :guest
- role :administrator, :default_permission => :allow
-
- permission :edit_user do
- allow :moderator
- deny :guest
- allow :moderator do |role_user, target_user|
- role_user == target_user.creator
- end
- end
-
- permission :edit_users do
- allow :moderator
- end
-
-end
-
-
-Credits
-=======
-
-Copyright (c) 2009 Henning Koch, released under the MIT license
View
67 README.rdoc
@@ -0,0 +1,67 @@
+= Aegis - role-based permissions for your user models
+
+Aegis allows you to managed fine-grained and complex permission for user accounts in a central place.
+
+=== Example
+
+First, let's define some roles:
+
+ # app/models/permissions.rb
+ class Permissions < Aegis::Permissions
+
+ role :moderator
+ role :registered_user
+ role :guest
+ role :administrator, :default_permission => :allow
+
+ permission :edit_post do |user, post|
+ allow registered_user do
+ post.creator == user # a registered_user can only edit his own posts
+ end
+ allow :moderator
+ end
+
+ permission :read_post do |post|
+ allow :everyone
+ deny :guest do
+ post.private? # guests may not read private posts
+ end
+ end
+
+ end
+
+
+Now we assign roles to users. For this, the users table needs to have a string foo
+column 'role_name'.
+
+ # app/models/user.rb
+ class User
+ has_role
+ end
+
+
+These permissions may be used in views and controllers:
+
+ # app/views/posts/index.html.erb
+ @posts.each do |post|
+ <% if current_user.may_read_post? post %>
+ <%= render post %>
+ <% if current_user.may_edit_post? post %>
+ <%= link_to 'Edit', edit_post_path(post) %>
+ <% end %>
+ <% end %>
+ <% end %>
+
+
+ # app/controllers/posts_controller.rb
+ class PostsController
+ # ...
+
+ def update
+ @post = Post.find(params[:id])
+ current_user.may_edit_post! @post
+
+ # ...
+ end
+
+ end
View
8 aegis.gemspec
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = %q{aegis}
- s.version = "0.0.0"
+ s.version = "0.0.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Henning Koch"]
@@ -17,13 +17,17 @@ Gem::Specification.new do |s|
"README",
"Rakefile",
"VERSION",
- "init.rb",
+ "aegis.gemspec",
+ "lib/aegis.rb",
+ "lib/aegis/constants.rb",
"lib/aegis/has_role.rb",
"lib/aegis/normalization.rb",
"lib/aegis/permission_error.rb",
+ "lib/aegis/permission_evaluator.rb",
"lib/aegis/permissions.rb",
"lib/aegis/role.rb",
"lib/rails/active_record.rb",
+ "pkg/aegis-0.0.0.gem",
"test/app_root/app/controllers/application_controller.rb",
"test/app_root/app/models/permissions.rb",
"test/app_root/app/models/soldier.rb",
View
1  test/app_root/log/.gitignore
@@ -0,0 +1 @@
+*.log
Please sign in to comment.
Something went wrong with that request. Please try again.