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,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,36 @@
1
+ source :rubygems
2
+
3
+ group :default do
4
+ gem 'rails', '>= 3.1'
5
+ gem 'sugar-high', '>= 0.6.1'
6
+ gem 'sweetloader', '>= 0.1.6'
7
+ gem 'hashie', '>= 1.2.0'
8
+
9
+ gem 'cantango-config', '~> 0.1.9'
10
+ end
11
+
12
+ group :development do
13
+ gem "bundler", ">= 1.1.rc"
14
+ gem "jeweler", ">= 1.6.4"
15
+ gem "rcov", ">= 0"
16
+ end
17
+
18
+ group :test do
19
+ gem 'require_all', '~> 1.2.0'
20
+
21
+ gem 'forgery'
22
+ gem 'sqlite3'
23
+ # Data
24
+ gem 'database_cleaner'
25
+ gem 'factory_girl'
26
+
27
+ # Specs
28
+ gem 'spork'
29
+
30
+ # Debug and performance tests
31
+ gem 'cutter'
32
+ end
33
+
34
+ group :test, :development do
35
+ gem "rspec", ">= 2.6.0"
36
+ end
@@ -0,0 +1,147 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.1.3)
5
+ actionpack (= 3.1.3)
6
+ mail (~> 2.3.0)
7
+ actionpack (3.1.3)
8
+ activemodel (= 3.1.3)
9
+ activesupport (= 3.1.3)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ i18n (~> 0.6)
13
+ rack (~> 1.3.5)
14
+ rack-cache (~> 1.1)
15
+ rack-mount (~> 0.8.2)
16
+ rack-test (~> 0.6.1)
17
+ sprockets (~> 2.0.3)
18
+ activemodel (3.1.3)
19
+ activesupport (= 3.1.3)
20
+ builder (~> 3.0.0)
21
+ i18n (~> 0.6)
22
+ activerecord (3.1.3)
23
+ activemodel (= 3.1.3)
24
+ activesupport (= 3.1.3)
25
+ arel (~> 2.2.1)
26
+ tzinfo (~> 0.3.29)
27
+ activeresource (3.1.3)
28
+ activemodel (= 3.1.3)
29
+ activesupport (= 3.1.3)
30
+ activesupport (3.1.3)
31
+ multi_json (~> 1.0)
32
+ arel (2.2.1)
33
+ builder (3.0.0)
34
+ cancan (1.6.7)
35
+ cantango-config (0.1.9.2)
36
+ cantango-core (~> 0.1.9)
37
+ hashie (~> 1.2)
38
+ rails (>= 3.1)
39
+ sugar-high (>= 0.6.1)
40
+ sweetloader (~> 0.1.6)
41
+ cantango-core (0.1.9.3)
42
+ cancan (>= 1.4)
43
+ hashie (~> 1.2)
44
+ rails (>= 3.0.1)
45
+ sugar-high (>= 0.6.0)
46
+ sweetloader (~> 0.1.5)
47
+ colorize (0.5.8)
48
+ cutter (0.8.2)
49
+ activesupport (>= 2.3.5)
50
+ colorize (>= 0.5)
51
+ database_cleaner (0.7.0)
52
+ diff-lcs (1.1.3)
53
+ erubis (2.7.0)
54
+ factory_girl (2.3.2)
55
+ activesupport
56
+ forgery (0.5.0)
57
+ git (1.2.5)
58
+ hashie (1.2.0)
59
+ hike (1.2.1)
60
+ i18n (0.6.0)
61
+ jeweler (1.6.4)
62
+ bundler (~> 1.0)
63
+ git (>= 1.2.5)
64
+ rake
65
+ json (1.6.3)
66
+ mail (2.3.0)
67
+ i18n (>= 0.4.0)
68
+ mime-types (~> 1.16)
69
+ treetop (~> 1.4.8)
70
+ mime-types (1.17.2)
71
+ multi_json (1.0.4)
72
+ polyglot (0.3.3)
73
+ rack (1.3.5)
74
+ rack-cache (1.1)
75
+ rack (>= 0.4)
76
+ rack-mount (0.8.3)
77
+ rack (>= 1.0.0)
78
+ rack-ssl (1.3.2)
79
+ rack
80
+ rack-test (0.6.1)
81
+ rack (>= 1.0)
82
+ rails (3.1.3)
83
+ actionmailer (= 3.1.3)
84
+ actionpack (= 3.1.3)
85
+ activerecord (= 3.1.3)
86
+ activeresource (= 3.1.3)
87
+ activesupport (= 3.1.3)
88
+ bundler (~> 1.0)
89
+ railties (= 3.1.3)
90
+ railties (3.1.3)
91
+ actionpack (= 3.1.3)
92
+ activesupport (= 3.1.3)
93
+ rack-ssl (~> 1.3.2)
94
+ rake (>= 0.8.7)
95
+ rdoc (~> 3.4)
96
+ thor (~> 0.14.6)
97
+ rake (0.9.2.2)
98
+ rcov (0.9.11)
99
+ rdoc (3.11)
100
+ json (~> 1.4)
101
+ require_all (1.2.0)
102
+ rspec (2.7.0)
103
+ rspec-core (~> 2.7.0)
104
+ rspec-expectations (~> 2.7.0)
105
+ rspec-mocks (~> 2.7.0)
106
+ rspec-core (2.7.1)
107
+ rspec-expectations (2.7.0)
108
+ diff-lcs (~> 1.1.2)
109
+ rspec-mocks (2.7.0)
110
+ spork (0.8.5)
111
+ sprockets (2.0.3)
112
+ hike (~> 1.2)
113
+ rack (~> 1.0)
114
+ tilt (~> 1.1, != 1.3.0)
115
+ sqlite3 (1.3.4)
116
+ sugar-high (0.6.2.1)
117
+ activesupport (>= 3.0.1)
118
+ sweetloader (0.1.6)
119
+ activesupport (>= 3.0.1)
120
+ i18n
121
+ thor (0.14.6)
122
+ tilt (1.3.3)
123
+ treetop (1.4.10)
124
+ polyglot
125
+ polyglot (>= 0.3.1)
126
+ tzinfo (0.3.31)
127
+
128
+ PLATFORMS
129
+ ruby
130
+
131
+ DEPENDENCIES
132
+ bundler (>= 1.1.rc)
133
+ cantango-config (~> 0.1.9)
134
+ cutter
135
+ database_cleaner
136
+ factory_girl
137
+ forgery
138
+ hashie (>= 1.2.0)
139
+ jeweler (>= 1.6.4)
140
+ rails (>= 3.1)
141
+ rcov
142
+ require_all (~> 1.2.0)
143
+ rspec (>= 2.6.0)
144
+ spork
145
+ sqlite3
146
+ sugar-high (>= 0.6.1)
147
+ sweetloader (>= 0.1.6)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Kristian Mandrup
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,83 @@
1
+ # CanTango Roles
2
+
3
+ Roles and Role groups extension for [CanTango](https://github.com/kristianmandrup/cantango)
4
+
5
+ ## Status: Dec 9, 2011
6
+
7
+ Most specs except those for Permits have been completed and demonstrates that the functionality works as it should.
8
+
9
+ ## Ability helper
10
+
11
+ * Ability::Helper
12
+ * Role
13
+ * RoleGroup
14
+
15
+ These modules are typically included into an Ability in order to access the roles of the ability subject, typically a user (or in rare cases an account).
16
+
17
+ The `Role` module has a `#roles` method which returns the role list of the subject.
18
+ The `RoleGroup` module has a `#role_groups` method which returns the role group list of the subject.
19
+
20
+ ## Configuration Registry
21
+
22
+ Roles and RoleGroups configuration via a Registry.
23
+
24
+ Roles configuration:
25
+
26
+ ```ruby
27
+ CanTango.config do |config|
28
+ config.roles do |roles|
29
+ roles.register :admin, :guest, :basic
30
+ roles.system = :simple_roles
31
+ roles.exclude :admin # filter
32
+ end
33
+ ```
34
+
35
+ Role groups configuration:
36
+
37
+ ```ruby
38
+ CanTango.config do |config|
39
+ config.roles_groups do |role_groups|
40
+ role_groups.register :editors, :publishers
41
+ role_groups.system = :troles
42
+ role_groups.only :editors # filter
43
+ end
44
+ end
45
+ ```
46
+
47
+ ## Permits
48
+
49
+ Role and RoleGroup Permits for the Permits engine Ability executor.
50
+
51
+ ## Permit Generators
52
+
53
+ Role and RoleGroup Permit Generators
54
+
55
+ `rails g cantango:role_permit admin`
56
+
57
+ *Role group*
58
+
59
+ `rails g cantango:role_permit admin --group`
60
+
61
+ ## Filters
62
+
63
+ Role and RoleGroup filters can be used to filter out specific Role and RoleGroup Permits.
64
+
65
+ ## Helpers
66
+
67
+ Role and RoleGroup helper methods which can be reused in various places, such as Ability executors, Permits etc.
68
+
69
+ ## Contributing to cantango-roles
70
+
71
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
72
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
73
+ * Fork the project
74
+ * Start a feature/bugfix branch
75
+ * Commit and push until you are happy with your contribution
76
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
77
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
78
+
79
+ ## Copyright
80
+
81
+ Copyright (c) 2011 Kristian Mandrup. See LICENSE.txt for
82
+ further details.
83
+
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "cantango-roles"
18
+ gem.homepage = "http://github.com/kristianmandrup/cantango-roles"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Roles extension for CanTango}
21
+ gem.description = %Q{Roles and Role groups for CanTango}
22
+ gem.email = "kmandrup@gmail.com"
23
+ gem.authors = ["Kristian Mandrup"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "cantango-roles #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,11 @@
1
+ require 'sugar-high/array'
2
+ require 'sugar-high/blank'
3
+ require 'hashie'
4
+ require 'sweetloader'
5
+
6
+ require 'cantango/core'
7
+ require 'cantango/config'
8
+
9
+ SweetLoader.mode = :require
10
+
11
+ require 'cantango/roles_ext'
@@ -0,0 +1,9 @@
1
+ module CanTango
2
+ sweet_scope :ns => {:CanTango => 'cantango/roles_ext'} do
3
+ sweetload :Helpers, :Ability, :Builder, :Configuration, :Engine, :Filter
4
+
5
+ if defined? CanTango::Permit
6
+ sweetload :Permit
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module CanTango
2
+ module Ability
3
+ sweet_scope :ns => {:CanTango => 'cantango/roles_ext'} do
4
+ sweetload :Helper
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module CanTango::Ability
2
+ module Helper
3
+ sweet_scope :ns => {:CanTango => 'cantango/roles_ext'} do
4
+ sweetload :Role, :RoleGroup
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module CanTango::Ability::Helper
2
+ module Role
3
+ include CanTango::Helpers::Role
4
+
5
+ # return list roles the user has
6
+ def roles
7
+ return [] if !subject.respond_to?(roles_list_meth) || roles_of(subject).blank?
8
+ roles_of(subject).flatten
9
+ end
10
+
11
+ protected
12
+
13
+ def roles_of subject
14
+ @subj_roles ||= subject.send(roles_list_meth)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module CanTango::Ability::Helper
2
+ module RoleGroup
3
+ include CanTango::Helpers::RoleGroup
4
+
5
+ # return list of symbols for role groups the user belongs to
6
+ def role_groups
7
+ return [] if !subject.respond_to?(role_groups_list_meth) || role_groups_of(subject).blank?
8
+ role_groups_of(subject).flatten
9
+ end
10
+
11
+ protected
12
+
13
+ def role_groups_of subject
14
+ @subj_role_groups ||= subject.send(role_groups_list_meth)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module CanTango
2
+ module Builder
3
+ sweet_scope :ns => {:CanTango => 'cantango/roles_ext'} do
4
+ sweetload :Permit
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module CanTango::Builder
2
+ module Permit
3
+ if defined? CanTango::Permit
4
+ sweetload :Role, :RoleGroup
5
+ end
6
+ end
7
+ end