erp_tech_svcs 4.0.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
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,147 +0,0 @@
1
- module ErpTechSvcs
2
- module Extensions
3
- module ActiveRecord
4
- module HasUserDefinedData
5
-
6
- module Errors
7
- class UserDefinedFieldAlreadyExists < StandardError
8
- def to_s
9
- "User defined field already exists."
10
- end
11
- end
12
-
13
- class UserDefinedFieldDoesNotExist < StandardError
14
- def to_s
15
- "User defined field does not exist."
16
- end
17
- end
18
-
19
- class UserDefinedDataDoesNotExist < StandardError
20
- def to_s
21
- "User defined data does not exist."
22
- end
23
- end
24
- end
25
-
26
- def self.included(base)
27
- base.extend(ClassMethods)
28
- end
29
-
30
- module ClassMethods
31
-
32
- def has_user_defined_data
33
- extend HasUserDefinedData::SingletonMethods
34
- include HasUserDefinedData::InstanceMethods
35
- end
36
-
37
- end
38
-
39
- module SingletonMethods
40
-
41
- def remove_all_user_defined_data
42
- UserDefinedData.destroy_all("model_name = #{self.name}")
43
- end
44
-
45
- alias remove_user_fields remove_all_user_defined_data
46
-
47
- def user_defined_fields(scope=nil)
48
- user_defined_data = if scope
49
- # return array and remove nil if none with specified scope
50
- [UserDefinedData.where('scope = ? and model_name = ?', scope, self.name).first].compact
51
- else
52
- UserDefinedData.where('model_name = ?', self.name).all
53
- end
54
-
55
- if user_defined_data.empty?
56
- []
57
- else
58
- user_defined_data.collect(&:user_defined_fields).flatten
59
- end
60
-
61
- end
62
-
63
- alias user_fields user_defined_fields
64
-
65
- def user_defined_field(field_name, scope=nil)
66
- UserDefinedField.joins(:user_defined_data)
67
- .where('model_name = ?', self.name)
68
- .where('scope = ?', scope)
69
- .where('field_name = ?', field_name).first
70
- end
71
-
72
- alias user_field user_defined_field
73
-
74
- def add_user_defined_field(field_name, label, data_type, scope=nil)
75
- current_user_field = self.user_field(field_name, scope)
76
-
77
- if current_user_field
78
- raise Error::UserDefinedFieldAlreadyExists
79
- else
80
- user_defined_field = UserDefinedField.new(field_name: field_name, label: label, data_type: data_type)
81
-
82
- user_defined_data = if scope
83
- # return array and remove nil if none with specified scope
84
- UserDefinedData.where('scope = ? and model_name = ?', scope, self.name).first
85
- else
86
- UserDefinedData.where('scope = ? and model_name = ?', nil, self.name)
87
- end
88
-
89
- user_defined_data = UserDefinedData.new(scope: scope, model_name: self.name) unless user_defined_data
90
-
91
- user_defined_data.user_defined_fields << user_defined_field
92
- user_defined_data.save
93
-
94
- user_defined_field
95
- end
96
-
97
- end
98
-
99
- alias add_user_field add_user_defined_field
100
-
101
- def update_user_defined_field(field_name, label, scope=nil)
102
- current_user_field = self.user_field(field_name, scope)
103
-
104
- if current_user_field
105
- current_user_field.label = label
106
- current_user_field.save
107
- else
108
- raise Errors::UserDefinedFieldDoesNotExist
109
- end
110
- end
111
-
112
- alias update_user_field update_user_defined_field
113
-
114
- def remove_user_defined_field(field_name, scope=nil)
115
- user_defined_data = if scope
116
- # return array and remove nil if none with specified scope
117
- UserDefinedData.where('scope = ? and model_name = ?', scope, self.name).first
118
- else
119
- UserDefinedData.where('scope = ? and model_name = ?', nil, self.name)
120
- end
121
-
122
- if user_defined_data
123
- user_defined_field = user_defined_data.user_defined_fields.where('field_name = ?', field_name)
124
-
125
- if user_defined_field
126
- user_defined_field.destroy
127
- else
128
- raise Errors::UserDefinedFieldDoesNotExist
129
- end
130
- else
131
- raise Errors::UserDefinedDataDoesNotExist
132
- end
133
- end
134
-
135
- alias remove_user_field remove_user_defined_field
136
-
137
- end
138
-
139
- module InstanceMethods
140
-
141
- end
142
-
143
- end #HasUserDefinedData
144
- end #ActiveRecord
145
- end #Extensions
146
- end #ErpTechSvcs
147
-
@@ -1,47 +0,0 @@
1
- require "benchmark"
2
-
3
- module ErpTechSvcs
4
- module Sessions
5
- # Delayed Job to Reset Daily Assignments to Forecast
6
- class DeleteExpiredSessionsJob
7
-
8
- def initialize
9
- @priority = 1
10
- end
11
-
12
- def perform
13
- time = Benchmark.measure do
14
- begin
15
- process_job
16
- rescue => exception
17
- ErpTechSvcs::Util::CompassLogger.delete_expired_sessions_job.error("An unrecoverable error has occured, the job will be rescheduled: #{exception.message} : #{exception.backtrace}")
18
- end
19
- end #benchmark
20
-
21
- # Run once per day
22
- date = Date.tomorrow
23
- start_time = DateTime.civil(date.year, date.month, date.day, 2, 0, 1, -(5.0/24.0))
24
-
25
- Delayed::Job.enqueue(DeleteExpiredSessionsJob.new(), @priority, start_time)
26
-
27
- #update job tracker
28
- JobTracker.job_ran('Delete Expired Sessions', self.class.name, ("(%.4fs)" % time.real), start_time)
29
- end
30
-
31
- def self.schedule_job(schedule_dt)
32
- Delayed::Job.enqueue(DeleteExpiredSessionsJob.new(), @priority, schedule_dt)
33
- end
34
-
35
- def process_job
36
- start_time = Time.now
37
-
38
- ErpTechSvcs::Sessions::DeleteExpiredSessionsService.new.execute
39
-
40
- end_time = Time.now
41
-
42
- return end_time - start_time
43
- end
44
-
45
- end #Close DeleteExpiredSessionsJob
46
- end #Close Sessions
47
- end #Close ErpTechSvcs
@@ -1,15 +0,0 @@
1
- module ErpTechSvcs
2
- module Sessions
3
- class DeleteExpiredSessionsService
4
-
5
- def initialize
6
- @session_age = ErpTechSvcs::Config.session_expires_in_hours.hours
7
- end
8
-
9
- def execute
10
- ActiveRecord::SessionStore::Session.delete_all ['updated_at < ?', @session_age.ago]
11
- end
12
-
13
- end
14
- end
15
- end
@@ -1,87 +0,0 @@
1
- require 'logger'
2
- module ErpTechSvcs
3
- module Util
4
- class CompassLogger
5
- include Singleton
6
-
7
- @@writers = {}
8
-
9
- def CompassLogger.debug(msg)
10
- if defined?(logger)
11
- logger.debug(msg)
12
- else
13
- CompassLogger.app_logger()
14
- @@writers["app_logger"].debug(msg)
15
- end
16
- end
17
-
18
- def CompassLogger.info(msg)
19
- if defined?(logger)
20
- logger.info(msg)
21
- else
22
- CompassLogger.app_logger()
23
- @@writers["app_logger"].info(msg)
24
- end
25
- end
26
-
27
- def CompassLogger.warn(msg)
28
- if defined?(logger)
29
- logger.warn(msg)
30
- else
31
- CompassLogger.app_logger()
32
- @@writers["app_logger"].warn(msg)
33
- end
34
- end
35
-
36
- def CompassLogger.error(msg)
37
- if defined?(logger)
38
- logger.error(msg)
39
- else
40
- CompassLogger.app_logger()
41
- @@writers["app_logger"].error(msg)
42
- end
43
- end
44
-
45
- def CompassLogger.fatal(msg)
46
- if defined?(logger)
47
- logger.fatal(msg)
48
- else
49
- CompassLogger.app_logger()
50
- @@writers["app_logger"].fatal(msg)
51
- end
52
- end
53
-
54
- def CompassLogger.stdout(msg)
55
- if CompassLogger.log_level() == 0
56
- puts msg
57
- end
58
- end
59
-
60
- def CompassLogger.method_missing(method, *args, &block)
61
- unless @@writers.has_key?(method)
62
- logger = Logger.new(CompassLogger.log_path(method))
63
- logger.level = CompassLogger.log_level()
64
- @@writers[method] = logger
65
- end
66
- @@writers[method]
67
- end
68
-
69
- def CompassLogger.app_logger()
70
- path = File.join(ErpTechSvcs::Config.compass_logger_path, "#{Rails.env rescue 'rake'}.log")
71
- unless @@writers.has_key?("app_logger")
72
- logger = Logger.new(path)
73
- logger.level = CompassLogger.log_level()
74
- @@writers["app_logger"] = logger
75
- end
76
- end
77
-
78
- def CompassLogger.log_level()
79
- ActiveRecord::Base.logger.level rescue Logger::DEBUG
80
- end
81
-
82
- def CompassLogger.log_path(method)
83
- File.join(ErpTechSvcs::Config.compass_logger_path, "#{Rails.env rescue ''}_#{method}.log")
84
- end
85
- end
86
- end
87
- end