alberich 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +18 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +37 -0
- data/Rakefile +34 -0
- data/alberich.gemspec +34 -0
- data/app/assets/javascripts/alberich/application.js +15 -0
- data/app/assets/javascripts/alberich/permissions.js +2 -0
- data/app/assets/javascripts/alberich/privileges.js +2 -0
- data/app/assets/javascripts/alberich/roles.js +2 -0
- data/app/assets/stylesheets/alberich/application.css +13 -0
- data/app/assets/stylesheets/alberich/permissions.css +4 -0
- data/app/assets/stylesheets/alberich/privileges.css +4 -0
- data/app/assets/stylesheets/alberich/roles.css +4 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/alberich/application_controller.rb +4 -0
- data/app/controllers/alberich/application_controller_helper.rb +118 -0
- data/app/controllers/alberich/permissions_controller.rb +211 -0
- data/app/controllers/alberich/privileges_controller.rb +105 -0
- data/app/controllers/alberich/roles_controller.rb +97 -0
- data/app/helpers/alberich/application_helper.rb +4 -0
- data/app/helpers/alberich/permissions_helper.rb +4 -0
- data/app/helpers/alberich/privileges_helper.rb +4 -0
- data/app/helpers/alberich/roles_helper.rb +4 -0
- data/app/models/alberich/base_permission_object.rb +42 -0
- data/app/models/alberich/derived_permission.rb +25 -0
- data/app/models/alberich/entity.rb +27 -0
- data/app/models/alberich/entity_target_observer.rb +16 -0
- data/app/models/alberich/permission.rb +59 -0
- data/app/models/alberich/permission_session.rb +33 -0
- data/app/models/alberich/permissioned_object.rb +139 -0
- data/app/models/alberich/privilege.rb +29 -0
- data/app/models/alberich/role.rb +37 -0
- data/app/models/alberich/session_entity.rb +15 -0
- data/app/views/alberich/permissions/_form.html.haml +27 -0
- data/app/views/alberich/permissions/_list.html.haml +1 -0
- data/app/views/alberich/permissions/_objects.html.haml +38 -0
- data/app/views/alberich/permissions/_permissions.html.haml +45 -0
- data/app/views/alberich/permissions/index.html.haml +2 -0
- data/app/views/alberich/permissions/new.html.haml +5 -0
- data/app/views/alberich/permissions/show.html.haml +12 -0
- data/app/views/alberich/privileges/_form.html.haml +19 -0
- data/app/views/alberich/privileges/_list.html.haml +17 -0
- data/app/views/alberich/privileges/create.html.haml +2 -0
- data/app/views/alberich/privileges/destroy.html.haml +2 -0
- data/app/views/alberich/privileges/edit.html.haml +5 -0
- data/app/views/alberich/privileges/index.html.haml +5 -0
- data/app/views/alberich/privileges/new.html.haml +5 -0
- data/app/views/alberich/privileges/show.html.haml +12 -0
- data/app/views/alberich/privileges/update.html.haml +2 -0
- data/app/views/alberich/roles/_form.html.haml +24 -0
- data/app/views/alberich/roles/edit.html.haml +7 -0
- data/app/views/alberich/roles/index.html.haml +23 -0
- data/app/views/alberich/roles/new.html.haml +5 -0
- data/app/views/alberich/roles/show.html.haml +16 -0
- data/app/views/layouts/alberich/application.html.erb +14 -0
- data/config/initializers/haml.rb +1 -0
- data/config/routes.rb +17 -0
- data/db/migrate/20120925162242_create_alberich_roles.rb +12 -0
- data/db/migrate/20121022223626_create_alberich_privileges.rb +12 -0
- data/db/migrate/20121023051301_create_alberich_base_permission_objects.rb +9 -0
- data/db/migrate/20121023233648_create_alberich_permission_sessions.rb +11 -0
- data/db/migrate/20121027023136_create_alberich_entities.rb +34 -0
- data/db/migrate/20121204205213_create_alberich_session_entities.rb +12 -0
- data/db/migrate/20121205180518_create_alberich_permissions.rb +13 -0
- data/db/migrate/20130107043252_create_alberich_derived_permissions.rb +18 -0
- data/lib/alberich.rb +10 -0
- data/lib/alberich/#version.rb# +3 -0
- data/lib/alberich/engine.rb +10 -0
- data/lib/alberich/version.rb +3 -0
- data/lib/generators/alberich/install_generator.rb +15 -0
- data/lib/generators/alberich/templates/README +6 -0
- data/lib/generators/alberich/templates/alberich.rb +11 -0
- data/lib/tasks/alberich_tasks.rake +4 -0
- data/spec/controllers/alberich/permissions_controller_spec.rb +112 -0
- data/spec/controllers/alberich/privileges_controller_spec.rb +131 -0
- data/spec/controllers/alberich/roles_controller_spec.rb +130 -0
- data/spec/factories/alberich/permission.rb +51 -0
- data/spec/factories/alberich/permission_session.rb +7 -0
- data/spec/factories/alberich/privilege.rb +6 -0
- data/spec/factories/alberich/role.rb +103 -0
- data/spec/factories/child_resource.rb +14 -0
- data/spec/factories/child_resource.rb~ +7 -0
- data/spec/factories/global_resource.rb +11 -0
- data/spec/factories/global_resource.rb~ +25 -0
- data/spec/factories/parent_resource.rb +12 -0
- data/spec/factories/parent_resource.rb~ +7 -0
- data/spec/factories/standalone_resource.rb +7 -0
- data/spec/factories/standalone_resource.rb~ +11 -0
- data/spec/factories/user.rb +30 -0
- data/spec/factories/user_group.rb +8 -0
- data/spec/models/alberich/derived_permission_spec.rb +34 -0
- data/spec/models/alberich/entity_spec.rb +15 -0
- data/spec/models/alberich/permission_spec.rb +133 -0
- data/spec/models/alberich/privilege_spec.rb +39 -0
- data/spec/models/alberich/role_spec.rb +33 -0
- data/spec/models/alberich/session_entity_spec.rb +24 -0
- data/spec/spec_helper.rb +81 -0
- data/spec/support/routes.rb +41 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/javascripts/child_resources.js +2 -0
- data/test/dummy/app/assets/javascripts/global_resources.js +2 -0
- data/test/dummy/app/assets/javascripts/parent_resources.js +2 -0
- data/test/dummy/app/assets/javascripts/standalone_resources.js +2 -0
- data/test/dummy/app/assets/javascripts/user_groups.js +2 -0
- data/test/dummy/app/assets/javascripts/users.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/child_resources.css +4 -0
- data/test/dummy/app/assets/stylesheets/global_resources.css +4 -0
- data/test/dummy/app/assets/stylesheets/parent_resources.css +4 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/assets/stylesheets/standalone_resources.css +4 -0
- data/test/dummy/app/assets/stylesheets/user_groups.css +4 -0
- data/test/dummy/app/assets/stylesheets/users.css +4 -0
- data/test/dummy/app/controllers/application_controller.rb +73 -0
- data/test/dummy/app/controllers/child_resources_controller.rb +99 -0
- data/test/dummy/app/controllers/child_resources_controller.rb~ +83 -0
- data/test/dummy/app/controllers/global_resources_controller.rb +95 -0
- data/test/dummy/app/controllers/global_resources_controller.rb~ +83 -0
- data/test/dummy/app/controllers/parent_resources_controller.rb +101 -0
- data/test/dummy/app/controllers/parent_resources_controller.rb~ +83 -0
- data/test/dummy/app/controllers/standalone_resources_controller.rb +101 -0
- data/test/dummy/app/controllers/standalone_resources_controller.rb~ +83 -0
- data/test/dummy/app/controllers/user_groups_controller.rb +131 -0
- data/test/dummy/app/controllers/user_sessions_controller.rb +38 -0
- data/test/dummy/app/controllers/users_controller.rb +87 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/child_resources_helper.rb +2 -0
- data/test/dummy/app/helpers/global_resources_helper.rb +2 -0
- data/test/dummy/app/helpers/parent_resources_helper.rb +2 -0
- data/test/dummy/app/helpers/standalone_resources_helper.rb +2 -0
- data/test/dummy/app/helpers/user_groups_helper.rb +2 -0
- data/test/dummy/app/helpers/users_helper.rb +2 -0
- data/test/dummy/app/models/child_resource.rb +25 -0
- data/test/dummy/app/models/child_resource.rb~ +4 -0
- data/test/dummy/app/models/global_resource.rb +3 -0
- data/test/dummy/app/models/parent_resource.rb +32 -0
- data/test/dummy/app/models/parent_resource.rb~ +3 -0
- data/test/dummy/app/models/standalone_resource.rb +22 -0
- data/test/dummy/app/models/standalone_resource.rb~ +3 -0
- data/test/dummy/app/models/user.rb +80 -0
- data/test/dummy/app/models/user_group.rb +12 -0
- data/test/dummy/app/views/child_resources/_form.html.erb +30 -0
- data/test/dummy/app/views/child_resources/_form.html.erb~ +29 -0
- data/test/dummy/app/views/child_resources/edit.html.erb +6 -0
- data/test/dummy/app/views/child_resources/index.html.erb +25 -0
- data/test/dummy/app/views/child_resources/index.html.erb~ +27 -0
- data/test/dummy/app/views/child_resources/new.html.erb +5 -0
- data/test/dummy/app/views/child_resources/show.html.erb +20 -0
- data/test/dummy/app/views/child_resources/show.html.erb~ +20 -0
- data/test/dummy/app/views/global_resources/_form.html.erb +25 -0
- data/test/dummy/app/views/global_resources/edit.html.erb +6 -0
- data/test/dummy/app/views/global_resources/index.html.erb +25 -0
- data/test/dummy/app/views/global_resources/new.html.erb +5 -0
- data/test/dummy/app/views/global_resources/show.html.erb +15 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/parent_resources/_form.html.erb +25 -0
- data/test/dummy/app/views/parent_resources/edit.html.erb +6 -0
- data/test/dummy/app/views/parent_resources/index.html.erb +25 -0
- data/test/dummy/app/views/parent_resources/index.html.erb~ +25 -0
- data/test/dummy/app/views/parent_resources/new.html.erb +5 -0
- data/test/dummy/app/views/parent_resources/show.html.erb +44 -0
- data/test/dummy/app/views/parent_resources/show.html.erb~ +15 -0
- data/test/dummy/app/views/standalone_resources/_form.html.erb +25 -0
- data/test/dummy/app/views/standalone_resources/edit.html.erb +6 -0
- data/test/dummy/app/views/standalone_resources/index.html.erb +25 -0
- data/test/dummy/app/views/standalone_resources/new.html.erb +5 -0
- data/test/dummy/app/views/standalone_resources/show.html.erb +15 -0
- data/test/dummy/app/views/user_groups/_form.html.haml +9 -0
- data/test/dummy/app/views/user_groups/add_members.html.haml +18 -0
- data/test/dummy/app/views/user_groups/edit.html.haml +13 -0
- data/test/dummy/app/views/user_groups/index.html.haml +20 -0
- data/test/dummy/app/views/user_groups/new.html.haml +11 -0
- data/test/dummy/app/views/user_groups/show.html.haml +42 -0
- data/test/dummy/app/views/user_sessions/new.html.haml +26 -0
- data/test/dummy/app/views/users/_form.html.haml +25 -0
- data/test/dummy/app/views/users/edit.html.haml +14 -0
- data/test/dummy/app/views/users/index.html.haml +26 -0
- data/test/dummy/app/views/users/new.html.haml +11 -0
- data/test/dummy/app/views/users/show.html.haml +56 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/alberich.rb +13 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/warden.rb +79 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +33 -0
- data/test/dummy/db/migrate/20120801010101_create_users.rb +20 -0
- data/test/dummy/db/migrate/20121121054319_create_user_groups.rb +16 -0
- data/test/dummy/db/migrate/20130220160811_create_global_resources.rb +10 -0
- data/test/dummy/db/migrate/20130220175258_create_standalone_resources.rb +10 -0
- data/test/dummy/db/migrate/20130226145412_create_parent_resources.rb +10 -0
- data/test/dummy/db/migrate/20130226151256_create_child_resources.rb +12 -0
- data/test/dummy/db/migrate/20130226151256_create_child_resources.rb~ +12 -0
- data/test/dummy/db/schema.rb +151 -0
- data/test/dummy/db/seeds.rb +65 -0
- data/test/dummy/lib/password.rb +58 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/child_resources.yml +11 -0
- data/test/dummy/test/fixtures/global_resources.yml +9 -0
- data/test/dummy/test/fixtures/parent_resources.yml +9 -0
- data/test/dummy/test/fixtures/standalone_resources.yml +9 -0
- data/test/dummy/test/fixtures/user_groups.yml +9 -0
- data/test/dummy/test/fixtures/users.yml +37 -0
- data/test/dummy/test/functional/child_resources_controller_test.rb +49 -0
- data/test/dummy/test/functional/global_resources_controller_test.rb +49 -0
- data/test/dummy/test/functional/parent_resources_controller_test.rb +49 -0
- data/test/dummy/test/functional/standalone_resources_controller_test.rb +49 -0
- data/test/dummy/test/functional/user_groups_controller_test.rb +49 -0
- data/test/dummy/test/functional/users_controller_test.rb +39 -0
- data/test/dummy/test/unit/child_resource_test.rb +7 -0
- data/test/dummy/test/unit/global_resource_test.rb +7 -0
- data/test/dummy/test/unit/helpers/child_resources_helper_test.rb +4 -0
- data/test/dummy/test/unit/helpers/global_resources_helper_test.rb +4 -0
- data/test/dummy/test/unit/helpers/parent_resources_helper_test.rb +4 -0
- data/test/dummy/test/unit/helpers/standalone_resources_helper_test.rb +4 -0
- data/test/dummy/test/unit/helpers/user_groups_helper_test.rb +4 -0
- data/test/dummy/test/unit/helpers/users_helper_test.rb +4 -0
- data/test/dummy/test/unit/parent_resource_test.rb +7 -0
- data/test/dummy/test/unit/standalone_resource_test.rb +7 -0
- data/test/dummy/test/unit/user_group_test.rb +7 -0
- data/test/dummy/test/unit/user_test.rb +7 -0
- data/test/integration/alberich/permission_test.rb +7 -0
- data/test/integration/alberich/privilege_test.rb +7 -0
- data/test/integration/alberich/role_test.rb +7 -0
- metadata +639 -0
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,56 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
div.field, div.actions {
|
20
|
+
margin-bottom: 10px;
|
21
|
+
}
|
22
|
+
|
23
|
+
#notice {
|
24
|
+
color: green;
|
25
|
+
}
|
26
|
+
|
27
|
+
.field_with_errors {
|
28
|
+
padding: 2px;
|
29
|
+
background-color: red;
|
30
|
+
display: table;
|
31
|
+
}
|
32
|
+
|
33
|
+
#error_explanation {
|
34
|
+
width: 450px;
|
35
|
+
border: 2px solid red;
|
36
|
+
padding: 7px;
|
37
|
+
padding-bottom: 0;
|
38
|
+
margin-bottom: 20px;
|
39
|
+
background-color: #f0f0f0;
|
40
|
+
}
|
41
|
+
|
42
|
+
#error_explanation h2 {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
padding: 5px 5px 5px 15px;
|
46
|
+
font-size: 12px;
|
47
|
+
margin: -7px;
|
48
|
+
margin-bottom: 0px;
|
49
|
+
background-color: #c00;
|
50
|
+
color: #fff;
|
51
|
+
}
|
52
|
+
|
53
|
+
#error_explanation ul li {
|
54
|
+
font-size: 12px;
|
55
|
+
list-style: square;
|
56
|
+
}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
protect_from_forgery
|
3
|
+
|
4
|
+
def require_user
|
5
|
+
return if current_user or http_auth_user
|
6
|
+
respond_to do |format|
|
7
|
+
format.html do
|
8
|
+
store_location
|
9
|
+
flash[:notice] = "Please log in first."
|
10
|
+
redirect_to login_url
|
11
|
+
end
|
12
|
+
format.js { head :unauthorized }
|
13
|
+
format.xml { head :unauthorized }
|
14
|
+
format.json { head :unauthorized }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def require_user_api
|
19
|
+
return if current_user or http_auth_user
|
20
|
+
respond_to do |format|
|
21
|
+
format.xml { head :unauthorized }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def require_no_user
|
26
|
+
return true unless current_user
|
27
|
+
store_location
|
28
|
+
flash[:notice] = "You must be logged out to access this page."
|
29
|
+
redirect_to account_url
|
30
|
+
end
|
31
|
+
|
32
|
+
def http_auth_user
|
33
|
+
return unless request.authorization && request.authorization =~ /^Basic (.*)/m
|
34
|
+
authenticate!(:scope => :api)
|
35
|
+
frozen = request.session_options.frozen?
|
36
|
+
request.session_options = request.session_options.dup if frozen
|
37
|
+
request.session_options[:expire_after] = 2.minutes
|
38
|
+
request.session_options.freeze if frozen
|
39
|
+
# we use :api scope for authentication to avoid saving session.
|
40
|
+
# But it's handy to set authenticated user in default scope, so we
|
41
|
+
# can use current_user, instead of current_user(:api)
|
42
|
+
env['warden'].set_user(user(:api)) if user(:api)
|
43
|
+
return user(:api)
|
44
|
+
end
|
45
|
+
|
46
|
+
def store_location
|
47
|
+
session[:return_to] = request.get? ? request.fullpath : request.referer
|
48
|
+
end
|
49
|
+
|
50
|
+
def back_or_default_url(default)
|
51
|
+
return session[:return_to] || default
|
52
|
+
session[:return_to] = nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_permissions_tab(perm_obj, path_prefix = '',
|
56
|
+
polymorphic_path_extras = {})
|
57
|
+
add_permissions_common(false, perm_obj, path_prefix,
|
58
|
+
polymorphic_path_extras)
|
59
|
+
if "permissions" == params[:details_tab]
|
60
|
+
require_privilege(Privilege::PERM_VIEW, perm_obj)
|
61
|
+
end
|
62
|
+
if check_privilege(Privilege::PERM_VIEW, perm_obj)
|
63
|
+
if @tabs
|
64
|
+
@tabs << {:name => "Role Assignments",
|
65
|
+
:view => 'permissions/permissions',
|
66
|
+
:id => 'permissions',
|
67
|
+
:count => perm_obj.permissions.count,
|
68
|
+
:pretty_view_toggle => 'disabled'}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
class ChildResourcesController < ApplicationController
|
2
|
+
# GET /child_resources
|
3
|
+
# GET /child_resources.json
|
4
|
+
def index
|
5
|
+
@child_resources = ChildResource.
|
6
|
+
list_for_user(current_session, current_user, Alberich::Privilege::VIEW)
|
7
|
+
|
8
|
+
respond_to do |format|
|
9
|
+
format.html # index.html.erb
|
10
|
+
format.json { render json: @child_resources }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# GET /child_resources/1
|
15
|
+
# GET /child_resources/1.json
|
16
|
+
def show
|
17
|
+
@child_resource = ChildResource.find(params[:id])
|
18
|
+
# require view permissions on this object
|
19
|
+
require_privilege(Alberich::Privilege::VIEW, @child_resource)
|
20
|
+
|
21
|
+
respond_to do |format|
|
22
|
+
format.html # show.html.erb
|
23
|
+
format.json { render json: @child_resource }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# GET /child_resources/new
|
28
|
+
# GET /child_resources/new.json
|
29
|
+
def new
|
30
|
+
@parent_resource = ParentResource.find(params[:parent_resource_id])
|
31
|
+
require_privilege(Alberich::Privilege::CREATE, ChildResource,
|
32
|
+
@parent_resource)
|
33
|
+
@child_resource = ChildResource.new(:parent_resource_id=>
|
34
|
+
@parent_resource.id)
|
35
|
+
respond_to do |format|
|
36
|
+
format.html # new.html.erb
|
37
|
+
format.json { render json: @child_resource }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# GET /child_resources/1/edit
|
42
|
+
def edit
|
43
|
+
@child_resource = ChildResource.find(params[:id])
|
44
|
+
# require modify permissions for this object
|
45
|
+
require_privilege(Alberich::Privilege::MODIFY, @child_resource)
|
46
|
+
end
|
47
|
+
|
48
|
+
# POST /child_resources
|
49
|
+
# POST /child_resources.json
|
50
|
+
def create
|
51
|
+
@parent_resource = ParentResource.find(params[:child_resource][:parent_resource_id])
|
52
|
+
require_privilege(Alberich::Privilege::CREATE, ChildResource,
|
53
|
+
@parent_resource)
|
54
|
+
@child_resource = ChildResource.new(params[:child_resource])
|
55
|
+
|
56
|
+
respond_to do |format|
|
57
|
+
if @child_resource.save
|
58
|
+
@child_resource.assign_owner_roles(current_user)
|
59
|
+
format.html { redirect_to @child_resource, notice: 'Child resource was successfully created.' }
|
60
|
+
format.json { render json: @child_resource, status: :created, location: @child_resource }
|
61
|
+
else
|
62
|
+
format.html { render action: "new" }
|
63
|
+
format.json { render json: @child_resource.errors, status: :unprocessable_entity }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# PUT /child_resources/1
|
69
|
+
# PUT /child_resources/1.json
|
70
|
+
def update
|
71
|
+
@child_resource = ChildResource.find(params[:id])
|
72
|
+
# require modify permissions for this object
|
73
|
+
require_privilege(Alberich::Privilege::MODIFY, @child_resource)
|
74
|
+
|
75
|
+
respond_to do |format|
|
76
|
+
if @child_resource.update_attributes(params[:child_resource])
|
77
|
+
format.html { redirect_to @child_resource, notice: 'Child resource was successfully updated.' }
|
78
|
+
format.json { head :no_content }
|
79
|
+
else
|
80
|
+
format.html { render action: "edit" }
|
81
|
+
format.json { render json: @child_resource.errors, status: :unprocessable_entity }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# DELETE /child_resources/1
|
87
|
+
# DELETE /child_resources/1.json
|
88
|
+
def destroy
|
89
|
+
@child_resource = ChildResource.find(params[:id])
|
90
|
+
# require modify permissions for this object
|
91
|
+
require_privilege(Alberich::Privilege::MODIFY, @child_resource)
|
92
|
+
@child_resource.destroy
|
93
|
+
|
94
|
+
respond_to do |format|
|
95
|
+
format.html { redirect_to child_resources_url }
|
96
|
+
format.json { head :no_content }
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class ChildResourcesController < ApplicationController
|
2
|
+
# GET /child_resources
|
3
|
+
# GET /child_resources.json
|
4
|
+
def index
|
5
|
+
@child_resources = ChildResource.all
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.erb
|
9
|
+
format.json { render json: @child_resources }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /child_resources/1
|
14
|
+
# GET /child_resources/1.json
|
15
|
+
def show
|
16
|
+
@child_resource = ChildResource.find(params[:id])
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.html # show.html.erb
|
20
|
+
format.json { render json: @child_resource }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# GET /child_resources/new
|
25
|
+
# GET /child_resources/new.json
|
26
|
+
def new
|
27
|
+
@child_resource = ChildResource.new
|
28
|
+
|
29
|
+
respond_to do |format|
|
30
|
+
format.html # new.html.erb
|
31
|
+
format.json { render json: @child_resource }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# GET /child_resources/1/edit
|
36
|
+
def edit
|
37
|
+
@child_resource = ChildResource.find(params[:id])
|
38
|
+
end
|
39
|
+
|
40
|
+
# POST /child_resources
|
41
|
+
# POST /child_resources.json
|
42
|
+
def create
|
43
|
+
@child_resource = ChildResource.new(params[:child_resource])
|
44
|
+
|
45
|
+
respond_to do |format|
|
46
|
+
if @child_resource.save
|
47
|
+
format.html { redirect_to @child_resource, notice: 'Child resource was successfully created.' }
|
48
|
+
format.json { render json: @child_resource, status: :created, location: @child_resource }
|
49
|
+
else
|
50
|
+
format.html { render action: "new" }
|
51
|
+
format.json { render json: @child_resource.errors, status: :unprocessable_entity }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# PUT /child_resources/1
|
57
|
+
# PUT /child_resources/1.json
|
58
|
+
def update
|
59
|
+
@child_resource = ChildResource.find(params[:id])
|
60
|
+
|
61
|
+
respond_to do |format|
|
62
|
+
if @child_resource.update_attributes(params[:child_resource])
|
63
|
+
format.html { redirect_to @child_resource, notice: 'Child resource was successfully updated.' }
|
64
|
+
format.json { head :no_content }
|
65
|
+
else
|
66
|
+
format.html { render action: "edit" }
|
67
|
+
format.json { render json: @child_resource.errors, status: :unprocessable_entity }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# DELETE /child_resources/1
|
73
|
+
# DELETE /child_resources/1.json
|
74
|
+
def destroy
|
75
|
+
@child_resource = ChildResource.find(params[:id])
|
76
|
+
@child_resource.destroy
|
77
|
+
|
78
|
+
respond_to do |format|
|
79
|
+
format.html { redirect_to child_resources_url }
|
80
|
+
format.json { head :no_content }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
class GlobalResourcesController < ApplicationController
|
2
|
+
# GET /global_resources
|
3
|
+
# GET /global_resources.json
|
4
|
+
def index
|
5
|
+
#alberich global permissions check
|
6
|
+
require_privilege(Alberich::Privilege::VIEW, GlobalResource)
|
7
|
+
@global_resources = GlobalResource.all
|
8
|
+
|
9
|
+
respond_to do |format|
|
10
|
+
format.html # index.html.erb
|
11
|
+
format.json { render json: @global_resources }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# GET /global_resources/1
|
16
|
+
# GET /global_resources/1.json
|
17
|
+
def show
|
18
|
+
#alberich global permissions check
|
19
|
+
require_privilege(Alberich::Privilege::VIEW, GlobalResource)
|
20
|
+
@global_resource = GlobalResource.find(params[:id])
|
21
|
+
|
22
|
+
respond_to do |format|
|
23
|
+
format.html # show.html.erb
|
24
|
+
format.json { render json: @global_resource }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# GET /global_resources/new
|
29
|
+
# GET /global_resources/new.json
|
30
|
+
def new
|
31
|
+
#alberich global permissions check
|
32
|
+
require_privilege(Alberich::Privilege::CREATE, GlobalResource)
|
33
|
+
@global_resource = GlobalResource.new
|
34
|
+
|
35
|
+
respond_to do |format|
|
36
|
+
format.html # new.html.erb
|
37
|
+
format.json { render json: @global_resource }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# GET /global_resources/1/edit
|
42
|
+
def edit
|
43
|
+
#alberich global permissions check
|
44
|
+
require_privilege(Alberich::Privilege::MODIFY, GlobalResource)
|
45
|
+
@global_resource = GlobalResource.find(params[:id])
|
46
|
+
end
|
47
|
+
|
48
|
+
# POST /global_resources
|
49
|
+
# POST /global_resources.json
|
50
|
+
def create
|
51
|
+
@global_resource = GlobalResource.new(params[:global_resource])
|
52
|
+
|
53
|
+
respond_to do |format|
|
54
|
+
if @global_resource.save
|
55
|
+
format.html { redirect_to @global_resource, notice: 'Global resource was successfully created.' }
|
56
|
+
format.json { render json: @global_resource, status: :created, location: @global_resource }
|
57
|
+
else
|
58
|
+
format.html { render action: "new" }
|
59
|
+
format.json { render json: @global_resource.errors, status: :unprocessable_entity }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# PUT /global_resources/1
|
65
|
+
# PUT /global_resources/1.json
|
66
|
+
def update
|
67
|
+
#alberich global permissions check
|
68
|
+
require_privilege(Alberich::Privilege::MODIFY, GlobalResource)
|
69
|
+
@global_resource = GlobalResource.find(params[:id])
|
70
|
+
|
71
|
+
respond_to do |format|
|
72
|
+
if @global_resource.update_attributes(params[:global_resource])
|
73
|
+
format.html { redirect_to @global_resource, notice: 'Global resource was successfully updated.' }
|
74
|
+
format.json { head :no_content }
|
75
|
+
else
|
76
|
+
format.html { render action: "edit" }
|
77
|
+
format.json { render json: @global_resource.errors, status: :unprocessable_entity }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# DELETE /global_resources/1
|
83
|
+
# DELETE /global_resources/1.json
|
84
|
+
def destroy
|
85
|
+
#alberich global permissions check
|
86
|
+
require_privilege(Alberich::Privilege::MODIFY, GlobalResource)
|
87
|
+
@global_resource = GlobalResource.find(params[:id])
|
88
|
+
@global_resource.destroy
|
89
|
+
|
90
|
+
respond_to do |format|
|
91
|
+
format.html { redirect_to global_resources_url }
|
92
|
+
format.json { head :no_content }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|