jobshop 0.0.163 → 0.0.167

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +3 -3
  3. data/Rakefile +8 -17
  4. data/app/controllers/jobshop/application_controller.rb +5 -4
  5. data/app/controllers/jobshop/places_controller.rb +0 -4
  6. data/app/controllers/jobshop/users_controller.rb +0 -3
  7. data/app/mailers/jobshop/application_mailer.rb +0 -2
  8. data/app/mailers/jobshop/rfq_responder_mailer.rb +18 -0
  9. data/app/models/jobshop/ability.rb +1 -1
  10. data/app/models/jobshop/customer.rb +30 -0
  11. data/app/models/jobshop/customer/category.rb +19 -0
  12. data/app/models/jobshop/customer/contact.rb +28 -0
  13. data/app/models/jobshop/employee.rb +46 -0
  14. data/app/models/jobshop/employment.rb +25 -0
  15. data/app/models/jobshop/employment_version.rb +10 -0
  16. data/app/models/jobshop/inspection/boolean_criterion.rb +2 -2
  17. data/app/models/jobshop/inspection/deviation_criterion.rb +4 -4
  18. data/app/models/jobshop/inspection/limit_criterion.rb +6 -4
  19. data/app/models/jobshop/inspection/report.rb +2 -0
  20. data/app/models/jobshop/inspection/result.rb +2 -2
  21. data/app/models/jobshop/mailman.rb +22 -0
  22. data/app/models/jobshop/order.rb +2 -6
  23. data/app/models/jobshop/order_line.rb +2 -3
  24. data/app/models/jobshop/organization.rb +15 -6
  25. data/app/models/jobshop/place.rb +2 -0
  26. data/app/models/jobshop/product.rb +0 -3
  27. data/app/models/jobshop/rfq.rb +12 -6
  28. data/app/models/jobshop/user.rb +2 -17
  29. data/app/views/jobshop/rfq_responder_mailer/verified_contact.html.erb +5 -0
  30. data/app/views/jobshop/rfq_responder_mailer/verified_contact.text.erb +3 -0
  31. data/app/views/layouts/jobshop/application.html.haml +15 -0
  32. data/app/views/layouts/jobshop/mailer.html.erb +13 -0
  33. data/config/initializers/devise.rb +290 -0
  34. data/config/locales/devise.en.yml +64 -0
  35. data/config/routes.rb +1 -2
  36. data/db/migrate/20170311194758_initialize_jobshop.rb +42 -2
  37. data/db/migrate/20171216021339_create_organizations.rb +1 -4
  38. data/db/migrate/20171216021400_create_employees.rb +47 -0
  39. data/db/migrate/20171216021554_create_people.rb +13 -18
  40. data/db/migrate/20171216021853_create_customers.rb +57 -0
  41. data/db/migrate/20171216022020_create_places.rb +8 -9
  42. data/db/migrate/20171216022135_create_products.rb +6 -13
  43. data/db/migrate/20171216022605_create_orders.rb +19 -36
  44. data/db/migrate/20171216023018_create_roles.rb +5 -3
  45. data/db/migrate/20171216035357_create_things.rb +4 -4
  46. data/db/migrate/20171219022118_create_routing_processes.rb +15 -15
  47. data/db/migrate/20180107203241_create_inspections.rb +15 -14
  48. data/db/migrate/20181117023949_create_rfqs.rb +27 -19
  49. data/db/migrate/20181118014603_create_mailmen.rb +6 -4
  50. data/db/seeds.rb +126 -0
  51. data/lib/generators/jobshop/app/app_generator.rb +1 -1
  52. data/lib/generators/jobshop/app/templates/Procfile.tt +1 -0
  53. data/lib/generators/jobshop/app/templates/config/database.yml.tt +5 -5
  54. data/lib/generators/jobshop/{dummy/dummy_generator.rb → canary/canary_generator.rb} +13 -14
  55. data/lib/generators/jobshop/{dummy → canary}/templates/config/boot.rb.tt +0 -0
  56. data/lib/jobshop.rb +41 -12
  57. data/lib/jobshop/cli.rb +16 -82
  58. data/lib/jobshop/cli/app_generator.rb +38 -0
  59. data/lib/jobshop/cli/application.rb +14 -0
  60. data/lib/jobshop/cli/canary.rb +52 -0
  61. data/lib/jobshop/configuration.rb +16 -11
  62. data/lib/jobshop/engine.rb +39 -28
  63. data/lib/jobshop/helpers/migration.rb +78 -2
  64. data/lib/jobshop/mailroom/base_handler.rb +33 -0
  65. data/lib/jobshop/mailroom/null_handler.rb +10 -0
  66. data/lib/jobshop/mailroom/postmaster.rb +77 -0
  67. data/lib/jobshop/mailroom/rfq_handler.rb +39 -0
  68. data/lib/jobshop/version.rb +3 -1
  69. data/lib/tasks/jobshop_tasks.rake +7 -6
  70. metadata +98 -69
  71. data/app/controllers/concerns/email_token_validation.rb +0 -59
  72. data/app/controllers/concerns/jobshop/authentication_handler.rb +0 -15
  73. data/app/controllers/concerns/jobshop/authorization_handler.rb +0 -29
  74. data/app/controllers/jobshop/session_activations_controller.rb +0 -13
  75. data/app/controllers/jobshop/sessions_controller.rb +0 -20
  76. data/app/email_handlers/jobshop/rfq_handler.rb +0 -43
  77. data/app/models/jobshop/company.rb +0 -35
  78. data/app/models/jobshop/company/type.rb +0 -17
  79. data/app/models/jobshop/company_person.rb +0 -15
  80. data/app/models/jobshop/person.rb +0 -30
  81. data/app/models/jobshop/session_activation.rb +0 -30
  82. data/app/serializers/jobshop/test_user_serializer.rb +0 -10
  83. data/app/services/jobshop/authentication_service.rb +0 -20
  84. data/app/services/jobshop/authorization_service.rb +0 -30
  85. data/app/services/jobshop/jwt_service.rb +0 -17
  86. data/db/migrate/20171216021853_create_companies.rb +0 -64
  87. data/db/migrate/20171216023022_create_sessions.rb +0 -23
  88. data/lib/jobshop/cli/spinner.rb +0 -21
  89. data/lib/jobshop/dummy_app.rb +0 -190
  90. data/lib/jobshop/postmaster.rb +0 -89
@@ -1,23 +0,0 @@
1
- # frozen_string_literals: true
2
-
3
- require "jobshop/helpers/migration.rb"
4
-
5
- class CreateSessions < ActiveRecord::Migration[5.2]
6
- include Jobshop::Helpers::Migration
7
-
8
- def change
9
- create_table :jobshop_sessions, id: false do |t|
10
- t.uuid :organization_id, null: false
11
- t.uuid :user_id, null: false
12
- t.string :activation_token, null: false, activation_token: { unique: true }
13
- t.index %i[ organization_id user_id activation_token ], unique: true,
14
- name: :idx_jobshop_sessions_pkey
15
- t.timestamps
16
- end
17
-
18
- idx_table_name_pkey :jobshop_sessions
19
- fk_organization_id :jobshop_sessions
20
- foreign_key :jobshop_sessions, :jobshop_users,
21
- %i[ organization_id user_id ]
22
- end
23
- end
@@ -1,21 +0,0 @@
1
- require "tty-spinner"
2
-
3
- module Jobshop
4
- module CLI
5
- module UI
6
- extend self
7
-
8
- def do_with_spinner(name, &block)
9
- title = "[:spinner] #{name.ljust(40, '.')}"
10
- spinner = TTY::Spinner.new(title, format: :dots)
11
- spinner.auto_spin
12
- t1 = Time.now
13
- retval = yield
14
- t2 = Time.now
15
- delta = t2 - t1
16
- spinner.success("done (#{delta}s)")
17
- retval
18
- end
19
- end
20
- end
21
- end
@@ -1,190 +0,0 @@
1
- # frozen_string_literals: true
2
-
3
- require "rails/version"
4
-
5
- require "jobshop/cli"
6
- require "jobshop/cli/spinner"
7
-
8
- module Jobshop
9
- class DummyApp
10
- WIDGET_TYPES = [ "A", "B", "C" ]
11
- WIDGET_SHAPES = [ "triangle", "square", "pentagon", "hexagon", "heptagon" ]
12
- WIDGET_COLLECTION_SCHEMA = {
13
- "properties": {
14
- "shape": {
15
- "title": "Widget Shape",
16
- "description": "The shape of the widget",
17
- "enum": WIDGET_SHAPES
18
- },
19
- "size": {
20
- "title": "Nominal Size",
21
- "description": "Nominal size of new widget",
22
- "type": "number"
23
- }
24
- },
25
- "required": [ "shape", "size" ],
26
- "additionalProperties": false
27
- }
28
-
29
- WIDGET_PACK_POSITIONS = [ "A", "B", "C", "D" ]
30
- WIDGET_PACK_COLLECTION_SCHEMA = {
31
- "properties": {
32
- "widgets": {
33
- "type": "object",
34
- "patternProperties": {
35
- "^[A-Z]$": {
36
- "type": "string",
37
- "format": "uri"
38
- }
39
- },
40
- "additionalProperties": false
41
- }
42
- },
43
- "additionalProperties": false
44
- }
45
-
46
- class << self
47
- include CLI::UI
48
-
49
- def destroy!
50
- FileUtils.rmtree(path)
51
- end
52
-
53
- def exist?
54
- Dir.exist?(path)
55
- end
56
-
57
- def rakefile
58
- File.join(path, "Rakefile")
59
- end
60
-
61
- def path
62
- @path ||= File.expand_path("spec/dummy")
63
- end
64
-
65
- def factory_paths
66
- [ Jobshop::Engine.root.join("spec", "factories") ]
67
- end
68
-
69
- def seed # rubocop:disable Metrics/MethodLength
70
- with_dummy_app do
71
- do_with_spinner("Loading factories") do
72
- require "factory_bot_rails"
73
- FactoryBot.definition_file_paths = factory_paths
74
- FactoryBot.find_definitions if Rails.env.development?
75
- end
76
-
77
- do_with_spinner("Cleaning database") do
78
- clean_database
79
- end
80
-
81
- @org = do_with_spinner("Creating test Organization") do
82
- FactoryBot.create(:organization)
83
- end
84
-
85
- @ceo = do_with_spinner("Creating test Person") do
86
- FactoryBot.create(:person, :ceo, organization: @org)
87
- end
88
-
89
- @places = do_with_spinner("Creating test Places") do
90
- FactoryBot.create_list(:place, 10, organization: @org)
91
- end
92
-
93
- @companies = do_with_spinner("Creating test companies") do
94
- FactoryBot.create_list(:company, 10, organization: @org,
95
- created_by: @ceo)
96
- end
97
-
98
- @products = do_with_spinner("Creating test Products") do
99
- FactoryBot.create_list(:product, 10,
100
- organization: @org,
101
- created_by: @ceo)
102
- end
103
-
104
- do_with_spinner("Creating test Routers for Products") do
105
- @products.each do |product|
106
- rp = FactoryBot.create(:routing_process, organization: @org,
107
- product: product)
108
- FactoryBot.create_list(:routing_step, rand(1..4),organization: @org,
109
- routing_process: rp)
110
- end
111
- end
112
-
113
- do_with_spinner("Creating sample Orders") do
114
- 50.times do
115
- ord = FactoryBot.create(:order, organization: @org,
116
- company: @companies.sample,
117
- created_by: @ceo)
118
- FactoryBot.create_list(:order_line, rand(1..4), organization: @org,
119
- order: ord,
120
- product: @products.sample,
121
- created_by: @ceo)
122
- end
123
- end
124
-
125
- @widgets = do_with_spinner("Creating Collection of widgets") do
126
- wc = FactoryBot.create(:widget_collection,
127
- organization: @org)
128
- FactoryBot.create_list(:widget_thing, 50, organization: @org,
129
- collection: wc)
130
- end
131
-
132
- @widget_packs = do_with_spinner("Creating Collection of widget packs") do
133
- wpc = FactoryBot.create(:widget_pack_collection,
134
- organization: @org)
135
- FactoryBot.create_list(:widget_pack_thing, 50, organization: @org,
136
- collection: wpc,
137
- widgets: @widgets)
138
- end
139
-
140
- do_with_spinner("Creating Inspection Reports") do
141
- 5.times do
142
- report = FactoryBot.create(:inspection_report, organization: @org)
143
- 5.times do |index|
144
- FactoryBot.create(Jobshop::Inspection::CRITERION_TYPES.sample,
145
- organization: @org, report: report,
146
- position: (index + 1))
147
- end
148
- 5.times do |index|
149
- tuple = FactoryBot.create(:inspection_tuple, organization: @org,
150
- report: report, position: (index + 1))
151
- report.criteria.each do |criterion|
152
- FactoryBot.create(:inspection_result, organization: @org,
153
- report: report, criterion: criterion,
154
- tuple: tuple)
155
- end
156
- end
157
- end
158
- end
159
-
160
- do_with_spinner("Creating RFQ Mailman") do
161
- @org.mailmen.create!(address: "rfq@jobshop.io", handler_type: "Jobshop::RFQHandler")
162
- end
163
-
164
- do_with_spinner("Creating sample RFQs") do
165
- 50.times do
166
- FactoryBot.create(:rfq, organization: @org,
167
- company: @companies.sample)
168
- end
169
- end
170
- end
171
- end
172
-
173
- private def with_dummy_app(*)
174
- begin
175
- require "#{Jobshop::DummyApp.path}/config/environment"
176
- rescue LoadError
177
- abort "Dummy app does not exist. Run `jobshop dummy` to create it."
178
- end
179
-
180
- yield
181
- end
182
-
183
- private def clean_database
184
- require "database_cleaner"
185
- DatabaseCleaner.strategy = :truncation
186
- DatabaseCleaner.clean
187
- end
188
- end
189
- end
190
- end
@@ -1,89 +0,0 @@
1
- # frozen_string_literals: true
2
-
3
- require "aws-sdk-s3"
4
- require "mail"
5
- require "shoryuken"
6
-
7
- module Jobshop
8
- # Jobshop::Postmaster
9
- #
10
- # Reponsible for processing incoming email and dispatching it to its handler.
11
- class Postmaster
12
- include Shoryuken::Worker
13
-
14
- shoryuken_options queue: Jobshop.configuration.aws.incoming_email_queue
15
-
16
- def perform(sqs_msg, *)
17
- @event = S3EventMessage.new(sqs_msg.body) || return
18
- tempfile = Tempfile.new
19
-
20
- s3.get_object({ bucket: @event.bucket, key: @event.key }, target: tempfile)
21
-
22
- message = Mail.new(File.read(tempfile))
23
- recipient = Mail::Address.new(message.to.first)
24
- mailbox = recipient.local.split("+").first
25
- handler_address = "#{mailbox}@#{recipient.domain}"
26
- mailman = Mailman.find_by(address: handler_address)
27
-
28
- # TODO: If no mailman registered, look for domain. If no domain found
29
- # TODO: treat as spam.
30
- if mailman
31
- klass = mailman.handler_type.constantize
32
- handler = klass.new(message, organization: mailman.organization)
33
- success = handler.process
34
- if success
35
- copy_to(handler.processed_copy_prefix) if handler.copy_after_processing?
36
- delete_incoming if handler.delete_after_processing?
37
- sqs_msg.delete
38
- end
39
- else
40
- return
41
- end
42
-
43
- ensure
44
- @event = nil
45
- tempfile.close
46
- tempfile.unlink
47
- end
48
-
49
- def s3
50
- @s3 ||= Aws::S3::Client.new
51
- end
52
-
53
- def copy_to(prefix)
54
- key = prefix + "/" + @event.key.split("/").last
55
-
56
- s3.copy_object({
57
- copy_source: @event.bucket + "/" + @event.key,
58
- bucket: Jobshop.configuration.aws.s3_bucket,
59
- key: key
60
- }) || raise("Could not copy incoming rfq to processed folder")
61
- end
62
-
63
- def delete_incoming
64
- s3.delete_object({
65
- bucket: @event.bucket, key: @event.key
66
- }) || raise("Could not delete incoming email")
67
- end
68
-
69
- class S3EventMessage
70
- def initialize(message)
71
- @message = JSON.parse(message)
72
-
73
- return false unless records
74
- end
75
-
76
- def records
77
- @records ||= @message["Records"] || []
78
- end
79
-
80
- def bucket
81
- records.first.dig "s3", "bucket", "name"
82
- end
83
-
84
- def key
85
- records.first.dig "s3", "object", "key"
86
- end
87
- end
88
- end
89
- end