erp_invoicing 3.0.6 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/app/models/billing_account.rb +5 -3
  2. data/app/models/calculate_balance_strategy_type.rb +2 -0
  3. data/app/models/invoice.rb +2 -0
  4. data/app/models/invoice_item.rb +1 -0
  5. data/app/models/invoice_item_type.rb +1 -0
  6. data/app/models/invoice_party_role.rb +1 -0
  7. data/app/models/invoice_payment_strategy_type.rb +2 -0
  8. data/app/models/invoice_payment_term.rb +2 -0
  9. data/app/models/invoice_payment_term_set.rb +2 -0
  10. data/app/models/invoice_payment_term_type.rb +2 -0
  11. data/app/models/invoice_type.rb +1 -0
  12. data/app/models/payment_application.rb +2 -1
  13. data/app/models/recurring_payment.rb +2 -0
  14. data/db/migrate/20111121000000_invoicing_services.rb +13 -1
  15. data/lib/erp_invoicing/version.rb +2 -2
  16. data/lib/erp_invoicing.rb +4 -0
  17. data/public/javascripts/erp_app/desktop/applications/invoice_management/billing_accounts_panel.js +0 -1
  18. data/public/javascripts/erp_app/shared/invoices_grid_panel.js +1 -1
  19. data/spec/dummy/config/application.rb +6 -0
  20. data/spec/dummy/config/environments/spec.rb +3 -0
  21. data/spec/dummy/db/data_migrations/20101011152441_payment_gateway_actions.erp_commerce.rb +28 -0
  22. data/spec/dummy/db/data_migrations/20101014142230_financial_txn_types.erp_txns_and_accts.rb +16 -0
  23. data/spec/dummy/db/data_migrations/20110109173616_create_capability_scope_types.erp_tech_svcs.rb +15 -0
  24. data/spec/dummy/db/data_migrations/20110324010232_product_role_types.erp_products.rb +24 -0
  25. data/spec/dummy/db/data_migrations/20110509223702_add_publisher_role.knitkit.rb +22 -0
  26. data/spec/dummy/db/data_migrations/20110525001935_add_usd_currency.erp_base_erp_svcs.rb +12 -0
  27. data/spec/dummy/db/data_migrations/20110527160807_add_default_prod_avail_types.erp_products.rb +27 -0
  28. data/spec/dummy/db/data_migrations/20110605231556_create_order_party_roles.erp_orders.rb +24 -0
  29. data/spec/dummy/db/data_migrations/20110608185830_create_default_dynamic_models_and_forms.erp_forms.rb +33 -0
  30. data/spec/dummy/db/data_migrations/20110609150135_add_iso_codes.erp_base_erp_svcs.rb +19 -0
  31. data/spec/dummy/db/data_migrations/20110728201729_erp_app_setup.erp_app.rb +252 -0
  32. data/spec/dummy/db/data_migrations/20110728201730_create_desktop_app_product_manager.erp_products.rb +26 -0
  33. data/spec/dummy/db/data_migrations/20110728201731_create_desktop_app_order_manager.erp_orders.rb +26 -0
  34. data/spec/dummy/db/data_migrations/20110728201732_create_organizer_app_order_management.erp_orders.rb +15 -0
  35. data/spec/dummy/db/data_migrations/20110728201733_update_preferences.erp_app.rb +53 -0
  36. data/spec/dummy/db/data_migrations/20110802200222_schedule_delete_expired_sessions_job.erp_tech_svcs.rb +16 -0
  37. data/spec/dummy/db/data_migrations/20110816153456_add_knitkit_application.knitkit.rb +32 -0
  38. data/spec/dummy/db/data_migrations/20110816161238_create_desktop_app_audit_log_viewer.erp_app.rb +21 -0
  39. data/spec/dummy/db/data_migrations/20110817160743_add_file_manager_application.erp_app.rb +32 -0
  40. data/spec/dummy/db/data_migrations/20110828190913_create_desktop_app_dynamic_forms.erp_forms.rb +19 -0
  41. data/spec/dummy/db/data_migrations/20110913145838_setup_compass_ae_instance.erp_base_erp_svcs.rb +12 -0
  42. data/spec/dummy/db/data_migrations/20111108183739_add_default_capabilities.erp_app.rb +23 -0
  43. data/spec/dummy/db/data_migrations/20111108183740_add_new_contact_widgets.erp_app.rb +42 -0
  44. data/spec/dummy/db/data_migrations/20111111144706_setup_audit_log_types.erp_tech_svcs.rb +22 -0
  45. data/spec/dummy/db/data_migrations/20111118182910_setup_knitkit_capabilities.knitkit.rb +128 -0
  46. data/spec/dummy/db/data_migrations/20111121153349_create_bill_pay_organizer_application.erp_invoicing.rb +15 -0
  47. data/spec/dummy/db/data_migrations/20120109173616_create_download_capability_type.erp_tech_svcs.rb +14 -0
  48. data/spec/dummy/db/data_migrations/20120118181839_create_invoice_management_desktop_application.erp_invoicing.rb +27 -0
  49. data/spec/dummy/db/data_migrations/20120127144444_create_website_role_types.knitkit.rb +14 -0
  50. data/spec/dummy/db/data_migrations/20120127150505_create_website_default_configuration.knitkit.rb +73 -0
  51. data/spec/dummy/db/data_migrations/20120127150506_add_primary_host_to_website_configuration.knitkit.rb +34 -0
  52. data/spec/dummy/db/data_migrations/20120229160222_add_userinfo_widget.erp_app.rb +29 -0
  53. data/spec/dummy/db/data_migrations/20120229174322_add_billpay_widget.erp_invoicing.rb +27 -0
  54. data/spec/dummy/db/data_migrations/20120229174343_add_orders_widget.erp_orders.rb +29 -0
  55. data/spec/dummy/db/data_migrations/20120316150424_add_is_template_to_default_website_config.knitkit.rb +17 -0
  56. data/spec/dummy/db/data_migrations/20120405193721_create_party_and_role_type_for_communication_events.erp_app.rb +11 -0
  57. data/spec/dummy/db/data_migrations/20120411180756_create_user_management_mobile_application.erp_app.rb +19 -0
  58. data/spec/dummy/db/data_migrations/20120418164215_create_configuration_management_desktop_application.erp_app.rb +23 -0
  59. data/spec/dummy/db/data_migrations/20120605154637_add_calculate_balance_strategy_types.erp_invoicing.rb +21 -0
  60. data/spec/dummy/db/data_migrations/20120809020508_update_website_and_configuration.knitkit.rb +78 -0
  61. data/spec/dummy/db/data_migrations/20120824013449_create_ticket_form.erp_forms.rb +67 -0
  62. data/spec/dummy/db/data_migrations/20121026013449_update_ticket_form.erp_forms.rb +65 -0
  63. data/spec/dummy/db/data_migrations/20121026191738_update_contact_form.erp_forms.rb +27 -0
  64. data/spec/dummy/db/data_migrations/20121116155018_create_group_relationship_and_role_types.erp_tech_svcs.rb +20 -0
  65. data/spec/dummy/db/data_migrations/20121129185611_upgrade_website_role_iid.knitkit.rb +21 -0
  66. data/spec/dummy/db/data_migrations/20121130201859_upgrade_remove_system_mgmt_app.erp_app.rb +16 -0
  67. data/spec/dummy/db/data_migrations/20121130212146_note_capabilities.erp_tech_svcs.rb +24 -0
  68. data/spec/dummy/db/data_migrations/20121218175028_create_security_management_desktop_application.erp_app.rb +23 -0
  69. data/spec/dummy/db/migrate/20121214000230_base_erp_services.erp_base_erp_svcs.rb +461 -0
  70. data/spec/dummy/db/migrate/20121214000231_base_tech_services.erp_tech_svcs.rb +255 -0
  71. data/spec/dummy/db/migrate/20121214000232_create_has_attribute_tables.erp_tech_svcs.rb +39 -0
  72. data/spec/dummy/db/migrate/20121214000233_base_app_framework.erp_app.rb +276 -0
  73. data/spec/dummy/db/migrate/20121214000234_dynamic_forms.erp_forms.rb +95 -0
  74. data/spec/dummy/db/migrate/20121214000235_create_tickets.erp_forms.rb +19 -0
  75. data/spec/dummy/db/migrate/20121214000236_upgrade_dynamic_forms_table.erp_forms.rb +32 -0
  76. data/spec/dummy/db/migrate/20121214000237_setup_knitkit.knitkit.rb +316 -0
  77. data/spec/dummy/db/migrate/20121214000238_invoicing_services.erp_invoicing.rb +277 -0
  78. data/spec/dummy/db/migrate/20121214000239_base_inventory.erp_inventory.rb +91 -0
  79. data/spec/dummy/db/migrate/20121214000240_base_inventory_indexes.erp_inventory.rb +48 -0
  80. data/spec/dummy/db/migrate/20121214000241_base_txns_and_accts.erp_txns_and_accts.rb +364 -0
  81. data/spec/dummy/db/migrate/20121214000242_agreements_services.erp_agreements.rb +160 -0
  82. data/spec/dummy/db/migrate/20121214000243_agreements_services_indexes.erp_agreements.rb +52 -0
  83. data/spec/dummy/db/migrate/20121214000244_base_orders.erp_orders.rb +178 -0
  84. data/spec/dummy/db/migrate/20121214000245_base_products.erp_products.rb +234 -0
  85. data/spec/dummy/db/migrate/20121214000246_base_products_indexes.erp_products.rb +59 -0
  86. data/spec/dummy/db/migrate/20121214000247_erp_commerce_base.erp_commerce.rb +442 -0
  87. data/spec/dummy/db/migrate/20121214000248_base_work_efforts.erp_work_effort.rb +211 -0
  88. data/spec/dummy/db/migrate/20130107181155_create_groups.erp_tech_svcs.rb +19 -0
  89. data/spec/dummy/db/migrate/20130107181156_upgrade_security.erp_tech_svcs.rb +54 -0
  90. data/spec/dummy/db/migrate/20130107181157_upgrade_security2.erp_tech_svcs.rb +270 -0
  91. data/spec/dummy/db/schema.rb +2569 -0
  92. data/spec/dummy/db/spec.sqlite3 +0 -0
  93. data/spec/dummy/log/spec.log +64744 -0
  94. data/spec/models/billing_account_spec.rb +1 -7
  95. data/spec/models/invoice_spec.rb +2 -1
  96. data/spec/models/payment_application_spec.rb +1 -1
  97. data/spec/spec_helper.rb +18 -10
  98. metadata +203 -20
  99. data/db/migrate/20120228184317_add_text_to_pay_to_recurring_payments.rb +0 -13
  100. data/db/migrate/20120301155722_add_billing_date_to_billing_account.rb +0 -13
  101. data/db/migrate/20120605144227_create_calcuate_balance_strategy_type.rb +0 -18
  102. data/db/migrate/20120605144900_add_calculate_balance_strategy_to_billing_account.rb +0 -7
  103. data/db/migrate/20120605150425_add_balance_to_invoice.rb +0 -9
@@ -0,0 +1,211 @@
1
+ # This migration comes from erp_work_effort (originally 20100220000000)
2
+ class BaseWorkEfforts < ActiveRecord::Migration
3
+
4
+ def self.up
5
+
6
+ ## work_efforts
7
+ unless table_exists?(:work_efforts)
8
+ create_table :work_efforts do |t|
9
+ t.string :description
10
+ t.string :type
11
+ t.datetime :started_at
12
+ t.datetime :finished_at
13
+ t.integer :projected_completion_time
14
+ t.integer :actual_completion_time
15
+
16
+ t.timestamps
17
+
18
+ #polymorphic columns
19
+ t.integer :facility_id
20
+ t.string :facility_type
21
+ t.integer :work_effort_record_id
22
+ t.string :work_effort_record_type
23
+
24
+ #foreign keys
25
+ t.integer :projected_cost_id
26
+ t.integer :actual_cost_id
27
+
28
+ #better nested set columns
29
+ t.integer :parent_id
30
+ t.integer :lft
31
+ t.integer :rgt
32
+ end
33
+
34
+ add_index :work_efforts, [:work_effort_record_id, :work_effort_record_type], :name => "work_effort_record_id_type"
35
+ add_index :work_efforts, [:facility_type, :facility_id], :name => "facility"
36
+ add_index :work_efforts, :finished_at
37
+ end
38
+
39
+ ## work_requirements
40
+ unless table_exists?(:work_requirements)
41
+ create_table :work_requirements do |t|
42
+ t.string :description
43
+ t.string :type
44
+ t.integer :projected_completion_time
45
+ t.timestamps
46
+
47
+ #polymorphic columns
48
+ t.integer :work_requirement_record_id
49
+ t.string :work_requirement_record_type
50
+ t.integer :facility_id
51
+ t.string :facility_type
52
+
53
+ # foreign keys
54
+ t.integer :cost_id
55
+
56
+ #better nested set columns
57
+ t.integer :parent_id
58
+ t.integer :lft
59
+ t.integer :rgt
60
+ end
61
+ end
62
+
63
+ ## work_requirement_work_effort_status_types
64
+ unless table_exists?(:work_requirement_work_effort_status_types)
65
+ create_table :work_requirement_work_effort_status_types do |t|
66
+ t.timestamps
67
+
68
+ #foreign keys
69
+ t.integer :work_requirement_id
70
+ t.integer :work_effort_status_type_id
71
+ t.boolean :is_initial_status
72
+ end
73
+ end
74
+
75
+ ## work_effort_statuses
76
+ unless table_exists?(:work_effort_statuses)
77
+ create_table :work_effort_statuses do |t|
78
+ t.datetime :started_at
79
+ t.datetime :finished_at
80
+ t.integer :work_effort_id
81
+ t.integer :work_effort_status_type_id
82
+
83
+ t.timestamps
84
+ end
85
+
86
+ add_index :work_effort_statuses, :work_effort_status_type_id
87
+ add_index :work_effort_statuses, :work_effort_id
88
+ end
89
+
90
+ ## work_effort_status_types
91
+ unless table_exists?(:work_effort_status_types)
92
+ create_table :work_effort_status_types do |t|
93
+ t.string :internal_identifier
94
+ t.string :description
95
+ t.integer :next_status_id
96
+ t.integer :previous_status_id
97
+
98
+ t.timestamps
99
+ end
100
+
101
+ add_index :work_effort_status_types, :internal_identifier
102
+ add_index :work_effort_status_types, :description
103
+ end
104
+
105
+ ## work_effort_assignments
106
+ unless table_exists?(:work_effort_assignments)
107
+ create_table :work_effort_assignments do |t|
108
+ #foreign keys
109
+ t.references :work_effort
110
+
111
+ t.datetime :assigned_at
112
+ t.datetime :assigned_from
113
+ t.datetime :assigned_thru
114
+ t.datetime :unassigned_at
115
+
116
+ #Polymorphic Columns
117
+ t.integer :assigned_to_id
118
+ t.string :assigned_to_type
119
+ t.integer :assigned_by_id
120
+ t.string :assigned_by_type
121
+
122
+ t.timestamps
123
+ end
124
+
125
+ add_index :work_effort_assignments, [:assigned_to_id, :assigned_to_type], :name => "assigned_to"
126
+ add_index :work_effort_assignments, :assigned_from
127
+ add_index :work_effort_assignments, :assigned_thru
128
+ add_index :work_effort_assignments, :work_effort_id
129
+ end
130
+
131
+ ## valid_work_assignments
132
+ unless table_exists?(:valid_work_assignments)
133
+ create_table :valid_work_assignments do |t|
134
+ t.integer :role_type_id
135
+ t.integer :work_requirement_id
136
+
137
+ t.timestamps
138
+ end
139
+
140
+ end
141
+
142
+ ## valid_work_assignment_attributes
143
+ unless table_exists?(:valid_work_assignment_attributes)
144
+ create_table :valid_work_assignment_attributes do |t|
145
+ t.integer :valid_work_assignment_id
146
+ t.string :name
147
+ t.string :type
148
+ t.string :value
149
+
150
+ t.timestamps
151
+ end
152
+ end
153
+
154
+ ## party_resource_availabilities
155
+ unless table_exists?(:party_resource_availabilities)
156
+ create_table :party_resource_availabilities do |t|
157
+ t.datetime :from_date
158
+ t.datetime :to_date
159
+ t.integer :party_id
160
+ t.integer :pra_type_id #:party_resource_availability_type_id is too long
161
+
162
+ t.timestamps
163
+ end
164
+
165
+ add_index :party_resource_availabilities, :from_date
166
+ add_index :party_resource_availabilities, :to_date
167
+ add_index :party_resource_availabilities, :pra_type_id
168
+ add_index :party_resource_availabilities, :party_id
169
+ end
170
+
171
+ unless table_exists?(:party_resource_availability_types)
172
+ create_table :party_resource_availability_types do |t|
173
+ t.string :description
174
+ t.string :internal_identifier
175
+
176
+ t.timestamps
177
+ end
178
+
179
+ add_index :party_resource_availability_types, :internal_identifier
180
+ add_index :party_resource_availability_types, :description
181
+ end
182
+
183
+ ## costs
184
+ unless table_exists?(:costs)
185
+ create_table :costs do |t|
186
+ t.integer :money_id
187
+ t.timestamps
188
+ end
189
+ end
190
+
191
+ end
192
+
193
+ def self.down
194
+ # Drop all tables, including those that were originally created then deleted
195
+ [
196
+ # Old tables deleted and no longer used
197
+ :work_requirement_assignabilities,
198
+ # Currently used tables
199
+ :category_classifications, :categories, :work_requirement_assignability_attributes,
200
+ :valid_work_assignments, :work_effort_assignments, :work_effort_status_types,
201
+ :work_effort_statuses, :work_requirement_work_effort_status_types,
202
+ :work_requirements, :work_efforts, :party_resource_availabilities, :party_resource_availability_types,
203
+ :costs
204
+ ].each do |tbl|
205
+ if table_exists?(tbl)
206
+ drop_table tbl
207
+ end
208
+ end
209
+
210
+ end
211
+ end
@@ -0,0 +1,19 @@
1
+ # This migration comes from erp_tech_svcs (originally 20121116151510)
2
+ class CreateGroups < ActiveRecord::Migration
3
+ def self.up
4
+ unless table_exists?(:groups)
5
+ create_table :groups do |t|
6
+ t.column :description, :string
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ [ :groups ].each do |tbl|
14
+ if table_exists?(tbl)
15
+ drop_table tbl
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,54 @@
1
+ # This migration comes from erp_tech_svcs (originally 20121126171612)
2
+ class UpgradeSecurity < ActiveRecord::Migration
3
+
4
+ def self.up
5
+ unless table_exists?(:capability_accessors)
6
+ create_table :capability_accessors do |t|
7
+ t.string :capability_accessor_record_type
8
+ t.integer :capability_accessor_record_id
9
+ t.integer :capability_id
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :capability_accessors, :capability_id
14
+ add_index :capability_accessors, [:capability_accessor_record_id, :capability_accessor_record_type], :name => 'capability_accessor_record_index'
15
+ end
16
+
17
+ unless columns(:capabilities).collect {|c| c.name}.include?('scope_query')
18
+ add_column :capabilities, :description, :string
19
+ add_column :capabilities, :capability_resource_type, :string
20
+ add_column :capabilities, :capability_resource_id, :integer
21
+ add_column :capabilities, :scope_type_id, :integer
22
+ add_column :capabilities, :scope_query, :text
23
+
24
+ add_index :capabilities, :scope_type_id
25
+ add_index :capabilities, [:capability_resource_id, :capability_resource_type], :name => 'capability_resource_index'
26
+ end
27
+
28
+ unless table_exists?(:scope_types)
29
+ create_table :scope_types do |t|
30
+ t.string :description
31
+ t.string :internal_identifier
32
+ t.timestamps
33
+ end
34
+
35
+ add_index :scope_types, :internal_identifier
36
+ end
37
+
38
+ unless table_exists?(:parties_security_roles)
39
+ create_table :parties_security_roles, :id => false do |t|
40
+ t.integer :party_id
41
+ t.integer :security_role_id
42
+ end
43
+
44
+ add_index :parties_security_roles, :party_id
45
+ add_index :parties_security_roles, :security_role_id
46
+ end
47
+
48
+ rename_table :roles, :security_roles unless table_exists?(:security_roles)
49
+
50
+ end
51
+
52
+ def self.down
53
+ end
54
+ end
@@ -0,0 +1,270 @@
1
+ # This migration comes from erp_tech_svcs (originally 20121126173506)
2
+ class UpgradeSecurity2 < ActiveRecord::Migration
3
+ def self.up
4
+ if table_exists?(:secured_models)
5
+ Website.all.each do |w|
6
+ old_role_iid = "website_#{w.name.underscore.gsub("'","").gsub(",","")}_access"
7
+
8
+ r = SecurityRole.find_by_internal_identifier(old_role_iid)
9
+ unless r.nil?
10
+ r.internal_identifier = w.website_role_iid
11
+ r.save
12
+ end
13
+ end
14
+ instance = ScopeType.create(:description => 'Instance', :internal_identifier => 'instance')
15
+ class_scope_type = ScopeType.create(:description => 'Class', :internal_identifier => 'class')
16
+ ScopeType.create(:description => 'Query', :internal_identifier => 'query')
17
+
18
+ execute('BEGIN TRANSACTION')
19
+ puts "populating parties_security_roles"
20
+ sql =
21
+ "INSERT INTO parties_security_roles (
22
+ party_id,
23
+ security_role_id
24
+ )
25
+ SELECT
26
+ u.party_id AS party_id,
27
+ rsm.role_id AS security_role_id
28
+ FROM secured_models sm
29
+ JOIN roles_secured_models rsm ON sm.id=rsm.secured_model_id
30
+ JOIN users u ON sm.secured_record_id=u.id
31
+ WHERE sm.secured_record_type='User'"
32
+
33
+ execute(sql)
34
+ execute('COMMIT')
35
+
36
+ execute('BEGIN TRANSACTION')
37
+ puts "populating capabilities with secure File Assets"
38
+ sql =
39
+ "INSERT INTO capabilities (
40
+ capability_type_id,
41
+ capability_resource_type,
42
+ capability_resource_id,
43
+ scope_type_id
44
+ )
45
+ SELECT
46
+ c.capability_type_id AS capability_type_id,
47
+ 'FileAsset' AS capability_resource_type,
48
+ cm.capable_model_record_id AS capability_resource_id,
49
+ #{instance.id} AS scope_type_id
50
+ FROM capable_models AS cm
51
+ JOIN capabilities_capable_models AS ccm ON ccm.capable_model_id = cm.id
52
+ JOIN capabilities AS c ON ccm.capability_id = c.id
53
+ JOIN secured_models AS sm ON sm.secured_record_id = c.id AND sm.secured_record_type = 'Capability'
54
+ JOIN roles_secured_models AS rsm ON rsm.secured_model_id = sm.id
55
+ JOIN security_roles AS r ON r.id = rsm.role_id
56
+ WHERE cm.capable_model_record_type = 'FileAsset'"
57
+
58
+ execute(sql)
59
+ execute('COMMIT')
60
+
61
+ view = CapabilityType.find_by_internal_identifier('view')
62
+
63
+ execute('BEGIN TRANSACTION')
64
+ puts "populating capabilities with secure Website Sections"
65
+ sql =
66
+ "INSERT INTO capabilities (
67
+ capability_type_id,
68
+ capability_resource_type,
69
+ capability_resource_id,
70
+ scope_type_id
71
+ )
72
+ SELECT
73
+ #{view.id} AS capability_type_id,
74
+ 'WebsiteSection' AS capability_resource_type,
75
+ ws.id AS capability_resource_id,
76
+ #{instance.id} AS scope_type_id
77
+ FROM secured_models sm
78
+ JOIN roles_secured_models rsm ON sm.id=rsm.secured_model_id
79
+ JOIN website_sections ws ON sm.secured_record_id=ws.id
80
+ WHERE sm.secured_record_type='WebsiteSection'"
81
+
82
+ execute(sql)
83
+ execute('COMMIT')
84
+
85
+ execute('BEGIN TRANSACTION')
86
+ puts "populating capabilities with secure Website Nav Items"
87
+ sql =
88
+ "INSERT INTO capabilities (
89
+ capability_type_id,
90
+ capability_resource_type,
91
+ capability_resource_id,
92
+ scope_type_id
93
+ )
94
+ SELECT
95
+ #{view.id} AS capability_type_id,
96
+ 'WebsiteNavItem' AS capability_resource_type,
97
+ ws.id AS capability_resource_id,
98
+ #{instance.id} AS scope_type_id
99
+ FROM secured_models sm
100
+ JOIN roles_secured_models rsm ON sm.id=rsm.secured_model_id
101
+ JOIN website_sections ws ON sm.secured_record_id=ws.id
102
+ WHERE sm.secured_record_type='WebsiteNavItem'"
103
+
104
+ execute(sql)
105
+ execute('COMMIT')
106
+
107
+ # delete obsolete records: Application, Widget, dupes?
108
+ Capability.where("capability_resource_type IS NULL").delete_all
109
+
110
+ admin = SecurityRole.find_by_internal_identifier('admin')
111
+ website_author = SecurityRole.find_by_internal_identifier('website_author')
112
+ layout_author = SecurityRole.find_by_internal_identifier('layout_author')
113
+ content_author = SecurityRole.find_by_internal_identifier('content_author')
114
+ designer = SecurityRole.find_by_internal_identifier('designer')
115
+ publisher = SecurityRole.find_by_internal_identifier('publisher')
116
+
117
+ # add instance capabilities to roles
118
+ instance_capabilities = Capability.where(:scope_type_id => instance.id).all
119
+ instance_capabilities.each do |c|
120
+ case c.capability_resource_type
121
+ when 'FileAsset'
122
+ admin.add_capability(c)
123
+ website_author.add_capability(c)
124
+ content_author.add_capability(c)
125
+ if c.capability_resource.file_asset_holder_type == 'Website'
126
+ website_role = c.capability_resource.file_asset_holder.role
127
+ website_role.add_capability(c)
128
+ end
129
+ when 'WebsiteSection'
130
+ admin.add_capability(c)
131
+ website_author.add_capability(c)
132
+ website_role = c.capability_resource.website.role
133
+ website_role.add_capability(c)
134
+ when 'WebsiteNavItem'
135
+ admin.add_capability(c)
136
+ website_author.add_capability(c)
137
+ website_role = c.capability_resource.website_nav.website.role
138
+ website_role.add_capability(c)
139
+ end
140
+ end
141
+
142
+ # add knitkit class capabilities to roles
143
+ admin.add_capability('create', 'WebsiteNav')
144
+ admin.add_capability('delete', 'WebsiteNav')
145
+ admin.add_capability('edit', 'WebsiteNav')
146
+
147
+ website_author.add_capability('create', 'WebsiteNav')
148
+ website_author.add_capability('delete', 'WebsiteNav')
149
+ website_author.add_capability('edit', 'WebsiteNav')
150
+
151
+ admin.add_capability('create', 'Website')
152
+ admin.add_capability('delete', 'Website')
153
+ admin.add_capability('edit', 'Website')
154
+ admin.add_capability('import', 'Website')
155
+ admin.add_capability('publish', 'Website')
156
+ admin.add_capability('activate', 'Website')
157
+
158
+ website_author.add_capability('create', 'Website')
159
+ website_author.add_capability('delete', 'Website')
160
+ website_author.add_capability('edit', 'Website')
161
+ website_author.add_capability('import', 'Website')
162
+ publisher.add_capability('publish', 'Website')
163
+ publisher.add_capability('activate', 'Website')
164
+
165
+ admin.add_capability('create', 'WebsiteHost')
166
+ admin.add_capability('delete', 'WebsiteHost')
167
+ admin.add_capability('edit', 'WebsiteHost')
168
+
169
+ website_author.add_capability('create', 'WebsiteHost')
170
+ website_author.add_capability('delete', 'WebsiteHost')
171
+ website_author.add_capability('edit', 'WebsiteHost')
172
+
173
+ admin.add_capability('create', 'WebsiteSection')
174
+ admin.add_capability('delete', 'WebsiteSection')
175
+ admin.add_capability('edit', 'WebsiteSection')
176
+ admin.add_capability('secure', 'WebsiteSection')
177
+ admin.add_capability('unsecure', 'WebsiteSection')
178
+
179
+ website_author.add_capability('create', 'WebsiteSection')
180
+ website_author.add_capability('delete', 'WebsiteSection')
181
+ website_author.add_capability('edit', 'WebsiteSection')
182
+ website_author.add_capability('secure', 'WebsiteSection')
183
+ website_author.add_capability('unsecure', 'WebsiteSection')
184
+
185
+ admin.add_capability('create', 'WebsiteSectionLayout')
186
+ admin.add_capability('edit', 'WebsiteSectionLayout')
187
+
188
+ layout_author.add_capability('create', 'WebsiteSectionLayout')
189
+ layout_author.add_capability('edit', 'WebsiteSectionLayout')
190
+
191
+ admin.add_capability('create', 'Content')
192
+ admin.add_capability('delete', 'Content')
193
+ admin.add_capability('edit', 'Content')
194
+ admin.add_capability('publish', 'Content')
195
+ admin.add_capability('revert_version', 'Content')
196
+ admin.add_capability('add_existing', 'Content')
197
+ admin.add_capability('edit_html', 'Content')
198
+ admin.add_capability('edit_excerpt', 'Content')
199
+
200
+ content_author.add_capability('create', 'Content')
201
+ content_author.add_capability('delete', 'Content')
202
+ content_author.add_capability('edit', 'Content')
203
+ content_author.add_capability('publish', 'Content')
204
+ content_author.add_capability('revert_version', 'Content')
205
+ content_author.add_capability('add_existing', 'Content')
206
+ content_author.add_capability('edit_html', 'Content')
207
+ content_author.add_capability('edit_excerpt', 'Content')
208
+
209
+ admin.add_capability('create', 'WebsiteNavItem')
210
+ admin.add_capability('delete', 'WebsiteNavItem')
211
+ admin.add_capability('edit', 'WebsiteNavItem')
212
+ admin.add_capability('secure', 'WebsiteNavItem')
213
+ admin.add_capability('unsecure', 'WebsiteNavItem')
214
+
215
+ website_author.add_capability('create', 'WebsiteNavItem')
216
+ website_author.add_capability('delete', 'WebsiteNavItem')
217
+ website_author.add_capability('edit', 'WebsiteNavItem')
218
+ website_author.add_capability('secure', 'WebsiteNavItem')
219
+ website_author.add_capability('unsecure', 'WebsiteNavItem')
220
+
221
+ admin.add_capability('view', 'Theme')
222
+ designer.add_capability('view', 'Theme')
223
+
224
+ admin.add_capability('view', 'SiteImageAsset')
225
+ website_author.add_capability('view', 'SiteImageAsset')
226
+ content_author.add_capability('view', 'SiteImageAsset')
227
+
228
+ content_author.add_capability('view', 'GlobalImageAsset')
229
+
230
+ admin.add_capability('view', 'GlobalImageAsset')
231
+ admin.add_capability('upload', 'GlobalImageAsset')
232
+ admin.add_capability('delete', 'GlobalImageAsset')
233
+
234
+ website_author.add_capability('view', 'GlobalImageAsset')
235
+ website_author.add_capability('upload', 'GlobalImageAsset')
236
+ website_author.add_capability('delete', 'GlobalImageAsset')
237
+
238
+ admin.add_capability('view', 'SiteFileAsset')
239
+ website_author.add_capability('view', 'SiteFileAsset')
240
+ content_author.add_capability('view', 'SiteFileAsset')
241
+
242
+ content_author.add_capability('view', 'GlobalFileAsset')
243
+
244
+ admin.add_capability('view', 'GlobalFileAsset')
245
+ admin.add_capability('upload', 'GlobalFileAsset')
246
+ admin.add_capability('delete', 'GlobalFileAsset')
247
+
248
+ website_author.add_capability('view', 'GlobalFileAsset')
249
+ website_author.add_capability('upload', 'GlobalFileAsset')
250
+ website_author.add_capability('delete', 'GlobalFileAsset')
251
+
252
+ admin.add_capability('drag_item', 'WebsiteTree')
253
+ website_author.add_capability('drag_item', 'WebsiteTree')
254
+
255
+ # update capability descriptions
256
+ Capability.all.each do |c|
257
+ c.update_description
258
+ end
259
+
260
+ drop_table :capable_models
261
+ drop_table :capabilities_capable_models
262
+ drop_table :secured_models
263
+ drop_table :roles_secured_models
264
+ remove_column :capabilities, :resource
265
+ end
266
+ end
267
+
268
+ def self.down
269
+ end
270
+ end