mobile_workflow_cli 0.1.4 → 0.1.6
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +55 -55
- data/README.md +8 -5
- data/bin/mwf +6 -1
- data/bin/mwf-delete +6 -1
- data/lib/mobile_workflow_cli/app_builder.rb +3 -21
- data/lib/mobile_workflow_cli/app_generator.rb +8 -45
- data/lib/mobile_workflow_cli/dokku_backend.rb +2 -0
- data/lib/mobile_workflow_cli/version.rb +1 -1
- data/templates/Gemfile.erb +3 -0
- metadata +2 -9
- data/templates/api_controller.rb +0 -32
- data/templates/application_controller.rb +0 -2
- data/templates/controller.rb +0 -39
- data/templates/controller_generator.rb +0 -18
- data/templates/controller_spec.rb +0 -41
- data/templates/model.rb +0 -56
- data/templates/notifications_controller.rb +0 -93
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4981fe507e2bcc740e26bfc7667f0c2a308605f20ea39113fcc7694716049258
|
4
|
+
data.tar.gz: 73166990d43c3245b37f006b444df724f53f6348ae1b4912a64f39f0126bd663
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25cc9ff4a539f6a4b15ca285c989265c433bb8ea31485c7f34d29eaae1aaf6ba0eb3a6025ee3483d0b4cda377a7c99b42289bc984aef0f8c96b22f8ecaf5234f
|
7
|
+
data.tar.gz: 02512a878c496d452fcc922aae23c0db0466619a2eaafe1b620073bf1f52c4e538f6b50971088a7f24122fbb79bc54ca5d48e7e4c54307e49bce091a25a12f41
|
data/Gemfile.lock
CHANGED
@@ -1,63 +1,63 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mobile_workflow_cli (0.1.
|
4
|
+
mobile_workflow_cli (0.1.6)
|
5
5
|
administrate
|
6
6
|
rails (>= 6.0.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actioncable (6.0.3.
|
12
|
-
actionpack (= 6.0.3.
|
11
|
+
actioncable (6.0.3.2)
|
12
|
+
actionpack (= 6.0.3.2)
|
13
13
|
nio4r (~> 2.0)
|
14
14
|
websocket-driver (>= 0.6.1)
|
15
|
-
actionmailbox (6.0.3.
|
16
|
-
actionpack (= 6.0.3.
|
17
|
-
activejob (= 6.0.3.
|
18
|
-
activerecord (= 6.0.3.
|
19
|
-
activestorage (= 6.0.3.
|
20
|
-
activesupport (= 6.0.3.
|
15
|
+
actionmailbox (6.0.3.2)
|
16
|
+
actionpack (= 6.0.3.2)
|
17
|
+
activejob (= 6.0.3.2)
|
18
|
+
activerecord (= 6.0.3.2)
|
19
|
+
activestorage (= 6.0.3.2)
|
20
|
+
activesupport (= 6.0.3.2)
|
21
21
|
mail (>= 2.7.1)
|
22
|
-
actionmailer (6.0.3.
|
23
|
-
actionpack (= 6.0.3.
|
24
|
-
actionview (= 6.0.3.
|
25
|
-
activejob (= 6.0.3.
|
22
|
+
actionmailer (6.0.3.2)
|
23
|
+
actionpack (= 6.0.3.2)
|
24
|
+
actionview (= 6.0.3.2)
|
25
|
+
activejob (= 6.0.3.2)
|
26
26
|
mail (~> 2.5, >= 2.5.4)
|
27
27
|
rails-dom-testing (~> 2.0)
|
28
|
-
actionpack (6.0.3.
|
29
|
-
actionview (= 6.0.3.
|
30
|
-
activesupport (= 6.0.3.
|
28
|
+
actionpack (6.0.3.2)
|
29
|
+
actionview (= 6.0.3.2)
|
30
|
+
activesupport (= 6.0.3.2)
|
31
31
|
rack (~> 2.0, >= 2.0.8)
|
32
32
|
rack-test (>= 0.6.3)
|
33
33
|
rails-dom-testing (~> 2.0)
|
34
34
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
35
|
-
actiontext (6.0.3.
|
36
|
-
actionpack (= 6.0.3.
|
37
|
-
activerecord (= 6.0.3.
|
38
|
-
activestorage (= 6.0.3.
|
39
|
-
activesupport (= 6.0.3.
|
35
|
+
actiontext (6.0.3.2)
|
36
|
+
actionpack (= 6.0.3.2)
|
37
|
+
activerecord (= 6.0.3.2)
|
38
|
+
activestorage (= 6.0.3.2)
|
39
|
+
activesupport (= 6.0.3.2)
|
40
40
|
nokogiri (>= 1.8.5)
|
41
|
-
actionview (6.0.3.
|
42
|
-
activesupport (= 6.0.3.
|
41
|
+
actionview (6.0.3.2)
|
42
|
+
activesupport (= 6.0.3.2)
|
43
43
|
builder (~> 3.1)
|
44
44
|
erubi (~> 1.4)
|
45
45
|
rails-dom-testing (~> 2.0)
|
46
46
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
47
|
-
activejob (6.0.3.
|
48
|
-
activesupport (= 6.0.3.
|
47
|
+
activejob (6.0.3.2)
|
48
|
+
activesupport (= 6.0.3.2)
|
49
49
|
globalid (>= 0.3.6)
|
50
|
-
activemodel (6.0.3.
|
51
|
-
activesupport (= 6.0.3.
|
52
|
-
activerecord (6.0.3.
|
53
|
-
activemodel (= 6.0.3.
|
54
|
-
activesupport (= 6.0.3.
|
55
|
-
activestorage (6.0.3.
|
56
|
-
actionpack (= 6.0.3.
|
57
|
-
activejob (= 6.0.3.
|
58
|
-
activerecord (= 6.0.3.
|
50
|
+
activemodel (6.0.3.2)
|
51
|
+
activesupport (= 6.0.3.2)
|
52
|
+
activerecord (6.0.3.2)
|
53
|
+
activemodel (= 6.0.3.2)
|
54
|
+
activesupport (= 6.0.3.2)
|
55
|
+
activestorage (6.0.3.2)
|
56
|
+
actionpack (= 6.0.3.2)
|
57
|
+
activejob (= 6.0.3.2)
|
58
|
+
activerecord (= 6.0.3.2)
|
59
59
|
marcel (~> 0.3.1)
|
60
|
-
activesupport (6.0.3.
|
60
|
+
activesupport (6.0.3.2)
|
61
61
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
62
62
|
i18n (>= 0.7, < 2)
|
63
63
|
minitest (~> 5.1)
|
@@ -74,7 +74,7 @@ GEM
|
|
74
74
|
momentjs-rails (~> 2.8)
|
75
75
|
sassc-rails (~> 2.1)
|
76
76
|
selectize-rails (~> 0.6)
|
77
|
-
autoprefixer-rails (9.
|
77
|
+
autoprefixer-rails (9.8.4)
|
78
78
|
execjs
|
79
79
|
builder (3.2.4)
|
80
80
|
byebug (11.1.3)
|
@@ -106,7 +106,7 @@ GEM
|
|
106
106
|
activerecord
|
107
107
|
kaminari-core (= 1.2.1)
|
108
108
|
kaminari-core (1.2.1)
|
109
|
-
loofah (2.
|
109
|
+
loofah (2.6.0)
|
110
110
|
crass (~> 1.0.2)
|
111
111
|
nokogiri (>= 1.5.9)
|
112
112
|
mail (2.7.1)
|
@@ -123,32 +123,32 @@ GEM
|
|
123
123
|
nio4r (2.5.2)
|
124
124
|
nokogiri (1.10.9)
|
125
125
|
mini_portile2 (~> 2.4.0)
|
126
|
-
rack (2.2.
|
126
|
+
rack (2.2.3)
|
127
127
|
rack-test (1.1.0)
|
128
128
|
rack (>= 1.0, < 3)
|
129
|
-
rails (6.0.3.
|
130
|
-
actioncable (= 6.0.3.
|
131
|
-
actionmailbox (= 6.0.3.
|
132
|
-
actionmailer (= 6.0.3.
|
133
|
-
actionpack (= 6.0.3.
|
134
|
-
actiontext (= 6.0.3.
|
135
|
-
actionview (= 6.0.3.
|
136
|
-
activejob (= 6.0.3.
|
137
|
-
activemodel (= 6.0.3.
|
138
|
-
activerecord (= 6.0.3.
|
139
|
-
activestorage (= 6.0.3.
|
140
|
-
activesupport (= 6.0.3.
|
129
|
+
rails (6.0.3.2)
|
130
|
+
actioncable (= 6.0.3.2)
|
131
|
+
actionmailbox (= 6.0.3.2)
|
132
|
+
actionmailer (= 6.0.3.2)
|
133
|
+
actionpack (= 6.0.3.2)
|
134
|
+
actiontext (= 6.0.3.2)
|
135
|
+
actionview (= 6.0.3.2)
|
136
|
+
activejob (= 6.0.3.2)
|
137
|
+
activemodel (= 6.0.3.2)
|
138
|
+
activerecord (= 6.0.3.2)
|
139
|
+
activestorage (= 6.0.3.2)
|
140
|
+
activesupport (= 6.0.3.2)
|
141
141
|
bundler (>= 1.3.0)
|
142
|
-
railties (= 6.0.3.
|
142
|
+
railties (= 6.0.3.2)
|
143
143
|
sprockets-rails (>= 2.0.0)
|
144
144
|
rails-dom-testing (2.0.3)
|
145
145
|
activesupport (>= 4.2.0)
|
146
146
|
nokogiri (>= 1.6)
|
147
147
|
rails-html-sanitizer (1.3.0)
|
148
148
|
loofah (~> 2.3)
|
149
|
-
railties (6.0.3.
|
150
|
-
actionpack (= 6.0.3.
|
151
|
-
activesupport (= 6.0.3.
|
149
|
+
railties (6.0.3.2)
|
150
|
+
actionpack (= 6.0.3.2)
|
151
|
+
activesupport (= 6.0.3.2)
|
152
152
|
method_source
|
153
153
|
rake (>= 0.8.7)
|
154
154
|
thor (>= 0.20.3, < 2.0)
|
@@ -190,7 +190,7 @@ GEM
|
|
190
190
|
websocket-driver (0.7.2)
|
191
191
|
websocket-extensions (>= 0.1.0)
|
192
192
|
websocket-extensions (0.1.5)
|
193
|
-
zeitwerk (2.3.
|
193
|
+
zeitwerk (2.3.1)
|
194
194
|
|
195
195
|
PLATFORMS
|
196
196
|
ruby
|
data/README.md
CHANGED
@@ -6,18 +6,21 @@ The server contains
|
|
6
6
|
* API
|
7
7
|
* Password protected admin console (for updating the data)
|
8
8
|
|
9
|
+
## Prereqs
|
10
|
+
|
11
|
+
Install RubyVersionManager (RVM) with latest stable Ruby and Rails
|
12
|
+
|
13
|
+
`\curl -sSL https://get.rvm.io | bash -s stable --rails`
|
14
|
+
|
9
15
|
## Installation
|
10
16
|
|
11
17
|
Install the utility
|
12
18
|
|
13
|
-
|
14
|
-
gem 'mobile_workflow_cli'
|
15
|
-
```
|
19
|
+
`gem 'mobile_workflow_cli'`
|
16
20
|
|
17
21
|
## Usage
|
18
22
|
|
19
|
-
|
20
|
-
|
23
|
+
`mwf --help`
|
21
24
|
|
22
25
|
## License
|
23
26
|
|
data/bin/mwf
CHANGED
data/bin/mwf-delete
CHANGED
@@ -17,37 +17,19 @@ module MobileWorkflowCli
|
|
17
17
|
generate 'rspec:install'
|
18
18
|
end
|
19
19
|
|
20
|
-
def controller_generator
|
21
|
-
copy_file 'controller_generator.rb', 'lib/generators/mobile_workflow/controller_generator.rb'
|
22
|
-
copy_file 'controller.rb', 'lib/generators/mobile_workflow/templates/controller.rb'
|
23
|
-
copy_file 'controller_spec.rb', 'lib/generators/mobile_workflow/templates/controller_spec.rb'
|
24
|
-
end
|
25
|
-
|
26
20
|
def ability_generator
|
27
21
|
copy_file 'ability.rb', 'app/models/ability.rb'
|
28
22
|
end
|
29
23
|
|
30
|
-
def application_controller
|
31
|
-
copy_file 'application_controller.rb', 'app/controllers/application_controller.rb'
|
32
|
-
end
|
33
|
-
|
34
|
-
def api_controller
|
35
|
-
copy_file 'api_controller.rb', 'app/controllers/api_controller.rb'
|
36
|
-
end
|
37
|
-
|
38
|
-
def model_template
|
39
|
-
copy_file 'model.rb', 'lib/templates/active_record/model/model.rb'
|
40
|
-
end
|
41
|
-
|
42
24
|
def active_storage
|
43
25
|
rails_command 'active_storage:install'
|
44
26
|
copy_file 'storage.s3.yml', 'config/storage.yml'
|
45
27
|
gsub_file 'config/environments/production.rb', 'config.active_storage.service = :local', 'config.active_storage.service = :amazon'
|
46
28
|
end
|
47
29
|
|
48
|
-
def
|
49
|
-
copy_file
|
50
|
-
|
30
|
+
def mobile_workflow_generator(open_api_spec_path)
|
31
|
+
copy_file open_api_spec_path, 'config/open_api_spec.json'
|
32
|
+
generate 'mobile_workflow:install'
|
51
33
|
end
|
52
34
|
|
53
35
|
def s3_backend(region)
|
@@ -25,30 +25,18 @@ module MobileWorkflowCli
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def finish_template
|
28
|
-
run "spring stop"
|
29
|
-
|
30
28
|
super
|
31
29
|
after_bundle do
|
32
|
-
|
33
|
-
build :api_controller
|
34
|
-
build :notifications_controller if options[:s3_storage]
|
35
|
-
build :model_template
|
30
|
+
run "spring stop"
|
36
31
|
build :procfiles
|
37
32
|
build :rspec_generator
|
38
|
-
build :controller_generator
|
39
33
|
build :ability_generator
|
40
34
|
build :active_storage if options[:s3_storage]
|
41
|
-
|
42
|
-
open_api_spec = read_openapi_spec
|
43
|
-
generate_models(open_api_spec)
|
35
|
+
build :mobile_workflow_generator, ARGV[1]
|
44
36
|
setup_db
|
45
|
-
|
46
37
|
generate_administrate
|
47
|
-
generate_controllers_and_routes(open_api_spec)
|
48
38
|
|
49
|
-
|
50
|
-
admin_password = SecureRandom.base64(12)
|
51
|
-
generate_dot_env(admin_user, admin_password)
|
39
|
+
generate_dot_env
|
52
40
|
initial_git_commit
|
53
41
|
|
54
42
|
build :heroku if options[:heroku]
|
@@ -66,12 +54,6 @@ module MobileWorkflowCli
|
|
66
54
|
# Todo: MBS - move these methods to the builder class
|
67
55
|
# Ideally override RailsBuilder methods
|
68
56
|
private
|
69
|
-
def read_openapi_spec
|
70
|
-
openapi_spec_path = ARGV[1]
|
71
|
-
say "Loading model from OpenAPI Spec: #{openapi_spec_path}"
|
72
|
-
return JSON.parse(File.read(openapi_spec_path)).with_indifferent_access
|
73
|
-
end
|
74
|
-
|
75
57
|
def generate_administrate
|
76
58
|
generate 'administrate:install'
|
77
59
|
file 'app/assets/config/manifest.js', <<-CODE
|
@@ -90,29 +72,7 @@ module Admin
|
|
90
72
|
end
|
91
73
|
end
|
92
74
|
CODE
|
93
|
-
|
94
|
-
|
95
|
-
def generate_models(openapi_spec)
|
96
|
-
say "Generating models"
|
97
|
-
openapi_spec[:components][:schemas].each_pair do |name, schema|
|
98
|
-
next if ["answer", "attachment"].include? name # Don't generate schemas for MW schemas
|
99
|
-
|
100
|
-
generated_properties_args = schema["properties"].keys.collect{|key| "#{key}:string" }.join(" ")
|
101
|
-
if yes? "Use generated schema #{name}(#{generated_properties_args})[yn]?"
|
102
|
-
generate(:model, "#{name.underscore} #{generated_properties_args}")
|
103
|
-
else
|
104
|
-
properties_args = ask "Specify schema for #{name}: (e.g. text:string image:attachment region:reference)"
|
105
|
-
generate(:model, "#{name.underscore} #{properties_args}")
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def generate_controllers_and_routes(openapi_spec)
|
111
|
-
say "Generating controllers"
|
112
|
-
controller_names = openapi_spec[:paths].keys.collect{|url_path| url_path.split('/').last.pluralize }
|
113
|
-
controller_names.each {|n| generate "mobile_workflow:controller #{n.singularize}" }
|
114
|
-
controller_names.each {|n| route "resources :#{n}, only: [:index, :show, :create]" }
|
115
|
-
route "root to: 'admin/#{controller_names.first}#index'"
|
75
|
+
generate 'administrate:routes'
|
116
76
|
end
|
117
77
|
|
118
78
|
def setup_db
|
@@ -126,7 +86,10 @@ CODE
|
|
126
86
|
git commit: %Q{ -m 'Initial commit' }
|
127
87
|
end
|
128
88
|
|
129
|
-
def generate_dot_env
|
89
|
+
def generate_dot_env
|
90
|
+
admin_user = 'admin'
|
91
|
+
admin_password = SecureRandom.base64(12)
|
92
|
+
|
130
93
|
file '.env', <<-CODE
|
131
94
|
ADMIN_USER=#{admin_user}
|
132
95
|
ADMIN_PASSWORD=#{admin_password}
|
@@ -8,6 +8,8 @@ class DokkuBackend
|
|
8
8
|
remote_command "dokku apps:create #{@dokku_app_name}"
|
9
9
|
remote_command "dokku postgres:create #{@dokku_app_name}"
|
10
10
|
remote_command "dokku postgres:link #{@dokku_app_name} #{@dokku_app_name}"
|
11
|
+
remote_command "dokku domains:enable #{@dokku_app_name}"
|
12
|
+
remote_command "dokku letsencrypt #{@dokku_app_name}"
|
11
13
|
|
12
14
|
local_command "git remote add dokku dokku@#{@dokku_host}:#{@dokku_app_name}"
|
13
15
|
end
|
data/templates/Gemfile.erb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobile_workflow_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Brooke-Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: administrate
|
@@ -89,13 +89,6 @@ files:
|
|
89
89
|
- templates/Procfile.dev
|
90
90
|
- templates/README.md.erb
|
91
91
|
- templates/ability.rb
|
92
|
-
- templates/api_controller.rb
|
93
|
-
- templates/application_controller.rb
|
94
|
-
- templates/controller.rb
|
95
|
-
- templates/controller_generator.rb
|
96
|
-
- templates/controller_spec.rb
|
97
|
-
- templates/model.rb
|
98
|
-
- templates/notifications_controller.rb
|
99
92
|
- templates/storage.s3.yml
|
100
93
|
homepage: https://github.com/FutureWorkshops/MobileWorkflowCli
|
101
94
|
licenses:
|
data/templates/api_controller.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
class ApiController < ActionController::API
|
2
|
-
def current_user
|
3
|
-
nil
|
4
|
-
end
|
5
|
-
|
6
|
-
def binary_urls(object)
|
7
|
-
return unless params["binaries"]
|
8
|
-
|
9
|
-
params["binaries"].collect do |binary|
|
10
|
-
property = binary["identifier"].split('/')[0] # i.e. image/jpg --> image, video/mp4 --> video
|
11
|
-
|
12
|
-
{
|
13
|
-
"identifier" => binary["identifier"],
|
14
|
-
"url" => presigned_url("#{object.class.name.underscore}/#{object.id}/#{property}"),
|
15
|
-
"method" => "PUT"
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
def presigned_url(key)
|
22
|
-
presigner.presigned_url(:put_object, bucket: ENV['AWS_BUCKET_NAME'], key: key, metadata: {})
|
23
|
-
end
|
24
|
-
|
25
|
-
def presigner
|
26
|
-
Aws::S3::Presigner.new(client: s3_client)
|
27
|
-
end
|
28
|
-
|
29
|
-
def s3_client
|
30
|
-
Aws::S3::Client.new(region: ENV['AWS_REGION'], access_key_id: ENV['AWS_ACCESS_ID'], secret_access_key: ENV['AWS_SECRET_KEY'])
|
31
|
-
end
|
32
|
-
end
|
data/templates/controller.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
class <%= controller_class_name %>Controller < ApiController
|
2
|
-
before_action :rewrite_payload, only: :create
|
3
|
-
|
4
|
-
load_and_authorize_resource
|
5
|
-
|
6
|
-
def index
|
7
|
-
render json: @<%= controller_class_name.underscore %>.collect(&:list_item_as_json)
|
8
|
-
end
|
9
|
-
|
10
|
-
def show
|
11
|
-
render json: @<%= controller_class_name.singularize.underscore %>.display_as_json
|
12
|
-
end
|
13
|
-
|
14
|
-
def create
|
15
|
-
if @<%= controller_class_name.singularize.underscore %>.save
|
16
|
-
render json: { binary_urls: binary_urls(@<%= controller_class_name.singularize.underscore %>), response: @<%= controller_class_name.singularize.underscore %> }, status: :created
|
17
|
-
else
|
18
|
-
head :unprocessable_entity
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
def rewrite_payload
|
24
|
-
Rails.logger.debug "Pre-rewrite params: #{params}"
|
25
|
-
|
26
|
-
# Use this method to make any changes to parameters
|
27
|
-
|
28
|
-
# Example to get properties from question
|
29
|
-
# params[:payload][:name] = params.dig(:payload, :name, :answer)
|
30
|
-
|
31
|
-
# Example to get properties from previous list
|
32
|
-
# passport_id = params.dig(:payload, :choose_passport, :selected, :id)
|
33
|
-
end
|
34
|
-
|
35
|
-
def <%= controller_class_name.singularize.underscore %>_params
|
36
|
-
# Permit any fields you want to save
|
37
|
-
params.require(:payload).permit(:name)
|
38
|
-
end
|
39
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module MobileWorkflow
|
2
|
-
module Generators
|
3
|
-
# Custom scaffolding generator
|
4
|
-
class ControllerGenerator < Rails::Generators::NamedBase
|
5
|
-
include Rails::Generators::ResourceHelpers
|
6
|
-
|
7
|
-
def self.source_root
|
8
|
-
Rails.root
|
9
|
-
end
|
10
|
-
|
11
|
-
def copy_controller_and_spec_files
|
12
|
-
template "lib/generators/mobile_workflow/templates/controller.rb", File.join("app/controllers", "#{controller_file_name}_controller.rb")
|
13
|
-
template "lib/generators/mobile_workflow/templates/controller_spec.rb", File.join("spec/controllers", "#{controller_file_name}_controller_spec.rb")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails_helper'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
RSpec.describe <%= controller_class_name %>Controller do
|
7
|
-
let(:params) { {} }
|
8
|
-
let(:json_response) { JSON.parse(response.body, symbolize_names: true) }
|
9
|
-
|
10
|
-
describe 'GET #index' do
|
11
|
-
let!(:<%= controller_class_name.singularize.underscore %>) { <%= controller_class_name.singularize %>.create }
|
12
|
-
before(:each) { get :index, params: params }
|
13
|
-
|
14
|
-
context 'ok' do
|
15
|
-
it { expect(json_response[0][:id]).to eq <%= controller_class_name.singularize.underscore %>.id }
|
16
|
-
it { expect(response.status).to eq 200 }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'GET #show' do
|
21
|
-
let(:<%= controller_class_name.singularize.underscore %>) { <%= controller_class_name.singularize %>.create }
|
22
|
-
let(:params) { { id: <%= controller_class_name.singularize.underscore %>.id } }
|
23
|
-
before(:each) { get :show, params: params }
|
24
|
-
|
25
|
-
context 'ok' do
|
26
|
-
it { expect(response.status).to eq 200 }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe 'POST #create' do
|
31
|
-
let(:payload_params) { {text: 'OK'} }
|
32
|
-
let(:params) { { payload: payload_params, binaries: [{identifier: 'record', mimetype: 'video/mp4'}] } }
|
33
|
-
before(:each) { post :create, params: params }
|
34
|
-
|
35
|
-
context 'ok' do
|
36
|
-
it { expect(<%= controller_class_name.singularize %>.count).to eq 1 }
|
37
|
-
it { expect(response.status).to eq 201 }
|
38
|
-
it { expect(json_response[:binary_urls]).to_not be_nil }
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/templates/model.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
<% module_namespacing do -%>
|
2
|
-
class <%= class_name %> < <%= parent_class_name.classify %>
|
3
|
-
# Enable if you need to generate attachment URLs
|
4
|
-
# include Rails.application.routes.url_helpers
|
5
|
-
|
6
|
-
<% attributes.select(&:reference?).each do |attribute| -%>
|
7
|
-
belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %>
|
8
|
-
<% end -%>
|
9
|
-
<% attributes.select(&:attachment?).each do |attribute| -%>
|
10
|
-
has_one_attached :<%= attribute.name %>
|
11
|
-
<% end -%>
|
12
|
-
<% attributes.select(&:attachments?).each do |attribute| -%>
|
13
|
-
has_many_attached :<%= attribute.name %>
|
14
|
-
<% end -%>
|
15
|
-
|
16
|
-
def list_item_as_json
|
17
|
-
{
|
18
|
-
id: id,
|
19
|
-
text: text,
|
20
|
-
# detailText: nil,
|
21
|
-
# sfSymbolName: nil,
|
22
|
-
# imageURL: preview_url(image, height: 100, width: 100)
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
def display_as_json
|
27
|
-
[
|
28
|
-
{label: "ID", text: text, mimeType: 'text/plain'},
|
29
|
-
{label: "Text", text: text, mimeType: 'text/plain'}
|
30
|
-
]
|
31
|
-
end
|
32
|
-
|
33
|
-
# private
|
34
|
-
# include Rails.application.routes.url_helpers # for attachment URLs
|
35
|
-
# def preview_url(attachment, height:, width:, options: { resize_to_fill: [height, width]} )
|
36
|
-
# return nil unless attachment.attached?
|
37
|
-
#
|
38
|
-
# if attachment.image?
|
39
|
-
# Rails.application.routes.url_helpers.rails_representation_url(attachment.variant(combine_options: options), host: attachment_host)
|
40
|
-
# elsif attachment.previewable?
|
41
|
-
# Rails.application.routes.url_helpers.rails_representation_url(attachment.preview(options), host: attachment_host)
|
42
|
-
# else
|
43
|
-
# return nil
|
44
|
-
# end
|
45
|
-
# end
|
46
|
-
#
|
47
|
-
# def attachment_url(attachment)
|
48
|
-
# Rails.application.routes.url_helpers.rails_blob_url(attachment, host: attachment_host)
|
49
|
-
# end
|
50
|
-
#
|
51
|
-
# def attachment_host
|
52
|
-
# "https://#{ENV['HEROKU_APP_NAME']}.herokuapp.com"
|
53
|
-
# end
|
54
|
-
|
55
|
-
end
|
56
|
-
<% end -%>
|
@@ -1,93 +0,0 @@
|
|
1
|
-
class NotificationsController < ApiController
|
2
|
-
before_action :verify_request_authenticity
|
3
|
-
|
4
|
-
def create
|
5
|
-
Rails.logger.info("Message body: #{message_body}")
|
6
|
-
|
7
|
-
case message_body['Type']
|
8
|
-
when 'SubscriptionConfirmation'
|
9
|
-
confirm_subscription ? (head :ok) : (head :bad_request)
|
10
|
-
else
|
11
|
-
@object = find_object
|
12
|
-
@object.send("#{attribute_name}=",active_record_blob)
|
13
|
-
if @object.save
|
14
|
-
head :ok
|
15
|
-
else
|
16
|
-
Rails.logger.warn "Error saving object: #{@object} #{object.errors.full_messages}"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
def verify_request_authenticity
|
23
|
-
head :unauthorized if raw_post.blank?
|
24
|
-
|
25
|
-
#head :unauthorized if raw_post.blank? || !message_verifier.authentic?(raw_post) # Not working
|
26
|
-
end
|
27
|
-
|
28
|
-
def active_record_blob
|
29
|
-
s3_object = s3_bucket.object(object_key)
|
30
|
-
checksum_base64 = checksum_base64(object_key, s3_object)
|
31
|
-
ActiveStorage::Blob.create! key: s3_object.key, filename: s3_object.key, byte_size: s3_object.size, checksum: checksum_base64, content_type: s3_object.content_type
|
32
|
-
end
|
33
|
-
|
34
|
-
def checksum_base64(object_key, s3_object)
|
35
|
-
path = Tempfile.new(object_key).path
|
36
|
-
s3_object.download_file(path)
|
37
|
-
file = File.new(path)
|
38
|
-
Digest::MD5.file(file).base64digest
|
39
|
-
end
|
40
|
-
|
41
|
-
def find_object
|
42
|
-
object_class_name, object_id = key_identifiers
|
43
|
-
object_class_name.camelcase.constantize.find(object_id.to_i)
|
44
|
-
end
|
45
|
-
|
46
|
-
def attribute_name
|
47
|
-
key_identifiers[2]
|
48
|
-
end
|
49
|
-
|
50
|
-
def key_identifiers
|
51
|
-
object_class_name, object_id, attribute_name = object_key.split("/")
|
52
|
-
return object_class_name, object_id, attribute_name
|
53
|
-
end
|
54
|
-
|
55
|
-
def object_key
|
56
|
-
@object_key ||= message['Records'][0]['s3']['object']['key']
|
57
|
-
end
|
58
|
-
|
59
|
-
def message
|
60
|
-
message = JSON.parse(message_body['Message'])
|
61
|
-
end
|
62
|
-
|
63
|
-
def message_body
|
64
|
-
@message_body ||= JSON.parse(raw_post)
|
65
|
-
end
|
66
|
-
|
67
|
-
def raw_post
|
68
|
-
@raw_post ||= request.raw_post
|
69
|
-
end
|
70
|
-
|
71
|
-
def message_verifier
|
72
|
-
@message_verifier ||= Aws::SNS::MessageVerifier.new
|
73
|
-
end
|
74
|
-
|
75
|
-
def confirm_subscription
|
76
|
-
sns_client.confirm_subscription(
|
77
|
-
topic_arn: message_body['TopicArn'],
|
78
|
-
token: message_body['Token']
|
79
|
-
)
|
80
|
-
return true
|
81
|
-
rescue Aws::SNS::Errors::ServiceError => e
|
82
|
-
Rails.logger.warn(e.message)
|
83
|
-
return false
|
84
|
-
end
|
85
|
-
|
86
|
-
def s3_bucket
|
87
|
-
Aws::S3::Resource.new(region: ENV['AWS_REGION'], access_key_id: ENV['AWS_ACCESS_ID'], secret_access_key: ENV['AWS_SECRET_KEY']).bucket(ENV['AWS_BUCKET_NAME'])
|
88
|
-
end
|
89
|
-
|
90
|
-
def sns_client
|
91
|
-
Aws::SNS::Client.new(region: ENV['AWS_REGION'], access_key_id: ENV['AWS_ACCESS_ID'], secret_access_key: ENV['AWS_SECRET_KEY'])
|
92
|
-
end
|
93
|
-
end
|