alberich 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (242) hide show
  1. data/Gemfile +18 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +37 -0
  4. data/Rakefile +34 -0
  5. data/alberich.gemspec +34 -0
  6. data/app/assets/javascripts/alberich/application.js +15 -0
  7. data/app/assets/javascripts/alberich/permissions.js +2 -0
  8. data/app/assets/javascripts/alberich/privileges.js +2 -0
  9. data/app/assets/javascripts/alberich/roles.js +2 -0
  10. data/app/assets/stylesheets/alberich/application.css +13 -0
  11. data/app/assets/stylesheets/alberich/permissions.css +4 -0
  12. data/app/assets/stylesheets/alberich/privileges.css +4 -0
  13. data/app/assets/stylesheets/alberich/roles.css +4 -0
  14. data/app/assets/stylesheets/scaffold.css +56 -0
  15. data/app/controllers/alberich/application_controller.rb +4 -0
  16. data/app/controllers/alberich/application_controller_helper.rb +118 -0
  17. data/app/controllers/alberich/permissions_controller.rb +211 -0
  18. data/app/controllers/alberich/privileges_controller.rb +105 -0
  19. data/app/controllers/alberich/roles_controller.rb +97 -0
  20. data/app/helpers/alberich/application_helper.rb +4 -0
  21. data/app/helpers/alberich/permissions_helper.rb +4 -0
  22. data/app/helpers/alberich/privileges_helper.rb +4 -0
  23. data/app/helpers/alberich/roles_helper.rb +4 -0
  24. data/app/models/alberich/base_permission_object.rb +42 -0
  25. data/app/models/alberich/derived_permission.rb +25 -0
  26. data/app/models/alberich/entity.rb +27 -0
  27. data/app/models/alberich/entity_target_observer.rb +16 -0
  28. data/app/models/alberich/permission.rb +59 -0
  29. data/app/models/alberich/permission_session.rb +33 -0
  30. data/app/models/alberich/permissioned_object.rb +139 -0
  31. data/app/models/alberich/privilege.rb +29 -0
  32. data/app/models/alberich/role.rb +37 -0
  33. data/app/models/alberich/session_entity.rb +15 -0
  34. data/app/views/alberich/permissions/_form.html.haml +27 -0
  35. data/app/views/alberich/permissions/_list.html.haml +1 -0
  36. data/app/views/alberich/permissions/_objects.html.haml +38 -0
  37. data/app/views/alberich/permissions/_permissions.html.haml +45 -0
  38. data/app/views/alberich/permissions/index.html.haml +2 -0
  39. data/app/views/alberich/permissions/new.html.haml +5 -0
  40. data/app/views/alberich/permissions/show.html.haml +12 -0
  41. data/app/views/alberich/privileges/_form.html.haml +19 -0
  42. data/app/views/alberich/privileges/_list.html.haml +17 -0
  43. data/app/views/alberich/privileges/create.html.haml +2 -0
  44. data/app/views/alberich/privileges/destroy.html.haml +2 -0
  45. data/app/views/alberich/privileges/edit.html.haml +5 -0
  46. data/app/views/alberich/privileges/index.html.haml +5 -0
  47. data/app/views/alberich/privileges/new.html.haml +5 -0
  48. data/app/views/alberich/privileges/show.html.haml +12 -0
  49. data/app/views/alberich/privileges/update.html.haml +2 -0
  50. data/app/views/alberich/roles/_form.html.haml +24 -0
  51. data/app/views/alberich/roles/edit.html.haml +7 -0
  52. data/app/views/alberich/roles/index.html.haml +23 -0
  53. data/app/views/alberich/roles/new.html.haml +5 -0
  54. data/app/views/alberich/roles/show.html.haml +16 -0
  55. data/app/views/layouts/alberich/application.html.erb +14 -0
  56. data/config/initializers/haml.rb +1 -0
  57. data/config/routes.rb +17 -0
  58. data/db/migrate/20120925162242_create_alberich_roles.rb +12 -0
  59. data/db/migrate/20121022223626_create_alberich_privileges.rb +12 -0
  60. data/db/migrate/20121023051301_create_alberich_base_permission_objects.rb +9 -0
  61. data/db/migrate/20121023233648_create_alberich_permission_sessions.rb +11 -0
  62. data/db/migrate/20121027023136_create_alberich_entities.rb +34 -0
  63. data/db/migrate/20121204205213_create_alberich_session_entities.rb +12 -0
  64. data/db/migrate/20121205180518_create_alberich_permissions.rb +13 -0
  65. data/db/migrate/20130107043252_create_alberich_derived_permissions.rb +18 -0
  66. data/lib/alberich.rb +10 -0
  67. data/lib/alberich/#version.rb# +3 -0
  68. data/lib/alberich/engine.rb +10 -0
  69. data/lib/alberich/version.rb +3 -0
  70. data/lib/generators/alberich/install_generator.rb +15 -0
  71. data/lib/generators/alberich/templates/README +6 -0
  72. data/lib/generators/alberich/templates/alberich.rb +11 -0
  73. data/lib/tasks/alberich_tasks.rake +4 -0
  74. data/spec/controllers/alberich/permissions_controller_spec.rb +112 -0
  75. data/spec/controllers/alberich/privileges_controller_spec.rb +131 -0
  76. data/spec/controllers/alberich/roles_controller_spec.rb +130 -0
  77. data/spec/factories/alberich/permission.rb +51 -0
  78. data/spec/factories/alberich/permission_session.rb +7 -0
  79. data/spec/factories/alberich/privilege.rb +6 -0
  80. data/spec/factories/alberich/role.rb +103 -0
  81. data/spec/factories/child_resource.rb +14 -0
  82. data/spec/factories/child_resource.rb~ +7 -0
  83. data/spec/factories/global_resource.rb +11 -0
  84. data/spec/factories/global_resource.rb~ +25 -0
  85. data/spec/factories/parent_resource.rb +12 -0
  86. data/spec/factories/parent_resource.rb~ +7 -0
  87. data/spec/factories/standalone_resource.rb +7 -0
  88. data/spec/factories/standalone_resource.rb~ +11 -0
  89. data/spec/factories/user.rb +30 -0
  90. data/spec/factories/user_group.rb +8 -0
  91. data/spec/models/alberich/derived_permission_spec.rb +34 -0
  92. data/spec/models/alberich/entity_spec.rb +15 -0
  93. data/spec/models/alberich/permission_spec.rb +133 -0
  94. data/spec/models/alberich/privilege_spec.rb +39 -0
  95. data/spec/models/alberich/role_spec.rb +33 -0
  96. data/spec/models/alberich/session_entity_spec.rb +24 -0
  97. data/spec/spec_helper.rb +81 -0
  98. data/spec/support/routes.rb +41 -0
  99. data/test/dummy/README.rdoc +261 -0
  100. data/test/dummy/Rakefile +7 -0
  101. data/test/dummy/app/assets/javascripts/application.js +15 -0
  102. data/test/dummy/app/assets/javascripts/child_resources.js +2 -0
  103. data/test/dummy/app/assets/javascripts/global_resources.js +2 -0
  104. data/test/dummy/app/assets/javascripts/parent_resources.js +2 -0
  105. data/test/dummy/app/assets/javascripts/standalone_resources.js +2 -0
  106. data/test/dummy/app/assets/javascripts/user_groups.js +2 -0
  107. data/test/dummy/app/assets/javascripts/users.js +2 -0
  108. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  109. data/test/dummy/app/assets/stylesheets/child_resources.css +4 -0
  110. data/test/dummy/app/assets/stylesheets/global_resources.css +4 -0
  111. data/test/dummy/app/assets/stylesheets/parent_resources.css +4 -0
  112. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  113. data/test/dummy/app/assets/stylesheets/standalone_resources.css +4 -0
  114. data/test/dummy/app/assets/stylesheets/user_groups.css +4 -0
  115. data/test/dummy/app/assets/stylesheets/users.css +4 -0
  116. data/test/dummy/app/controllers/application_controller.rb +73 -0
  117. data/test/dummy/app/controllers/child_resources_controller.rb +99 -0
  118. data/test/dummy/app/controllers/child_resources_controller.rb~ +83 -0
  119. data/test/dummy/app/controllers/global_resources_controller.rb +95 -0
  120. data/test/dummy/app/controllers/global_resources_controller.rb~ +83 -0
  121. data/test/dummy/app/controllers/parent_resources_controller.rb +101 -0
  122. data/test/dummy/app/controllers/parent_resources_controller.rb~ +83 -0
  123. data/test/dummy/app/controllers/standalone_resources_controller.rb +101 -0
  124. data/test/dummy/app/controllers/standalone_resources_controller.rb~ +83 -0
  125. data/test/dummy/app/controllers/user_groups_controller.rb +131 -0
  126. data/test/dummy/app/controllers/user_sessions_controller.rb +38 -0
  127. data/test/dummy/app/controllers/users_controller.rb +87 -0
  128. data/test/dummy/app/helpers/application_helper.rb +2 -0
  129. data/test/dummy/app/helpers/child_resources_helper.rb +2 -0
  130. data/test/dummy/app/helpers/global_resources_helper.rb +2 -0
  131. data/test/dummy/app/helpers/parent_resources_helper.rb +2 -0
  132. data/test/dummy/app/helpers/standalone_resources_helper.rb +2 -0
  133. data/test/dummy/app/helpers/user_groups_helper.rb +2 -0
  134. data/test/dummy/app/helpers/users_helper.rb +2 -0
  135. data/test/dummy/app/models/child_resource.rb +25 -0
  136. data/test/dummy/app/models/child_resource.rb~ +4 -0
  137. data/test/dummy/app/models/global_resource.rb +3 -0
  138. data/test/dummy/app/models/parent_resource.rb +32 -0
  139. data/test/dummy/app/models/parent_resource.rb~ +3 -0
  140. data/test/dummy/app/models/standalone_resource.rb +22 -0
  141. data/test/dummy/app/models/standalone_resource.rb~ +3 -0
  142. data/test/dummy/app/models/user.rb +80 -0
  143. data/test/dummy/app/models/user_group.rb +12 -0
  144. data/test/dummy/app/views/child_resources/_form.html.erb +30 -0
  145. data/test/dummy/app/views/child_resources/_form.html.erb~ +29 -0
  146. data/test/dummy/app/views/child_resources/edit.html.erb +6 -0
  147. data/test/dummy/app/views/child_resources/index.html.erb +25 -0
  148. data/test/dummy/app/views/child_resources/index.html.erb~ +27 -0
  149. data/test/dummy/app/views/child_resources/new.html.erb +5 -0
  150. data/test/dummy/app/views/child_resources/show.html.erb +20 -0
  151. data/test/dummy/app/views/child_resources/show.html.erb~ +20 -0
  152. data/test/dummy/app/views/global_resources/_form.html.erb +25 -0
  153. data/test/dummy/app/views/global_resources/edit.html.erb +6 -0
  154. data/test/dummy/app/views/global_resources/index.html.erb +25 -0
  155. data/test/dummy/app/views/global_resources/new.html.erb +5 -0
  156. data/test/dummy/app/views/global_resources/show.html.erb +15 -0
  157. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  158. data/test/dummy/app/views/parent_resources/_form.html.erb +25 -0
  159. data/test/dummy/app/views/parent_resources/edit.html.erb +6 -0
  160. data/test/dummy/app/views/parent_resources/index.html.erb +25 -0
  161. data/test/dummy/app/views/parent_resources/index.html.erb~ +25 -0
  162. data/test/dummy/app/views/parent_resources/new.html.erb +5 -0
  163. data/test/dummy/app/views/parent_resources/show.html.erb +44 -0
  164. data/test/dummy/app/views/parent_resources/show.html.erb~ +15 -0
  165. data/test/dummy/app/views/standalone_resources/_form.html.erb +25 -0
  166. data/test/dummy/app/views/standalone_resources/edit.html.erb +6 -0
  167. data/test/dummy/app/views/standalone_resources/index.html.erb +25 -0
  168. data/test/dummy/app/views/standalone_resources/new.html.erb +5 -0
  169. data/test/dummy/app/views/standalone_resources/show.html.erb +15 -0
  170. data/test/dummy/app/views/user_groups/_form.html.haml +9 -0
  171. data/test/dummy/app/views/user_groups/add_members.html.haml +18 -0
  172. data/test/dummy/app/views/user_groups/edit.html.haml +13 -0
  173. data/test/dummy/app/views/user_groups/index.html.haml +20 -0
  174. data/test/dummy/app/views/user_groups/new.html.haml +11 -0
  175. data/test/dummy/app/views/user_groups/show.html.haml +42 -0
  176. data/test/dummy/app/views/user_sessions/new.html.haml +26 -0
  177. data/test/dummy/app/views/users/_form.html.haml +25 -0
  178. data/test/dummy/app/views/users/edit.html.haml +14 -0
  179. data/test/dummy/app/views/users/index.html.haml +26 -0
  180. data/test/dummy/app/views/users/new.html.haml +11 -0
  181. data/test/dummy/app/views/users/show.html.haml +56 -0
  182. data/test/dummy/config.ru +4 -0
  183. data/test/dummy/config/application.rb +59 -0
  184. data/test/dummy/config/boot.rb +10 -0
  185. data/test/dummy/config/database.yml +25 -0
  186. data/test/dummy/config/environment.rb +5 -0
  187. data/test/dummy/config/environments/development.rb +37 -0
  188. data/test/dummy/config/environments/production.rb +67 -0
  189. data/test/dummy/config/environments/test.rb +37 -0
  190. data/test/dummy/config/initializers/alberich.rb +13 -0
  191. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  192. data/test/dummy/config/initializers/inflections.rb +15 -0
  193. data/test/dummy/config/initializers/mime_types.rb +5 -0
  194. data/test/dummy/config/initializers/secret_token.rb +7 -0
  195. data/test/dummy/config/initializers/session_store.rb +8 -0
  196. data/test/dummy/config/initializers/warden.rb +79 -0
  197. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  198. data/test/dummy/config/locales/en.yml +5 -0
  199. data/test/dummy/config/routes.rb +33 -0
  200. data/test/dummy/db/migrate/20120801010101_create_users.rb +20 -0
  201. data/test/dummy/db/migrate/20121121054319_create_user_groups.rb +16 -0
  202. data/test/dummy/db/migrate/20130220160811_create_global_resources.rb +10 -0
  203. data/test/dummy/db/migrate/20130220175258_create_standalone_resources.rb +10 -0
  204. data/test/dummy/db/migrate/20130226145412_create_parent_resources.rb +10 -0
  205. data/test/dummy/db/migrate/20130226151256_create_child_resources.rb +12 -0
  206. data/test/dummy/db/migrate/20130226151256_create_child_resources.rb~ +12 -0
  207. data/test/dummy/db/schema.rb +151 -0
  208. data/test/dummy/db/seeds.rb +65 -0
  209. data/test/dummy/lib/password.rb +58 -0
  210. data/test/dummy/public/404.html +26 -0
  211. data/test/dummy/public/422.html +26 -0
  212. data/test/dummy/public/500.html +25 -0
  213. data/test/dummy/public/favicon.ico +0 -0
  214. data/test/dummy/script/rails +6 -0
  215. data/test/dummy/test/fixtures/child_resources.yml +11 -0
  216. data/test/dummy/test/fixtures/global_resources.yml +9 -0
  217. data/test/dummy/test/fixtures/parent_resources.yml +9 -0
  218. data/test/dummy/test/fixtures/standalone_resources.yml +9 -0
  219. data/test/dummy/test/fixtures/user_groups.yml +9 -0
  220. data/test/dummy/test/fixtures/users.yml +37 -0
  221. data/test/dummy/test/functional/child_resources_controller_test.rb +49 -0
  222. data/test/dummy/test/functional/global_resources_controller_test.rb +49 -0
  223. data/test/dummy/test/functional/parent_resources_controller_test.rb +49 -0
  224. data/test/dummy/test/functional/standalone_resources_controller_test.rb +49 -0
  225. data/test/dummy/test/functional/user_groups_controller_test.rb +49 -0
  226. data/test/dummy/test/functional/users_controller_test.rb +39 -0
  227. data/test/dummy/test/unit/child_resource_test.rb +7 -0
  228. data/test/dummy/test/unit/global_resource_test.rb +7 -0
  229. data/test/dummy/test/unit/helpers/child_resources_helper_test.rb +4 -0
  230. data/test/dummy/test/unit/helpers/global_resources_helper_test.rb +4 -0
  231. data/test/dummy/test/unit/helpers/parent_resources_helper_test.rb +4 -0
  232. data/test/dummy/test/unit/helpers/standalone_resources_helper_test.rb +4 -0
  233. data/test/dummy/test/unit/helpers/user_groups_helper_test.rb +4 -0
  234. data/test/dummy/test/unit/helpers/users_helper_test.rb +4 -0
  235. data/test/dummy/test/unit/parent_resource_test.rb +7 -0
  236. data/test/dummy/test/unit/standalone_resource_test.rb +7 -0
  237. data/test/dummy/test/unit/user_group_test.rb +7 -0
  238. data/test/dummy/test/unit/user_test.rb +7 -0
  239. data/test/integration/alberich/permission_test.rb +7 -0
  240. data/test/integration/alberich/privilege_test.rb +7 -0
  241. data/test/integration/alberich/role_test.rb +7 -0
  242. metadata +639 -0
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,37 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+
25
+ # Raise exception on mass assignment protection for Active Record models
26
+ config.active_record.mass_assignment_sanitizer = :strict
27
+
28
+ # Log the query plan for queries taking more than this (works
29
+ # with SQLite, MySQL, and PostgreSQL)
30
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
31
+
32
+ # Do not compress assets
33
+ config.assets.compress = false
34
+
35
+ # Expands the lines which load the assets
36
+ config.assets.debug = true
37
+ end
@@ -0,0 +1,67 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+ # Compress JavaScripts and CSS
15
+ config.assets.compress = true
16
+
17
+ # Don't fallback to assets pipeline if a precompiled asset is missed
18
+ config.assets.compile = false
19
+
20
+ # Generate digests for assets URLs
21
+ config.assets.digest = true
22
+
23
+ # Defaults to nil and saved in location specified by config.assets.prefix
24
+ # config.assets.manifest = YOUR_PATH
25
+
26
+ # Specifies the header that your server uses for sending files
27
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
29
+
30
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31
+ # config.force_ssl = true
32
+
33
+ # See everything in the log (default is :info)
34
+ # config.log_level = :debug
35
+
36
+ # Prepend all log lines with the following tags
37
+ # config.log_tags = [ :subdomain, :uuid ]
38
+
39
+ # Use a different logger for distributed setups
40
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
41
+
42
+ # Use a different cache store in production
43
+ # config.cache_store = :mem_cache_store
44
+
45
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
46
+ # config.action_controller.asset_host = "http://assets.example.com"
47
+
48
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
49
+ # config.assets.precompile += %w( search.js )
50
+
51
+ # Disable delivery errors, bad email addresses will be ignored
52
+ # config.action_mailer.raise_delivery_errors = false
53
+
54
+ # Enable threaded mode
55
+ # config.threadsafe!
56
+
57
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
58
+ # the I18n.default_locale when a translation can not be found)
59
+ config.i18n.fallbacks = true
60
+
61
+ # Send deprecation notices to registered listeners
62
+ config.active_support.deprecation = :notify
63
+
64
+ # Log the query plan for queries taking more than this (works
65
+ # with SQLite, MySQL, and PostgreSQL)
66
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
67
+ end
@@ -0,0 +1,37 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
27
+ # Tell Action Mailer not to deliver emails to the real world.
28
+ # The :test delivery method accumulates sent emails in the
29
+ # ActionMailer::Base.deliveries array.
30
+ config.action_mailer.delivery_method = :test
31
+
32
+ # Raise exception on mass assignment protection for Active Record models
33
+ config.active_record.mass_assignment_sanitizer = :strict
34
+
35
+ # Print deprecation notices to the stderr
36
+ config.active_support.deprecation = :stderr
37
+ end
@@ -0,0 +1,13 @@
1
+ Alberich.user_class = "User"
2
+ Alberich.groups_for_user_method = "all_groups"
3
+ Alberich.user_group_class = "UserGroup"
4
+ Alberich.permissioned_object_classes = ["StandaloneResource",
5
+ "ParentResource",
6
+ "ChildResource"]
7
+ Alberich.additional_privilege_scopes = ["User", "GlobalResource"]
8
+
9
+ Alberich.require_user_method = "require_user"
10
+
11
+ ActiveSupport.on_load(:action_controller) do
12
+ ActionController::Base.send(:include, Alberich::ApplicationControllerHelper)
13
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
11
+ #
12
+ # These inflection rules are supported but not enabled by default:
13
+ # ActiveSupport::Inflector.inflections do |inflect|
14
+ # inflect.acronym 'RESTful'
15
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = '1456949ecb52d46f41d8e31d399c3c1e9e07a8d3237e46783932fcc5a2995c5a2656d6158d2f7f6baa2ce60e8a1d4d44f5ef5ff83cf5619b3a88213e053c9d12'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,79 @@
1
+ Rails.configuration.middleware.use RailsWarden::Manager do |config|
2
+ config.failure_app = UserSessionsController
3
+ config.default_scope = :user
4
+
5
+ # all UI requests are handled in the default scope
6
+ config.scope_defaults(
7
+ :user,
8
+ :strategies => :database,
9
+ :store => true,
10
+ :action => 'unauthenticated'
11
+ )
12
+
13
+ config.scope_defaults(
14
+ :api,
15
+ :strategies => :database,
16
+ :store => true,
17
+ :action => 'unauthenticated'
18
+ )
19
+ end
20
+
21
+ class Warden::SessionSerializer
22
+ def serialize(user)
23
+ raise ArgumentError, "Cannot serialize invalid user object: #{user}" if not user.is_a? User and user.id.is_a? Integer
24
+ user.id
25
+ end
26
+
27
+ def deserialize(id)
28
+ raise ArgumentError, "Cannot deserialize non-integer id: #{id}" unless id.is_a? Integer
29
+ User.find(id) rescue nil
30
+ end
31
+ end
32
+
33
+ module Warden::Mixins::Common
34
+ def get_credentials
35
+ if request.authorization && request.authorization =~ /^Basic (.*)/m
36
+ Rails.logger.debug("Using basic HTTP auth header")
37
+ Base64.decode64($1).split(/:/, 2)
38
+ else
39
+ [params[:username], params[:password]]
40
+ end
41
+ end
42
+ end
43
+
44
+ # authenticate against database
45
+ Warden::Strategies.add(:database) do
46
+ def authenticate!
47
+ username, password = get_credentials
48
+ return unless username && password
49
+ Rails.logger.debug("Warden is authenticating #{username} against database")
50
+ ipaddress = request.env[ 'HTTP_X_FORWARDED_FOR' ] ? request.env[ 'HTTP_X_FORWARDED_FOR' ] : request.remote_ip
51
+ u = User.authenticate(username, password, ipaddress)
52
+ u ? success!(u) : fail!("Username or password is not correct - could not log in")
53
+ end
54
+ end
55
+
56
+ Warden::Manager.after_authentication do |user,auth,opts|
57
+ current_session_id = auth.request.session_options[:id]
58
+ session = auth.env['rack.session']
59
+ perm_session = Alberich::PermissionSession.create!(:user => user,
60
+ :session_id => current_session_id)
61
+ session[:permission_session_id] = perm_session.id
62
+ perm_session.update_session_entities(user)
63
+ end
64
+ Warden::Manager.after_set_user do |user,auth,opts|
65
+ current_session_id = auth.request.session_options[:id]
66
+ session = auth.env['rack.session']
67
+ perm_session_id = session[:permission_session_id]
68
+ if perm_session_id
69
+ perm_session = Alberich::PermissionSession.find_by_id(perm_session_id)
70
+ #if session_id doesn't match what we originally set, update the value
71
+ # This isn't needed for perm checks (that's why we store
72
+ # permission_session_id), but matching the correct session_id will facilitate
73
+ # permission_session cleanup
74
+ if perm_session && (perm_session.session_id != current_session_id)
75
+ perm_session.session_id = current_session_id
76
+ perm_session.save!
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,33 @@
1
+ Rails.application.routes.draw do
2
+ resources :child_resources
3
+
4
+
5
+ resources :parent_resources
6
+
7
+
8
+ resources :standalone_resources
9
+
10
+
11
+ resources :global_resources
12
+
13
+
14
+ resources :user_groups do
15
+ member do
16
+ get 'add_members'
17
+ get 'add_member'
18
+ delete 'remove_member'
19
+ end
20
+ end
21
+
22
+ root :to => "users#index"
23
+
24
+ resources :users
25
+ resource :user_session
26
+ match 'login', :to => 'user_sessions#new', :as => 'login'
27
+ match 'logout', :to => 'user_sessions#destroy', :as => 'logout'
28
+ match 'register', :to => 'users#new', :as => 'register'
29
+
30
+ resource 'account', :to => 'users'
31
+
32
+ mount Alberich::Engine => "/alberich"
33
+ end
@@ -0,0 +1,20 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :username, :null => false
5
+ t.string :email
6
+ t.string :crypted_password
7
+ t.string :first_name
8
+ t.string :last_name
9
+ t.integer :login_count, :null => false, :default => 0
10
+ t.integer :failed_login_count, :null => false, :default => 0
11
+ t.datetime :last_request_at
12
+ t.datetime :current_login_at
13
+ t.datetime :last_login_at
14
+ t.string :current_login_ip
15
+ t.string :last_login_ip
16
+
17
+ t.timestamps
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ class CreateUserGroups < ActiveRecord::Migration
2
+ def change
3
+ create_table :user_groups do |t|
4
+ t.string :name, :null => false
5
+ t.string :description
6
+
7
+ t.integer :lock_version, :default => 0
8
+ t.timestamps
9
+ end
10
+
11
+ create_table :members_user_groups, :id => false do |t|
12
+ t.integer :user_group_id, :null => false
13
+ t.integer :member_id, :null => false
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ class CreateGlobalResources < ActiveRecord::Migration
2
+ def change
3
+ create_table :global_resources do |t|
4
+ t.string :name
5
+ t.string :description
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreateStandaloneResources < ActiveRecord::Migration
2
+ def change
3
+ create_table :standalone_resources do |t|
4
+ t.string :name
5
+ t.string :description
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreateParentResources < ActiveRecord::Migration
2
+ def change
3
+ create_table :parent_resources do |t|
4
+ t.string :name
5
+ t.string :description
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end