erp_tech_svcs 4.0.0 → 4.2.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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -24
  3. data/app/controllers/api/v1/audit_log_items_controller.rb +33 -0
  4. data/app/controllers/api/v1/audit_logs_controller.rb +32 -0
  5. data/app/controllers/api/v1/capabilities_controller.rb +160 -0
  6. data/app/controllers/api/v1/file_assets_controller.rb +40 -0
  7. data/app/controllers/api/v1/groups_controller.rb +236 -0
  8. data/app/controllers/api/v1/security_roles_controller.rb +276 -0
  9. data/app/controllers/api/v1/users_controller.rb +262 -0
  10. data/app/controllers/erp_tech_svcs/session_controller.rb +8 -5
  11. data/app/controllers/erp_tech_svcs/user_controller.rb +14 -15
  12. data/app/mailers/user_mailer.rb +8 -5
  13. data/app/models/audit_log.rb +111 -36
  14. data/app/models/audit_log_item.rb +30 -0
  15. data/app/models/audit_log_item_type.rb +1 -0
  16. data/app/models/audit_log_type.rb +19 -0
  17. data/app/models/capability.rb +22 -6
  18. data/app/models/extensions/tracked_status_type.rb +3 -0
  19. data/app/models/file_asset.rb +245 -20
  20. data/app/models/file_asset_holder.rb +20 -0
  21. data/app/models/group.rb +38 -25
  22. data/app/models/notification.rb +32 -13
  23. data/app/models/notification_type.rb +13 -0
  24. data/app/models/security_role.rb +17 -4
  25. data/app/models/user.rb +116 -29
  26. data/app/validators/password_strength_validator.rb +1 -1
  27. data/app/views/user_mailer/activation_needed_email.html.erb +293 -15
  28. data/app/views/user_mailer/reset_password_email.html.erb +268 -13
  29. data/config/initializers/logger.rb +19 -0
  30. data/config/initializers/sorcery.rb +2 -0
  31. data/config/initializers/wickedpdf.rb +4 -0
  32. data/config/routes.rb +64 -0
  33. data/db/data_migrations/20110802200222_schedule_delete_expired_sessions_job.rb +1 -5
  34. data/db/data_migrations/20150819140550_create_job_tracker_for_notification.rb +14 -0
  35. data/db/migrate/20080805000010_base_tech_services.rb +99 -39
  36. data/db/migrate/20150414151421_add_nested_set_columns_to_security_role.rb +13 -0
  37. data/db/migrate/20150609003216_update_user_for_sorcery.rb +11 -0
  38. data/db/migrate/20150819135108_add_custom_fields_to_notifications.rb +5 -0
  39. data/db/migrate/20160122155402_add_description_to_file_asset.rb +13 -0
  40. data/db/migrate/20160310163060_add_created_by_updated_by_to_erp_tech_svcs.rb +35 -0
  41. data/db/migrate/20160313161611_add_tenant_id_to_audit_log.rb +16 -0
  42. data/lib/erp_tech_svcs.rb +6 -10
  43. data/lib/erp_tech_svcs/config.rb +7 -2
  44. data/lib/erp_tech_svcs/delayed_jobs/delete_expired_sessions_job.rb +49 -0
  45. data/lib/erp_tech_svcs/delayed_jobs/notification_job.rb +50 -0
  46. data/lib/erp_tech_svcs/engine.rb +0 -1
  47. data/lib/erp_tech_svcs/erp_tech_svcs_audit_log.rb +12 -6
  48. data/lib/erp_tech_svcs/extensions.rb +0 -1
  49. data/lib/erp_tech_svcs/extensions/active_record/has_capability_accessors.rb +57 -29
  50. data/lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb +57 -31
  51. data/lib/erp_tech_svcs/extensions/active_record/has_security_roles.rb +12 -4
  52. data/lib/erp_tech_svcs/extensions/active_record/is_json.rb +22 -15
  53. data/lib/erp_tech_svcs/extensions/active_record/scoped_by.rb +16 -13
  54. data/lib/erp_tech_svcs/extensions/compass_ae/erp_base_erp_svcs/controllers/api/parties_controller.rb +15 -0
  55. data/lib/erp_tech_svcs/file_support.rb +1 -0
  56. data/lib/erp_tech_svcs/file_support/file_system_manager.rb +77 -44
  57. data/lib/erp_tech_svcs/file_support/manager.rb +12 -3
  58. data/lib/erp_tech_svcs/file_support/railties/compass_ae_resolver.rb +49 -0
  59. data/lib/erp_tech_svcs/file_support/s3_manager.rb +73 -51
  60. data/lib/erp_tech_svcs/utils/compass_access_negotiator.rb +11 -2
  61. data/lib/erp_tech_svcs/utils/default_nested_set_methods.rb +238 -46
  62. data/lib/erp_tech_svcs/version.rb +1 -1
  63. data/lib/tasks/erp_tech_svcs_tasks.rake +43 -5
  64. metadata +73 -42
  65. data/app/models/user_defined_data.rb +0 -6
  66. data/app/models/user_defined_field.rb +0 -8
  67. data/config/initializers/pdfkit.rb +0 -18
  68. data/db/data_migrations/20121130212146_note_capabilities.rb +0 -23
  69. data/db/migrate/20121116151510_create_groups.rb +0 -18
  70. data/db/migrate/20121126171612_upgrade_security.rb +0 -53
  71. data/db/migrate/20121126173506_upgrade_security2.rb +0 -274
  72. data/db/migrate/20130410135419_add_queue_to_delayed_jobs.rb +0 -13
  73. data/db/migrate/20130610163240_create_notifications.rb +0 -37
  74. data/db/migrate/20130725212647_add_party_id_idx_to_users.rb +0 -9
  75. data/db/migrate/20131113213843_add_audit_log_item_old_value.rb +0 -13
  76. data/db/migrate/20131113213844_add_erp_tech_svcs_missing_indexes.rb +0 -31
  77. data/db/migrate/20131129203603_add_user_defined_fields.rb +0 -43
  78. data/db/migrate/20141013060204_add_custom_fields_to_notifications.rb +0 -12
  79. data/db/migrate/20141108182427_add_scoped_by_to_file_assets.rb +0 -14
  80. data/lib/erp_tech_svcs/extensions/active_record/has_user_defined_data.rb +0 -147
  81. data/lib/erp_tech_svcs/sessions/delete_expired_sessions_job.rb +0 -47
  82. data/lib/erp_tech_svcs/sessions/delete_expired_sessions_service.rb +0 -15
  83. data/lib/erp_tech_svcs/utils/compass_logger.rb +0 -87
@@ -1,14 +1,269 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
5
- </head>
6
- <body>
7
- <h1>We have reset the password for, <%= @user.username %></h1>
8
- <p>
9
- The new password is <%= @user.password_confirmation %>.
10
- To login and update your password follow this link: <a href="<%= @url %>"><%= @url %></a>
11
- </p>
12
- <p>Thanks for being a member and have a great day!</p>
13
- </body>
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"/>
7
+ <title>Reset Password</title>
8
+ <style type="text/css">
9
+ .ReadMsgBody {
10
+ width: 100%;
11
+ background-color: #ffffff;
12
+ }
13
+
14
+ .ExternalClass {
15
+ width: 100%;
16
+ background-color: #ffffff;
17
+ }
18
+
19
+ html {
20
+ width: 100%;
21
+ }
22
+
23
+ body {
24
+ -webkit-text-size-adjust: none;
25
+ -ms-text-size-adjust: none;
26
+ margin: 0;
27
+ padding: 0;
28
+ }
29
+
30
+ table {
31
+ border-spacing: 0;
32
+ border-collapse: collapse;
33
+ }
34
+
35
+ img {
36
+ display: block !important;
37
+ }
38
+
39
+ table td {
40
+ border-collapse: collapse;
41
+ }
42
+
43
+ .top-margin {
44
+ height: 50px;
45
+ }
46
+
47
+ .main-header {
48
+ padding: 50px 100px;
49
+ background: rgba(0, 0, 0, 0.5);
50
+ font-weight: 300;
51
+ }
52
+
53
+ .footer {
54
+ margin-top: 20px;
55
+ }
56
+
57
+ /* ----------- media queries (responsive) ----------- */
58
+
59
+ @media only screen and (max-width: 640px) {
60
+ body .show {
61
+ display: block !important;
62
+ }
63
+
64
+ body .hide {
65
+ display: none !important;
66
+ }
67
+
68
+ body .container590 {
69
+ width: 440px !important;
70
+ }
71
+ }
72
+
73
+ @media only screen and (max-width: 480px) {
74
+ body .show {
75
+ display: block !important;
76
+ }
77
+
78
+ body .hide {
79
+ display: none !important;
80
+ }
81
+
82
+ body .container590 {
83
+ width: 280px !important;
84
+ }
85
+ }
86
+
87
+ </style>
88
+ </head>
89
+
90
+ <body>
91
+
92
+ <div class="top-margin"></div>
93
+
94
+ <table border="0" width="100%" cellpadding="0" cellspacing="0" data-module="module1" data-thumb="">
95
+ <tr>
96
+ <td align="center" bgcolor="323232"
97
+ style="background-image: url('https://truenorthtechnology.com/download/uh-oh-2.jpg?path=&disposition=inline'); background-size: cover; background-position: top center; background-repeat: repeat;">
98
+
99
+ <table border="0" align="center" cellpadding="0" cellspacing="0" class="container590">
100
+
101
+ <tr>
102
+ <td height="25" style="font-size: 25px; line-height: 25px;">&nbsp;</td>
103
+ </tr>
104
+
105
+
106
+ <tr>
107
+ <td height="30" style="font-size: 30px; line-height: 30px;">&nbsp;</td>
108
+ </tr>
109
+ <tr>
110
+ <td height="50" style="font-size: 50px; line-height: 50px;">&nbsp;</td>
111
+ </tr>
112
+
113
+ <tr>
114
+ <td class="main-header" align="center" height="42"
115
+ style="color: #ffffff; font-size: 32px; font-family: 'Open Sans', Calibri, sans-serif; mso-line-height-rule: exactly; line-height: 42px;">
116
+
117
+ <!-- ============ title header ============ -->
118
+
119
+ <div style="line-height: 34px;">
120
+ <span>
121
+ <multiline>
122
+ <h2>Hello, <%= @user.username %></h2><br>
123
+ You have requested to reset your password.
124
+
125
+ </multiline>
126
+ </span>
127
+ </div>
128
+ </td>
129
+ </tr>
130
+
131
+ <tr>
132
+ <td height="10" style="font-size: 10px; line-height: 10px;">&nbsp;</td>
133
+ </tr>
134
+
135
+
136
+ <tr>
137
+ <td height="50" style="font-size: 50px; line-height: 50px;">&nbsp;</td>
138
+ </tr>
139
+
140
+ <tr>
141
+ <td align="center">
142
+
143
+ <table class="cta-button" border="0" align="center" width="163" cellpadding="0" cellspacing="0"
144
+ style="border: none">
145
+ <tr>
146
+ <td height="10" style="font-size: 10px; line-height: 10px;">&nbsp;</td>
147
+ </tr>
148
+
149
+ <tr>
150
+ <td>
151
+ <table border="0" align="center" cellpadding="0" cellspacing="0">
152
+ <tr>
153
+ <td align="center"
154
+ style="color: #ffffff; font-size: 13px; font-family: 'Open Sans', Calibri, sans-serif; font-weight: 600; line-height: 24px;">
155
+ <!-- ============ headline button ============ -->
156
+ </td>
157
+
158
+ <td width="14" align="right" valign="middle">
159
+
160
+ </td>
161
+ </tr>
162
+ </table>
163
+ </td>
164
+ </tr>
165
+
166
+ <tr>
167
+ <td height="10" style="font-size: 10px; line-height: 10px;">&nbsp;</td>
168
+ </tr>
169
+
170
+ </table>
171
+ </td>
172
+ </tr>
173
+
174
+ <tr>
175
+ <td height="115" style="font-size: 115px; line-height: 115px;">&nbsp;</td>
176
+ </tr>
177
+
178
+ </table>
179
+ </td>
180
+ </tr>
181
+
182
+ </table>
183
+
184
+ <div class="body-text" style="margin-top:10px;">
185
+
186
+
187
+ <table border="0" align="center" width="124" cellpadding="0" cellspacing="0"
188
+ bgcolor="5ab600" style="border-radius: 3px;">
189
+ <tr>
190
+ <td height="6" style="font-size: 6px; line-height: 6px;">&nbsp;</td>
191
+ </tr>
192
+
193
+ <tr>
194
+ <td>
195
+ <table border="0" align="center" cellpadding="0" cellspacing="0">
196
+ <tr>
197
+ <td align="center"
198
+ style="color: #ffffff; font-size: 13px; font-family: Open Sans, Calibri, sans-serif; font-weight: 700;">
199
+
200
+ <div style="line-height: 24px;">
201
+ <span>
202
+ <a href="<%= @url %>"
203
+ style="color: #ffffff; text-decoration: none;">
204
+ <singleline>Reset</singleline>
205
+ </a>
206
+ </span>
207
+ </div>
208
+ </td>
209
+ </tr>
210
+ </table>
211
+ </td>
212
+ </tr>
213
+
214
+ <tr>
215
+ <td height="6" style="font-size: 6px; line-height: 6px;">&nbsp;</td>
216
+ </tr>
217
+ </table>
218
+
219
+ <h2 style="text-align: center; color: #555; font-size: 24px; font-family: 'Open Sans', Calibri, sans-serif; font-weight: 200;">Have
220
+ a great day!</h2>
221
+
222
+ </div>
223
+
224
+ <table class="footer" border="0" width="100%" cellpadding="0" cellspacing="0" bgcolor="2d2d2d" data-module="module16">
225
+
226
+ <tr>
227
+ <td height="20" style="font-size: 20px; line-height: 20px;">&nbsp;</td>
228
+ </tr>
229
+
230
+ <tr>
231
+ <td align="center">
232
+
233
+ <table border="0" align="center" width="590" class="container590" cellpadding="0" cellspacing="0">
234
+
235
+ <tr>
236
+ <td align="center">
237
+
238
+ <table border="0" class="container590" align="center" cellpadding="0" cellspacing="0">
239
+ <tr>
240
+ <td align="center"
241
+ style="color: #717171; font-size: 14px; font-family: 'Open Sans', Calibri, sans-serif; line-height: 25px;">
242
+ <div style=" line-height: 25px;">
243
+ <span>
244
+ <multiline>
245
+ © 2015 Copyright. All Rights Reserved.
246
+ </multiline>
247
+ </span>
248
+ </div>
249
+ </td>
250
+ </tr>
251
+
252
+ </table>
253
+
254
+ </td>
255
+ </tr>
256
+
257
+ </table>
258
+ </td>
259
+ </tr>
260
+
261
+ <tr>
262
+ <td height="20" style="font-size: 20px; line-height: 20px;">&nbsp;</td>
263
+ </tr>
264
+
265
+ </table>
266
+
267
+
268
+ </body>
14
269
  </html>
@@ -0,0 +1,19 @@
1
+ Logger::SimpleFormatter.class_eval do
2
+ def call(severity, time, progname, msg)
3
+ # generate the info part of the line
4
+ lead_string = "[#{time.strftime('%Y-%m-%d %H:%M:%S.%L')}] [" + sprintf("%-5s","#{severity}") + "]"
5
+ lead_string = lead_string + " [#{progname}]" unless progname.nil? or progname.empty?
6
+
7
+ # figure out how far it needs to be indented
8
+ # add +1 because we manually insert a space when outputting the message
9
+ indent = "".rjust(lead_string.length+1)
10
+
11
+ # use the logger default method to prepare the message for output
12
+ msg = msg2str(msg)
13
+
14
+ # indent all subsequent lines to help with readability
15
+ msg.gsub!( /([\r\n]+)/, "\\1#{indent}") if msg.respond_to? :gsub
16
+
17
+ "#{lead_string} #{msg}\n"
18
+ end
19
+ end
@@ -59,6 +59,8 @@ Rails.application.config.sorcery.configure do |config|
59
59
 
60
60
  # --- user config ---
61
61
  config.user_config do |user|
62
+ user.downcase_username_before_authenticating = true
63
+
62
64
  # -- core --
63
65
  user.username_attribute_names = [:username, :email] # specify username
64
66
  # attributes, for example:
@@ -0,0 +1,4 @@
1
+ WickedPdf.config = {
2
+ exe_path: '/usr/local/bin/wkhtmltopdf',
3
+ page_size: 'A4'
4
+ }
@@ -9,4 +9,68 @@ Rails.application.routes.draw do
9
9
  get "/users/activate/:activation_token" => 'erp_tech_svcs/user#activate'
10
10
  post "/users/reset_password" => 'erp_tech_svcs/user#reset_password'
11
11
  post "/users/update_password" => 'erp_tech_svcs/user#update_password'
12
+
13
+ namespace :api do
14
+ namespace :v1 do
15
+
16
+ resources :parties, defaults: { :format => 'json' } do
17
+ member do
18
+ get :user
19
+ end
20
+
21
+ resources :users, defaults: { :format => 'json'}, only: [:create]
22
+ end
23
+
24
+ resources :users, defaults: { :format => 'json' } do
25
+ member do
26
+ put :reset_password
27
+ get :effective_security
28
+ put :update_security
29
+ end
30
+
31
+ resources :security_roles, defaults: { :format => 'json' }
32
+ resources :groups, defaults: { :format => 'json' }
33
+ resources :capabilities, defaults: { :format => 'json' }
34
+ end
35
+
36
+ resources :audit_logs, defaults: { :format => 'json' } do
37
+ resources :audit_log_items, defaults: { :format => 'json'}
38
+ end
39
+
40
+ resources :security_roles, defaults: { :format => 'json' } do
41
+ collection do
42
+ get :selected
43
+ get :available
44
+ put :add
45
+ put :remove
46
+ end
47
+ end
48
+
49
+ resources :groups, defaults: { :format => 'json' } do
50
+ member do
51
+ get :effective_security
52
+ end
53
+
54
+ collection do
55
+ get :selected
56
+ get :available
57
+ put :add
58
+ put :remove
59
+ end
60
+ end
61
+
62
+ resources :capabilities, defaults: { :format => 'json' } do
63
+ collection do
64
+ get :selected
65
+ get :available
66
+ put :add
67
+ put :remove
68
+ end
69
+ end
70
+
71
+ resources :file_assets, defaults: { :format => 'json' }
72
+
73
+ end
74
+ end
75
+
12
76
  end
@@ -1,11 +1,7 @@
1
1
  class ScheduleDeleteExpiredSessionsJob
2
2
 
3
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)
4
+ ErpTechSvcs::DelayedJobs::DeleteExpiredSessionsJob.schedule_job(Time.now)
9
5
  end
10
6
 
11
7
  def self.down
@@ -0,0 +1,14 @@
1
+ class CreateJobTrackerForNotification
2
+
3
+ def self.up
4
+ JobTracker.create(
5
+ :job_name => 'Notification Job',
6
+ :job_klass => 'ErpTechSvcs::DelayedJobs::NotificationJob'
7
+ )
8
+ end
9
+
10
+ def self.down
11
+ JobTracker.find_by_job_name('Notification Job').destroy
12
+ end
13
+
14
+ end
@@ -1,5 +1,7 @@
1
1
  class BaseTechServices < ActiveRecord::Migration
2
2
  def self.up
3
+
4
+ # users
3
5
  unless table_exists?(:users)
4
6
  # Create the users table
5
7
  create_table :users do |t|
@@ -27,7 +29,7 @@ class BaseTechServices < ActiveRecord::Migration
27
29
  t.string :reset_password_token, :default => nil
28
30
  t.datetime :reset_password_token_expires_at, :default => nil
29
31
  t.datetime :reset_password_email_sent_at, :default => nil
30
-
32
+
31
33
  #user activation
32
34
  t.string :activation_state, :default => nil
33
35
  t.string :activation_token, :default => nil
@@ -38,6 +40,9 @@ class BaseTechServices < ActiveRecord::Migration
38
40
  t.string :security_question_2
39
41
  t.string :security_answer_2
40
42
 
43
+ t.string :auth_token
44
+ t.datetime :auth_token_expires_at
45
+
41
46
  t.timestamps
42
47
  end
43
48
  add_index :users, :email, :unique => true
@@ -49,6 +54,7 @@ class BaseTechServices < ActiveRecord::Migration
49
54
  add_index :users, :party_id, :name => 'users_party_id_idx'
50
55
  end
51
56
 
57
+ # groups
52
58
  unless table_exists?(:groups)
53
59
  create_table :groups do |t|
54
60
  t.column :description, :string
@@ -63,9 +69,11 @@ class BaseTechServices < ActiveRecord::Migration
63
69
  t.column :internal_identifier, :string
64
70
  t.column :external_identifier, :string
65
71
  t.column :external_id_source, :string
66
-
72
+
67
73
  t.timestamps
68
74
  end
75
+
76
+ add_index :security_roles, :internal_identifier, :name => 'security_roles_internal_identifier_idx'
69
77
  end
70
78
 
71
79
  unless table_exists?(:sessions)
@@ -75,17 +83,17 @@ class BaseTechServices < ActiveRecord::Migration
75
83
  t.text :data
76
84
  t.timestamps
77
85
  end
78
- add_index :sessions, :session_id
79
- add_index :sessions, :updated_at
86
+ add_index :sessions, :session_id
87
+ add_index :sessions, :updated_at
80
88
  end
81
89
 
82
90
  unless table_exists?(:audit_logs)
83
91
  # Create audit_logs
84
- create_table :audit_logs do |t|
85
- t.string :application
86
- t.string :description
87
- t.integer :party_id
88
- t.text :additional_info
92
+ create_table :audit_logs do |t|
93
+ t.string :application
94
+ t.string :description
95
+ t.integer :party_id
96
+ t.text :additional_info
89
97
  t.references :audit_log_type
90
98
 
91
99
  #polymorphic columns
@@ -95,6 +103,7 @@ class BaseTechServices < ActiveRecord::Migration
95
103
  end
96
104
  add_index :audit_logs, :party_id
97
105
  add_index :audit_logs, [:event_record_id, :event_record_type], :name => 'event_record_index'
106
+ add_index :audit_logs, :audit_log_type_id, :name => 'audit_logs_audit_log_type_id_idx'
98
107
  end
99
108
 
100
109
  unless table_exists?(:audit_log_types)
@@ -114,23 +123,30 @@ class BaseTechServices < ActiveRecord::Migration
114
123
 
115
124
  t.timestamps
116
125
  end
126
+
127
+ add_index :audit_log_types, :internal_identifier, :name => 'audit_log_types_internal_identifier_idx'
128
+ add_index :audit_log_types, :parent_id, :name => 'audit_log_types_parent_id_idx'
117
129
  end
118
130
 
119
131
  unless table_exists?(:audit_log_items)
120
132
  # Create audit_log_items
121
- create_table :audit_log_items do |t|
133
+ create_table :audit_log_items do |t|
122
134
  t.references :audit_log
123
135
  t.references :audit_log_item_type
124
- t.string :audit_log_item_value
125
- t.string :description
136
+ t.string :audit_log_item_value
137
+ t.string :audit_log_item_old_value
138
+ t.string :description
126
139
 
127
140
  t.timestamps
128
141
  end
142
+
143
+ add_index :audit_log_items, :audit_log_id, :name => 'audit_log_items_audit_log_id_idx'
144
+ add_index :audit_log_items, :audit_log_item_type_id, :name => 'audit_log_items_audit_log_item_type_id_idx'
129
145
  end
130
146
 
131
147
  unless table_exists?(:audit_log_item_types)
132
148
  # Create audit_log_item_types
133
- create_table :audit_log_item_types do |t|
149
+ create_table :audit_log_item_types do |t|
134
150
  t.string :internal_identifier
135
151
  t.string :external_identifier
136
152
  t.string :external_id_source
@@ -144,11 +160,16 @@ class BaseTechServices < ActiveRecord::Migration
144
160
 
145
161
  t.timestamps
146
162
  end
163
+
164
+ add_index :audit_log_item_types, :internal_identifier, :name => 'audit_log_item_types_internal_identifier_idx'
165
+ add_index :audit_log_item_types, :parent_id, :name => 'audit_log_item_types_parent_id_idx'
166
+ add_index :audit_log_item_types, :lft, :name => 'audit_log_item_types_lft_idx'
167
+ add_index :audit_log_item_types, :rgt, :name => 'audit_log_item_types_rgt_idx'
147
168
  end
148
-
169
+
170
+ # file_assets
149
171
  unless table_exists?(:file_assets)
150
172
  create_table :file_assets do |t|
151
- t.references :file_asset_holder, :polymorphic => true
152
173
  t.string :type
153
174
  t.string :name
154
175
  t.string :directory
@@ -158,33 +179,47 @@ class BaseTechServices < ActiveRecord::Migration
158
179
  t.datetime :data_updated_at
159
180
  t.string :width
160
181
  t.string :height
182
+ t.text :scoped_by
161
183
 
162
184
  t.timestamps
163
185
  end
164
186
  add_index :file_assets, :type
165
- add_index :file_assets, [:file_asset_holder_id, :file_asset_holder_type], :name => 'file_asset_holder_idx'
166
187
  add_index :file_assets, :name
167
188
  add_index :file_assets, :directory
168
189
  end
169
-
190
+
191
+ # file_asset_holders
192
+ unless table_exists?(:file_asset_holders)
193
+ create_table :file_asset_holders do |t|
194
+ t.references :file_asset
195
+ t.references :file_asset_holder, :polymorphic => true
196
+ t.text :scoped_by
197
+
198
+ t.timestamps
199
+ end
200
+
201
+ add_index :file_asset_holders, :file_asset_id, :name => 'file_asset_holder_file_id_idx'
202
+ add_index :file_asset_holders, [:file_asset_holder_id, :file_asset_holder_type], :name => 'file_asset_holder_idx'
203
+ end
204
+
205
+ # delayed_jobs
170
206
  unless table_exists?(:delayed_jobs)
171
207
  create_table :delayed_jobs, :force => true do |table|
172
- table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
173
- table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
174
- table.text :handler # YAML-encoded string of the object that will do work
175
- table.text :last_error # reason for last failure (See Note below)
176
- table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
177
- table.datetime :locked_at # Set when a client is working on this object
178
- table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
179
- table.string :locked_by # Who is working on this object (if locked)
180
- table.string :queue
208
+ table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
209
+ table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
210
+ table.text :handler # YAML-encoded string of the object that will do work
211
+ table.text :last_error # reason for last failure (See Note below)
212
+ table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
213
+ table.datetime :locked_at # Set when a client is working on this object
214
+ table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
215
+ table.string :locked_by # Who is working on this object (if locked)
216
+ table.string :queue
181
217
  table.timestamps
182
218
  end
183
219
  add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
184
220
  end
185
221
 
186
222
  unless table_exists?(:capable_models)
187
- # create the roles table
188
223
  create_table :capable_models do |t|
189
224
  t.references :capable_model_record, :polymorphic => true
190
225
 
@@ -195,23 +230,22 @@ class BaseTechServices < ActiveRecord::Migration
195
230
  end
196
231
 
197
232
  unless table_exists?(:capability_types)
198
- # create the roles table
199
233
  create_table :capability_types do |t|
200
234
  t.string :internal_identifier
201
235
  t.string :description
202
236
  t.timestamps
203
237
  end
238
+
239
+ add_index :capability_types, :internal_identifier, :name => 'capability_types_internal_identifier_idx'
204
240
  end
205
241
 
206
242
  unless table_exists?(:capabilities)
207
- # create the roles table
208
243
  create_table :capabilities do |t|
209
244
  t.string :description
210
245
  t.references :capability_type
211
- t.string :capability_resource_type
212
- t.integer :capability_resource_id
246
+ t.references :capability_resource, :polymorphic => true
213
247
  t.integer :scope_type_id
214
- t.text :scope_query
248
+ t.text :scope_query
215
249
  t.timestamps
216
250
  end
217
251
 
@@ -222,8 +256,7 @@ class BaseTechServices < ActiveRecord::Migration
222
256
 
223
257
  unless table_exists?(:capability_accessors)
224
258
  create_table :capability_accessors do |t|
225
- t.string :capability_accessor_record_type
226
- t.integer :capability_accessor_record_id
259
+ t.references :capability_accessor_record, :polymorphic => true
227
260
  t.integer :capability_id
228
261
  t.timestamps
229
262
  end
@@ -252,15 +285,42 @@ class BaseTechServices < ActiveRecord::Migration
252
285
  add_index :parties_security_roles, :security_role_id
253
286
  end
254
287
 
288
+ unless table_exists? :notifications
289
+ create_table :notifications do |t|
290
+ t.string :type
291
+ t.references :created_by
292
+ t.text :message
293
+ t.references :notification_type
294
+ t.string :current_state
295
+
296
+ t.timestamps
297
+ end
298
+
299
+ add_index :notifications, :notification_type_id
300
+ add_index :notifications, :created_by_id
301
+ add_index :notifications, :type
302
+ end
303
+
304
+ unless table_exists? :notification_types
305
+ create_table :notification_types do |t|
306
+ t.string :internal_identifier
307
+ t.string :description
308
+
309
+ t.timestamps
310
+ end
311
+
312
+ add_index :notification_types, :internal_identifier
313
+ end
314
+
255
315
  end
256
316
 
257
317
  def self.down
258
318
  # check that each table exists before trying to delete it.
259
- [ :groups,
260
- :audit_logs, :sessions, :simple_captcha_data,
261
- :capability_accessors, :capability_types, :capabilities,:scope_types,
262
- :parties_security_roles, :roles, :audit_log_items, :audit_log_item_types,
263
- :users, :file_assets, :delayed_jobs
319
+ [:groups, :notifications, :notification_types,
320
+ :audit_logs, :sessions, :simple_captcha_data,
321
+ :capability_accessors, :capability_types, :capabilities, :scope_types,
322
+ :parties_security_roles, :roles, :audit_log_items, :audit_log_item_types,
323
+ :users, :file_assets, :delayed_jobs
264
324
  ].each do |tbl|
265
325
  if table_exists?(tbl)
266
326
  drop_table tbl