bmaland-aegis 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bmaland-aegis.gemspec +99 -0
- data/lib/aegis/has_role.rb +95 -79
- data/test/has_role_test.rb +11 -1
- metadata +3 -2
data/Rakefile
CHANGED
@@ -31,7 +31,7 @@ begin
|
|
31
31
|
gemspec.homepage = "http://github.com/bmaland/aegis"
|
32
32
|
gemspec.description = "Aegis is a role-based permission system, where all users are given a role. It is possible to define detailed and complex permissions for each role very easily."
|
33
33
|
gemspec.authors = ["Henning Koch"]
|
34
|
-
gemspec.version = '1.1.
|
34
|
+
gemspec.version = '1.1.6'
|
35
35
|
end
|
36
36
|
rescue LoadError
|
37
37
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.6
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{bmaland-aegis}
|
8
|
+
s.version = "1.1.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Henning Koch"]
|
12
|
+
s.date = %q{2009-11-11}
|
13
|
+
s.description = %q{Aegis is a role-based permission system, where all users are given a role. It is possible to define detailed and complex permissions for each role very easily.}
|
14
|
+
s.email = %q{github@makandra.de}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"MIT-LICENSE",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"bmaland-aegis.gemspec",
|
25
|
+
"init.rb",
|
26
|
+
"lib/aegis.rb",
|
27
|
+
"lib/aegis/constants.rb",
|
28
|
+
"lib/aegis/has_role.rb",
|
29
|
+
"lib/aegis/normalization.rb",
|
30
|
+
"lib/aegis/permission_error.rb",
|
31
|
+
"lib/aegis/permission_evaluator.rb",
|
32
|
+
"lib/aegis/permissions.rb",
|
33
|
+
"lib/aegis/role.rb",
|
34
|
+
"lib/rails/active_record.rb",
|
35
|
+
"test/app_root/app/controllers/application_controller.rb",
|
36
|
+
"test/app_root/app/models/permissions.rb",
|
37
|
+
"test/app_root/app/models/soldier.rb",
|
38
|
+
"test/app_root/app/models/user.rb",
|
39
|
+
"test/app_root/app/models/user_subclass.rb",
|
40
|
+
"test/app_root/config/boot.rb",
|
41
|
+
"test/app_root/config/database.yml",
|
42
|
+
"test/app_root/config/environment.rb",
|
43
|
+
"test/app_root/config/environments/in_memory.rb",
|
44
|
+
"test/app_root/config/environments/mysql.rb",
|
45
|
+
"test/app_root/config/environments/postgresql.rb",
|
46
|
+
"test/app_root/config/environments/sqlite.rb",
|
47
|
+
"test/app_root/config/environments/sqlite3.rb",
|
48
|
+
"test/app_root/config/routes.rb",
|
49
|
+
"test/app_root/db/migrate/20090408115228_create_users.rb",
|
50
|
+
"test/app_root/db/migrate/20090429075648_create_soldiers.rb",
|
51
|
+
"test/app_root/lib/console_with_fixtures.rb",
|
52
|
+
"test/app_root/log/.gitignore",
|
53
|
+
"test/app_root/script/console",
|
54
|
+
"test/has_role_options_test.rb",
|
55
|
+
"test/has_role_test.rb",
|
56
|
+
"test/permissions_test.rb",
|
57
|
+
"test/test_helper.rb",
|
58
|
+
"test/validation_test.rb"
|
59
|
+
]
|
60
|
+
s.homepage = %q{http://github.com/bmaland/aegis}
|
61
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
62
|
+
s.require_paths = ["lib"]
|
63
|
+
s.rubygems_version = %q{1.3.5}
|
64
|
+
s.summary = %q{Role-based permissions for your user models.}
|
65
|
+
s.test_files = [
|
66
|
+
"test/validation_test.rb",
|
67
|
+
"test/permissions_test.rb",
|
68
|
+
"test/test_helper.rb",
|
69
|
+
"test/app_root/db/migrate/20090408115228_create_users.rb",
|
70
|
+
"test/app_root/db/migrate/20090429075648_create_soldiers.rb",
|
71
|
+
"test/app_root/lib/console_with_fixtures.rb",
|
72
|
+
"test/app_root/app/controllers/application_controller.rb",
|
73
|
+
"test/app_root/app/models/permissions.rb",
|
74
|
+
"test/app_root/app/models/soldier.rb",
|
75
|
+
"test/app_root/app/models/user_subclass.rb",
|
76
|
+
"test/app_root/app/models/user.rb",
|
77
|
+
"test/app_root/config/environments/sqlite3.rb",
|
78
|
+
"test/app_root/config/environments/sqlite.rb",
|
79
|
+
"test/app_root/config/environments/postgresql.rb",
|
80
|
+
"test/app_root/config/environments/in_memory.rb",
|
81
|
+
"test/app_root/config/environments/mysql.rb",
|
82
|
+
"test/app_root/config/environment.rb",
|
83
|
+
"test/app_root/config/routes.rb",
|
84
|
+
"test/app_root/config/boot.rb",
|
85
|
+
"test/has_role_options_test.rb",
|
86
|
+
"test/has_role_test.rb"
|
87
|
+
]
|
88
|
+
|
89
|
+
if s.respond_to? :specification_version then
|
90
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
91
|
+
s.specification_version = 3
|
92
|
+
|
93
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
94
|
+
else
|
95
|
+
end
|
96
|
+
else
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
data/lib/aegis/has_role.rb
CHANGED
@@ -1,79 +1,95 @@
|
|
1
|
-
module Aegis
|
2
|
-
module HasRole
|
3
|
-
|
4
|
-
def validates_role_name(options = {})
|
5
|
-
validates_each :role_name do |record, attr, value|
|
6
|
-
options[:message] ||= ActiveRecord::Errors.default_error_messages[:inclusion]
|
7
|
-
role = ::Permissions.find_role_by_name(value)
|
8
|
-
record.errors.add attr, options[:message] if role.nil?
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
alias_method :validates_role, :validates_role_name
|
13
|
-
|
14
|
-
def has_role(options = {})
|
15
|
-
|
16
|
-
if options[:name_accessor]
|
17
|
-
options[:name_reader] = "#{options[:name_accessor]}"
|
18
|
-
options[:name_writer] = "#{options[:name_accessor]}="
|
19
|
-
options.delete(:name_accessor)
|
20
|
-
end
|
21
|
-
|
22
|
-
self.class_eval do
|
23
|
-
|
24
|
-
class_inheritable_accessor :aegis_role_name_reader, :aegis_role_name_writer
|
25
|
-
|
26
|
-
self.aegis_role_name_reader = (options[:name_reader] || "role_name").to_sym
|
27
|
-
self.aegis_role_name_writer = (options[:name_writer] || "role_name=").to_sym
|
28
|
-
|
29
|
-
def aegis_role_name_reader
|
30
|
-
self.class.class_eval{ aegis_role_name_reader }
|
31
|
-
end
|
32
|
-
|
33
|
-
def aegis_role_name_writer
|
34
|
-
self.class.class_eval{ aegis_role_name_writer }
|
35
|
-
end
|
36
|
-
|
37
|
-
def aegis_role_name
|
38
|
-
send(aegis_role_name_reader)
|
39
|
-
end
|
40
|
-
|
41
|
-
def aegis_role_name=(value)
|
42
|
-
send(aegis_role_name_writer, value)
|
43
|
-
end
|
44
|
-
|
45
|
-
def role
|
46
|
-
::Permissions.find_role_by_name!(aegis_role_name)
|
47
|
-
end
|
48
|
-
|
49
|
-
def role=(role_or_name)
|
50
|
-
self.aegis_role_name = if role_or_name.is_a?(Aegis::Role)
|
51
|
-
role_or_name.name
|
52
|
-
else
|
53
|
-
role_or_name.to_s
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
# Delegate may_...? and may_...! methods to the user's role.
|
60
|
-
def method_missing_with_aegis_permissions(symb, *args)
|
61
|
-
method_name = symb.to_s
|
62
|
-
if method_name =~ /^may_(.+?)[\!\?]$/
|
63
|
-
role.send(symb, self, *args)
|
64
|
-
elsif method_name =~ /^(.*?)\?$/ && queried_role = ::Permissions.find_role_by_name($1)
|
65
|
-
role == queried_role
|
66
|
-
else
|
67
|
-
method_missing_without_aegis_permissions(symb, *args)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
alias_method_chain :method_missing, :aegis_permissions
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
1
|
+
module Aegis
|
2
|
+
module HasRole
|
3
|
+
|
4
|
+
def validates_role_name(options = {})
|
5
|
+
validates_each :role_name do |record, attr, value|
|
6
|
+
options[:message] ||= ActiveRecord::Errors.default_error_messages[:inclusion]
|
7
|
+
role = ::Permissions.find_role_by_name(value)
|
8
|
+
record.errors.add attr, options[:message] if role.nil?
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
alias_method :validates_role, :validates_role_name
|
13
|
+
|
14
|
+
def has_role(options = {})
|
15
|
+
|
16
|
+
if options[:name_accessor]
|
17
|
+
options[:name_reader] = "#{options[:name_accessor]}"
|
18
|
+
options[:name_writer] = "#{options[:name_accessor]}="
|
19
|
+
options.delete(:name_accessor)
|
20
|
+
end
|
21
|
+
|
22
|
+
self.class_eval do
|
23
|
+
|
24
|
+
class_inheritable_accessor :aegis_role_name_reader, :aegis_role_name_writer
|
25
|
+
|
26
|
+
self.aegis_role_name_reader = (options[:name_reader] || "role_name").to_sym
|
27
|
+
self.aegis_role_name_writer = (options[:name_writer] || "role_name=").to_sym
|
28
|
+
|
29
|
+
def aegis_role_name_reader
|
30
|
+
self.class.class_eval{ aegis_role_name_reader }
|
31
|
+
end
|
32
|
+
|
33
|
+
def aegis_role_name_writer
|
34
|
+
self.class.class_eval{ aegis_role_name_writer }
|
35
|
+
end
|
36
|
+
|
37
|
+
def aegis_role_name
|
38
|
+
send(aegis_role_name_reader)
|
39
|
+
end
|
40
|
+
|
41
|
+
def aegis_role_name=(value)
|
42
|
+
send(aegis_role_name_writer, value)
|
43
|
+
end
|
44
|
+
|
45
|
+
def role
|
46
|
+
::Permissions.find_role_by_name!(aegis_role_name)
|
47
|
+
end
|
48
|
+
|
49
|
+
def role=(role_or_name)
|
50
|
+
self.aegis_role_name = if role_or_name.is_a?(Aegis::Role)
|
51
|
+
role_or_name.name
|
52
|
+
else
|
53
|
+
role_or_name.to_s
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
# Delegate may_...? and may_...! methods to the user's role.
|
60
|
+
def method_missing_with_aegis_permissions(symb, *args)
|
61
|
+
method_name = symb.to_s
|
62
|
+
if method_name =~ /^may_(.+?)[\!\?]$/
|
63
|
+
role.send(symb, self, *args)
|
64
|
+
elsif method_name =~ /^(.*?)\?$/ && queried_role = ::Permissions.find_role_by_name($1)
|
65
|
+
role == queried_role
|
66
|
+
else
|
67
|
+
method_missing_without_aegis_permissions(symb, *args)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
alias_method_chain :method_missing, :aegis_permissions
|
72
|
+
|
73
|
+
def respond_to_with_aegis_permissions?(symb, include_private = false)
|
74
|
+
if symb.to_s =~ /^may_(.+?)[\!\?]$/
|
75
|
+
true
|
76
|
+
else
|
77
|
+
respond_to_without_aegis_permissions?(symb, include_private)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
alias_method_chain :respond_to?, :aegis_permissions
|
82
|
+
|
83
|
+
def set_default_aegis_role_name
|
84
|
+
if new_record?
|
85
|
+
self.aegis_role_name ||= self.class.aegis_default_role_name
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
data/test/has_role_test.rb
CHANGED
@@ -39,10 +39,20 @@ class HasRoleTest < ActiveSupport::TestCase
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
should "have a default
|
42
|
+
should "have a default role" do
|
43
43
|
assert :guest, User.new(:role_name => nil).role.name
|
44
44
|
end
|
45
45
|
|
46
|
+
should "know that they respond to permission methods" do
|
47
|
+
assert @guest.respond_to?(:may_foo?)
|
48
|
+
assert @guest.respond_to?(:may_foo!)
|
49
|
+
end
|
50
|
+
|
51
|
+
should "retain the usual respond_to behaviour for non-permission methods" do
|
52
|
+
assert !@guest.respond_to?(:nonexisting_method)
|
53
|
+
assert @guest.respond_to?(:to_s)
|
54
|
+
end
|
55
|
+
|
46
56
|
end
|
47
57
|
|
48
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bmaland-aegis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henning Koch
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-11 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- README.rdoc
|
28
28
|
- Rakefile
|
29
29
|
- VERSION
|
30
|
+
- bmaland-aegis.gemspec
|
30
31
|
- init.rb
|
31
32
|
- lib/aegis.rb
|
32
33
|
- lib/aegis/constants.rb
|