erp_tech_svcs 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/GPL-3-LICENSE +674 -0
- data/README.rdoc +2 -0
- data/Rakefile +30 -0
- data/app/assets/javascripts/erp_tech_svcs/application.js +9 -0
- data/app/assets/stylesheets/erp_tech_svcs/application.css +7 -0
- data/app/controllers/erp_tech_svcs/session_controller.rb +19 -0
- data/app/controllers/erp_tech_svcs/user_controller.rb +40 -0
- data/app/helpers/erp_tech_svcs/application_helper.rb +4 -0
- data/app/mailers/user_mailer.rb +16 -0
- data/app/models/audit_log.rb +60 -0
- data/app/models/audit_log_item.rb +4 -0
- data/app/models/audit_log_item_type.rb +6 -0
- data/app/models/audit_log_type.rb +24 -0
- data/app/models/capability.rb +8 -0
- data/app/models/capability_type.rb +3 -0
- data/app/models/capable_model.rb +4 -0
- data/app/models/encryption_key.rb +9 -0
- data/app/models/extensions/contact_purpose.rb +3 -0
- data/app/models/extensions/contact_type.rb +3 -0
- data/app/models/extensions/note.rb +6 -0
- data/app/models/extensions/note_type.rb +3 -0
- data/app/models/extensions/party.rb +3 -0
- data/app/models/extensions/relationship_type.rb +3 -0
- data/app/models/extensions/role_type.rb +3 -0
- data/app/models/file_asset.rb +178 -0
- data/app/models/role.rb +17 -0
- data/app/models/secured_model.rb +13 -0
- data/app/models/user.rb +33 -0
- data/app/views/layouts/application.html.erb +14 -0
- data/app/views/layouts/erp_tech_svcs/application.html.erb +14 -0
- data/app/views/user_mailer/activation_needed_email.html.erb +14 -0
- data/app/views/user_mailer/reset_password_email.html.erb +14 -0
- data/config/initializers/erp_tech_svcs.rb +7 -0
- data/config/initializers/file_support.rb +1 -0
- data/config/initializers/pdfkit.rb +18 -0
- data/config/initializers/sorcery.rb +199 -0
- data/config/routes.rb +9 -0
- data/db/data_migrations/20110802200222_schedule_delete_expired_sessions_job.rb +15 -0
- data/db/data_migrations/20111111144706_setup_audit_log_types.rb +21 -0
- data/db/migrate/20080805000010_base_tech_services.rb +247 -0
- data/db/migrate/20111109161549_add_capabilites.rb +56 -0
- data/db/migrate/upgrade/20111109161550_update_roles.rb +33 -0
- data/db/migrate/upgrade/20111109161551_update_user.rb +88 -0
- data/lib/erp_tech_svcs/application_installer.rb +102 -0
- data/lib/erp_tech_svcs/config.rb +27 -0
- data/lib/erp_tech_svcs/engine.rb +14 -0
- data/lib/erp_tech_svcs/extensions/active_record/acts_as_versioned.rb +494 -0
- data/lib/erp_tech_svcs/extensions/active_record/has_capabilities.rb +139 -0
- data/lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb +40 -0
- data/lib/erp_tech_svcs/extensions/active_record/has_roles.rb +126 -0
- data/lib/erp_tech_svcs/extensions.rb +5 -0
- data/lib/erp_tech_svcs/file_support/aws_s3_patch.rb +3 -0
- data/lib/erp_tech_svcs/file_support/base.rb +30 -0
- data/lib/erp_tech_svcs/file_support/file_manipulator.rb +37 -0
- data/lib/erp_tech_svcs/file_support/file_system_manager.rb +167 -0
- data/lib/erp_tech_svcs/file_support/manager.rb +147 -0
- data/lib/erp_tech_svcs/file_support/paperclip_patch.rb +28 -0
- data/lib/erp_tech_svcs/file_support/railties/s3_resolver.rb +79 -0
- data/lib/erp_tech_svcs/file_support/s3_manager.rb +211 -0
- data/lib/erp_tech_svcs/file_support.rb +10 -0
- data/lib/erp_tech_svcs/sessions/delete_expired_sessions_job.rb +40 -0
- data/lib/erp_tech_svcs/sessions/delete_expired_sessions_service.rb +15 -0
- data/lib/erp_tech_svcs/utils/attachment_fu_patch.rb +15 -0
- data/lib/erp_tech_svcs/utils/compass_access_negotiator.rb +57 -0
- data/lib/erp_tech_svcs/utils/compass_logger.rb +94 -0
- data/lib/erp_tech_svcs/utils/compass_pdf.rb +72 -0
- data/lib/erp_tech_svcs/utils/default_nested_set_methods.rb +33 -0
- data/lib/erp_tech_svcs/utils/pdf_processor.rb +106 -0
- data/lib/erp_tech_svcs/version.rb +3 -0
- data/lib/erp_tech_svcs.rb +20 -0
- data/lib/tasks/erp_tech_svcs_tasks.rake +42 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +43 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +8 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/spec.rb +27 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/schema.rb +571 -0
- data/spec/dummy/db/spec.sqlite3 +0 -0
- data/spec/dummy/log/spec.log +2862 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/capability_type.rb +5 -0
- data/spec/factories/role.rb +5 -0
- data/spec/factories/users.rb +9 -0
- data/spec/lib/erp_tech_svcs/extensions/active_record/has_roles_spec.rb +68 -0
- data/spec/models/audit_log_spec.rb +48 -0
- data/spec/models/audit_log_type_spec.rb +9 -0
- data/spec/models/role_spec.rb +17 -0
- data/spec/models/user_spec.rb +27 -0
- data/spec/spec_helper.rb +61 -0
- metadata +273 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# The first thing you need to configure is which modules you need in your app.
|
|
2
|
+
# The default is nothing which will include only core features (password encryption, login/logout).
|
|
3
|
+
# Available submodules are: :user_activation, :http_basic_auth, :remember_me,
|
|
4
|
+
# :reset_password, :session_timeout, :brute_force_protection, :activity_logging, :external
|
|
5
|
+
Rails.application.config.sorcery.submodules = [:user_activation,:remember_me,:reset_password,:brute_force_protection,:activity_logging]
|
|
6
|
+
|
|
7
|
+
# Here you can configure each submodule's features.
|
|
8
|
+
Rails.application.config.sorcery.configure do |config|
|
|
9
|
+
# -- core --
|
|
10
|
+
# config.not_authenticated_action = :not_authenticated # what controller action to call for
|
|
11
|
+
# non-authenticated users.
|
|
12
|
+
# You can also override 'not_authenticated'
|
|
13
|
+
# instead.
|
|
14
|
+
|
|
15
|
+
# config.save_return_to_url = true # when a non logged in user tries to enter
|
|
16
|
+
# a page that requires login,
|
|
17
|
+
# save the URL he wanted to reach,
|
|
18
|
+
# and send him there after login, using
|
|
19
|
+
# 'redirect_back_or_to'.
|
|
20
|
+
|
|
21
|
+
# config.cookie_domain = nil # set domain option for cookies
|
|
22
|
+
# Useful for remember_me submodule
|
|
23
|
+
|
|
24
|
+
# -- session timeout --
|
|
25
|
+
# config.session_timeout = 3600 # how long in seconds to keep the session alive.
|
|
26
|
+
# config.session_timeout_from_last_action = false # use the last action as the beginning of
|
|
27
|
+
# session timeout.
|
|
28
|
+
|
|
29
|
+
# -- http_basic_auth --
|
|
30
|
+
# config.controller_to_realm_map = {"application" => "Application"} # What realm to display for which controller name.
|
|
31
|
+
# For example {"My App" => "Application"}
|
|
32
|
+
|
|
33
|
+
# -- activity logging --
|
|
34
|
+
# config.register_login_time = true # will register the time of last user login, every login.
|
|
35
|
+
# config.register_logout_time = true # will register the time of last user logout, every logout.
|
|
36
|
+
# config.register_last_activity_time = true # will register the time of last user action, every action.
|
|
37
|
+
|
|
38
|
+
# -- external --
|
|
39
|
+
# config.external_providers = [] # What providers are supported by this app,
|
|
40
|
+
# i.e. [:twitter, :facebook, :github] .
|
|
41
|
+
# config.ca_file = 'path/to/ca_file' # Path to ca_file. By default use a internal ca-bundle.crt.
|
|
42
|
+
# You can change it by your local ca_file.
|
|
43
|
+
# i.e. '/etc/pki/tls/certs/ca-bundle.crt'
|
|
44
|
+
|
|
45
|
+
# config.twitter.key = "eYVNBjBDi33aa9GkA3w"
|
|
46
|
+
# config.twitter.secret = "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8"
|
|
47
|
+
# config.twitter.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=twitter"
|
|
48
|
+
# config.twitter.user_info_mapping = {:email => "screen_name"}
|
|
49
|
+
#
|
|
50
|
+
# config.facebook.key = "34cebc81c08a521bc66e212f947d73ec"
|
|
51
|
+
# config.facebook.secret = "5b458d179f61d4f036ee66a497ffbcd0"
|
|
52
|
+
# config.facebook.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=facebook"
|
|
53
|
+
# config.facebook.user_info_mapping = {:email => "name"}
|
|
54
|
+
#
|
|
55
|
+
# config.github.key = ""
|
|
56
|
+
# config.github.secret = ""
|
|
57
|
+
# config.github.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=github"
|
|
58
|
+
# config.github.user_info_mapping = {:email => "name"}
|
|
59
|
+
|
|
60
|
+
# --- user config ---
|
|
61
|
+
config.user_config do |user|
|
|
62
|
+
# -- core --
|
|
63
|
+
user.username_attribute_names = [:username, :email] # specify username
|
|
64
|
+
# attributes, for example:
|
|
65
|
+
# [:username, :email].
|
|
66
|
+
|
|
67
|
+
user.password_attribute_name = :password # change *virtual* password
|
|
68
|
+
# attribute, the one which is used
|
|
69
|
+
# until an encrypted one is
|
|
70
|
+
# generated.
|
|
71
|
+
|
|
72
|
+
# user.email_attribute_name = :email # change default email attribute.
|
|
73
|
+
|
|
74
|
+
# user.crypted_password_attribute_name = :crypted_password # change default crypted_password
|
|
75
|
+
# attribute.
|
|
76
|
+
|
|
77
|
+
# user.salt_join_token = "" # what pattern to use to join the
|
|
78
|
+
# password with the salt
|
|
79
|
+
|
|
80
|
+
# user.salt_attribute_name = :salt # change default salt attribute.
|
|
81
|
+
|
|
82
|
+
# user.stretches = nil # how many times to apply
|
|
83
|
+
# encryption to the password.
|
|
84
|
+
|
|
85
|
+
# user.encryption_key = nil # encryption key used to encrypt
|
|
86
|
+
# reversible encryptions such as
|
|
87
|
+
# AES256.
|
|
88
|
+
#
|
|
89
|
+
# WARNING:
|
|
90
|
+
#
|
|
91
|
+
# If used for users' passwords, changing this key
|
|
92
|
+
# will leave passwords undecryptable!
|
|
93
|
+
|
|
94
|
+
# user.custom_encryption_provider = nil # use an external encryption
|
|
95
|
+
# class.
|
|
96
|
+
|
|
97
|
+
# user.encryption_algorithm = :bcrypt # encryption algorithm name. See
|
|
98
|
+
# 'encryption_algorithm=' for
|
|
99
|
+
# available options.
|
|
100
|
+
|
|
101
|
+
# user.subclasses_inherit_config = false # make this configuration
|
|
102
|
+
# inheritable for subclasses.
|
|
103
|
+
# Useful for ActiveRecord's STI.
|
|
104
|
+
|
|
105
|
+
# -- user_activation --
|
|
106
|
+
# user.activation_state_attribute_name = :activation_state # the attribute name to hold
|
|
107
|
+
# activation state
|
|
108
|
+
# (active/pending).
|
|
109
|
+
|
|
110
|
+
# user.activation_token_attribute_name = :activation_token # the attribute name to hold
|
|
111
|
+
# activation code (sent by email).
|
|
112
|
+
|
|
113
|
+
# user.activation_token_expires_at_attribute_name = :activation_token_expires_at # the attribute name to hold
|
|
114
|
+
# activation code expiration date.
|
|
115
|
+
|
|
116
|
+
# user.activation_token_expiration_period = nil # how many seconds before the
|
|
117
|
+
# activation code expires. nil for
|
|
118
|
+
# never expires.
|
|
119
|
+
|
|
120
|
+
user.user_activation_mailer = UserMailer # your mailer class. Required.
|
|
121
|
+
|
|
122
|
+
# user.activation_needed_email_method_name = :activation_needed_email # activation needed email method
|
|
123
|
+
# on your mailer class.
|
|
124
|
+
|
|
125
|
+
user.activation_success_email_method_name = nil # activation success email method
|
|
126
|
+
# on your mailer class.
|
|
127
|
+
|
|
128
|
+
# user.prevent_non_active_users_to_login = true # do you want to prevent or allow
|
|
129
|
+
# users that did not activate by
|
|
130
|
+
# email to login?
|
|
131
|
+
|
|
132
|
+
# -- reset_password --
|
|
133
|
+
# user.reset_password_token_attribute_name = :reset_password_token # reset password code
|
|
134
|
+
# attribute name.
|
|
135
|
+
|
|
136
|
+
# user.reset_password_token_expires_at_attribute_name = :reset_password_token_expires_at # expires at attribute
|
|
137
|
+
# name.
|
|
138
|
+
|
|
139
|
+
# user.reset_password_email_sent_at_attribute_name = :reset_password_email_sent_at # when was email sent,
|
|
140
|
+
# used for hammering
|
|
141
|
+
# protection.
|
|
142
|
+
|
|
143
|
+
user.reset_password_mailer = UserMailer # mailer class. Needed.
|
|
144
|
+
|
|
145
|
+
# user.reset_password_email_method_name = :reset_password_email # reset password email
|
|
146
|
+
# method on your mailer
|
|
147
|
+
# class.
|
|
148
|
+
|
|
149
|
+
# user.reset_password_expiration_period = nil # how many seconds
|
|
150
|
+
# before the reset
|
|
151
|
+
# request expires. nil
|
|
152
|
+
# for never expires.
|
|
153
|
+
|
|
154
|
+
# user.reset_password_time_between_emails = 5 * 60 # hammering protection,
|
|
155
|
+
# how long to wait
|
|
156
|
+
# before allowing
|
|
157
|
+
# another email to be
|
|
158
|
+
# sent.
|
|
159
|
+
|
|
160
|
+
# -- brute_force_protection --
|
|
161
|
+
# user.failed_logins_count_attribute_name = :failed_logins_count # failed logins attribute name.
|
|
162
|
+
|
|
163
|
+
# user.lock_expires_at_attribute_name = :lock_expires_at # this field indicates whether
|
|
164
|
+
# user is banned and when it will
|
|
165
|
+
# be active again.
|
|
166
|
+
|
|
167
|
+
user.consecutive_login_retries_amount_limit = 5 # how many failed logins allowed.
|
|
168
|
+
|
|
169
|
+
# user.login_lock_time_period = 60 * 60 # how long the user should be
|
|
170
|
+
# banned. in seconds. 0 for
|
|
171
|
+
# permanent.
|
|
172
|
+
|
|
173
|
+
# -- activity logging --
|
|
174
|
+
#user.last_login_at_attribute_name = :last_sign_in_at # last login attribute name.
|
|
175
|
+
# user.last_logout_at_attribute_name = :last_logout_at # last logout attribute name.
|
|
176
|
+
# user.last_activity_at_attribute_name = :last_activity_at # last activity attribute name.
|
|
177
|
+
# user.activity_timeout = 10 * 60 # how long since last activity is
|
|
178
|
+
# the user defined logged out?
|
|
179
|
+
|
|
180
|
+
# -- external --
|
|
181
|
+
# user.authentications_class = nil # class which holds the various
|
|
182
|
+
# external provider data for this
|
|
183
|
+
# user.
|
|
184
|
+
|
|
185
|
+
# user.authentications_user_id_attribute_name = :user_id # user's identifier in
|
|
186
|
+
# authentications class.
|
|
187
|
+
|
|
188
|
+
# user.provider_attribute_name = :provider # provider's identifier in
|
|
189
|
+
# authentications class.
|
|
190
|
+
|
|
191
|
+
# user.provider_uid_attribute_name = :uid # user's external unique
|
|
192
|
+
# identifier in authentications
|
|
193
|
+
# class.
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# This line must come after the 'user config' block.
|
|
197
|
+
config.user_class = "User" # define which model authenticates
|
|
198
|
+
# with sorcery.
|
|
199
|
+
end
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Rails.application.routes.draw do
|
|
2
|
+
#handle login / logout
|
|
3
|
+
match "/session/sign_in" => 'erp_tech_svcs/session#create'
|
|
4
|
+
match "/session/sign_out" => 'erp_tech_svcs/session#destroy'
|
|
5
|
+
|
|
6
|
+
#handle activation
|
|
7
|
+
get "/users/activate/:activation_token" => 'erp_tech_svcs/user#activate'
|
|
8
|
+
post "/users/reset_password" => 'erp_tech_svcs/user#reset_password'
|
|
9
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class ScheduleDeleteExpiredSessionsJob
|
|
2
|
+
|
|
3
|
+
def self.up
|
|
4
|
+
#insert data here
|
|
5
|
+
date = Date.tomorrow
|
|
6
|
+
start_time = DateTime.civil(date.year, date.month, date.day, 2, 0, 1, -(5.0/24.0))
|
|
7
|
+
|
|
8
|
+
ErpTechSvcs::Sessions::DeleteExpiredSessionsJob.schedule_job(start_time)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.down
|
|
12
|
+
#remove data here
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class SetupAuditLogTypes
|
|
2
|
+
|
|
3
|
+
def self.up
|
|
4
|
+
application_alt = AuditLogType.create(:description => 'Application', :internal_identifier => 'application')
|
|
5
|
+
|
|
6
|
+
[
|
|
7
|
+
{:description => 'Custom Message', :internal_identifier => 'custom_message'},
|
|
8
|
+
{:description => 'Successful Logout', :internal_identifier => 'successful_logout'},
|
|
9
|
+
{:description => 'Successful Login', :internal_identifier => 'successful_login'},
|
|
10
|
+
{:description => 'Accessed Area', :internal_identifier => 'accessed_area'},
|
|
11
|
+
{:description => 'Session Timeout', :internal_identifier => 'session_timeout'}
|
|
12
|
+
].each do |alt_hash|
|
|
13
|
+
AuditLogType.create(alt_hash).move_to_child_of(application_alt)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.down
|
|
18
|
+
AuditLogType.destroy_all
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
class BaseTechServices < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
unless table_exists?(:users)
|
|
4
|
+
# Create the users table
|
|
5
|
+
create_table :users do |t|
|
|
6
|
+
t.string :username
|
|
7
|
+
t.string :email
|
|
8
|
+
t.references :party
|
|
9
|
+
t.string :type
|
|
10
|
+
t.string :salt, :default => nil
|
|
11
|
+
t.string :crypted_password, :default => nil
|
|
12
|
+
|
|
13
|
+
#activity logging
|
|
14
|
+
t.datetime :last_login_at, :default => nil
|
|
15
|
+
t.datetime :last_logout_at, :default => nil
|
|
16
|
+
t.datetime :last_activity_at, :default => nil
|
|
17
|
+
|
|
18
|
+
#brute force protection
|
|
19
|
+
t.integer :failed_logins_count, :default => 0
|
|
20
|
+
t.datetime :lock_expires_at, :default => nil
|
|
21
|
+
|
|
22
|
+
#remember me
|
|
23
|
+
t.string :remember_me_token, :default => nil
|
|
24
|
+
t.datetime :remember_me_token_expires_at, :default => nil
|
|
25
|
+
|
|
26
|
+
#reset password
|
|
27
|
+
t.string :reset_password_token, :default => nil
|
|
28
|
+
t.datetime :reset_password_token_expires_at, :default => nil
|
|
29
|
+
t.datetime :reset_password_email_sent_at, :default => nil
|
|
30
|
+
|
|
31
|
+
#user activation
|
|
32
|
+
t.string :activation_state, :default => nil
|
|
33
|
+
t.string :activation_token, :default => nil
|
|
34
|
+
t.datetime :activation_token_expires_at, :default => nil
|
|
35
|
+
|
|
36
|
+
t.timestamps
|
|
37
|
+
end
|
|
38
|
+
add_index :users, :email, :unique => true
|
|
39
|
+
add_index :users, :username, :unique => true
|
|
40
|
+
add_index :users, [:last_logout_at, :last_activity_at], :name => 'activity_idx', :unique => true
|
|
41
|
+
add_index :users, :remember_me_token, :unique => true
|
|
42
|
+
add_index :users, :reset_password_token, :unique => true
|
|
43
|
+
add_index :users, :activation_token, :unique => true
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
unless table_exists?(:roles)
|
|
48
|
+
# create the roles table
|
|
49
|
+
create_table :roles do |t|
|
|
50
|
+
t.column :description, :string
|
|
51
|
+
t.column :internal_identifier, :string
|
|
52
|
+
t.column :external_identifier, :string
|
|
53
|
+
t.column :external_id_source, :string
|
|
54
|
+
|
|
55
|
+
t.timestamps
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
unless table_exists?(:sessions)
|
|
60
|
+
# Create sessions table
|
|
61
|
+
create_table :sessions do |t|
|
|
62
|
+
t.string :session_id, :null => false
|
|
63
|
+
t.text :data
|
|
64
|
+
t.timestamps
|
|
65
|
+
end
|
|
66
|
+
add_index :sessions, :session_id
|
|
67
|
+
add_index :sessions, :updated_at
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
unless table_exists?(:audit_logs)
|
|
71
|
+
# Create audit_logs
|
|
72
|
+
create_table :audit_logs do |t|
|
|
73
|
+
t.string :application
|
|
74
|
+
t.string :description
|
|
75
|
+
t.integer :party_id
|
|
76
|
+
t.text :additional_info
|
|
77
|
+
t.references :audit_log_type
|
|
78
|
+
|
|
79
|
+
#polymorphic columns
|
|
80
|
+
t.references :event_record, :polymorphic => true
|
|
81
|
+
|
|
82
|
+
t.timestamps
|
|
83
|
+
end
|
|
84
|
+
add_index :audit_logs, :party_id
|
|
85
|
+
add_index :audit_logs, [:event_record_id, :event_record_type], :name => 'event_record_index'
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
unless table_exists?(:audit_log_types)
|
|
89
|
+
# Create audit_logs
|
|
90
|
+
create_table :audit_log_types do |t|
|
|
91
|
+
t.string :description
|
|
92
|
+
t.string :error_code
|
|
93
|
+
t.string :comments
|
|
94
|
+
t.string :internal_identifier
|
|
95
|
+
t.string :external_identifier
|
|
96
|
+
t.string :external_id_source
|
|
97
|
+
|
|
98
|
+
#better nested set columns
|
|
99
|
+
t.integer :parent_id
|
|
100
|
+
t.integer :lft
|
|
101
|
+
t.integer :rgt
|
|
102
|
+
|
|
103
|
+
t.timestamps
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
unless table_exists?(:audit_log_items)
|
|
108
|
+
# Create audit_log_items
|
|
109
|
+
create_table :audit_log_items do |t|
|
|
110
|
+
t.references :audit_log
|
|
111
|
+
t.references :audit_log_item_type
|
|
112
|
+
t.string :audit_log_item_value
|
|
113
|
+
t.string :description
|
|
114
|
+
|
|
115
|
+
t.timestamps
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
unless table_exists?(:audit_log_item_types)
|
|
120
|
+
# Create audit_log_item_types
|
|
121
|
+
create_table :audit_log_item_types do |t|
|
|
122
|
+
t.string :internal_identifier
|
|
123
|
+
t.string :external_identifier
|
|
124
|
+
t.string :external_id_source
|
|
125
|
+
t.string :description
|
|
126
|
+
t.string :comments
|
|
127
|
+
|
|
128
|
+
#better nested set columns
|
|
129
|
+
t.integer :parent_id
|
|
130
|
+
t.integer :lft
|
|
131
|
+
t.integer :rgt
|
|
132
|
+
|
|
133
|
+
t.timestamps
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
unless table_exists?(:secured_models)
|
|
138
|
+
create_table :secured_models do |t|
|
|
139
|
+
t.references :secured_record, :polymorphic => true
|
|
140
|
+
|
|
141
|
+
t.timestamps
|
|
142
|
+
end
|
|
143
|
+
add_index :secured_models, [:secured_record_id, :secured_record_type], :name => 'secured_record_idx'
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
unless table_exists?(:roles_secured_models)
|
|
147
|
+
create_table :roles_secured_models, :id => false do |t|
|
|
148
|
+
t.references :secured_model
|
|
149
|
+
t.references :role
|
|
150
|
+
|
|
151
|
+
t.timestamps
|
|
152
|
+
end
|
|
153
|
+
add_index :roles_secured_models, :secured_model_id
|
|
154
|
+
add_index :roles_secured_models, :role_id
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
unless table_exists?(:file_assets)
|
|
158
|
+
create_table :file_assets do |t|
|
|
159
|
+
t.references :file_asset_holder, :polymorphic => true
|
|
160
|
+
t.string :type
|
|
161
|
+
t.string :name
|
|
162
|
+
t.string :directory
|
|
163
|
+
t.string :data_file_name
|
|
164
|
+
t.string :data_content_type
|
|
165
|
+
t.integer :data_file_size
|
|
166
|
+
t.datetime :data_updated_at
|
|
167
|
+
|
|
168
|
+
t.timestamps
|
|
169
|
+
end
|
|
170
|
+
add_index :file_assets, :type
|
|
171
|
+
add_index :file_assets, [:file_asset_holder_id, :file_asset_holder_type], :name => 'file_asset_holder_idx'
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
unless table_exists?(:delayed_jobs)
|
|
175
|
+
create_table :delayed_jobs, :force => true do |table|
|
|
176
|
+
table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
|
|
177
|
+
table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
|
|
178
|
+
table.text :handler # YAML-encoded string of the object that will do work
|
|
179
|
+
table.text :last_error # reason for last failure (See Note below)
|
|
180
|
+
table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
|
|
181
|
+
table.datetime :locked_at # Set when a client is working on this object
|
|
182
|
+
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
|
|
183
|
+
table.string :locked_by # Who is working on this object (if locked)
|
|
184
|
+
table.timestamps
|
|
185
|
+
end
|
|
186
|
+
add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
unless table_exists?(:capable_models)
|
|
190
|
+
# create the roles table
|
|
191
|
+
create_table :capable_models do |t|
|
|
192
|
+
t.references :capable_model_record, :polymorphic => true
|
|
193
|
+
|
|
194
|
+
t.timestamps
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
add_index :capable_models, [:capable_model_record_id, :capable_model_record_type], :name => 'capable_model_record_idx'
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
unless table_exists?(:capability_types)
|
|
201
|
+
# create the roles table
|
|
202
|
+
create_table :capability_types do |t|
|
|
203
|
+
t.string :internal_identifier
|
|
204
|
+
t.string :description
|
|
205
|
+
t.timestamps
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
unless table_exists?(:capabilities)
|
|
210
|
+
# create the roles table
|
|
211
|
+
create_table :capabilities do |t|
|
|
212
|
+
t.string :resource
|
|
213
|
+
t.references :capability_type
|
|
214
|
+
t.timestamps
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
add_index :capabilities, :capability_type_id
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
unless table_exists?(:capabilities_capable_models)
|
|
221
|
+
# create the roles table
|
|
222
|
+
create_table :capabilities_capable_models, :id => false do |t|
|
|
223
|
+
t.references :capable_model
|
|
224
|
+
t.references :capability
|
|
225
|
+
t.timestamps
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
add_index :capabilities_capable_models, :capable_model_id
|
|
229
|
+
add_index :capabilities_capable_models, :capability_id
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def self.down
|
|
235
|
+
# check that each table exists before trying to delete it.
|
|
236
|
+
[
|
|
237
|
+
:audit_logs, :sessions, :simple_captcha_data,
|
|
238
|
+
:capable_models, :capability_types, :capabilities,:capabilities_capable_models,
|
|
239
|
+
:roles_users, :roles, :audit_log_items, :audit_log_item_types,
|
|
240
|
+
:users, :secured_models, :roles_secured_models, :file_assets, :delayed_jobs
|
|
241
|
+
].each do |tbl|
|
|
242
|
+
if table_exists?(tbl)
|
|
243
|
+
drop_table tbl
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
class AddCapabilites < ActiveRecord::Migration
|
|
2
|
+
def up
|
|
3
|
+
unless table_exists?(:capable_models)
|
|
4
|
+
# create the roles table
|
|
5
|
+
create_table :capable_models do |t|
|
|
6
|
+
t.references :capable_model_record, :polymorphic => true
|
|
7
|
+
|
|
8
|
+
t.timestamps
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
add_index :capable_models, [:capable_model_record_id, :capable_model_record_type], :name => 'capable_model_record_idx'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
unless table_exists?(:capability_types)
|
|
15
|
+
# create the roles table
|
|
16
|
+
create_table :capability_types do |t|
|
|
17
|
+
t.string :internal_identifier
|
|
18
|
+
t.string :description
|
|
19
|
+
t.timestamps
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
unless table_exists?(:capabilities)
|
|
24
|
+
# create the roles table
|
|
25
|
+
create_table :capabilities do |t|
|
|
26
|
+
t.string :resource
|
|
27
|
+
t.references :capability_type
|
|
28
|
+
t.timestamps
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
add_index :capabilities, :capability_type_id
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
unless table_exists?(:capabilities_capable_models)
|
|
35
|
+
# create the roles table
|
|
36
|
+
create_table :capabilities_capable_models, :id => false do |t|
|
|
37
|
+
t.references :capable_model
|
|
38
|
+
t.references :capability
|
|
39
|
+
t.timestamps
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
add_index :capabilities_capable_models, :capable_model_id
|
|
43
|
+
add_index :capabilities_capable_models, :capability_id
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def down
|
|
48
|
+
[
|
|
49
|
+
:capable_models, :capability_types, :capabilities,:capabilities_capable_models
|
|
50
|
+
].each do |tbl|
|
|
51
|
+
if table_exists?(tbl)
|
|
52
|
+
drop_table tbl
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class UpdateRoles < ActiveRecord::Migration
|
|
2
|
+
def up
|
|
3
|
+
|
|
4
|
+
roles_users = ActiveRecord::Base.connection.select_all("select * from roles_users")
|
|
5
|
+
roles_users.each do |role_user|
|
|
6
|
+
secured_model = SecuredModel.find_by_secured_record_id_and_secured_record_type(role_user['user_id'], 'User')
|
|
7
|
+
if secured_model.nil?
|
|
8
|
+
secured_model = SecuredModel.new
|
|
9
|
+
secured_model.secured_record = User.find(role_user['user_id'])
|
|
10
|
+
secured_model.save
|
|
11
|
+
end
|
|
12
|
+
secured_model.roles << Role.find(role_user['role_id'])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
roles_widgets = ActiveRecord::Base.connection.select_all("select * from roles_widgets")
|
|
16
|
+
roles_widgets.each do |role_widget|
|
|
17
|
+
secured_model = SecuredModel.find_by_secured_record_id_and_secured_record_type(role_widget['widget_id'], 'Widget')
|
|
18
|
+
if secured_model.nil?
|
|
19
|
+
secured_model = SecuredModel.new
|
|
20
|
+
secured_model.secured_record = Widget.find(role_widget['widget_id'])
|
|
21
|
+
secured_model.save
|
|
22
|
+
end
|
|
23
|
+
secured_model.roles << Role.find(role_widget['role_id'])
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
drop_table :roles_users
|
|
27
|
+
drop_table :roles_widgets
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def down
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
class UpdateUser < ActiveRecord::Migration
|
|
2
|
+
def up
|
|
3
|
+
unless columns(:users).collect {|c| c.name}.include?('activation_state')
|
|
4
|
+
|
|
5
|
+
#have to move over current users
|
|
6
|
+
current_users = []
|
|
7
|
+
User.all.each do |user|
|
|
8
|
+
current_users << {
|
|
9
|
+
:enabled => user.enabled,
|
|
10
|
+
:email => user.email
|
|
11
|
+
}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
#change_columns
|
|
15
|
+
change_column :users, :salt, :string
|
|
16
|
+
change_column :users, :crypted_password, :string
|
|
17
|
+
|
|
18
|
+
#remove old columns
|
|
19
|
+
remove_column :users, :name
|
|
20
|
+
remove_column :users, :activated_at
|
|
21
|
+
remove_column :users, :enabled
|
|
22
|
+
remove_column :users, :identity_url
|
|
23
|
+
remove_column :users, :invitation_id
|
|
24
|
+
remove_column :users, :invitation_limit
|
|
25
|
+
remove_column :users, :club_number
|
|
26
|
+
remove_column :users, :owner_number
|
|
27
|
+
remove_column :users, :dob
|
|
28
|
+
remove_column :users, :ssn_last_four
|
|
29
|
+
remove_column :users, :salutation
|
|
30
|
+
remove_column :users, :first_name
|
|
31
|
+
remove_column :users, :last_name
|
|
32
|
+
remove_column :users, :street_address
|
|
33
|
+
remove_column :users, :city
|
|
34
|
+
remove_column :users, :state_province
|
|
35
|
+
remove_column :users, :postal_code
|
|
36
|
+
remove_column :users, :country
|
|
37
|
+
remove_column :users, :phone
|
|
38
|
+
remove_column :users, :security_question_1
|
|
39
|
+
remove_column :users, :security_answer_1
|
|
40
|
+
remove_column :users, :security_question_2
|
|
41
|
+
remove_column :users, :security_answer_2
|
|
42
|
+
|
|
43
|
+
#rename columns
|
|
44
|
+
rename_column :users, :remember_token, :remember_me_token
|
|
45
|
+
rename_column :users, :remember_token_expires_at, :remember_me_token_expires_at
|
|
46
|
+
rename_column :users, :activation_code, :activation_token
|
|
47
|
+
rename_column :users, :activation_code_expires_at, :activation_token_expires_at
|
|
48
|
+
rename_column :users, :password_reset_code, :password_reset_token
|
|
49
|
+
rename_column :users, :lock_count, :failed_logins_count
|
|
50
|
+
rename_column :users, :login, :username
|
|
51
|
+
|
|
52
|
+
if columns(:users).collect {|c| c.name}.include?('user_type')
|
|
53
|
+
rename_column :users, :user_type, :type
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
#activity logging
|
|
57
|
+
add_column :users, :last_login_at, :datetime, :default => nil
|
|
58
|
+
add_column :users, :last_logout_at, :datetime, :default => nil
|
|
59
|
+
add_column :users, :last_activity_at, :datetime, :default => nil
|
|
60
|
+
add_index :users, [:last_logout_at, :last_activity_at], :name => 'activity_idx'
|
|
61
|
+
|
|
62
|
+
#brute force protection
|
|
63
|
+
add_column :users, :lock_expires_at, :datetime, :default => nil
|
|
64
|
+
|
|
65
|
+
#reset password
|
|
66
|
+
add_column :users, :reset_password_token, :datetime, :default => nil
|
|
67
|
+
add_column :users, :reset_password_token_expires_at, :datetime, :default => nil
|
|
68
|
+
add_column :users, :reset_password_email_sent_at, :datetime, :default => nil
|
|
69
|
+
|
|
70
|
+
#user activation
|
|
71
|
+
add_column :users, :activation_state, :string, :default => nil
|
|
72
|
+
|
|
73
|
+
current_users.each do |user_hash|
|
|
74
|
+
if user_hash[:enabled]
|
|
75
|
+
User.reset_column_information
|
|
76
|
+
user = User.find_by_email(user_hash[:email])
|
|
77
|
+
user.activate!
|
|
78
|
+
user.password_confirmation = 'password'
|
|
79
|
+
user.change_password!('password')
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def down
|
|
87
|
+
end
|
|
88
|
+
end
|