pixelforce_kit 0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +299 -0
  5. data/LICENSE +21 -0
  6. data/README.md +73 -0
  7. data/Rakefile +6 -0
  8. data/app/controllers/admin/api/admin_base_controller.rb +116 -0
  9. data/app/controllers/admin/api/app_versions_controller.rb +26 -0
  10. data/app/controllers/admin/api/available_modules_controller.rb +20 -0
  11. data/app/controllers/api/base_controller.rb +82 -0
  12. data/app/controllers/api/v1/health_check_controller.rb +12 -0
  13. data/app/controllers/application_controller.rb +10 -0
  14. data/app/controllers/auth/passwords_controller.rb +7 -0
  15. data/app/controllers/concerns/.keep +0 -0
  16. data/app/controllers/concerns/exception_handler.rb +57 -0
  17. data/app/controllers/concerns/request_header_handler.rb +35 -0
  18. data/app/controllers/concerns/response_handler.rb +51 -0
  19. data/app/controllers/concerns/search_params_parser.rb +35 -0
  20. data/app/controllers/pages_controller.rb +36 -0
  21. data/app/controllers/users_controller.rb +3 -0
  22. data/app/models/ahoy/event.rb +8 -0
  23. data/app/models/ahoy/visit.rb +6 -0
  24. data/app/models/application_record.rb +11 -0
  25. data/app/models/concerns/account_deletable.rb +26 -0
  26. data/app/models/concerns/assets_uploadable.rb +20 -0
  27. data/app/models/concerns/codenamable.rb +13 -0
  28. data/app/models/concerns/image_sizable.rb +58 -0
  29. data/app/models/concerns/isolationable.rb +18 -0
  30. data/app/models/concerns/searchable.rb +94 -0
  31. data/app/models/concerns/taggable.rb +57 -0
  32. data/app/models/tag.rb +13 -0
  33. data/app/models/tag_attachable.rb +6 -0
  34. data/app/models/tag_category.rb +5 -0
  35. data/bin/console +14 -0
  36. data/bin/setup +8 -0
  37. data/db/migrate/20220617021719_create_ahoy_visits_and_events.rb +67 -0
  38. data/db/migrate/20240828040425_create_tags.rb +12 -0
  39. data/db/migrate/20240828040646_create_tag_attachables.rb +9 -0
  40. data/db/migrate/20240912054241_create_tag_categories.rb +11 -0
  41. data/db/schema.rb +24 -0
  42. data/lib/pixelforce_kit/engine.rb +17 -0
  43. data/lib/pixelforce_kit/initializer/ahoy.rb +50 -0
  44. data/lib/pixelforce_kit/railtie.rb +4 -0
  45. data/lib/pixelforce_kit/recipes/capistrano_recipes/base.rb +4 -0
  46. data/lib/pixelforce_kit/recipes/capistrano_recipes/elbas.rb +10 -0
  47. data/lib/pixelforce_kit/recipes/capistrano_recipes/logrotate.rb +10 -0
  48. data/lib/pixelforce_kit/recipes/capistrano_recipes/puma.rb +46 -0
  49. data/lib/pixelforce_kit/recipes/capistrano_recipes/resque.rb +43 -0
  50. data/lib/pixelforce_kit/recipes/capistrano_recipes/resque_scheduler.rb +43 -0
  51. data/lib/pixelforce_kit/recipes/capistrano_recipes/sidekiq.rb +88 -0
  52. data/lib/pixelforce_kit/recipes/capistrano_recipes/supervisor.rb +9 -0
  53. data/lib/pixelforce_kit/recipes/capistrano_recipes/unicorn.rb +58 -0
  54. data/lib/pixelforce_kit/recipes/templates/logrotate.erb +10 -0
  55. data/lib/pixelforce_kit/recipes/templates/nginx_config.erb +32 -0
  56. data/lib/pixelforce_kit/recipes/templates/nginx_puma_config.erb +43 -0
  57. data/lib/pixelforce_kit/recipes/templates/puma.rb.erb +34 -0
  58. data/lib/pixelforce_kit/recipes/templates/puma_systemd.erb +19 -0
  59. data/lib/pixelforce_kit/recipes/templates/resque_init.erb +49 -0
  60. data/lib/pixelforce_kit/recipes/templates/resque_scheduler_init.erb +49 -0
  61. data/lib/pixelforce_kit/recipes/templates/resque_scheduler_supervisor.erb +13 -0
  62. data/lib/pixelforce_kit/recipes/templates/resque_supervisor.erb +13 -0
  63. data/lib/pixelforce_kit/recipes/templates/sidekiq_init.erb +49 -0
  64. data/lib/pixelforce_kit/recipes/templates/sidekiq_supervisor.erb +12 -0
  65. data/lib/pixelforce_kit/recipes/templates/sidekiq_systemd.erb +17 -0
  66. data/lib/pixelforce_kit/recipes/templates/supervisor.erb +19 -0
  67. data/lib/pixelforce_kit/recipes/templates/unicorn_init.erb +55 -0
  68. data/lib/pixelforce_kit/recipes/templates/unicorn_supervisor.erb +13 -0
  69. data/lib/pixelforce_kit/recipes.rb +4 -0
  70. data/lib/pixelforce_kit/spec_helper.rb +120 -0
  71. data/lib/pixelforce_kit/version.rb +3 -0
  72. data/lib/pixelforce_kit.rb +8 -0
  73. data/pixelforce_kit.gemspec +33 -0
  74. metadata +269 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9eb1ebeb58e607f988a36ba20788d1ac6bbfee708f7e73b720118ada30e8b63c
4
+ data.tar.gz: 3c8ae485b66fecb9adba79cc32138e3405950964211877c50af53171b0e4e472
5
+ SHA512:
6
+ metadata.gz: a620fe8c8ed32557b758d1ae6650ae106dfc4d244dd683adda8183ab52bec458d8c5406ffb41c567bcce34b7013c3e5e6df3d387f55891e7ee68179791d91d11
7
+ data.tar.gz: a14632e7c4d665f82dafcdd3c812ca6e2d891fda01488ada1635dcefd9efdb87d7e243c0fa048dc2ebd599d53799a9aec2d4a4697e13d9d699ebc8439af276a6
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /pkg
2
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pixelforce_kit.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,299 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pixelforce_kit (0.9)
5
+ ahoy_matey
6
+ capistrano (> 3.0.0)
7
+ devise
8
+ devise_token_auth
9
+ elbas
10
+ jbuilder
11
+ kaminari
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ actioncable (7.1.5)
17
+ actionpack (= 7.1.5)
18
+ activesupport (= 7.1.5)
19
+ nio4r (~> 2.0)
20
+ websocket-driver (>= 0.6.1)
21
+ zeitwerk (~> 2.6)
22
+ actionmailbox (7.1.5)
23
+ actionpack (= 7.1.5)
24
+ activejob (= 7.1.5)
25
+ activerecord (= 7.1.5)
26
+ activestorage (= 7.1.5)
27
+ activesupport (= 7.1.5)
28
+ mail (>= 2.7.1)
29
+ net-imap
30
+ net-pop
31
+ net-smtp
32
+ actionmailer (7.1.5)
33
+ actionpack (= 7.1.5)
34
+ actionview (= 7.1.5)
35
+ activejob (= 7.1.5)
36
+ activesupport (= 7.1.5)
37
+ mail (~> 2.5, >= 2.5.4)
38
+ net-imap
39
+ net-pop
40
+ net-smtp
41
+ rails-dom-testing (~> 2.2)
42
+ actionpack (7.1.5)
43
+ actionview (= 7.1.5)
44
+ activesupport (= 7.1.5)
45
+ nokogiri (>= 1.8.5)
46
+ racc
47
+ rack (>= 2.2.4)
48
+ rack-session (>= 1.0.1)
49
+ rack-test (>= 0.6.3)
50
+ rails-dom-testing (~> 2.2)
51
+ rails-html-sanitizer (~> 1.6)
52
+ actiontext (7.1.5)
53
+ actionpack (= 7.1.5)
54
+ activerecord (= 7.1.5)
55
+ activestorage (= 7.1.5)
56
+ activesupport (= 7.1.5)
57
+ globalid (>= 0.6.0)
58
+ nokogiri (>= 1.8.5)
59
+ actionview (7.1.5)
60
+ activesupport (= 7.1.5)
61
+ builder (~> 3.1)
62
+ erubi (~> 1.11)
63
+ rails-dom-testing (~> 2.2)
64
+ rails-html-sanitizer (~> 1.6)
65
+ activejob (7.1.5)
66
+ activesupport (= 7.1.5)
67
+ globalid (>= 0.3.6)
68
+ activemodel (7.1.5)
69
+ activesupport (= 7.1.5)
70
+ activerecord (7.1.5)
71
+ activemodel (= 7.1.5)
72
+ activesupport (= 7.1.5)
73
+ timeout (>= 0.4.0)
74
+ activestorage (7.1.5)
75
+ actionpack (= 7.1.5)
76
+ activejob (= 7.1.5)
77
+ activerecord (= 7.1.5)
78
+ activesupport (= 7.1.5)
79
+ marcel (~> 1.0)
80
+ activesupport (7.1.5)
81
+ base64
82
+ benchmark (>= 0.3)
83
+ bigdecimal
84
+ concurrent-ruby (~> 1.0, >= 1.0.2)
85
+ connection_pool (>= 2.2.5)
86
+ drb
87
+ i18n (>= 1.6, < 2)
88
+ logger (>= 1.4.2)
89
+ minitest (>= 5.1)
90
+ mutex_m
91
+ securerandom (>= 0.3)
92
+ tzinfo (~> 2.0)
93
+ ahoy_matey (5.2.1)
94
+ activesupport (>= 6.1)
95
+ device_detector (>= 1)
96
+ safely_block (>= 0.4)
97
+ airbrussh (1.5.3)
98
+ sshkit (>= 1.6.1, != 1.7.0)
99
+ aws-eventstream (1.3.0)
100
+ aws-partitions (1.999.0)
101
+ aws-sdk-autoscaling (1.123.0)
102
+ aws-sdk-core (~> 3, >= 3.210.0)
103
+ aws-sigv4 (~> 1.5)
104
+ aws-sdk-core (3.211.0)
105
+ aws-eventstream (~> 1, >= 1.3.0)
106
+ aws-partitions (~> 1, >= 1.992.0)
107
+ aws-sigv4 (~> 1.9)
108
+ jmespath (~> 1, >= 1.6.1)
109
+ aws-sdk-ec2 (1.486.0)
110
+ aws-sdk-core (~> 3, >= 3.210.0)
111
+ aws-sigv4 (~> 1.5)
112
+ aws-sigv4 (1.10.1)
113
+ aws-eventstream (~> 1, >= 1.0.2)
114
+ base64 (0.2.0)
115
+ bcrypt (3.1.20)
116
+ benchmark (0.3.0)
117
+ bigdecimal (3.1.8)
118
+ builder (3.3.0)
119
+ capistrano (3.19.1)
120
+ airbrussh (>= 1.0.0)
121
+ i18n
122
+ rake (>= 10.0.0)
123
+ sshkit (>= 1.9.0)
124
+ concurrent-ruby (1.3.4)
125
+ connection_pool (2.4.1)
126
+ crass (1.0.6)
127
+ date (3.3.4)
128
+ device_detector (1.1.3)
129
+ devise (4.9.4)
130
+ bcrypt (~> 3.0)
131
+ orm_adapter (~> 0.1)
132
+ railties (>= 4.1.0)
133
+ responders
134
+ warden (~> 1.2.3)
135
+ devise_token_auth (1.2.4)
136
+ bcrypt (~> 3.0)
137
+ devise (> 3.5.2, < 5)
138
+ rails (>= 4.2.0, < 7.3)
139
+ diff-lcs (1.2.5)
140
+ drb (2.2.1)
141
+ elbas (3.0.4)
142
+ aws-sdk-autoscaling (~> 1)
143
+ aws-sdk-ec2 (~> 1)
144
+ capistrano (> 3)
145
+ erubi (1.13.0)
146
+ faker (3.4.2)
147
+ i18n (>= 1.8.11, < 2)
148
+ globalid (1.2.1)
149
+ activesupport (>= 6.1)
150
+ i18n (1.14.6)
151
+ concurrent-ruby (~> 1.0)
152
+ io-console (0.7.2)
153
+ irb (1.14.1)
154
+ rdoc (>= 4.0.0)
155
+ reline (>= 0.4.2)
156
+ jbuilder (2.13.0)
157
+ actionview (>= 5.0.0)
158
+ activesupport (>= 5.0.0)
159
+ jmespath (1.6.2)
160
+ kaminari (1.2.2)
161
+ activesupport (>= 4.1.0)
162
+ kaminari-actionview (= 1.2.2)
163
+ kaminari-activerecord (= 1.2.2)
164
+ kaminari-core (= 1.2.2)
165
+ kaminari-actionview (1.2.2)
166
+ actionview
167
+ kaminari-core (= 1.2.2)
168
+ kaminari-activerecord (1.2.2)
169
+ activerecord
170
+ kaminari-core (= 1.2.2)
171
+ kaminari-core (1.2.2)
172
+ logger (1.6.1)
173
+ loofah (2.23.1)
174
+ crass (~> 1.0.2)
175
+ nokogiri (>= 1.12.0)
176
+ mail (2.8.1)
177
+ mini_mime (>= 0.1.1)
178
+ net-imap
179
+ net-pop
180
+ net-smtp
181
+ marcel (1.0.4)
182
+ mini_mime (1.1.5)
183
+ mini_portile2 (2.8.7)
184
+ minitest (5.25.1)
185
+ mutex_m (0.2.0)
186
+ net-imap (0.4.17)
187
+ date
188
+ net-protocol
189
+ net-pop (0.1.2)
190
+ net-protocol
191
+ net-protocol (0.2.2)
192
+ timeout
193
+ net-scp (4.0.0)
194
+ net-ssh (>= 2.6.5, < 8.0.0)
195
+ net-sftp (4.0.0)
196
+ net-ssh (>= 5.0.0, < 8.0.0)
197
+ net-smtp (0.5.0)
198
+ net-protocol
199
+ net-ssh (7.3.0)
200
+ nio4r (2.7.4)
201
+ nokogiri (1.16.7)
202
+ mini_portile2 (~> 2.8.2)
203
+ racc (~> 1.4)
204
+ orm_adapter (0.5.0)
205
+ ostruct (0.6.0)
206
+ psych (5.1.2)
207
+ stringio
208
+ racc (1.8.1)
209
+ rack (3.1.8)
210
+ rack-session (2.0.0)
211
+ rack (>= 3.0.0)
212
+ rack-test (2.1.0)
213
+ rack (>= 1.3)
214
+ rackup (2.1.0)
215
+ rack (>= 3)
216
+ webrick (~> 1.8)
217
+ rails (7.1.5)
218
+ actioncable (= 7.1.5)
219
+ actionmailbox (= 7.1.5)
220
+ actionmailer (= 7.1.5)
221
+ actionpack (= 7.1.5)
222
+ actiontext (= 7.1.5)
223
+ actionview (= 7.1.5)
224
+ activejob (= 7.1.5)
225
+ activemodel (= 7.1.5)
226
+ activerecord (= 7.1.5)
227
+ activestorage (= 7.1.5)
228
+ activesupport (= 7.1.5)
229
+ bundler (>= 1.15.0)
230
+ railties (= 7.1.5)
231
+ rails-dom-testing (2.2.0)
232
+ activesupport (>= 5.0.0)
233
+ minitest
234
+ nokogiri (>= 1.6)
235
+ rails-html-sanitizer (1.6.0)
236
+ loofah (~> 2.21)
237
+ nokogiri (~> 1.14)
238
+ railties (7.1.5)
239
+ actionpack (= 7.1.5)
240
+ activesupport (= 7.1.5)
241
+ irb
242
+ rackup (>= 1.0.0)
243
+ rake (>= 12.2)
244
+ thor (~> 1.0, >= 1.2.2)
245
+ zeitwerk (~> 2.6)
246
+ rake (13.0.1)
247
+ rdoc (6.7.0)
248
+ psych (>= 4.0.0)
249
+ reline (0.5.10)
250
+ io-console (~> 0.5)
251
+ responders (3.1.1)
252
+ actionpack (>= 5.2)
253
+ railties (>= 5.2)
254
+ rspec (3.5.0)
255
+ rspec-core (~> 3.5.0)
256
+ rspec-expectations (~> 3.5.0)
257
+ rspec-mocks (~> 3.5.0)
258
+ rspec-core (3.5.2)
259
+ rspec-support (~> 3.5.0)
260
+ rspec-expectations (3.5.0)
261
+ diff-lcs (>= 1.2.0, < 2.0)
262
+ rspec-support (~> 3.5.0)
263
+ rspec-mocks (3.5.0)
264
+ diff-lcs (>= 1.2.0, < 2.0)
265
+ rspec-support (~> 3.5.0)
266
+ rspec-support (3.5.0)
267
+ safely_block (0.4.1)
268
+ securerandom (0.3.1)
269
+ sshkit (1.23.2)
270
+ base64
271
+ net-scp (>= 1.1.2)
272
+ net-sftp (>= 2.1.2)
273
+ net-ssh (>= 2.8.0)
274
+ ostruct
275
+ stringio (3.1.1)
276
+ thor (1.3.2)
277
+ timeout (0.4.1)
278
+ tzinfo (2.0.6)
279
+ concurrent-ruby (~> 1.0)
280
+ warden (1.2.9)
281
+ rack (>= 2.0.9)
282
+ webrick (1.8.2)
283
+ websocket-driver (0.7.6)
284
+ websocket-extensions (>= 0.1.0)
285
+ websocket-extensions (0.1.5)
286
+ zeitwerk (2.6.18)
287
+
288
+ PLATFORMS
289
+ ruby
290
+
291
+ DEPENDENCIES
292
+ bundler (~> 2.1)
293
+ faker
294
+ pixelforce_kit!
295
+ rake (~> 13.0)
296
+ rspec (~> 3.0)
297
+
298
+ BUNDLED WITH
299
+ 2.2.33
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 BenZhang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # Pixelforce Kit
2
+
3
+ Pixelforce Kit implements
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pixelforce_kit'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pixelforce_kit
20
+
21
+ ## Usage
22
+ add below code to deploy.rb
23
+ ```ruby
24
+ require 'pixelforce_kit'
25
+ ```
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pixelforce_kit. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## supervisor support
38
+
39
+ The recipes for capistrano3 with supervisor support.
40
+ Please use `process:supervisor:task` to invoke it.
41
+ They relied on some capistrano plugins for some variables
42
+
43
+ * [**rvm**](https://github.com/capistrano/rvm) for `rvm_ruby_version`
44
+
45
+ Tweak some option for supervisor, the following value is default
46
+
47
+ ```ruby
48
+ set :autostart, 'true'
49
+ set :autorestart, 'true'
50
+ set :logfile_maxbytes, '1GB'
51
+ set :logfile_backups, '10'
52
+ ```
53
+
54
+ #### unicorn
55
+
56
+ Relied on unicornherder for supervisor monitoring.
57
+
58
+ #### puma
59
+
60
+ Get rid of capistrano-puma, and now generate puma config itself.
61
+
62
+ ```ruby
63
+ set :puma_threads, [0, 1]
64
+ set :puma_workers, 2
65
+ ```
66
+
67
+ ## sysvinit support
68
+
69
+ Please use `process:sysvinit:task` to invoke it.
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,116 @@
1
+ require 'csv'
2
+
3
+ module Admin
4
+ module Api
5
+ class AdminBaseController < ApplicationController
6
+ include DeviseTokenAuth::Concerns::SetUserByToken
7
+ include ResponseHandler
8
+ include RequestHeaderHandler
9
+ include ExceptionHandler
10
+
11
+ layout false
12
+
13
+ before_action :authenticate_admin_user!
14
+ before_action :format_params
15
+ before_action :prepare_pagination_params
16
+ after_action :track_admin_request
17
+
18
+ def authenticate_admin_user!
19
+ authenticate_admin_api_admin_user!
20
+ end
21
+
22
+ def current_admin_user
23
+ current_admin_api_admin_user
24
+ end
25
+
26
+ def log_target
27
+ @log_target
28
+ end
29
+
30
+ def admin_action_on_user_id
31
+ @admin_action_on_user_id = if log_target.present?
32
+ if log_target.is_a?(User)
33
+ log_target.id
34
+ else
35
+ log_target.user_id
36
+ end
37
+ end
38
+ end
39
+
40
+ def render_error(status, message, errors = nil, source: nil, meta: {})
41
+ super(status, message, errors, source: source, meta: meta, admin_server_error: true)
42
+ end
43
+
44
+ private
45
+
46
+ def track_admin_request
47
+ unless params[:action] == 'index' || params[:action] == 'show'
48
+ ahoy.track 'AdminLog', {
49
+ params: request.filtered_parameters,
50
+ url: request.original_url,
51
+ response: response.status
52
+ }
53
+ end
54
+ end
55
+
56
+ def set_response_format
57
+ if request.format.to_s != 'text/csv'
58
+ request.format = :json
59
+ self.content_type = 'application/json'
60
+ end
61
+ end
62
+
63
+ def pagination_headers(collection, item_name)
64
+ headers['Content-Range'] = "#{item_name} #{collection.offset_value}-#{collection.offset_value + collection.limit_value - 1}/#{collection.total_count}"
65
+ headers['Access-Control-Expose-Headers'] = 'Content-Range'
66
+ end
67
+
68
+ def pagination_headers_for_dropdown(item_name)
69
+ headers['Content-Range'] = "#{item_name} 0-999/1000"
70
+ headers['Access-Control-Expose-Headers'] = 'Content-Range'
71
+ end
72
+
73
+ def default_per_page
74
+ 10
75
+ end
76
+
77
+ def keywords
78
+ keyword = params[:filter].try(:[], :keyword)
79
+ if keyword.present?
80
+ @keywords = keyword.split(/,| */).reject(&:blank?).map { |value| "%#{value.strip}%" }
81
+ else
82
+ []
83
+ end
84
+ end
85
+
86
+ def export_resource_csv(resources, headers)
87
+ resources = resources.except(:limit, :offset)
88
+ table_name = resources.table_name
89
+ csv_data = CSV.generate(headers: true) do |csv|
90
+ csv << headers.map(&:titleize)
91
+ resources.find_each do |resource|
92
+ csv << headers.map { |header| resource.send(header.parameterize.to_sym) }
93
+ end
94
+ end
95
+ send_data csv_data, filename: "#{table_name}-#{Date.today}.csv"
96
+ end
97
+
98
+ def prepare_pagination_params
99
+ if params[:range].present? && params[:range].is_a?(Array) && params[:range].length == 2
100
+ beginning_offset = params[:range][0].to_i
101
+ end_offset = params[:range][1].to_i
102
+ per_page = end_offset - beginning_offset + 1
103
+ params[:perPage] = per_page
104
+ params[:page] = (beginning_offset / per_page) + 1
105
+ end
106
+ end
107
+
108
+ def format_params
109
+ if request.method_symbol == :get
110
+ params[:filter] = ActionController::Parameters.new(JSON.parse(params[:filter])) if params[:filter].present? && params[:filter].is_a?(String)
111
+ params[:range] = JSON.parse(params[:range]) if params[:range].present? && params[:range].is_a?(String)
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,26 @@
1
+ module Admin
2
+ module Api
3
+ class AppVersionsController < Admin::Api::AdminBaseController
4
+ def show
5
+ app_version = AppVersion.last
6
+ app_version ||= AppVersion.create!
7
+ render json: app_version.as_json(only: %i[id ios_minimum_version_number android_minimum_version_number])
8
+ end
9
+
10
+ def update
11
+ app_version = AppVersion.find(params[:id])
12
+ if app_version.update(app_version_params)
13
+ render json: app_version.as_json(only: %i[id ios_minimum_version_number android_minimum_version_number])
14
+ else
15
+ render_error(400, nil, app_version.errors)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def app_version_params
22
+ params.permit(:ios_minimum_version_number, :android_minimum_version_number)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ module Admin
2
+ module Api
3
+ class AvailableModulesController < AdminBaseController
4
+ def index
5
+ render json: [
6
+ {
7
+ "id": 1,
8
+ "name": 'Dashboard',
9
+ "path": '/dashboard'
10
+ },
11
+ {
12
+ "id": 2,
13
+ "name": 'Users',
14
+ "path": '/users'
15
+ }
16
+ ]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,82 @@
1
+ module Api
2
+ class BaseController < ApplicationController
3
+ include DeviseTokenAuth::Concerns::SetUserByToken
4
+ include ResponseHandler
5
+ include RequestHeaderHandler
6
+ include ExceptionHandler
7
+
8
+ protect_from_forgery with: :null_session
9
+
10
+ before_action :authenticate_user!
11
+ before_action :minimum_version_check!
12
+ before_action :set_user_timezone
13
+ before_action :create_user_devices!
14
+
15
+ after_action :track_request
16
+
17
+ def render_authenticate_error
18
+ return render json: {
19
+ errors: {
20
+ server: [I18n.t('devise.failure.unauthenticated')]
21
+ }
22
+ }, status: 401
23
+ end
24
+
25
+ private
26
+
27
+ def create_user_devices!
28
+ if current_user.present? && device_headers[:device_token].present?
29
+ user_device = UserDevice.find_or_initialize_by(device_token: device_headers[:device_token])
30
+
31
+ if user_device.persisted? && user_device.user_id != current_user.id
32
+ user_device.destroy!
33
+ user_device = UserDevice.new(device_token: device_headers[:device_token])
34
+ end
35
+
36
+ user_device.user_id = current_user.id
37
+ user_device.app_version = device_headers[:app_version]
38
+ user_device.platform = device_headers[:platform]
39
+ user_device.device_model = device_headers[:device_model]
40
+ user_device.os_version = device_headers[:os_version]
41
+ user_device.app_build_version = device_headers[:app_build_version]
42
+ user_device.save!
43
+ end
44
+ end
45
+
46
+ def set_user_timezone
47
+ if user_timezone && current_user && current_user.timezone != user_timezone
48
+ current_user.update(timezone: user_timezone)
49
+ end
50
+ end
51
+
52
+ def user_timezone
53
+ @user_timezone ||= device_headers[:user_timezone]
54
+ end
55
+
56
+ def minimum_version_check!
57
+ app_version = device_headers[:app_version]
58
+ platform = device_headers[:platform]
59
+
60
+ if app_version.present? && platform.present?
61
+ current_app_version = AppVersion.order(id: :desc).first
62
+
63
+ if current_app_version.present?
64
+ minimum_version = current_app_version.minimum_version(platform)
65
+
66
+ if minimum_version.present? && Gem::Version.new(app_version) < Gem::Version.new(minimum_version)
67
+ render_error(426, I18n.t('api.errors.upgrade_app_version'))
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ def track_request
74
+ api_version = request.path.split('/')[2]
75
+ ahoy.track "ApiRequest::#{api_version}", {
76
+ params: request.filtered_parameters,
77
+ url: request.original_url,
78
+ response: response.status
79
+ }
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,12 @@
1
+ module Api
2
+ module V1
3
+ class HealthCheckController < Api::BaseController
4
+ skip_after_action :track_request
5
+ skip_before_action :authenticate_user!
6
+
7
+ def index
8
+ render_success
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :null_session
3
+ skip_before_action :verify_authenticity_token, if: :json_request?
4
+
5
+ private
6
+
7
+ def json_request?
8
+ request.format.json?
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ class Auth::PasswordsController < Devise::PasswordsController
2
+ protected
3
+
4
+ def after_resetting_password_path_for(_resource)
5
+ reset_password_success_path
6
+ end
7
+ end
File without changes