acts_as_authoritah 1.0.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +15 -3
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE +4 -2
- data/README.md +29 -0
- data/Rakefile +2 -56
- data/acts_as_authoritah.gemspec +15 -44
- data/lib/acts_as_authoritah.rb +15 -16
- data/lib/acts_as_authoritah/access_control_list.rb +32 -0
- data/lib/acts_as_authoritah/access_rule.rb +31 -0
- data/lib/acts_as_authoritah/core.rb +37 -0
- data/lib/acts_as_authoritah/identifier_parser.rb +28 -0
- data/lib/acts_as_authoritah/matchers/controller_matcher.rb +10 -0
- data/lib/acts_as_authoritah/matchers/direct_matcher.rb +9 -0
- data/lib/acts_as_authoritah/matchers/scope_matcher.rb +15 -0
- data/lib/acts_as_authoritah/spreadsheets/access_rights_mapper.rb +14 -0
- data/lib/acts_as_authoritah/spreadsheets/spreadsheet_header_parser.rb +9 -0
- data/lib/acts_as_authoritah/spreadsheets/spreadsheet_reader.rb +37 -0
- data/lib/acts_as_authoritah/spreadsheets/spreadsheet_row_parser.rb +23 -0
- data/lib/acts_as_authoritah/spreadsheets/spreadsheet_wrapper.rb +16 -0
- data/lib/acts_as_authoritah/version.rb +3 -0
- data/spec/acts_as_authoritah/access_control_list_spec.rb +78 -0
- data/spec/acts_as_authoritah/access_rule_spec.rb +39 -0
- data/spec/acts_as_authoritah/core_spec.rb +63 -0
- data/spec/acts_as_authoritah/identifier_parser_spec.rb +111 -0
- data/spec/acts_as_authoritah/matchers/controller_matcher_spec.rb +20 -0
- data/spec/acts_as_authoritah/matchers/direct_matcher_spec.rb +20 -0
- data/spec/acts_as_authoritah/matchers/scope_matcher_spec.rb +25 -0
- data/spec/acts_as_authoritah/spreadsheets/access_rights_mapper_spec.rb +13 -0
- data/spec/acts_as_authoritah/spreadsheets/spreadsheet_header_parser_spec.rb +8 -0
- data/spec/acts_as_authoritah/spreadsheets/spreadsheet_reader_spec.rb +29 -0
- data/spec/acts_as_authoritah/spreadsheets/spreadsheet_row_parser_spec.rb +24 -0
- data/spec/acts_as_authoritah/spreadsheets/spreadsheet_wrapper_spec.rb +15 -0
- data/spec/data/default.xls +0 -0
- data/spec/spec_helper.rb +5 -0
- metadata +91 -72
- data/.document +0 -5
- data/README.rdoc +0 -123
- data/VERSION +0 -1
- data/lib/access_control.rb +0 -30
- data/lib/access_rights.rb +0 -88
- data/lib/custom_exceptions.rb +0 -8
- data/lib/handler.rb +0 -38
- data/lib/loader.rb +0 -27
- data/test/acts_as_authoritah_test.rb +0 -23
- data/test/test_helper.rb +0 -22
data/lib/custom_exceptions.rb
DELETED
data/lib/handler.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
module ActsAsAuthoritah
|
2
|
-
module Handler
|
3
|
-
CAN_METHOD = /^can_(.*)/
|
4
|
-
class_eval do
|
5
|
-
def handle_can_methods(feature_name,args)
|
6
|
-
acl = AccessRights::Default.clone
|
7
|
-
|
8
|
-
if args.is_a?(Array) and !args.empty? and args.first[:context]
|
9
|
-
context = args.first[:context].to_s
|
10
|
-
raise ActsAsAuthoritah::AccessRights::UnknownContext unless AccessRights::contexts.include?(context)
|
11
|
-
acl.merge! AccessRights::ACL[context]
|
12
|
-
end
|
13
|
-
|
14
|
-
raise ActsAsAuthoritah::AccessRights::RuleNotDefined unless acl.has_key?(feature_name)
|
15
|
-
|
16
|
-
args.is_a?(Array) and !args.empty? ? acl[feature_name][usertype(args.first)] : acl[feature_name][usertype]
|
17
|
-
end
|
18
|
-
|
19
|
-
def method_missing(method_name,*args)
|
20
|
-
r1 = /^can_/
|
21
|
-
method_name = method_name.to_s
|
22
|
-
|
23
|
-
if method_name =~ CAN_METHOD
|
24
|
-
method_name.chop! if method_name[-1].chr == "?"
|
25
|
-
handle_can_methods(method_name.gsub(r1,""),args)
|
26
|
-
else
|
27
|
-
super(method_name.to_sym,*args)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def respond_to?(method)
|
32
|
-
return true if method.to_s =~ CAN_METHOD
|
33
|
-
super
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/lib/loader.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module ActsAsAuthoritah
|
2
|
-
module Loader
|
3
|
-
|
4
|
-
def acts_as_authoritah(args={})
|
5
|
-
if File.exists?(args[:acl_folder]) and Dir.has_xls_files?(args[:acl_folder])
|
6
|
-
if args[:default]
|
7
|
-
AccessRights::load_all_files(args[:acl_folder],args[:default])
|
8
|
-
else
|
9
|
-
AccessRights::load_all_files(args[:acl_folder])
|
10
|
-
end
|
11
|
-
elsif !Dir.has_xls_files?(args[:acl_folder])
|
12
|
-
raise ActsAsAuthoritah::AccessRights::AclFilesNotFound
|
13
|
-
else
|
14
|
-
raise ActsAsAuthoritah::AccessRights::AclFolderNotFound
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def Dir.xls_files(dir)
|
22
|
-
Dir.entries(dir).reject{|f| File.directory?(f)}.select{|x| x.split(".").last.downcase == "xls"}
|
23
|
-
end
|
24
|
-
|
25
|
-
def Dir.has_xls_files?(dir)
|
26
|
-
!Dir.xls_files(dir).empty?
|
27
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
|
3
|
-
class ActsAsAuthoritahTest < Test::Unit::TestCase
|
4
|
-
def test_responds_to_all_can_methods
|
5
|
-
can_methods = ActsAsAuthoritah::AccessRights::feature_list.collect{|feature| 'can_' + feature + '?'}
|
6
|
-
assert_respond_to_all Factory.build(:anonymous_user),can_methods
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_should_not_respond_to_any_non_existing_methods
|
10
|
-
assert !Factory.build(:anonymous_user).respond_to?(:non_existant_method)
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_can_methods_should_function_as_per_the_access_rights_specified_in_spead_sheet
|
14
|
-
spreadsheet_hash = ActsAsAuthoritah::AccessRights::Default
|
15
|
-
|
16
|
-
spreadsheet_hash.each_pair {|feature,hash|
|
17
|
-
can_method = 'can_' + feature + '?'
|
18
|
-
hash.keys.each do |usertype|
|
19
|
-
assert_equal Factory.build(usertype + '_user').send(can_method),hash[usertype]
|
20
|
-
end
|
21
|
-
}
|
22
|
-
end
|
23
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'factory_girl'
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
-
require 'acts_as_authoritah'
|
8
|
-
require 'activerecord_test_connector'
|
9
|
-
|
10
|
-
ActiveRecordTestConnector.setup
|
11
|
-
|
12
|
-
#load users factory
|
13
|
-
require_relative 'factories/users'
|
14
|
-
|
15
|
-
class Test::Unit::TestCase
|
16
|
-
protected
|
17
|
-
def assert_respond_to_all object, methods
|
18
|
-
methods.each do |method|
|
19
|
-
[method.to_s, method.to_sym].each { |m| assert_respond_to object, m }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|