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
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateChildResources < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :child_resources do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :description
|
6
|
+
t.references :parent_resource
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
add_index :child_resources, :parent_resource_id
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateChildResources < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :child_resources do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :description
|
6
|
+
t.references :ParentResource
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
add_index :child_resources, :ParentResource_id
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(:version => 20130226151256) do
|
15
|
+
|
16
|
+
create_table "alberich_base_permission_objects", :force => true do |t|
|
17
|
+
t.string "name", :null => false
|
18
|
+
t.datetime "created_at", :null => false
|
19
|
+
t.datetime "updated_at", :null => false
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table "alberich_derived_permissions", :force => true do |t|
|
23
|
+
t.integer "permission_id", :null => false
|
24
|
+
t.integer "role_id", :null => false
|
25
|
+
t.integer "entity_id", :null => false
|
26
|
+
t.integer "permission_object_id"
|
27
|
+
t.string "permission_object_type"
|
28
|
+
t.integer "lock_version", :default => 0
|
29
|
+
t.datetime "created_at", :null => false
|
30
|
+
t.datetime "updated_at", :null => false
|
31
|
+
end
|
32
|
+
|
33
|
+
add_index "alberich_derived_permissions", ["permission_id"], :name => "index_alberich_derived_permissions_on_permission_id"
|
34
|
+
add_index "alberich_derived_permissions", ["permission_object_id", "permission_object_type"], :name => "index_alberich_derived_permissions_on_perm_obj"
|
35
|
+
|
36
|
+
create_table "alberich_entities", :force => true do |t|
|
37
|
+
t.string "name"
|
38
|
+
t.integer "entity_target_id", :null => false
|
39
|
+
t.string "entity_target_type", :null => false
|
40
|
+
t.integer "lock_version", :default => 0
|
41
|
+
t.datetime "created_at", :null => false
|
42
|
+
t.datetime "updated_at", :null => false
|
43
|
+
end
|
44
|
+
|
45
|
+
create_table "alberich_permission_sessions", :force => true do |t|
|
46
|
+
t.integer "user_id", :null => false
|
47
|
+
t.string "session_id", :null => false
|
48
|
+
t.integer "lock_version", :default => 0
|
49
|
+
t.datetime "created_at", :null => false
|
50
|
+
t.datetime "updated_at", :null => false
|
51
|
+
end
|
52
|
+
|
53
|
+
create_table "alberich_permissions", :force => true do |t|
|
54
|
+
t.integer "role_id", :null => false
|
55
|
+
t.integer "entity_id", :null => false
|
56
|
+
t.integer "permission_object_id"
|
57
|
+
t.string "permission_object_type"
|
58
|
+
t.integer "lock_version", :default => 0
|
59
|
+
t.datetime "created_at", :null => false
|
60
|
+
t.datetime "updated_at", :null => false
|
61
|
+
end
|
62
|
+
|
63
|
+
create_table "alberich_privileges", :force => true do |t|
|
64
|
+
t.integer "role_id", :null => false
|
65
|
+
t.string "target_type", :null => false
|
66
|
+
t.string "action", :null => false
|
67
|
+
t.integer "lock_version", :default => 0
|
68
|
+
t.datetime "created_at", :null => false
|
69
|
+
t.datetime "updated_at", :null => false
|
70
|
+
end
|
71
|
+
|
72
|
+
create_table "alberich_roles", :force => true do |t|
|
73
|
+
t.string "name", :null => false
|
74
|
+
t.string "scope", :null => false
|
75
|
+
t.integer "lock_version", :default => 0
|
76
|
+
t.boolean "assign_to_owner", :default => false
|
77
|
+
t.datetime "created_at", :null => false
|
78
|
+
t.datetime "updated_at", :null => false
|
79
|
+
end
|
80
|
+
|
81
|
+
create_table "alberich_session_entities", :force => true do |t|
|
82
|
+
t.integer "user_id", :null => false
|
83
|
+
t.integer "entity_id", :null => false
|
84
|
+
t.integer "permission_session_id", :null => false
|
85
|
+
t.integer "lock_version", :default => 0
|
86
|
+
t.datetime "created_at", :null => false
|
87
|
+
t.datetime "updated_at", :null => false
|
88
|
+
end
|
89
|
+
|
90
|
+
create_table "child_resources", :force => true do |t|
|
91
|
+
t.string "name"
|
92
|
+
t.string "description"
|
93
|
+
t.integer "parent_resource_id"
|
94
|
+
t.datetime "created_at", :null => false
|
95
|
+
t.datetime "updated_at", :null => false
|
96
|
+
end
|
97
|
+
|
98
|
+
add_index "child_resources", ["parent_resource_id"], :name => "index_child_resources_on_parent_resource_id"
|
99
|
+
|
100
|
+
create_table "global_resources", :force => true do |t|
|
101
|
+
t.string "name"
|
102
|
+
t.string "description"
|
103
|
+
t.datetime "created_at", :null => false
|
104
|
+
t.datetime "updated_at", :null => false
|
105
|
+
end
|
106
|
+
|
107
|
+
create_table "members_user_groups", :id => false, :force => true do |t|
|
108
|
+
t.integer "user_group_id", :null => false
|
109
|
+
t.integer "member_id", :null => false
|
110
|
+
end
|
111
|
+
|
112
|
+
create_table "parent_resources", :force => true do |t|
|
113
|
+
t.string "name"
|
114
|
+
t.string "description"
|
115
|
+
t.datetime "created_at", :null => false
|
116
|
+
t.datetime "updated_at", :null => false
|
117
|
+
end
|
118
|
+
|
119
|
+
create_table "standalone_resources", :force => true do |t|
|
120
|
+
t.string "name"
|
121
|
+
t.string "description"
|
122
|
+
t.datetime "created_at", :null => false
|
123
|
+
t.datetime "updated_at", :null => false
|
124
|
+
end
|
125
|
+
|
126
|
+
create_table "user_groups", :force => true do |t|
|
127
|
+
t.string "name", :null => false
|
128
|
+
t.string "description"
|
129
|
+
t.integer "lock_version", :default => 0
|
130
|
+
t.datetime "created_at", :null => false
|
131
|
+
t.datetime "updated_at", :null => false
|
132
|
+
end
|
133
|
+
|
134
|
+
create_table "users", :force => true do |t|
|
135
|
+
t.string "username", :null => false
|
136
|
+
t.string "email"
|
137
|
+
t.string "crypted_password"
|
138
|
+
t.string "first_name"
|
139
|
+
t.string "last_name"
|
140
|
+
t.integer "login_count", :default => 0, :null => false
|
141
|
+
t.integer "failed_login_count", :default => 0, :null => false
|
142
|
+
t.datetime "last_request_at"
|
143
|
+
t.datetime "current_login_at"
|
144
|
+
t.datetime "last_login_at"
|
145
|
+
t.string "current_login_ip"
|
146
|
+
t.string "last_login_ip"
|
147
|
+
t.datetime "created_at", :null => false
|
148
|
+
t.datetime "updated_at", :null => false
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# created admin user admin/password
|
2
|
+
user = User.find_by_username("admin")
|
3
|
+
unless user
|
4
|
+
user = User.new(:username => "admin", :email => "admin@example.com",
|
5
|
+
:password => "password",
|
6
|
+
:password_confirmation => "password",
|
7
|
+
:first_name => "Admin",
|
8
|
+
:last_name => "User")
|
9
|
+
user.save!
|
10
|
+
end
|
11
|
+
|
12
|
+
# Create default roles
|
13
|
+
VIEW = "view"
|
14
|
+
USE = "use"
|
15
|
+
MOD = "modify"
|
16
|
+
CRE = "create"
|
17
|
+
VPRM = "view_perms"
|
18
|
+
GPRM = "set_perms"
|
19
|
+
roles =
|
20
|
+
{
|
21
|
+
StandaloneResource =>
|
22
|
+
{"StandaloneResource User" => [false, {StandaloneResource => [VIEW,USE]}],
|
23
|
+
"StandaloneResource Owner"=> [true, {StandaloneResource => [VIEW,USE,MOD, VPRM,GPRM]}]},
|
24
|
+
ChildResource =>
|
25
|
+
{"ChildResource User" => [false, {ChildResource => [VIEW,USE]}],
|
26
|
+
"ChildResource Owner"=> [true, {ChildResource => [VIEW,USE,MOD, VPRM,GPRM]}]},
|
27
|
+
ParentResource =>
|
28
|
+
{"ParentResource User" => [false, {ParentResource => [VIEW,USE],
|
29
|
+
ChildResource => [ CRE]}],
|
30
|
+
"ParentResource Owner"=> [true, {ParentResource => [VIEW,USE,MOD, VPRM,GPRM],
|
31
|
+
ChildResource => [VIEW,USE,MOD,CRE,VPRM,GPRM]}]},
|
32
|
+
Alberich::BasePermissionObject =>
|
33
|
+
{"Site Admin" => [false, {User => [VIEW, MOD,CRE,VPRM,GPRM],
|
34
|
+
GlobalResource => [VIEW, MOD,CRE,VPRM,GPRM],
|
35
|
+
StandaloneResource => [VIEW,USE,MOD,CRE,VPRM,GPRM],
|
36
|
+
ParentResource => [VIEW,USE,MOD,CRE,VPRM,GPRM],
|
37
|
+
ChildResource => [VIEW,USE,MOD,CRE,VPRM,GPRM],
|
38
|
+
Alberich::BasePermissionObject => [VIEW,USE,MOD,CRE,VPRM,GPRM]}]}}
|
39
|
+
Alberich::Role.transaction do
|
40
|
+
roles.each do |role_scope, scoped_hash|
|
41
|
+
scoped_hash.each do |role_name, role_def|
|
42
|
+
role = Alberich::Role.find_or_initialize_by_name(role_name)
|
43
|
+
role.update_attributes({:name => role_name, :scope => role_scope.name,
|
44
|
+
:assign_to_owner => role_def[0]})
|
45
|
+
role.save!
|
46
|
+
role_def[1].each do |priv_type, priv_actions|
|
47
|
+
priv_actions.each do |action|
|
48
|
+
Alberich::Privilege.create!(:role => role,
|
49
|
+
:target_type => priv_type.name,
|
50
|
+
:action => action)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
#Assign global admin privileges to admin user
|
58
|
+
if Alberich::Permission.count == 0
|
59
|
+
Alberich::Permission.create(:entity => Alberich::Entity.for_target(user),
|
60
|
+
:role =>
|
61
|
+
Alberich::Role.find_by_name("Site Admin"),
|
62
|
+
:permission_object =>
|
63
|
+
Alberich::BasePermissionObject.
|
64
|
+
general_permission_scope)
|
65
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'digest/sha2'
|
2
|
+
|
3
|
+
# This module contains functions for hashing and storing passwords with
|
4
|
+
# SHA512 with 64 characters long random salt.
|
5
|
+
module Password
|
6
|
+
|
7
|
+
# Generates a new salt and rehashes the password
|
8
|
+
def Password.update(password)
|
9
|
+
salt = self.salt
|
10
|
+
hash = self.hash(password, salt)
|
11
|
+
self.store(hash, salt)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Checks the password against the stored password
|
15
|
+
def Password.check(password, store)
|
16
|
+
hash = self.get_hash(store)
|
17
|
+
salt = self.get_salt(store)
|
18
|
+
if self.hash(password, salt) == hash
|
19
|
+
true
|
20
|
+
else
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Generates random string like for length = 10 => "iCi5MxiTDn"
|
26
|
+
def self.generate_random_string(length)
|
27
|
+
length.to_i.times.collect { (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }.join
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
# Generates a psuedo-random 64 character string
|
33
|
+
def Password.salt
|
34
|
+
self.generate_random_string(64)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generates a 128 character hash
|
38
|
+
def Password.hash(password, salt)
|
39
|
+
digest = "#{password}:#{salt}"
|
40
|
+
500.times { digest = Digest::SHA512.hexdigest(digest) }
|
41
|
+
digest
|
42
|
+
end
|
43
|
+
|
44
|
+
# Mixes the hash and salt together for storage
|
45
|
+
def Password.store(hash, salt)
|
46
|
+
hash + salt
|
47
|
+
end
|
48
|
+
|
49
|
+
# Gets the hash from a stored password
|
50
|
+
def Password.get_hash(store)
|
51
|
+
store[0..127]
|
52
|
+
end
|
53
|
+
|
54
|
+
# Gets the salt from a stored password
|
55
|
+
def Password.get_salt(store)
|
56
|
+
store[128..191]
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
</div>
|
24
|
+
</body>
|
25
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|