acts_as_authoritah 2.0.4 → 2.0.5
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/.rvmrc
CHANGED
@@ -1,4 +1,48 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
2
|
|
3
|
-
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
4
5
|
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p125@authoritah"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.10.3" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
35
|
+
|
36
|
+
# If you use bundler, this might be useful to you:
|
37
|
+
# if [[ -s Gemfile ]] && {
|
38
|
+
# ! builtin command -v bundle >/dev/null ||
|
39
|
+
# builtin command -v bundle | grep $rvm_path/bin/bundle >/dev/null
|
40
|
+
# }
|
41
|
+
# then
|
42
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
43
|
+
# gem install bundler
|
44
|
+
# fi
|
45
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
46
|
+
# then
|
47
|
+
# bundle install | grep -vE '^Using|Your bundle is complete'
|
48
|
+
# fi
|
@@ -5,18 +5,18 @@ require "acts_as_authoritah/matchers/scope_matcher.rb"
|
|
5
5
|
|
6
6
|
class ActsAsAuthoritah::AccessControlList
|
7
7
|
include ActsAsAuthoritah::Matchers
|
8
|
-
|
8
|
+
|
9
9
|
attr_accessor :store
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(access_rules)
|
12
12
|
@store = {}
|
13
13
|
access_rules.each do |access_rule|
|
14
14
|
@store.merge! access_rule.to_rule
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
@matchers = [DirectMatcher, ControllerMatcher, ScopeMatcher]
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def match(identifier)
|
21
21
|
@matchers.each do |matcher|
|
22
22
|
access_rights = matcher.new(@store).match(identifier)
|
@@ -24,14 +24,19 @@ class ActsAsAuthoritah::AccessControlList
|
|
24
24
|
end
|
25
25
|
nil
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def match_identifier(identifier)
|
29
29
|
match(identifier) || {}
|
30
30
|
end
|
31
|
-
|
32
|
-
def merge
|
33
|
-
|
34
|
-
|
31
|
+
|
32
|
+
def merge(other_access_control_list)
|
33
|
+
a = self.deep_clone
|
34
|
+
a.store.merge!(other_access_control_list.store)
|
35
|
+
a
|
36
|
+
end
|
37
|
+
|
38
|
+
def deep_clone
|
39
|
+
Marshal::load(Marshal.dump(self))
|
35
40
|
end
|
36
|
-
|
37
|
-
end
|
41
|
+
|
42
|
+
end
|
@@ -19,25 +19,25 @@ module ActsAsAuthoritah
|
|
19
19
|
h.empty? ? !klass.send(:whitelist) : h[self.usertype(options)]
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
module ClassMethods
|
24
24
|
def acts_as_authoritah(path, options={})
|
25
25
|
@@whitelist = options[:whitelist] ||= false
|
26
26
|
loader = ActsAsAuthoritah::AclLoader.new(path)
|
27
27
|
@@contexts = loader.contexts
|
28
|
-
@@acls = loader.load
|
28
|
+
@@acls = loader.load
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def valid_contexts
|
32
32
|
@@contexts
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def get_acl(key = :default)
|
36
36
|
h = @@acls[key]
|
37
|
-
h = @@acls[:default].clone.merge
|
37
|
+
h = @@acls[:default].clone.merge(@@acls[key]) unless key.eql?(:default)
|
38
38
|
h
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def whitelist
|
42
42
|
@@whitelist
|
43
43
|
end
|
@@ -5,11 +5,11 @@ describe ActsAsAuthoritah::AccessControlList do
|
|
5
5
|
it "should build list" do
|
6
6
|
rule1 = ActsAsAuthoritah::AccessRule.new("Admin::Projects", "Surveys","update",{:admin => true, :anonymous => false})
|
7
7
|
rule2 = ActsAsAuthoritah::AccessRule.new("Admin::Users", "Configurations","edit",{:admin => true, :anonymous => false})
|
8
|
-
|
8
|
+
|
9
9
|
ActsAsAuthoritah::AccessControlList.new([rule1, rule2]).store.should eq rule1.to_rule.merge(rule2.to_rule)
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
context "match" do
|
14
14
|
before :each do
|
15
15
|
rules = [
|
@@ -20,22 +20,22 @@ describe ActsAsAuthoritah::AccessControlList do
|
|
20
20
|
ActsAsAuthoritah::AccessRule.new("Projects", "Surveys", "update", "e"),
|
21
21
|
ActsAsAuthoritah::AccessRule.new("", "Projects", nil, "f")
|
22
22
|
]
|
23
|
-
|
23
|
+
|
24
24
|
@acl = ActsAsAuthoritah::AccessControlList.new(rules)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
it "test1" do
|
28
28
|
@acl.match("Admin::ForumsController#index").should eq "a"
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
it "test2" do
|
32
32
|
@acl.match("Admin::Projects::SurveysController#index").should eq "d"
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
it "test3" do
|
36
36
|
@acl.match("Projects::SurveysController#index").should eq nil
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "test4" do
|
40
40
|
@acl.match("Projects::SurveysController#update").should eq "e"
|
41
41
|
end
|
@@ -43,39 +43,39 @@ describe ActsAsAuthoritah::AccessControlList do
|
|
43
43
|
it "test5" do
|
44
44
|
@acl.match("Projects::SurveysController#edit").should eq "b"
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
it "test6" do
|
48
48
|
@acl.match("Admin::Projects::HomeController#update").should eq "c"
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
it "test7" do
|
52
52
|
@acl.match("ProjectsController#create").should eq "f"
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
it "test8" do
|
56
56
|
@acl.match("Admin::ProjectsController#create").should eq "a"
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
context "match_identifier" do
|
62
62
|
before :each do
|
63
63
|
rules = [
|
64
64
|
ActsAsAuthoritah::AccessRule.new("Admin", nil, nil, "c"),
|
65
65
|
]
|
66
|
-
|
66
|
+
|
67
67
|
@acl = ActsAsAuthoritah::AccessControlList.new(rules)
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
it "should return {} if there is no match" do
|
71
71
|
@acl.match_identifier("LinksController#create").should eq({})
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
it "should return the matched value if there is a match" do
|
75
75
|
@acl.match_identifier("Admin::ProjectsController#create").should eq "c"
|
76
76
|
end
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
context "merge" do
|
80
80
|
before :each do
|
81
81
|
rules = [
|
@@ -83,19 +83,22 @@ describe ActsAsAuthoritah::AccessControlList do
|
|
83
83
|
ActsAsAuthoritah::AccessRule.new("Admin", "Projects", nil, "d"),
|
84
84
|
]
|
85
85
|
@acl1 = ActsAsAuthoritah::AccessControlList.new(rules)
|
86
|
-
|
86
|
+
|
87
87
|
rules = [
|
88
88
|
ActsAsAuthoritah::AccessRule.new("Admin", nil, nil, "C")
|
89
89
|
]
|
90
90
|
@acl2 = ActsAsAuthoritah::AccessControlList.new(rules)
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
it "should merge two @acl2 into @acl1 overriding common rule using the one from @acl2" do
|
94
94
|
@acl1.store.should eq({"Admin"=>"c", "Admin::ProjectsController"=>"d"})
|
95
95
|
@acl2.store.should eq({"Admin"=>"C"})
|
96
|
-
|
97
|
-
@acl1.
|
96
|
+
|
97
|
+
new_acl = @acl1.merge(@acl2)
|
98
|
+
|
99
|
+
new_acl.store.should eq({"Admin"=>"C", "Admin::ProjectsController"=>"d"})
|
100
|
+
@acl1.store.should eq({"Admin"=>"c", "Admin::ProjectsController"=>"d"})
|
98
101
|
@acl2.store.should eq({"Admin"=>"C"})
|
99
102
|
end
|
100
103
|
end
|
101
|
-
end
|
104
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_authoritah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2168867500 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2168867500
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &2168866300 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2168866300
|
36
36
|
description: Define user capabilities in your app
|
37
37
|
email:
|
38
38
|
- unni.tallman@gmail.com
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 1.8.
|
104
|
+
rubygems_version: 1.8.11
|
105
105
|
signing_key:
|
106
106
|
specification_version: 3
|
107
107
|
summary: Define user capabilities in your app
|