forked from makandra/aegis
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
makandra
committed
May 29, 2009
1 parent
2c491ad
commit 3c6ea59
Showing
6 changed files
with
62 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Aegis | ||
module Constants | ||
EVERYONE_ROLE_NAME = :everyone | ||
CRUD_VERBS = ["create", "read", "update", "destroy"] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module Aegis | ||
class PermissionEvaluator | ||
|
||
def initialize(role) | ||
@role = role | ||
end | ||
|
||
def evaluate(permissions, rule_args) | ||
@result = @role.allow_by_default? | ||
permissions.each do |permission| | ||
instance_exec(*rule_args, &permission) | ||
end | ||
@result | ||
end | ||
|
||
def allow(*role_name_or_names, &block) | ||
rule_encountered(role_name_or_names, true, &block) | ||
end | ||
|
||
def deny(*role_name_or_names, &block) | ||
rule_encountered(role_name_or_names, false, &block) | ||
end | ||
|
||
def rule_encountered(role_name_or_names, is_allow, &block) | ||
role_names = Array(role_name_or_names) | ||
if role_names.include?(@role.name) || role_names.include?(Aegis::Constants::EVERYONE_ROLE_NAME) | ||
@result = (block ? block.call : true) | ||
@result = !@result unless is_allow | ||
end | ||
end | ||
|
||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Include hook code here | ||
require 'aegis/constants' | ||
require 'aegis/normalization' | ||
require 'aegis/permission_error' | ||
require 'aegis/role' | ||
require 'aegis/permissions' | ||
require 'aegis/has_role' | ||
require 'rails/active_record' | ||
|
Binary file not shown.