cantango-roles 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +36 -0
  4. data/Gemfile.lock +147 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.mdown +83 -0
  7. data/Rakefile +53 -0
  8. data/VERSION +1 -0
  9. data/lib/cantango/roles.rb +11 -0
  10. data/lib/cantango/roles_ext.rb +9 -0
  11. data/lib/cantango/roles_ext/ability.rb +7 -0
  12. data/lib/cantango/roles_ext/ability/helper.rb +7 -0
  13. data/lib/cantango/roles_ext/ability/helper/role.rb +17 -0
  14. data/lib/cantango/roles_ext/ability/helper/role_group.rb +17 -0
  15. data/lib/cantango/roles_ext/builder.rb +7 -0
  16. data/lib/cantango/roles_ext/builder/permit.rb +7 -0
  17. data/lib/cantango/roles_ext/builder/permit/role.rb +35 -0
  18. data/lib/cantango/roles_ext/builder/permit/role_group.rb +61 -0
  19. data/lib/cantango/roles_ext/configuration.rb +13 -0
  20. data/lib/cantango/roles_ext/configuration/registry/role.rb +34 -0
  21. data/lib/cantango/roles_ext/configuration/role_groups.rb +17 -0
  22. data/lib/cantango/roles_ext/configuration/roles.rb +16 -0
  23. data/lib/cantango/roles_ext/configuration/system.rb +43 -0
  24. data/lib/cantango/roles_ext/engine.rb +7 -0
  25. data/lib/cantango/roles_ext/engine/permits.rb +5 -0
  26. data/lib/cantango/roles_ext/filter.rb +7 -0
  27. data/lib/cantango/roles_ext/filter/role.rb +29 -0
  28. data/lib/cantango/roles_ext/filter/role_group.rb +28 -0
  29. data/lib/cantango/roles_ext/helpers.rb +7 -0
  30. data/lib/cantango/roles_ext/helpers/role.rb +14 -0
  31. data/lib/cantango/roles_ext/helpers/role_group.rb +14 -0
  32. data/lib/cantango/roles_ext/permit.rb +0 -0
  33. data/lib/cantango/roles_ext/permit/helper/role_matcher.rb +13 -0
  34. data/lib/cantango/roles_ext/permit/role.rb +35 -0
  35. data/lib/cantango/roles_ext/permit/role_group.rb +47 -0
  36. data/lib/generators/cantango/base.rb +71 -0
  37. data/lib/generators/cantango/basic.rb +41 -0
  38. data/lib/generators/cantango/license_base.rb +15 -0
  39. data/lib/generators/cantango/permit_generator.rb +58 -0
  40. data/lib/generators/cantango/role_permit/role_permit_generator.rb +39 -0
  41. data/lib/generators/cantango/role_permit/templates/account_permit.erb +4 -0
  42. data/lib/generators/cantango/role_permit/templates/role_group_permit.erb +24 -0
  43. data/lib/generators/cantango/role_permit/templates/role_permit.erb +23 -0
  44. data/lib/generators/cantango/role_permits/role_permits_generator.rb +45 -0
  45. data/spec/cantango/ability/helper/role_group_spec.rb +33 -0
  46. data/spec/cantango/ability/helper/role_spec.rb +33 -0
  47. data/spec/cantango/ability/helper/shared/role_ex.rb +0 -0
  48. data/spec/cantango/ability/helper/shared/role_group_ex.rb +0 -0
  49. data/spec/cantango/builder/role_group_spec.rb +5 -0
  50. data/spec/cantango/builder/role_spec.rb +5 -0
  51. data/spec/cantango/configuration/role_groups_spec.rb +13 -0
  52. data/spec/cantango/configuration/role_registry_spec.rb +9 -0
  53. data/spec/cantango/configuration/roles_spec.rb +11 -0
  54. data/spec/cantango/configuration/shared/registry_ex.rb +40 -0
  55. data/spec/cantango/configuration/shared/role_registry_ex.rb +15 -0
  56. data/spec/cantango/configuration/shared/system_ex.rb +39 -0
  57. data/spec/cantango/configuration/system_spec.rb +9 -0
  58. data/spec/cantango/engine/permits_spec.rb +7 -0
  59. data/spec/cantango/filter/role_group_spec.rb +96 -0
  60. data/spec/cantango/filter/role_spec.rb +96 -0
  61. data/spec/cantango/helpers/role_group_spec.rb +26 -0
  62. data/spec/cantango/helpers/role_spec.rb +26 -0
  63. data/spec/fixtures/models.rb +2 -0
  64. data/spec/fixtures/models/admin.rb +2 -0
  65. data/spec/fixtures/models/admin_account.rb +22 -0
  66. data/spec/fixtures/models/items.rb +8 -0
  67. data/spec/fixtures/models/permission.rb +12 -0
  68. data/spec/fixtures/models/project.rb +2 -0
  69. data/spec/fixtures/models/simple_roles.rb +48 -0
  70. data/spec/fixtures/models/user.rb +52 -0
  71. data/spec/fixtures/models/user_account.rb +7 -0
  72. data/spec/helpers/current_user_accounts.rb +20 -0
  73. data/spec/helpers/current_users.rb +10 -0
  74. data/spec/spec_helper.rb +2 -0
  75. metadata +223 -0
@@ -0,0 +1,52 @@
1
+ require 'fixtures/models/simple_roles'
2
+
3
+ class User
4
+ attr_accessor :name, :account, :email, :roles, :role_groups
5
+
6
+ # tango_user # see macros
7
+
8
+ include ::SimpleRoles
9
+
10
+ def initialize name, email = nil, options = {}
11
+ @name = name
12
+ @email = email
13
+ set_option_vars options
14
+ end
15
+
16
+ def set_option_vars options = {}
17
+ options.each_pair do |name, value|
18
+ var = :"@#{name}"
19
+ self.instance_variable_set(var, value)
20
+ end
21
+ end
22
+
23
+ def email
24
+ @email ||= 'default@gmail.com'
25
+ end
26
+
27
+ def role
28
+ @role || ''
29
+ end
30
+
31
+ # This hash should be recalculated anytime the permissions collection changes
32
+ #
33
+
34
+ # after_update :recalculate_permissions_hash
35
+
36
+ def permissions_hash
37
+ @permissions_hash = permissions.hash
38
+ end
39
+
40
+ def permissions
41
+ @permissions ||= []
42
+ end
43
+
44
+ # allows implementation specific to ORM, fx using #all on some datastores such as Mongoid etc.
45
+ alias_method :all_permissions, :permissions
46
+
47
+ protected
48
+
49
+ def recalculate_permissions_hash
50
+ @permissions_hash = nil if self.permissions_changed?
51
+ end
52
+ end
@@ -0,0 +1,7 @@
1
+ class UserAccount
2
+ attr_accessor :user
3
+
4
+ def initialize user, options = {}
5
+ @user = user
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+
3
+ require 'current_users'
4
+
5
+ module CurrentUserAccounts
6
+ include ::CurrentUsers
7
+
8
+ def self.included(base)
9
+ base.extend ::CurrentUsers
10
+ end
11
+
12
+ def current_user_account
13
+ @current_user_account ||= ::UserAccount.new(current_user, :roles => [:user])
14
+ end
15
+
16
+ def current_admin_account
17
+ @current_admin_account ||= ::AdminAccount.new(current_admin, :roles => [:admin])
18
+ end
19
+ end
20
+
@@ -0,0 +1,10 @@
1
+ module CurrentUsers
2
+ def current_user
3
+ @current_user ||= ::User.new 'stan', 'stan@mail.ru', :role => 'user'
4
+ end
5
+
6
+ def current_admin
7
+ @current_admin ||= ::User.new 'admin', 'admin@mail.ru', :role => 'admin'
8
+ end
9
+ end
10
+
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+ require 'cantango/roles'
metadata ADDED
@@ -0,0 +1,223 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cantango-roles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kristian Mandrup
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70229316635760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70229316635760
25
+ - !ruby/object:Gem::Dependency
26
+ name: sugar-high
27
+ requirement: &70229316635220 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.6.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70229316635220
36
+ - !ruby/object:Gem::Dependency
37
+ name: sweetloader
38
+ requirement: &70229316634680 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 0.1.6
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70229316634680
47
+ - !ruby/object:Gem::Dependency
48
+ name: hashie
49
+ requirement: &70229316634160 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.0
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70229316634160
58
+ - !ruby/object:Gem::Dependency
59
+ name: cantango-config
60
+ requirement: &70229316633660 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 0.1.9
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70229316633660
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: &70229316633120 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: 1.1.rc
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70229316633120
80
+ - !ruby/object:Gem::Dependency
81
+ name: jeweler
82
+ requirement: &70229316632500 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: 1.6.4
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70229316632500
91
+ - !ruby/object:Gem::Dependency
92
+ name: rcov
93
+ requirement: &70229316631860 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70229316631860
102
+ - !ruby/object:Gem::Dependency
103
+ name: rspec
104
+ requirement: &70229316630340 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 2.6.0
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70229316630340
113
+ description: Roles and Role groups for CanTango
114
+ email: kmandrup@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files:
118
+ - LICENSE.txt
119
+ - README.mdown
120
+ files:
121
+ - .document
122
+ - .rspec
123
+ - Gemfile
124
+ - Gemfile.lock
125
+ - LICENSE.txt
126
+ - README.mdown
127
+ - Rakefile
128
+ - VERSION
129
+ - lib/cantango/roles.rb
130
+ - lib/cantango/roles_ext.rb
131
+ - lib/cantango/roles_ext/ability.rb
132
+ - lib/cantango/roles_ext/ability/helper.rb
133
+ - lib/cantango/roles_ext/ability/helper/role.rb
134
+ - lib/cantango/roles_ext/ability/helper/role_group.rb
135
+ - lib/cantango/roles_ext/builder.rb
136
+ - lib/cantango/roles_ext/builder/permit.rb
137
+ - lib/cantango/roles_ext/builder/permit/role.rb
138
+ - lib/cantango/roles_ext/builder/permit/role_group.rb
139
+ - lib/cantango/roles_ext/configuration.rb
140
+ - lib/cantango/roles_ext/configuration/registry/role.rb
141
+ - lib/cantango/roles_ext/configuration/role_groups.rb
142
+ - lib/cantango/roles_ext/configuration/roles.rb
143
+ - lib/cantango/roles_ext/configuration/system.rb
144
+ - lib/cantango/roles_ext/engine.rb
145
+ - lib/cantango/roles_ext/engine/permits.rb
146
+ - lib/cantango/roles_ext/filter.rb
147
+ - lib/cantango/roles_ext/filter/role.rb
148
+ - lib/cantango/roles_ext/filter/role_group.rb
149
+ - lib/cantango/roles_ext/helpers.rb
150
+ - lib/cantango/roles_ext/helpers/role.rb
151
+ - lib/cantango/roles_ext/helpers/role_group.rb
152
+ - lib/cantango/roles_ext/permit.rb
153
+ - lib/cantango/roles_ext/permit/helper/role_matcher.rb
154
+ - lib/cantango/roles_ext/permit/role.rb
155
+ - lib/cantango/roles_ext/permit/role_group.rb
156
+ - lib/generators/cantango/base.rb
157
+ - lib/generators/cantango/basic.rb
158
+ - lib/generators/cantango/license_base.rb
159
+ - lib/generators/cantango/permit_generator.rb
160
+ - lib/generators/cantango/role_permit/role_permit_generator.rb
161
+ - lib/generators/cantango/role_permit/templates/account_permit.erb
162
+ - lib/generators/cantango/role_permit/templates/role_group_permit.erb
163
+ - lib/generators/cantango/role_permit/templates/role_permit.erb
164
+ - lib/generators/cantango/role_permits/role_permits_generator.rb
165
+ - spec/cantango/ability/helper/role_group_spec.rb
166
+ - spec/cantango/ability/helper/role_spec.rb
167
+ - spec/cantango/ability/helper/shared/role_ex.rb
168
+ - spec/cantango/ability/helper/shared/role_group_ex.rb
169
+ - spec/cantango/builder/role_group_spec.rb
170
+ - spec/cantango/builder/role_spec.rb
171
+ - spec/cantango/configuration/role_groups_spec.rb
172
+ - spec/cantango/configuration/role_registry_spec.rb
173
+ - spec/cantango/configuration/roles_spec.rb
174
+ - spec/cantango/configuration/shared/registry_ex.rb
175
+ - spec/cantango/configuration/shared/role_registry_ex.rb
176
+ - spec/cantango/configuration/shared/system_ex.rb
177
+ - spec/cantango/configuration/system_spec.rb
178
+ - spec/cantango/engine/permits_spec.rb
179
+ - spec/cantango/filter/role_group_spec.rb
180
+ - spec/cantango/filter/role_spec.rb
181
+ - spec/cantango/helpers/role_group_spec.rb
182
+ - spec/cantango/helpers/role_spec.rb
183
+ - spec/fixtures/models.rb
184
+ - spec/fixtures/models/admin.rb
185
+ - spec/fixtures/models/admin_account.rb
186
+ - spec/fixtures/models/items.rb
187
+ - spec/fixtures/models/permission.rb
188
+ - spec/fixtures/models/project.rb
189
+ - spec/fixtures/models/simple_roles.rb
190
+ - spec/fixtures/models/user.rb
191
+ - spec/fixtures/models/user_account.rb
192
+ - spec/helpers/current_user_accounts.rb
193
+ - spec/helpers/current_users.rb
194
+ - spec/spec_helper.rb
195
+ homepage: http://github.com/kristianmandrup/cantango-roles
196
+ licenses:
197
+ - MIT
198
+ post_install_message:
199
+ rdoc_options: []
200
+ require_paths:
201
+ - lib
202
+ required_ruby_version: !ruby/object:Gem::Requirement
203
+ none: false
204
+ requirements:
205
+ - - ! '>='
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ segments:
209
+ - 0
210
+ hash: -2527536198998272544
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ none: false
213
+ requirements:
214
+ - - ! '>='
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ requirements: []
218
+ rubyforge_project:
219
+ rubygems_version: 1.8.6
220
+ signing_key:
221
+ specification_version: 3
222
+ summary: Roles extension for CanTango
223
+ test_files: []